/* 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, k; /* Open 'MLS-Aura_L3DM-Temperature_v02-21-c01_2006d020.he5' using grid API */ if ((gridfile1 = HE5_GDopen("MLS-Aura_L3DM-Temperature_v02-21-c01_2006d020.he5", H5F_ACC_RDONLY)) == -1) { fprintf(stderr, "error: cannot open grid 'MLS-Aura_L3DM-Temperature_v02-21-c01_2006d020.he5'\n"); return -1; } /* Open a grid named 'Temperature' */ if ((grid1 = HE5_GDattach(gridfile1, "Temperature")) == -1) { fprintf(stderr, "error: cannot attach to 'Temperature'\n"); return -1; } /* Retrieve information about 'L3dmValue' datafield */ if ((HE5_GDfieldinfo(grid1, "L3dmValue", &datafield1rank, datafield1dimsize, &datafield1type, datafield1dimname, datafield1maxdimname)) == -1) { fprintf(stderr, "error: cannot get the field info for 'L3dmValue'\n"); return -1; } /* Allocate buffer for 'L3dmValue' */ if ((datafield1data = malloc(sizeof(float) * 32 * 83 * 90)) == NULL) { fprintf(stderr, "error: cannot allocate memory for 'L3dmValue'\n"); return -1; } /* Read data from 'L3dmValue' */ if ((HE5_GDreadfield(grid1, "L3dmValue", NULL, NULL, NULL, datafield1data)) == -1) { fprintf(stderr, "error: cannot read field 'L3dmValue'\n"); return -1; } /* Dump data from 'L3dmValue' */ for (i = 0; i < 3; ++i) { for (j = 0; j < 8; ++j) { for (k = 0; k < 9; ++k) { printf("%f ", datafield1data[k + 90 * (j + 83 * i)]); } printf("\n"); } printf("\n"); } /* Release the buffer for 'L3dmValue' */ free(datafield1data); /* Close the grid named 'Temperature' */ if ((HE5_GDdetach(grid1)) == -1) { fprintf(stderr, "error: cannot detach from 'Temperature'\n"); return -1; } /* Close 'MLS-Aura_L3DM-Temperature_v02-21-c01_2006d020.he5' */ if ((HE5_GDclose(gridfile1)) == -1) { fprintf(stderr, "error: cannot close grid 'MLS-Aura_L3DM-Temperature_v02-21-c01_2006d020.he5'\n"); return -1; } return 0; }