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 HKT file.\n",
filename);
394 if (strstr(titleStr,
"pace oci level-1c")) {
399 printf(
"Input file %s is PACE OCI L1C file.\n",
filename);
405 if (strstr(titleStr,
"pace ocis level-1c")) {
410 printf(
"Input file %s is PACE OCIS L1C file.\n",
filename);
416 if (strstr(titleStr,
"pace harp2 level-1c")) {
421 printf(
"Input file %s is PACE HARP2 L1C file.\n",
filename);
427 if (strstr(titleStr,
"pace spexone level-1c")) {
432 printf(
"Input file %s is PACE SPEXone L1C file.\n",
filename);
438 if (strstr(titleStr,
"l1c ancillary file")) {
443 printf(
"Input file %s is L1C ancillary file.\n",
filename);
449 if (strstr(titleStr,
"spexone level-1b")) {
454 printf(
"Input file %s is PACE SPEXone file.\n",
filename);
461 if (strstr(titleStr,
"harp2 level-1b")) {
466 printf(
"Input file %s is PACE HARP2 file.\n",
filename);
474 if (strstr(titleStr,
"seawifs level-1a data")) {
478 char *dataTypeStr =
readAttrStr(ds_id,
"data_type");
480 if (strcmp(dataTypeStr,
"GAC") == 0) {
483 printf(
"Input file %s is SeaWiFS Level-1A GAC.\n",
filename);
489 printf(
"Input file %s is SeaWiFS Level-1A LAC.\n",
filename);
498 if (strstr(titleStr,
"octs level-1a gac data")) {
503 printf(
"Input file %s is OCTS Level-1A GAC netCDF.\n",
filename);
510 char *platformStr =
readAttrStr(ds_id,
"platform");
513 char *instrumentStr =
readAttrStr(ds_id,
"instrument");
515 char *processingLevelStr =
readAttrStr(ds_id,
"processing_level");
516 if (processingLevelStr) {
517 if (!strcmp(processingLevelStr,
"L1B")) {
519 }
else if (!strcmp(processingLevelStr,
"L2")) {
521 }
else if (!strcmp(processingLevelStr,
"L3 Binned")) {
523 }
else if (!strcmp(processingLevelStr,
"L3 Mapped")) {
530 printf(
"Input file %s is a NetCDF4 %s %s file.\n",
filename, instrumentStr, processingLevelStr);
532 free(processingLevelStr);
539 free(processingLevelStr);
555 sd_id = SDstart(
filename, DFACC_RDONLY);
562 if (SDreadattr(sd_id, SDfindattr(sd_id,
"Title"), (VOIDP)
title) == 0) {
563 if (strstr(
title,
"Level-3 Binned Data") !=
NULL) {
564 if (SDreadattr(sd_id, SDfindattr(sd_id,
"Sensor Name"), (VOIDP)
sensor) == 0) {
567 if (strcmp(
sensor,
"VIIRS") == 0) {
578 fprintf(
stderr,
"-E- %s Line %d: Unknown sensor name in Level-3 file %s\n", __FILE__, __LINE__,
filename);
582 fprintf(
stderr,
"-E- %s Line %d: No sensor name attribute in Level-3 file %s\n", __FILE__, __LINE__,
filename);
585 }
else if (strstr(
title,
"Level-2 Data") !=
NULL) {
586 if (SDreadattr(sd_id, SDfindattr(sd_id,
"Sensor Name"), (VOIDP)
sensor) == 0) {
594 fprintf(
stderr,
"-E- %s Line %d: Unknown sensor name in Level-2 file %s\n", __FILE__, __LINE__,
filename);
598 fprintf(
stderr,
"-E- %s Line %d: No sensor name attribute in Level-2 file %s\n", __FILE__, __LINE__,
filename);
601 }
else if (strcmp(
title,
"SeaWiFS Level-1A Data") == 0) {
604 if (SDreadattr(sd_id, SDfindattr(sd_id,
"Data Type"), (VOIDP) tempstr) == 0) {
605 if (strcmp(tempstr,
"GAC") == 0) {
608 printf(
"Input file %s is SeaWiFS Level-1A GAC.\n",
filename);
610 }
else if (strcmp(tempstr,
"LAC") == 0) {
613 printf(
"Input file %s is SeaWiFS Level-1A LAC.\n",
filename);
618 printf(
"Input file %s is assumed to be SeaWiFS Level-1A LAC.\n",
filename);
624 printf(
"Input file %s is assumed to be SeaWiFS Level-1A LAC.\n",
filename);
627 }
else if (strcmp(
title,
"OCTS Level-1A GAC Data") == 0) {
634 }
else if (strcmp(
title,
"OSMI Level-1A Data") == 0) {
641 }
else if (strcmp(
title,
"CZCS Level-1A Data") == 0) {
648 }
else if (strcmp(
title,
"OCM1 Level-1B (OBPG)") == 0) {
655 }
else if (strncmp(
title,
"OCM Level-1B", 12) == 0) {
662 }
else if (strcmp(
title,
"Oceansat OCM2 Level-1B Data") == 0) {
671 }
else if (strcmp(
title,
"SeaWiFS Level-1B") == 0) {
679 }
else if (strcmp(
title,
"MERIS Level-1B") == 0) {
686 }
else if (strcmp(
title,
"VIIRS Level-1B") == 0 || strcmp(
title,
"VIIRSN Level-1B") == 0) {
693 }
else if (strcmp(
title,
"VIIRSJ1 Level-1B") == 0) {
700 }
else if (strcmp(
title,
"VIIRSJ2 Level-1B") == 0) {
707 }
else if (strcmp(
title,
"OCM2 Level-1B") == 0) {
714 }
else if (strcmp(
title,
"OCTS Level-1B") == 0) {
721 }
else if (strcmp(
title,
"MOS Level-1B") == 0) {
728 }
else if (strcmp(
title,
"OCTS Level-1B LAC Data") == 0) {
735 }
else if (strcmp(
title,
"OSMI Level-1B") == 0) {
742 }
else if (strcmp(
title,
"HMODIST Level-1B") == 0 || strcmp(
title,
"MODIST Level-1B") == 0) {
748 printf(
"\n\n *** WARNING: polarization can not be computed from generic format ***\n\n");
750 }
else if (strcmp(
title,
"HMODISA Level-1B") == 0 || strcmp(
title,
"MODISA Level-1B") == 0) {
756 printf(
"\n\n *** WARNING: polarization can not be computed from generic format ***\n\n");
758 }
else if (strcmp(
title,
"CZCS Level-1B") == 0) {
766 }
else if (strstr(
title,
"Level-1 cross-calibration pixels") !=
NULL) {
767 if (SDreadattr(sd_id, SDfindattr(sd_id,
"sensorID"), (VOIDP) & (ret.
sensor_id)) != 0) {
768 fprintf(
stderr,
"-E- %s Line %d: Unrecognized sensor name, title %s in input HDF file %s\n", __FILE__, __LINE__,
title,
filename);
775 }
else if (strstr(
title,
"AVHRR") !=
NULL) {
783 fprintf(
stderr,
"-E- %s Line %d: Unrecognized title %s in input HDF file %s\n", __FILE__, __LINE__,
title,
filename);
787 }
else if (SDreadattr(sd_id, SDfindattr(sd_id,
"title"), (VOIDP)
title) == 0) {
798 }
else if (SDreadattr(sd_id, SDfindattr(sd_id,
"satellite"), (VOIDP)
title) == 0) {
800 if (strstr(
title,
"oceansat-1") !=
NULL) {
805 printf(
"Input file %s is %s.\n",
filename,
"OCM1 DB file");
811 }
else if (SDreadattr(sd_id, SDfindattr(sd_id,
"ArchiveMetadata.0"), (VOIDP) eosmeta) == 0) {
813 if (strstr(eosmeta,
"MODIS/Terra Calibrated Radiances 5-Min L1B Swath 1km") !=
NULL) {
819 printf(
"Input file %s is MODIS Terra Level-1B HDF-EOS product.\n",
filename);
822 }
else if (strstr(eosmeta,
"MODIS/Aqua Calibrated Radiances 5-Min L1B Swath 1km") !=
NULL) {
828 printf(
"Input file %s is MODIS Aqua Level-1B HDF-EOS product.\n",
filename);
831 }
else if (strstr(eosmeta,
"MODIS/Aqua Calibrated Radiances 5-Min L1B Swath 250m") !=
NULL) {
832 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);
834 }
else if (strstr(eosmeta,
"MODIS/Aqua Calibrated Radiances 5-Min L1B Swath 500m") !=
NULL) {
835 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);
837 }
else if (strstr(eosmeta,
"MODIS/Terra Calibrated Radiances 5-Min L1B Swath 250m") !=
NULL) {
838 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);
840 }
else if (strstr(eosmeta,
"MODIS/Terra Calibrated Radiances 5-Min L1B Swath 500m") !=
NULL) {
841 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);
843 }
else if (strstr(eosmeta,
"MODIS/Aqua Geolocation Fields") !=
NULL) {
848 printf(
"Input file %s is MODIS Aqua Geolocation Fields.\n",
filename);
850 }
else if (strstr(eosmeta,
"MODIS/Terra Geolocation Fields") !=
NULL) {
855 printf(
"Input file %s is MODIS Terra Geolocation Fields.\n",
filename);
858 fprintf(
stderr,
"-E- %s Line %d: Unrecognized HDF-EOS file %s\n", __FILE__, __LINE__,
filename);
863 }
else if ((SDfindattr(sd_id,
"Path_number") != -1) && (SDfindattr(sd_id,
"SOM_parameters.som_ellipsoid.a") != -1)) {
875 printf(
"Input file %s is MOS Level-1B standard product.\n",
filename);
878 fprintf(
stderr,
"-E- %s Line %d: Unrecognized input HDF file %s\n", __FILE__, __LINE__,
filename);
893 printf(
"Input file %s is a SeaBASS text file.\n",
filename);
909 printf(
"Input file %s is MERIS L1 file.\n",
filename);
921 printf(
"Input file %s is a Landsat 8/9 OLI L1B GEOTIFF file.\n",
filename);
927 char hdrfile[FILENAME_MAX], imgfile[FILENAME_MAX], navfile[FILENAME_MAX], gainfile[FILENAME_MAX];
930 printf(
"Input file %s is an AVIRIS file.\n",
filename);
938 printf(
"Input file %s is a PRISM file.\n",
filename);
946 printf(
"Input file %s is a Landsat 5 TM L1B GEOTIFF file.\n",
filename);
954 printf(
"Input file %s is a Landsat 7 TM L1B GEOTIFF file.\n",
filename);
980 const int lineSize = 500;
983 char line[lineSize + 1];
999 }
while (strlen(
line) == 0);
1002 if (strstr(
line,
"L1_METADATA_FILE") ==
NULL && strstr(
line,
"LANDSAT_METADATA_FILE") ==
NULL) {
1010 int foundSpacecraft = 0;
1011 int foundSensor = 0;
1014 for (
i = 0;
i < 60;
i++) {
1020 if (strstr(
line,
"SPACECRAFT_ID")) {
1021 if (strstr(
line,
"LANDSAT_8")) {
1022 foundSpacecraft = 1;
1025 else if (strstr(
line,
"LANDSAT_9")) {
1026 foundSpacecraft = 1;
1029 }
else if (strstr(
line,
"SENSOR_ID")) {
1030 if (strstr(
line,
"OLI")) {
1035 if (foundSpacecraft && foundSensor) {
1040 }
else if (isLandsat9) {
1069 const int lineSize = 500;
1072 char line[lineSize + 1];
1088 }
while (strlen(
line) == 0);
1091 if (strstr(
line,
"FILE_HEADER") ==
NULL) {
1099 int foundSpacecraft = 0;
1101 for (
i = 0;
i < 60;
i++) {
1108 if (strstr(
line,
"SATELLITE") || strstr(
line,
"SPACECRAFT_ID")) {
1109 if (strstr(
line,
"LANDSAT_8") || strstr(
line,
"LANDSAT_9")) {
1110 foundSpacecraft = 1;
1112 }
else if (strstr(
line,
"BAND_LIST")) {
1116 if (foundSpacecraft && foundBand) {
1137 const int lineSize = 500;
1139 char line[lineSize + 1];
1159 }
while (strlen(
line) == 0);
1162 if (strstr(
line,
"ENVI") ==
NULL) {
1185 const int lineSize = 500;
1188 char line[lineSize + 1];
1212 }
while (strlen(
line) == 0);
1215 if (strstr(
line,
"ENVI") ==
NULL) {
1222 int foundAviris = 0;
1223 int foundFormat = 0;
1225 for (
i = 0;
i < 20;
i++) {
1232 if (strstr(
line,
"AVIRIS")) {
1235 if (strstr(
line,
"orthocorrected")) {
1238 if (strstr(
line,
"interleave")) {
1242 if (foundAviris && foundFormat && foundOrtho) {
1269 const int lineSize = 500;
1272 char line[lineSize + 1];
1288 }
while (strlen(
line) == 0);
1291 if (strstr(
line,
"L1_METADATA_FILE") ==
NULL) {
1299 int foundSpacecraft = 0;
1300 int foundSensor = 0;
1301 for (
i = 0;
i < 20;
i++) {
1308 if (strstr(
line,
"SPACECRAFT_ID")) {
1309 if (strstr(
line,
"LANDSAT_5")) {
1310 foundSpacecraft = 1;
1312 }
else if (strstr(
line,
"SENSOR_ID")){
1313 if (strstr(
line,
"TM")) {
1318 if (foundSpacecraft && foundSensor) {
1345 const int lineSize = 500;
1348 char line[lineSize + 1];
1364 }
while (strlen(
line) == 0);
1367 if (strstr(
line,
"FILE_HEADER") ==
NULL) {
1375 int foundSpacecraft = 0;
1377 for (
i = 0;
i < 20;
i++) {
1384 if (strstr(
line,
"SATELLITE")) {
1385 if (strstr(
line,
"LANDSAT_5")) {
1386 foundSpacecraft = 1;
1388 }
else if (strstr(
line,
"BAND_LIST")) {
1392 if (foundSpacecraft && foundBand) {
1418 const int lineSize = 500;
1421 char line[lineSize + 1];
1437 }
while (strlen(
line) == 0);
1440 if (strstr(
line,
"L1_METADATA_FILE") ==
NULL) {
1448 int foundSpacecraft = 0;
1449 int foundSensor = 0;
1450 for (
i = 0;
i < 20;
i++) {
1457 if (strstr(
line,
"SPACECRAFT_ID")) {
1458 if (strstr(
line,
"LANDSAT_7")) {
1459 foundSpacecraft = 1;
1461 }
else if (strstr(
line,
"SENSOR_ID")){
1462 if (strstr(
line,
"ETM")) {
1467 if (foundSpacecraft && foundSensor) {
1492 fprintf(
stderr,
"-E- : input file %s does not exist or is read protected.\n",
filename);
1498 fgets(buffer, 2048-1, fp);
1499 if (strncmp(buffer,
"/begin_header", 13) == 0) {
1518 fgets(buffer, 2048-1, fp);
1519 if (strncmp(buffer,
"/end_header", 13) == 0) {
1521 }
else if (strncmp(buffer,
"/sensor=", 8) == 0) {
1522 for (
int i=8;
i<64;
i++){
1523 if (buffer[
i] ==
'\n'){