/* This example shows how to read a data field in HDF-EOS5 grid data. */ #include #include #include int main(int argc, char **argv) { hid_t gridfile1; hid_t grid1; int datafield1rank; hsize_t datafield1dimsize[32]; hid_t datafield1type; char datafield1dimname[512]; char datafield1maxdimname[512]; float *datafield1data; hsize_t i, j; /* Open 'TES-Aura_L3-CH4_r0000002135_F01_05.he5' using grid API */ if ((gridfile1 = HE5_GDopen("TES-Aura_L3-CH4_r0000002135_F01_05.he5", H5F_ACC_RDONLY)) == -1) { fprintf(stderr, "error: cannot open grid 'TES-Aura_L3-CH4_r0000002135_F01_05.he5'\n"); return -1; } /* Open a grid named 'NadirGrid' */ if ((grid1 = HE5_GDattach(gridfile1, "NadirGrid")) == -1) { fprintf(stderr, "error: cannot attach to 'NadirGrid'\n"); return -1; } /* Retrieve information about 'CH4AtSurface' datafield */ if ((HE5_GDfieldinfo(grid1, "CH4AtSurface", &datafield1rank, datafield1dimsize, &datafield1type, datafield1dimname, datafield1maxdimname)) == -1) { fprintf(stderr, "error: cannot get the field info for 'CH4AtSurface'\n"); return -1; } /* Allocate buffer for 'CH4AtSurface' */ if ((datafield1data = malloc(sizeof(float) * 90 * 83)) == NULL) { fprintf(stderr, "error: cannot allocate memory for 'CH4AtSurface'\n"); return -1; } /* Read data from 'CH4AtSurface' */ if ((HE5_GDreadfield(grid1, "CH4AtSurface", NULL, NULL, NULL, datafield1data)) == -1) { fprintf(stderr, "error: cannot read field 'CH4AtSurface'\n"); return -1; } /* Dump data from 'CH4AtSurface' */ for (i = 0; i < 9; ++i) { for (j = 0; j < 8; ++j) { printf("%f ", datafield1data[j + 83 * i]); } printf("\n"); } /* Release the buffer for 'CH4AtSurface' */ free(datafield1data); /* Close the grid named 'NadirGrid' */ if ((HE5_GDdetach(grid1)) == -1) { fprintf(stderr, "error: cannot detach from 'NadirGrid'\n"); return -1; } /* Close 'TES-Aura_L3-CH4_r0000002135_F01_05.he5' */ if ((HE5_GDclose(gridfile1)) == -1) { fprintf(stderr, "error: cannot close grid 'TES-Aura_L3-CH4_r0000002135_F01_05.he5'\n"); return -1; } return 0; }