/* 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; /* Open 'TES-Aura_L2-ANCILLARY_r0000005209_F04_04.he5' using swath API */ if ((swathfile1 = HE5_SWopen("TES-Aura_L2-ANCILLARY_r0000005209_F04_04.he5", H5F_ACC_RDONLY)) == -1) { fprintf(stderr, "error: cannot open swath 'TES-Aura_L2-ANCILLARY_r0000005209_F04_04.he5'\n"); return -1; } /* Open a swath named 'AncillaryNadirSwath' */ if ((swath1 = HE5_SWattach(swathfile1, "AncillaryNadirSwath")) == -1) { fprintf(stderr, "error: cannot attach to 'AncillaryNadirSwath'\n"); return -1; } /* Retrieve information about 'TropopausePressure' datafield */ if ((HE5_SWfieldinfo(swath1, "TropopausePressure", &datafield1rank, datafield1dimsize, &datafield1type, datafield1dimname, datafield1maxdimname)) == -1) { fprintf(stderr, "error: cannot get the field info for 'TropopausePressure'\n"); return -1; } /* Allocate buffer for 'TropopausePressure' */ if ((datafield1data = malloc(sizeof(float) * 3275)) == NULL) { fprintf(stderr, "error: cannot allocate memory for 'TropopausePressure'\n"); return -1; } /* Read data from 'TropopausePressure' */ if ((HE5_SWreadfield(swath1, "TropopausePressure", NULL, NULL, NULL, datafield1data)) == -1) { fprintf(stderr, "error: cannot read field 'TropopausePressure'\n"); return -1; } /* Dump data from 'TropopausePressure' */ for (i = 0; i < 30; ++i) { printf("%f ", datafield1data[i]); } printf("\n"); /* Release the buffer for 'TropopausePressure' */ 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) * 3275)) == 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) * 3275)) == 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 'AncillaryNadirSwath' */ if ((HE5_SWdetach(swath1)) == -1) { fprintf(stderr, "error: cannot detach from 'AncillaryNadirSwath'\n"); return -1; } /* Close 'TES-Aura_L2-ANCILLARY_r0000005209_F04_04.he5' */ if ((HE5_SWclose(swathfile1)) == -1) { fprintf(stderr, "error: cannot close swath 'TES-Aura_L2-ANCILLARY_r0000005209_F04_04.he5'\n"); return -1; } return 0; }