Home > Back-end >  Read the HDF data questions
Read the HDF data questions

Time:10-16

# include "hdf5. H"

# define H5FILE_NAME "SDS. H5
"# define DATASETNAME "IntArray
"3/* # define NX_SUB hyperslab dimensions */
# define NY_SUB 4
7 # define NX/* the output buffer dimensions */
# define NY 7
# define NZ 3
# define RANK 2
# define RANK_OUT 3

Int
The main (void)
{
Hid_t file, the dataset;/* handles */
Hid_t datatype, dataspace;
Hid_t memspace.
H5T_class_t t_class;/* data type class */
H5T_order_t order;/* data order */
Size_t size;/*
* the size of the data element
* stored in the file
*/
Hsize_t dimsm [3]./* the memory space dimensions */
Hsize_t dims_out [2]. Dataset dimensions/* */
Herr_t status;

Int data_out (NX) [New York] [NZ];/* the output buffer */

Hsize_t count [2]./* the size of the hyperslab in the file */
Hsize_t offset [2]./* hyperslab offset in the file */
Hsize_t count_out [3]./* the size of the hyperslab in memory */
Hsize_t offset_out [3]./* hyperslab offset in the memory */
Int I, j, k, status_n, rank;

For (j=0; j {
For (I=0; i {
For (k=0; K & lt; NZ; K++)
Data_out [j] [I] [k]=0;
}
}

/*
* to Open the file and the dataset.
*/
The file=H5Fopen (H5FILE_NAME H5F_ACC_RDONLY, H5P_DEFAULT);
The dataset=H5Dopen2 (file, DATASETNAME H5P_DEFAULT);

/*
* Get the datatype and dataspace handles and then query
* the dataset class, order, size, rank and dimensions.
*/
Datatype=H5Dget_type (dataset);/* datatype handle */
T_class=H5Tget_class (datatype);
If (t_class==H5T_INTEGER) printf (" Data set from the INTEGER type \ n ");
The order=H5Tget_order (datatype);
If (order==H5T_ORDER_LE) printf (" Little endian order \ n ");

Size=H5Tget_size (datatype);
Printf (" the Data size is % d \ n ", (int) size);

Dataspace=H5Dget_space (dataset);/* dataspace handle */
Rank=H5Sget_simple_extent_ndims (dataspace);
Status_n=H5Sget_simple_extent_dims (dataspace, dims_out, NULL);
Rank printf (" % d, % dimensions lu lu x % \ n ", rank,
(unsigned long) (dims_out [0]), (unsigned long) (dims_out [1]));

/*
* Define hyperslab in the dataset.
*/
Offset [0]=1;
Offset [1]=2;
The count [0]=NX_SUB;
The count [1]=NY_SUB;
Status=H5Sselect_hyperslab (dataspace, H5S_SELECT_SET, offset, NULL,
The count, NULL);

/*
* Define the memory dataspace.
*/
Dimsm [0]=NX;
Dimsm [1]=NY;
Dimsm [2]=NZ;
Memspace=H5Screate_simple (RANK_OUT dimsm, NULL);

/*
* Define the memory hyperslab.
*/
Offset_out [0]=3;
Offset_out [1]=0;
Offset_out [2]=0;
Count_out [0]=NX_SUB;
Count_out [1]=NY_SUB;
Count_out [2]=1;
Status=H5Sselect_hyperslab (memspace, H5S_SELECT_SET offset_out, NULL,
Count_out, NULL);

/*
* Read the data from hyperslab in the file into the hyperslab in
* the memory and display.
*/
Status=H5Dread (dataset, H5T_NATIVE_INT memspace, dataspace,
H5P_DEFAULT data_out);
For (j=0; j For (I=0; i printf("\n");
}
/*
* 0 0 0 0 0 0 0
* 0 0 0 0 0 0 0
* 0 0 0 0 0 0 0
* 6, 3, 4, 5 0 0 0
* 4 5 6 7 0 0 0
* 5 6 7 8 0 0 0
* 0 0 0 0 0 0 0
*/

/*
* the Close/release resources.
*/
H5Tclose (datatype);
H5Dclose (dataset);
H5Sclose (dataspace);
H5Sclose (memspace);
H5Fclose (file);

return 0;
}
Why I run out, the result is a full 0? The great god can help interpret it?

CodePudding user response:

Great god didn't bother to look for such a long lu said person wife

CodePudding user response:

Also looking forward to the answer
  • Related