/* 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 'AIRS.2002.09.01.L3.RetQuant_H030.v5.0.14.0.G07191213218.hdf' using grid API */ if ((gridfile1 = GDopen("AIRS.2002.09.01.L3.RetQuant_H030.v5.0.14.0.G07191213218.hdf", DFACC_RDONLY)) == -1) { fprintf(stderr, "error: cannot open grid 'AIRS.2002.09.01.L3.RetQuant_H030.v5.0.14.0.G07191213218.hdf'\n"); return -1; } /* Open a grid named 'L3Quant' */ if ((grid1 = GDattach(gridfile1, "L3Quant")) == -1) { fprintf(stderr, "error: cannot attach to 'L3Quant'\n"); return -1; } /* Retrieve information about 'Entropy' datafield */ if ((GDfieldinfo(grid1, "Entropy", &datafield1rank, datafield1dimsize, &datafield1type, datafield1dimname)) == -1) { fprintf(stderr, "error: cannot get the field info for 'Entropy'\n"); return -1; } /* Allocate buffer for 'Entropy' */ if ((datafield1data = malloc(sizeof(float32) * 200 * 36 * 72)) == NULL) { fprintf(stderr, "error: cannot allocate memory for 'Entropy'\n"); return -1; } /* Read data from 'Entropy' */ if ((GDreadfield(grid1, "Entropy", NULL, NULL, NULL, datafield1data)) == -1) { fprintf(stderr, "error: cannot read field 'Entropy'\n"); return -1; } /* Dump data from 'Entropy' */ for (i = 0; i < 3; ++i) { for (j = 0; j < 4; ++j) { for (k = 0; k < 5; ++k) { printf("%f ", datafield1data[k + 72 * (j + 36 * i)]); } printf("\n"); } printf("\n"); } /* Release the buffer for 'Entropy' */ free(datafield1data); /* Close the grid named 'L3Quant' */ if ((GDdetach(grid1)) == -1) { fprintf(stderr, "error: cannot detach from 'L3Quant'\n"); return -1; } /* Close 'AIRS.2002.09.01.L3.RetQuant_H030.v5.0.14.0.G07191213218.hdf' */ if ((GDclose(gridfile1)) == -1) { fprintf(stderr, "error: cannot close grid 'AIRS.2002.09.01.L3.RetQuant_H030.v5.0.14.0.G07191213218.hdf'\n"); return -1; } return 0; }