Hi Sahar,
On Mar 17, 2011, at 4:04 PM, sghanavati wrote:
> Hi,
>
> I am trying to read a 2 dimensional array of an unknown size from an h5file.
> The first dimension size is also read from the h5 file, the second dimension
> size is known and equal to 3. So I wrote the following code:
>
> In header I declare:
> struct h5_output_type {
> unsigned long dimension;
> float **centres;
> float * radius;
> };
>
> In function I have:
>
> H5::H5File h5file = H5::H5File();
> h5file.openFile("h5filename.h5", H5F_ACC_RDWR );
> H5::DataSet dataset_centre = group.openDataSet( "centre");
> H5::DataSet dataset_radius = group.openDataSet( "radius");
> H5::DataSpace dataspace = dataset_centre.getSpace();
> int rank = dataspace.getSimpleExtentNdims();
> hsize_t dims_out[2];
> int ndims = dataspace.getSimpleExtentDims( dims_out, NULL);
> H5::DataSpace memspace( rank, dims_out );
>
> struct h5_output_type *h5_data = (struct h5_output_type*) malloc(
> sizeof(*h5_data) );
> h5_data->dimension = (unsigned long)(dims_out[0]);
> h5_data->centres = (float **) malloc( sizeof(float *) * (unsigned
> long)(dims_out[0]) );
> for (int i=0; i<(unsigned long)(dims_out[0]) ;i++){
> h5_data->centres[i] = (float *) malloc (3 * sizeof(float));
> }
> h5_data->radius = (float*) malloc( sizeof(float) * (unsigned
> long)(dims_out[0]) );
> dataset_centre.read(h5_data->centres,H5::PredType::NATIVE_FLOAT,memspace,
> dataspace);
> dataset_radius.read(h5_data->radius,H5::PredType::NATIVE_FLOAT,memspace_r,
> dataspace_r);
>
> then when I try to access any of h5_data->centres[i][j] data I get
> "Segmentation fault" wheras h5_data->radius[i] works fine. Is the problem
> lies in the buffer the H5::DataSet::read( H5std_string & strg ,...) first
> input which should be a buffer? Is so then how can I correct this error
> with the double pointer? I tried:
> dataset_centre.read(&h5_data->centres,H5::PredType::NATIVE_FLOAT,memspace,
> dataspace);
> with no luck.
>
> also in the struct can I initialize the float * radius to 0 when I didn't
> declare its dimension?
You are allocating multiple, non-contiguous, arrays for the rows in the
'centres' field. Either, you have to write each row individually, or you have
to allocate a single buffer to pass to the HDF5 library.
Quincey
> Thank you in advance,
> Sahar
>
>
> --
> View this message in context:
> http://hdf-forum.184993.n3.nabble.com/error-segmentation-fault-reading-from-h5-file-to-a-double-pointer-tp2695306p2695306.html
> Sent from the hdf-forum mailing list archive at Nabble.com.
>
> _______________________________________________
> Hdf-forum is for HDF software users discussion.
> [email protected]
> http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org