23 #define EOSMETALEN 32768
36 static int hdf5AttributeReadString(hid_t group_id,
const char*
name,
char*
val) {
39 hid_t attribute_id = H5Aopen(group_id,
name, H5P_DEFAULT);
40 if(attribute_id >= 0) {
41 hid_t atype = H5Aget_type(attribute_id);
42 H5T_class_t type_class = H5Tget_class(atype);
43 if (type_class == H5T_STRING) {
44 hid_t atype_mem = H5Tget_native_type(atype, H5T_DIR_ASCEND);
45 status = H5Aread(attribute_id, atype_mem,
val);
53 H5Aclose(attribute_id);
57 static int hdf5AttributeStartsWith(hid_t group_id,
const char*
name,
char*
val) {
59 if(hdf5AttributeReadString(group_id,
name, buf)) {
60 if(strncmp(buf,
val, strlen(
val)) == 0) {
70 hid_t file_id, group_id, group2_id;
75 void *old_client_data;
76 H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
79 H5Eset_auto(H5E_DEFAULT,
NULL,
NULL);
81 file_id = H5Fopen(
filename, H5F_ACC_RDONLY, H5P_DEFAULT);
85 if(hdf5AttributeReadString(file_id,
"Platform_Short_Name", buf)) {
86 group_id = H5Gopen2(file_id,
"Data_Products/VIIRS-M1-SDR", H5P_DEFAULT);
88 if(hdf5AttributeStartsWith(group_id,
"Instrument_Short_Name",
"VIIRS")) {
89 if(strstr(buf,
"NPP") || strstr(buf,
"NPOESS")) {
94 printf(
"Input file %s is a VIIRS NPP SDR L1B HDF 5 file.\n",
filename);
96 }
else if(strstr(buf,
"JPSS-1") || strstr(buf,
"J01")) {
101 printf(
"Input file %s is a VIIRS JPSS-1 SDR L1B HDF 5 file.\n",
filename);
103 }
else if(strstr(buf,
"JPSS-2") || strstr(buf,
"J02")) {
108 printf(
"Input file %s is a VIIRS JPSS-2 SDR L1B HDF 5 file.\n",
filename);
119 group_id = H5Gopen2(file_id,
"metadata/FGDC/Identification_Information/Platform_and_Instrument_Identification", H5P_DEFAULT);
121 if(hdf5AttributeStartsWith(group_id,
"Instrument_Short_Name",
"hico")) {
122 group2_id = H5Gopen2(file_id,
"metadata/FGDC/Identification_Information/Processing_Level", H5P_DEFAULT);
124 if(hdf5AttributeStartsWith(group2_id,
"Processing_Level_Identifier",
"Level-1B")) {
128 printf(
"Input file %s is a HICO L1B HDF 5 file.\n",
filename);
141 group_id = H5Gopen2(file_id,
"HDFEOS/POINTS/Scene Header", H5P_DEFAULT);
143 if(hdf5AttributeStartsWith(group_id,
"Scene Title",
"GOCI Level-1B Data")) {
147 printf(
"Input file %s is a GOCI L1B HDF 5 file.\n",
filename);
157 group_id = H5Gopen2(file_id,
"Global_attributes", H5P_DEFAULT);
159 if(hdf5AttributeStartsWith(group_id,
"Satellite",
"Global Change Observation Mission - Climate (GCOM-C)")) {
160 if(hdf5AttributeStartsWith(group_id,
"Sensor",
"Second-generation Global Imager (SGLI)")) {
161 if(hdf5AttributeStartsWith(group_id,
"Product_level",
"Level-1B")) {
162 if(hdf5AttributeStartsWith(group_id,
"Product_name",
"Top of atmosphere radiance (reflectance)")) {
166 printf(
"Input file %s is a SGLI L1B HDF 5 file.\n",
filename);
181 H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
197 char tempstr[32] =
"";
202 printf(
"-E- %s: Input file '%s' does not exist or cannot open.\n", __FILE__,
filename);
219 if (strstr(titleStr,
"viirs level-1a")) {
220 char *platformStr =
readAttrStr(ds_id,
"platform");
223 if (strstr(platformStr,
"suomi-npp")) {
228 printf(
"Input file %s is VIIRS NPP L1A NetCDF4.\n",
filename);
230 }
else if (strstr(platformStr,
"jpss-1")) {
235 printf(
"Input file %s is VIIRS JPSS-1 L1A NetCDF4.\n",
filename);
237 }
else if (strstr(platformStr,
"jpss-2")) {
242 printf(
"Input file %s is VIIRS JPSS-2 L1A NetCDF4.\n",
filename);
251 if (strstr(titleStr,
"viirs m-band")) {
252 if (strstr(titleStr,
"viirs m-band reflected solar band")) {
255 printf(
"Input file %s is VIIRS NPP L1B NetCDF4.\n",
filename);
257 }
else if (strstr(titleStr,
"viirs m-band geolocation data")) {
260 printf(
"Input file %s is VIIRS NPP GEO NetCDF4.\n",
filename);
263 char *platformStr =
readAttrStr(ds_id,
"platform");
266 if (strstr(platformStr,
"suomi-npp")) {
269 }
else if (strstr(platformStr,
"jpss-1")) {
272 }
else if (strstr(platformStr,
"jpss-2")) {
282 if (strstr(titleStr,
"meris l1b")) {
287 printf(
"Input file %s is MERIS CC file.\n",
filename);
293 if (strstr(titleStr,
"ocia level-1b")) {
298 printf(
"Input file %s is OCIA L1B file.\n",
filename);
304 if (strstr(titleStr,
"aviris level-1b")) {
309 printf(
"Input file %s is AVIRIS L1B NetCDF4 file.\n",
filename);
315 if (strstr(titleStr,
"olci level 1b product")) {
317 if (strstr(titleStr,
"geo coordinates")) {
324 char *productNameStr =
readAttrStr(ds_id,
"product_name");
325 if(!strncmp(productNameStr,
"S3A", 3)) {
329 printf(
"Input file %s is OLCI S3A %s file.\n",
filename, subtype);
331 free(productNameStr);
335 }
else if(!strncmp(productNameStr,
"S3B", 3)) {
339 printf(
"Input file %s is OLCI S3B %s file.\n",
filename, subtype);
341 free(productNameStr);
346 free(productNameStr);
348 if (strstr(titleStr,
"hawkeye level-1a")) {
353 printf(
"Input file %s is HAWKEYE L1A file.\n",
filename);
359 if (strstr(titleStr,
"oci level-1b")) {
364 printf(
"Input file %s is PACE L1B file.\n",
filename);
370 if (strstr(titleStr,
"ocis level-1b")) {
375 printf(
"Input file %s is PACE L1B Simulated file.\n",
filename);
382 if (strstr(titleStr,
"hkt level-1a") ||
383 strstr(titleStr,
"pace hkt data")) {
388 printf(
"Input file %s is PACE L1A HKT file.\n",
filename);
395 if (strstr(titleStr,
"spexone level-1b")) {
400 printf(
"Input file %s is PACE SPEXone file.\n",
filename);
407 if (strstr(titleStr,
"harp2 level-1b")) {
412 printf(
"Input file %s is PACE HARP2 file.\n",
filename);
419 char *platformStr =
readAttrStr(ds_id,
"platform");
421 char *instrumentStr =
readAttrStr(ds_id,
"instrument");
423 char *processingLevelStr =
readAttrStr(ds_id,
"processing_level");
424 if (processingLevelStr) {
425 if (!strcmp(processingLevelStr,
"L1B")) {
427 }
else if (!strcmp(processingLevelStr,
"L2")) {
429 }
else if (!strcmp(processingLevelStr,
"L3 Binned")) {
431 }
else if (!strcmp(processingLevelStr,
"L3 Mapped")) {
438 printf(
"Input file %s is a NetCDF4 %s %s file.\n",
filename, instrumentStr, processingLevelStr);
440 free(processingLevelStr);
447 free(processingLevelStr);
463 sd_id = SDstart(
filename, DFACC_RDONLY);
470 if (SDreadattr(sd_id, SDfindattr(sd_id,
"Title"), (VOIDP)
title) == 0) {
471 if (strstr(
title,
"Level-3 Binned Data") !=
NULL) {
472 if (SDreadattr(sd_id, SDfindattr(sd_id,
"Sensor Name"), (VOIDP)
sensor) == 0) {
475 if (strcmp(
sensor,
"VIIRS") == 0) {
486 fprintf(
stderr,
"-E- %s Line %d: Unknown sensor name in Level-3 file %s\n", __FILE__, __LINE__,
filename);
490 fprintf(
stderr,
"-E- %s Line %d: No sensor name attribute in Level-3 file %s\n", __FILE__, __LINE__,
filename);
493 }
else if (strstr(
title,
"Level-2 Data") !=
NULL) {
494 if (SDreadattr(sd_id, SDfindattr(sd_id,
"Sensor Name"), (VOIDP)
sensor) == 0) {
502 fprintf(
stderr,
"-E- %s Line %d: Unknown sensor name in Level-2 file %s\n", __FILE__, __LINE__,
filename);
506 fprintf(
stderr,
"-E- %s Line %d: No sensor name attribute in Level-2 file %s\n", __FILE__, __LINE__,
filename);
509 }
else if (strcmp(
title,
"SeaWiFS Level-1A Data") == 0) {
512 if (SDreadattr(sd_id, SDfindattr(sd_id,
"Data Type"), (VOIDP) tempstr) == 0) {
513 if (strcmp(tempstr,
"GAC") == 0) {
516 printf(
"Input file %s is SeaWiFS Level-1A GAC.\n",
filename);
518 }
else if (strcmp(tempstr,
"LAC") == 0) {
521 printf(
"Input file %s is SeaWiFS Level-1A LAC.\n",
filename);
526 printf(
"Input file %s is assumed to be SeaWiFS Level-1A LAC.\n",
filename);
532 printf(
"Input file %s is assumed to be SeaWiFS Level-1A LAC.\n",
filename);
535 }
else if (strcmp(
title,
"OCTS Level-1A GAC Data") == 0) {
542 }
else if (strcmp(
title,
"OSMI Level-1A Data") == 0) {
549 }
else if (strcmp(
title,
"CZCS Level-1A Data") == 0) {
556 }
else if (strcmp(
title,
"OCM1 Level-1B (OBPG)") == 0) {
563 }
else if (strncmp(
title,
"OCM Level-1B", 12) == 0) {
570 }
else if (strcmp(
title,
"Oceansat OCM2 Level-1B Data") == 0) {
579 }
else if (strcmp(
title,
"SeaWiFS Level-1B") == 0) {
587 }
else if (strcmp(
title,
"MERIS Level-1B") == 0) {
594 }
else if (strcmp(
title,
"VIIRS Level-1B") == 0 || strcmp(
title,
"VIIRSN Level-1B") == 0) {
601 }
else if (strcmp(
title,
"OCM2 Level-1B") == 0) {
608 }
else if (strcmp(
title,
"OCTS Level-1B") == 0) {
615 }
else if (strcmp(
title,
"MOS Level-1B") == 0) {
622 }
else if (strcmp(
title,
"OCTS Level-1B LAC Data") == 0) {
629 }
else if (strcmp(
title,
"OSMI Level-1B") == 0) {
636 }
else if (strcmp(
title,
"HMODIST Level-1B") == 0 || strcmp(
title,
"MODIST Level-1B") == 0) {
642 printf(
"\n\n *** WARNING: polarization can not be computed from generic format ***\n\n");
644 }
else if (strcmp(
title,
"HMODISA Level-1B") == 0 || strcmp(
title,
"MODISA Level-1B") == 0) {
650 printf(
"\n\n *** WARNING: polarization can not be computed from generic format ***\n\n");
652 }
else if (strcmp(
title,
"CZCS Level-1B") == 0) {
660 }
else if (strstr(
title,
"Level-1 cross-calibration pixels") !=
NULL) {
661 if (SDreadattr(sd_id, SDfindattr(sd_id,
"sensorID"), (VOIDP) & (ret.
sensor_id)) != 0) {
662 fprintf(
stderr,
"-E- %s Line %d: Unrecognized sensor name, title %s in input HDF file %s\n", __FILE__, __LINE__,
title,
filename);
669 }
else if (strstr(
title,
"AVHRR") !=
NULL) {
677 fprintf(
stderr,
"-E- %s Line %d: Unrecognized title %s in input HDF file %s\n", __FILE__, __LINE__,
title,
filename);
681 }
else if (SDreadattr(sd_id, SDfindattr(sd_id,
"title"), (VOIDP)
title) == 0) {
692 }
else if (SDreadattr(sd_id, SDfindattr(sd_id,
"satellite"), (VOIDP)
title) == 0) {
694 if (strstr(
title,
"oceansat-1") !=
NULL) {
699 printf(
"Input file %s is %s.\n",
filename,
"OCM1 DB file");
705 }
else if (SDreadattr(sd_id, SDfindattr(sd_id,
"ArchiveMetadata.0"), (VOIDP) eosmeta) == 0) {
707 if (strstr(eosmeta,
"MODIS/Terra Calibrated Radiances 5-Min L1B Swath 1km") !=
NULL) {
713 printf(
"Input file %s is MODIS Terra Level-1B HDF-EOS product.\n",
filename);
716 }
else if (strstr(eosmeta,
"MODIS/Aqua Calibrated Radiances 5-Min L1B Swath 1km") !=
NULL) {
722 printf(
"Input file %s is MODIS Aqua Level-1B HDF-EOS product.\n",
filename);
725 }
else if (strstr(eosmeta,
"MODIS/Aqua Calibrated Radiances 5-Min L1B Swath 250m") !=
NULL) {
726 printf(
"Input file %s is MODIS Aqua Level-1B HDF-EOS product at 250m Resolution.\nThis file is no longer accepted as input.\nPlease use the 1KM (LAC) file and set resolution=250\n",
filename);
728 }
else if (strstr(eosmeta,
"MODIS/Aqua Calibrated Radiances 5-Min L1B Swath 500m") !=
NULL) {
729 printf(
"Input file %s is MODIS Aqua Level-1B HDF-EOS product at 500m Resolution.\nThis file is no longer accepted as input.\nPlease use the 1KM (LAC) file and set resolution=500\n",
filename);
731 }
else if (strstr(eosmeta,
"MODIS/Terra Calibrated Radiances 5-Min L1B Swath 250m") !=
NULL) {
732 printf(
"Input file %s is MODIS Terra Level-1B HDF-EOS product at 250m Resolution.\nThis file is no longer accepted as input.\nPlease use the 1KM (LAC) file and set resolution=250\n",
filename);
734 }
else if (strstr(eosmeta,
"MODIS/Terra Calibrated Radiances 5-Min L1B Swath 500m") !=
NULL) {
735 printf(
"Input file %s is MODIS Terra Level-1B HDF-EOS product at 500m Resolution.\nThis file is no longer accepted as input.\nPlease use the 1KM (LAC) file and set resolution=500\n",
filename);
737 }
else if (strstr(eosmeta,
"MODIS/Aqua Geolocation Fields") !=
NULL) {
742 printf(
"Input file %s is MODIS Aqua Geolocation Fields.\n",
filename);
744 }
else if (strstr(eosmeta,
"MODIS/Terra Geolocation Fields") !=
NULL) {
749 printf(
"Input file %s is MODIS Terra Geolocation Fields.\n",
filename);
752 fprintf(
stderr,
"-E- %s Line %d: Unrecognized HDF-EOS file %s\n", __FILE__, __LINE__,
filename);
758 }
else if (SDreadattr(sd_id, SDfindattr(sd_id,
"ASSOCIATEDPLATFORMSHORTNAME"), (VOIDP) eosmeta) == 0) {
759 if (strstr(eosmeta,
"Aqua") !=
NULL) {
764 printf(
"Input file %s is MODIS Aqua Level-1B IMAPP product.\n",
filename);
766 }
else if (strstr(eosmeta,
"Terra") !=
NULL) {
771 printf(
"Input file %s is MODIS Terra Level-1B IMAPP product.\n",
filename);
774 fprintf(
stderr,
"-E- %s Line %d: Unrecognized IMAPP format %s\n", __FILE__, __LINE__,
filename);
779 }
else if ((SDfindattr(sd_id,
"Path_number") != -1) && (SDfindattr(sd_id,
"SOM_parameters.som_ellipsoid.a") != -1)) {
791 printf(
"Input file %s is MOS Level-1B standard product.\n",
filename);
794 fprintf(
stderr,
"-E- %s Line %d: Unrecognized input HDF file %s\n", __FILE__, __LINE__,
filename);
809 printf(
"Input file %s is a SeaBASS text file.\n",
filename);
825 printf(
"Input file %s is MERIS L1 file.\n",
filename);
837 printf(
"Input file %s is a Landsat 8/9 OLI L1B GEOTIFF file.\n",
filename);
843 char hdrfile[FILENAME_MAX], imgfile[FILENAME_MAX], navfile[FILENAME_MAX], gainfile[FILENAME_MAX];
846 printf(
"Input file %s is an AVIRIS file.\n",
filename);
854 printf(
"Input file %s is a PRISM file.\n",
filename);
862 printf(
"Input file %s is a Landsat 5 TM L1B GEOTIFF file.\n",
filename);
870 printf(
"Input file %s is a Landsat 7 TM L1B GEOTIFF file.\n",
filename);
896 const int lineSize = 500;
899 char line[lineSize + 1];
915 }
while (strlen(
line) == 0);
918 if (strstr(
line,
"L1_METADATA_FILE") ==
NULL && strstr(
line,
"LANDSAT_METADATA_FILE") ==
NULL) {
926 int foundSpacecraft = 0;
930 for (
i = 0;
i < 60;
i++) {
936 if (strstr(
line,
"SPACECRAFT_ID")) {
937 if (strstr(
line,
"LANDSAT_8")) {
941 else if (strstr(
line,
"LANDSAT_9")) {
945 }
else if (strstr(
line,
"SENSOR_ID")) {
946 if (strstr(
line,
"OLI")) {
951 if (foundSpacecraft && foundSensor) {
956 }
else if (isLandsat9) {
985 const int lineSize = 500;
988 char line[lineSize + 1];
1004 }
while (strlen(
line) == 0);
1007 if (strstr(
line,
"FILE_HEADER") ==
NULL) {
1015 int foundSpacecraft = 0;
1017 for (
i = 0;
i < 60;
i++) {
1024 if (strstr(
line,
"SATELLITE") || strstr(
line,
"SPACECRAFT_ID")) {
1025 if (strstr(
line,
"LANDSAT_8") || strstr(
line,
"LANDSAT_9")) {
1026 foundSpacecraft = 1;
1028 }
else if (strstr(
line,
"BAND_LIST")) {
1032 if (foundSpacecraft && foundBand) {
1053 const int lineSize = 500;
1055 char line[lineSize + 1];
1075 }
while (strlen(
line) == 0);
1078 if (strstr(
line,
"ENVI") ==
NULL) {
1101 const int lineSize = 500;
1104 char line[lineSize + 1];
1128 }
while (strlen(
line) == 0);
1131 if (strstr(
line,
"ENVI") ==
NULL) {
1138 int foundAviris = 0;
1139 int foundFormat = 0;
1141 for (
i = 0;
i < 20;
i++) {
1148 if (strstr(
line,
"AVIRIS")) {
1151 if (strstr(
line,
"orthocorrected")) {
1154 if (strstr(
line,
"interleave")) {
1158 if (foundAviris && foundFormat && foundOrtho) {
1185 const int lineSize = 500;
1188 char line[lineSize + 1];
1204 }
while (strlen(
line) == 0);
1207 if (strstr(
line,
"L1_METADATA_FILE") ==
NULL) {
1215 int foundSpacecraft = 0;
1216 int foundSensor = 0;
1217 for (
i = 0;
i < 20;
i++) {
1224 if (strstr(
line,
"SPACECRAFT_ID")) {
1225 if (strstr(
line,
"LANDSAT_5")) {
1226 foundSpacecraft = 1;
1228 }
else if (strstr(
line,
"SENSOR_ID")){
1229 if (strstr(
line,
"TM")) {
1234 if (foundSpacecraft && foundSensor) {
1261 const int lineSize = 500;
1264 char line[lineSize + 1];
1280 }
while (strlen(
line) == 0);
1283 if (strstr(
line,
"FILE_HEADER") ==
NULL) {
1291 int foundSpacecraft = 0;
1293 for (
i = 0;
i < 20;
i++) {
1300 if (strstr(
line,
"SATELLITE")) {
1301 if (strstr(
line,
"LANDSAT_5")) {
1302 foundSpacecraft = 1;
1304 }
else if (strstr(
line,
"BAND_LIST")) {
1308 if (foundSpacecraft && foundBand) {
1334 const int lineSize = 500;
1337 char line[lineSize + 1];
1353 }
while (strlen(
line) == 0);
1356 if (strstr(
line,
"L1_METADATA_FILE") ==
NULL) {
1364 int foundSpacecraft = 0;
1365 int foundSensor = 0;
1366 for (
i = 0;
i < 20;
i++) {
1373 if (strstr(
line,
"SPACECRAFT_ID")) {
1374 if (strstr(
line,
"LANDSAT_7")) {
1375 foundSpacecraft = 1;
1377 }
else if (strstr(
line,
"SENSOR_ID")){
1378 if (strstr(
line,
"ETM")) {
1383 if (foundSpacecraft && foundSensor) {
1408 fprintf(
stderr,
"-E- : input file %s does not exist or is read protected.\n",
filename);
1414 fgets(buffer, 2048-1, fp);
1415 if (strncmp(buffer,
"/begin_header", 13) == 0) {
1434 fgets(buffer, 2048-1, fp);
1435 if (strncmp(buffer,
"/end_header", 13) == 0) {
1437 }
else if (strncmp(buffer,
"/sensor=", 8) == 0) {
1438 for (
int i=8;
i<64;
i++){
1439 if (buffer[
i] ==
'\n'){