/* * This example opens an NPP example file and reads a dataset with region references * VIIRS-MOD_GTM-EDR-GEO_Gran_0 under the /Data_Products/VIIRS-MOD-GTM-EDR-GEO group. * Then it finds information about the selected elements pointed by the third reference * and reads the data in. * Main illustrative functions: H5LRget_region_info, H5LRread_region */ #include #include #include "hdf5.h" #include "hdf5_hl.h" #include "H5LTpublic.h" #include "h5hl_region.h" #define filename "GMGTO_npp_d20030125_t0657104_e0659047_b00014_c20090811150425926728_unkn_SCI.h5" #define dsetname "/Data_Products/VIIRS-MOD-GTM-EDR-GEO/VIIRS-MOD-GTM-EDR-GEO_Gran_0" /* dataset with region references */ int main(void) { hid_t file_id; /* file identifier */ hid_t dset_id; /* region reference dataset identifier */ hdset_reg_ref_t ref[15]; /* array to read region references */ herr_t status; hid_t dtype; /* file datatype handle */ hid_t mtype; /* mempry datatype handle */ size_t msize; /* size of memory datatype */ size_t rnumelem; /* number of elements to read */ char *rdata; /* pointer to read buffer */ int i; /* * Open the NPP file. */ file_id = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT); /* * Open dataset and read the dataset with the region references. * We made an assumption that the size of the dataset is known. */ dset_id = H5Dopen(file_id, dsetname, H5P_DEFAULT); status = H5Dread(dset_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT,ref); /* * Get datatype of the data the region reference points to. */ status = H5LRget_region_info(file_id, (const hdset_reg_ref_t*)ref[2], NULL, NULL, NULL, &dtype, NULL, NULL, NULL); /* * Find the corresponding type in memory and its size. */ mtype = H5Tget_native_type(dtype, H5T_DIR_ASCEND); msize = H5Tget_size(mtype); /* * Find number of elements in the region to read. */ status = H5LRread_region(file_id,(const hdset_reg_ref_t*)ref[2], mtype, &rnumelem, NULL); /* * Allocate buffer to read data in. */ rdata = (char *) malloc (rnumelem * msize); status = H5LRread_region(file_id,(const hdset_reg_ref_t*)ref[2], mtype, NULL, rdata); /* * We need to discover an appropriate C type to print data */ if ((H5T_FLOAT == H5Tget_class(mtype)) & (sizeof(float) == msize)) { float tmp; /* temporary variables */ char *tmp_p; printf(" Number of elements pointed by a region reference is %ld \n", rnumelem); printf(" The first six elements are: \n"); tmp_p = rdata; for (i=0; i<6; i++) { memcpy (&tmp, tmp_p, msize); printf(" %7.3f ", tmp); tmp_p = tmp_p + msize; } printf("\n"); } free(rdata); /* * Close dataset with region references and file. */ status = H5Dclose(dset_id); status = H5Fclose(file_id); return 0; }