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

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

The HDF Group
[email protected]
====================



From: Hdf-forum [mailto:[email protected]] 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
/* 
 *   Writing and reading an existing dataset.
 */

#include <hdf5.h>
#define FILE "dset.h5"

main() {

   hid_t       dataspace, memspace;
   hid_t       file_id, dataset_id;  /* identifiers */
   herr_t      status;
   hsize_t     dims[1], dimsm[1];
   int         i, j; 
   double      dset_data[10], rdset_data[5];
   hsize_t     count[1], stride[1], block[1];
   hssize_t    start[1];

   /* Initialize the dataset. */
   for (i = 0; i < 10; i++)
        dset_data[i] = 10*i;

   printf ("\nCreate file, 1D dataset. Write data. Close all.\n");

   file_id = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

   dims[0] = 10;
   dataspace = H5Screate_simple (1, dims, NULL);
   dataset_id = H5Dcreate (file_id, "/data1d", H5T_IEEE_F64LE, dataspace,
                           H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

   status = H5Dwrite (dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, 
                      H5P_DEFAULT, dset_data);
  
   status = H5Dclose (dataset_id);
   status = H5Sclose (dataspace);
   status = H5Fclose (file_id);
 

   printf ("Reopen file and read 5 elements.\n");

   file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
   dataset_id = H5Dopen (file_id, "/data1d", H5P_DEFAULT);
   dataspace = H5Dget_space (dataset_id);

   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);

   for (i=0; i<5; i++)
      printf (" %lf", rdset_data[i]);
   printf ("\n");

   /* Close all. */
   status = H5Dclose(dataset_id);
   status = H5Sclose (dataspace);
   status = H5Sclose (memspace);
   status = H5Fclose(file_id);
}
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org

Reply via email to