(cross posted http://stackoverflow.com/questions/24883461 )

Hi all,

I'm a newbie with HDF5.

I built a *5x4* table.

Each cell of the table contains *3* integers

I'm trying to write a function `setyx` that would update a cell of the table at y,x


I wrote the C code below but it raises some errors:

|   #000: H5Dio.c line 225 in H5Dwrite(): can't prepare for writing data
    major:  Dataset
    minor:  Write  failed
  #001: H5Dio.c line 347 in H5D__pre_write(): can't write data
    major:  Dataset
    minor:  Write  failed
  #002: H5Dio.c line 685 in H5D__write(): src and dest data spaces have 
different sizes
    major:  Invalid  arguments to routine
    minor:  Bad  value|

what is the correct way to update a given cell at |(y,x)| ?


/* -------------------------------------------------------------------------------------------------------------*/
include "hdf5.h"

/** set 3 'int' values at y/x */
static void setyx(hid_t dataset, hid_t dataspace,
                  int y,int x,
                  int i1,int i2,int i3)
    {
    int values[3]={i1,i2,i3};
    hsize_t  starts[3]={y,x,0};
    hsize_t  counts[3]={1,1,1};
    hsize_t  dims_memory[3]={1,1,3};

H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, starts, NULL, counts, NULL);
    hid_t filespace = H5Dget_space(dataset);
    hid_t  memspace  = H5Screate_simple(3, dims_memory, NULL);

    H5Dwrite(dataset,
        H5T_NATIVE_INT,
        memspace,
        filespace,
        H5P_DEFAULT,
        values);

     H5Sclose(memspace);
     H5Sclose(filespace);
    }


int main (void)
     {
     hid_t       file, dataset;
     hid_t       dataspace;
     hsize_t     dims[3]={5,4,3};


     file = H5Fcreate("test.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
     dataspace = H5Screate_simple(3, dims, NULL);
     dataset = H5Dcreate(file, "/test", H5T_NATIVE_INT, dataspace,
                        H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
     setyx(dataset,dataspace,2,1, 100,200,300);

     H5Sclose(dataspace);
     H5Dclose(dataset);
     H5Fclose(file);
     return 0;
    }
/* -------------------------------------------------------------------------------------------------------------*/

_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Reply via email to