/* This example shows how to read a data field in HDF-EOS2 grid data. */ #include #include #include #include #include int main(int argc, char **argv) { int32 gridfile1; int32 grid1; int32 datafield1rank; int32 datafield1dimsize[32]; int32 datafield1type; char datafield1dimname[512]; float32 *datafield1data; int32 i, j, k; /* Open 'MISR_AM1_CGAS_FIRSTLOOK_AUG_30_2007_F11_0027.hdf' using grid API */ if ((gridfile1 = GDopen("MISR_AM1_CGAS_FIRSTLOOK_AUG_30_2007_F11_0027.hdf", DFACC_RDONLY)) == -1) { fprintf(stderr, "error: cannot open grid 'MISR_AM1_CGAS_FIRSTLOOK_AUG_30_2007_F11_0027.hdf'\n"); return -1; } /* Open a grid named 'AerosolParameterAverage' */ if ((grid1 = GDattach(gridfile1, "AerosolParameterAverage")) == -1) { fprintf(stderr, "error: cannot attach to 'AerosolParameterAverage'\n"); return -1; } /* Retrieve information about 'Optical depth average' datafield */ if ((GDfieldinfo(grid1, "Optical depth average", &datafield1rank, datafield1dimsize, &datafield1type, datafield1dimname)) == -1) { fprintf(stderr, "error: cannot get the field info for 'Optical depth average'\n"); return -1; } /* Allocate buffer for 'Optical depth average' */ if ((datafield1data = malloc(sizeof(float32) * 360 * 720 * 4)) == NULL) { fprintf(stderr, "error: cannot allocate memory for 'Optical depth average'\n"); return -1; } /* Read data from 'Optical depth average' */ if ((GDreadfield(grid1, "Optical depth average", NULL, NULL, NULL, datafield1data)) == -1) { fprintf(stderr, "error: cannot read field 'Optical depth average'\n"); return -1; } /* Dump data from 'Optical depth average' */ for (i = 0; i < 36; ++i) { for (j = 0; j < 72; ++j) { for (k = 0; k < 1; ++k) { printf("%f ", datafield1data[k + 4 * (j + 720 * i)]); } printf("\n"); } printf("\n"); } /* Release the buffer for 'Optical depth average' */ free(datafield1data); /* Close the grid named 'AerosolParameterAverage' */ if ((GDdetach(grid1)) == -1) { fprintf(stderr, "error: cannot detach from 'AerosolParameterAverage'\n"); return -1; } /* Close 'MISR_AM1_CGAS_FIRSTLOOK_AUG_30_2007_F11_0027.hdf' */ if ((GDclose(gridfile1)) == -1) { fprintf(stderr, "error: cannot close grid 'MISR_AM1_CGAS_FIRSTLOOK_AUG_30_2007_F11_0027.hdf'\n"); return -1; } return 0; }