/* * This example copies a hyperslab region of 'SatelliteRange' under * '/All_Data/VIIRS-MOD-GTM-EDR-GEO_All/' to another hyperslab region * '/SatelliteRange_Subset' under '/All_Data'. It then reads back * the newly created hyperslab region. * Main illustrative functions: H5LTread_region, H5LTcopy_region */ #include #include "hdf5.h" #include "hdf5_hl.h" #include "h5hl_region.h" #define filename "GMGTO_npp_d20030125_t0657104_e0659047_b00014_c20090811150425926728_unkn_SCI.h5" #define PATH_DEST "/Data_Products/SatelliteRange_Subset" /* Full path of the source dataset */ #define PATH_SRC "/All_Data/VIIRS-MOD-GTM-EDR-GEO_All/SatelliteRange" /* Full path to the destination dataset */ #define NRANK 2 /* rank of source and destination dataset */ int main(void) { hid_t file_id; /* file identifier */ hid_t dset_id; /* dataset identifier */ hid_t space_id; /* dataspace identifier */ hsize_t block_coord_src[4] = {3, 51, 7, 53}; /* source's block coordinates (3,51)-(7,53) */ hsize_t block_coord_dest[4] = {1, 1, 5, 3 }; /* destination's block coordinates (1,1)-(5,3) */ hsize_t dims[NRANK] = {7,5}; /* receiving dataset dimensions */ float rdata[5][3]; /* buffer to read destination data into */ int i,j; herr_t status; /* * Open the NPP file. */ file_id = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT); /* * First create the destination dataset "SatelliteRange_Subset" since it does not exist. * * NOTE: If the destination dataset does not already exist then H5LTcopy_region * will automatically create a destination dataset that is the same size * and rank of the source data and will, additionally, fill the destination * block starting at (0,0); thus ignoring the destination's block coordinates. */ space_id = H5Screate_simple(NRANK, dims, NULL); dset_id = H5Dcreate2(file_id, PATH_DEST, H5T_NATIVE_FLOAT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); status = H5Sclose(space_id); status = H5Fclose(file_id); /* * Copy a block of the "/All_Data/VIIRS-MOD-GTM-EDR-GEO_All/SatelliteRange" * data with block corner coordinates of (3,51)-(7,53) to * a subset of the "/Data_Products/SatelliteRange_Subset" with hyperslab * coordinates (1,1)-(5,3). * */ status = H5LTcopy_region(filename, PATH_SRC, block_coord_src, filename, PATH_DEST, block_coord_dest); /* * * Reads a subset region of "/Data_Products/SatelliteRange_Subset" * specified by coordinates (1,1)-(5,3). * */ status = H5LTread_region(filename, PATH_DEST, block_coord_dest, H5T_NATIVE_FLOAT, rdata); printf("Subset of /Data_Products/SatelliteRange_Subset with coordinates "); printf("(%d,%d)-(%d,%d):\n",(int)block_coord_dest[0],(int)block_coord_dest[1], (int)block_coord_dest[2],(int)block_coord_dest[3]); for (i=0; i< 5; i++) { printf("\n [ "); for (j=0; j< 3; j++) { printf("%f ", rdata[i][j]); } printf("]"); } printf("\n"); return 0; }