Coding with java API to read partial data

Hello: When I am coding with java API,I meet a question. If I hava a one-dimensional array(eg:1,2,.....,10),now I want to read 3-7,how can I only use 5 size of space to read data. My way: H5.H5Sselect_hyperslab(dataspace_id, HDF5Constants.H5S_SELECT_SET,start, null, count, null); H5.H5Dread(dataset_id, HDF5Constants.H5T_IEEE_F64LE,HDF5Constants.H5S_ALL, filespace_id, HDF5Constants.H5P_DEFAULT,dset_data); But dset_data's size hava to be 10,or at least 7. So how can I use 5 space to read partial data? Thanks for help

Hello QiangLiu!

If I understand correctly, you would like to just read 5 elements in the 1D dataset, starting at the 3rd element.
In that case, you would:

- Specify a 1D memory space of 5 elements

- Select (a hyperslab) of 5 elements from the file data space

- Pass in the memory space and file data space to H5Dread. Your read buffer would be 5 elements in size.

In C, it would look like this:

   double rdset_data[5];
   ...
  start [0] = 2;
   count [0] = 5;
   stride [0] = 1;
   block[0] = 1;

   status = H5Sselect_hyperslab (dataspace, H5S_SELECT_SET, start, stride,
                                  count, NULL);

   dimsm[0] = 5;
   memspace = H5Screate_simple (1, dimsm, NULL);

   status = H5Dread (dataset_id, H5T_NATIVE_DOUBLE, memspace, dataspace,
                                       H5P_DEFAULT, rdset_data);

See the attached C program for more details.
Let me know if you have more questions!

-Barbara

qiang.c (1.85 KB)

···

====================
Barbara Jones
The HDF Helpdesk

The HDF Group
help@hdfgroup.org

From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of QiangLiu
Sent: Wednesday, October 16, 2013 8:18 AM
To: Hdf-forum
Subject: [Hdf-forum] Coding with java API to read partial data

Hello:

       When I am coding with java API,I meet a question.

        If I hava a one-dimensional array(eg:1,2,.....,10),now I want to read 3-7,how can I only use 5 size of space to read data.

        My way:

        H5.H5Sselect_hyperslab(dataspace_id, HDF5Constants.H5S_SELECT_SET,start, null, count, null);

        H5.H5Dread(dataset_id, HDF5Constants.H5T_IEEE_F64LE,HDF5Constants.H5S_ALL, filespace_id, HDF5Constants.H5P_DEFAULT,dset_data);

        But dset_data's size hava to be 10,or at least 7.

        So how can I use 5 space to read partial data?

        Thanks for help