/* * 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 "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 */ hsize_t dims[1] = {15}; /* size of the VIIRS-MOD_GTM-EDR-GEO_Gran_0 dataset */ hdset_reg_ref_t ref[15]; /* array to read region references */ hsize_t buf[4]; /* buffer to read hyperslab coordinates defining region references */ herr_t status; size_t name_length = {1024}; char name[1024]; hid_t dtype; size_t numelem; char type_string[15]; size_t type_string_length = {15}; hsize_t rdims[2]; float *rdata; size_t rnumelem; 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 region reference information such as a name of the dataset the region reference point to, * number of contiguous blocks in the selection (should be 1) and the hyperslab coordinates (0,0) - (770,4120) */ status = H5LRget_region_info(file_id, (const hdset_reg_ref_t*)ref[2], &name_length, name, NULL, &dtype, NULL, &numelem, buf); /* * Display the info */ H5LTdtype_to_text(dtype, type_string, H5LT_DDL, &type_string_length); printf(" Information retrieved by H5LRget_region_info: \n"); printf(" Third element of the array with the region references points to %s \n", name); printf(" Length of the string above is %d \n", (int)name_length); printf(" Region's datatype is %s \n", type_string); printf(" Number of blocks in the region is %d \n", (int)numelem); printf(" Block's coordinates are (%d,%d) - (%d,%d) \n", (int)buf[0],(int)buf[1],(int)buf[2],(int)buf[3]); printf("\n"); /* * We will read data to the floating-point buffer; using information provided by H5LRget_region_info * allocate the buffer to read data in. */ rdims[0] = buf[2] - buf[0] + 1; rdims[1] = buf[3] - buf[1] + 1; rdata = (float *) malloc (rdims[0] * rdims[1] * sizeof(float)); /* * Read data pointed by the third region reference into a buffer and display the first six elements. */ status = H5LRread_region(file_id,(const hdset_reg_ref_t*)ref[2], H5T_NATIVE_FLOAT, &rnumelem, rdata); printf(" Information retrieved by H5LRread_region: \n"); printf(" Number of elements pointed by a region reference is %ld \n", rnumelem); printf(" The first six elements are: \n"); for (i=0; i<6; i++) printf(" %7.3f ", rdata[i]); printf("\n"); free(rdata); /* * Close dataset with region references and file. */ status = H5Dclose(dset_id); status = H5Fclose(file_id); return 0; }