/* This example shows how to read a data field and two geo-location fields in HDF-EOS5 swath data. */ #include #include #include int main(int argc, char **argv) { hid_t swathfile1; hid_t swath1; int datafield1rank; hsize_t datafield1dimsize[32]; hid_t datafield1type; char datafield1dimname[512]; char datafield1maxdimname[512]; float *datafield1data; int geofield1rank; hsize_t geofield1dimsize[32]; hid_t geofield1type; char geofield1dimname[512]; char geofield1maxdimname[512]; float *geofield1data; int geofield2rank; hsize_t geofield2dimsize[32]; hid_t geofield2type; char geofield2dimname[512]; char geofield2maxdimname[512]; float *geofield2data; hsize_t i, j; /* Open 'HIRDLS-Aura_L2_v02-04-09-c03_2005d033.he5' using swath API */ if ((swathfile1 = HE5_SWopen("HIRDLS-Aura_L2_v02-04-09-c03_2005d033.he5", H5F_ACC_RDONLY)) == -1) { fprintf(stderr, "error: cannot open swath 'HIRDLS-Aura_L2_v02-04-09-c03_2005d033.he5'\n"); return -1; } /* Open a swath named 'HIRDLS' */ if ((swath1 = HE5_SWattach(swathfile1, "HIRDLS")) == -1) { fprintf(stderr, "error: cannot attach to 'HIRDLS'\n"); return -1; } /* Retrieve information about 'CloudTopPressure' datafield */ if ((HE5_SWfieldinfo(swath1, "CloudTopPressure", &datafield1rank, datafield1dimsize, &datafield1type, datafield1dimname, datafield1maxdimname)) == -1) { fprintf(stderr, "error: cannot get the field info for 'CloudTopPressure'\n"); return -1; } /* Allocate buffer for 'CloudTopPressure' */ if ((datafield1data = malloc(sizeof(float) * 4500 * 1)) == NULL) { fprintf(stderr, "error: cannot allocate memory for 'CloudTopPressure'\n"); return -1; } /* Read data from 'CloudTopPressure' */ if ((HE5_SWreadfield(swath1, "CloudTopPressure", NULL, NULL, NULL, datafield1data)) == -1) { fprintf(stderr, "error: cannot read field 'CloudTopPressure'\n"); return -1; } /* Dump data from 'CloudTopPressure' */ for (i = 0; i < 30; ++i) { for (j = 0; j < 1; ++j) { printf("%f ", datafield1data[j + 1 * i]); } printf("\n"); } /* Release the buffer for 'CloudTopPressure' */ free(datafield1data); /* Retrieve information about 'Longitude' geolocation field */ if ((HE5_SWfieldinfo(swath1, "Longitude", &geofield1rank, geofield1dimsize, &geofield1type, geofield1dimname, geofield1maxdimname)) == -1) { fprintf(stderr, "error: cannot get the field info for 'Longitude'\n"); return -1; } /* Allocate buffer for 'Longitude' */ if ((geofield1data = malloc(sizeof(float) * 4500)) == NULL) { fprintf(stderr, "error: cannot allocate memory for 'Longitude'\n"); return -1; } /* Read data from 'Longitude' */ if ((HE5_SWreadfield(swath1, "Longitude", NULL, NULL, NULL, geofield1data)) == -1) { fprintf(stderr, "error: cannot read field 'Longitude'\n"); return -1; } /* Dump data from 'Longitude' */ for (i = 0; i < 30; ++i) { printf("%f ", geofield1data[i]); } printf("\n"); /* Release the buffer for 'Longitude' */ free(geofield1data); /* Retrieve information about 'Latitude' geolocation field */ if ((HE5_SWfieldinfo(swath1, "Latitude", &geofield2rank, geofield2dimsize, &geofield2type, geofield2dimname, geofield2maxdimname)) == -1) { fprintf(stderr, "error: cannot get the field info for 'Latitude'\n"); return -1; } /* Allocate buffer for 'Latitude' */ if ((geofield2data = malloc(sizeof(float) * 4500)) == NULL) { fprintf(stderr, "error: cannot allocate memory for 'Latitude'\n"); return -1; } /* Read data from 'Latitude' */ if ((HE5_SWreadfield(swath1, "Latitude", NULL, NULL, NULL, geofield2data)) == -1) { fprintf(stderr, "error: cannot read field 'Latitude'\n"); return -1; } /* Dump data from 'Latitude' */ for (i = 0; i < 30; ++i) { printf("%f ", geofield2data[i]); } printf("\n"); /* Release the buffer for 'Latitude' */ free(geofield2data); /* Close the swath named 'HIRDLS' */ if ((HE5_SWdetach(swath1)) == -1) { fprintf(stderr, "error: cannot detach from 'HIRDLS'\n"); return -1; } /* Close 'HIRDLS-Aura_L2_v02-04-09-c03_2005d033.he5' */ if ((HE5_SWclose(swathfile1)) == -1) { fprintf(stderr, "error: cannot close swath 'HIRDLS-Aura_L2_v02-04-09-c03_2005d033.he5'\n"); return -1; } return 0; }