/* * This example opens a file, and extracts * the bit field from a subset of a dataset. * The values are returned as a base-10 integer. * Main illustrative function: H5LTread_bitfield_value */ #include #include "hdf5.h" #include "hdf5_hl.h" #include "h5hl_region.h" #define FILENAME "SVI01-GIMFG_NPP_d2003125_t101038_e10116_b9_c2005829153351_dev.h5" #define DATASET "/All_Data/VIIRS-I1-SDR_All/QF_VIIRSI1SDR_Array" #define num_flags 1 int main(void) { int qf_data[5][6][1]; /* Read buffer */ unsigned int offset[1] = {1}; /* Starting bits to be extracted from element */ unsigned int length[1] = {2}; /* Number of bits to be extracted for each value */ hid_t file, space; /* Handles */ hid_t qf_dset; herr_t status; hsize_t start[3] = {0,0,0}; hsize_t count[3] = {5,6,1}; int i, j; /* * Open file. */ file = H5Fopen (FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT); /* * Open the data set */ qf_dset = H5Dopen (file, DATASET, H5P_DEFAULT); /* * Get dataspace and allocate memory for read buffer. Quality flags dataset * has the same dimensionality as corresponding product dataset; * we are using its dimensions for illustration purposes only. */ space = H5Dget_space (qf_dset); status = H5Sselect_hyperslab(space, H5S_SELECT_SET, start, NULL, count, NULL); /* * For each element read the value that takes first two bits and * store it in a char buffer. This selects all the elements (H5S_ALL) */ status = H5LTread_bitfield_value(qf_dset, num_flags, offset, length, space, (int *)qf_data); status = H5Sclose (space); /* Print out the bit field */ printf("Bit Field:\n"); for (i = 0; i<5; i++) { printf (" ["); for (j = 0; j<6; j++) { printf(" %d ", qf_data[i][j][0]); } printf("]\n"); } return 0; }