Due to the lapse in federal government funding, NASA is not updating this website. We sincerely regret this inconvenience.
NASA Logo
Ocean Color Science Software

ocssw V2022
filetype.c
Go to the documentation of this file.
1 #include <netcdf.h>
2 #include <hdf.h>
3 #include <hdf5.h>
4 #include <libgen.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9 
10 #include <dfutils.h>
11 #include <genutils.h>
12 #include <sensorDefs.h>
13 #include <sensorInfo.h>
14 
15 #include <hdf.h>
16 #include <mfhdf.h>
17 
18 #include "aviris.h"
19 #include "epr_api.h"
20 
21 #include "filetype.h"
22 
23 #define EOSMETALEN 32768
24 
25 static file_format chk_oli(char *filename);
26 static file_format chk_l5tm(char *filename);
27 static file_format chk_l7etm(char *filename);
28 static file_format chk_aviris(char *filename, char *hdrfile, char *imgfile, char *navfile, char *gainfile);
29 static file_format chk_prism(char *filename);
30 static file_format chk_seabass(char *filename);
31 
32 // defined in filetypeXml.cpp
34 
35 
36 static int hdf5AttributeReadString(hid_t group_id, const char* name, char* val) {
37  int result = 0;
38  herr_t status;
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);
46  if(status >= 0) {
47  result = 1;
48  }
49  H5Tclose(atype_mem);
50  }
51  H5Tclose(atype);
52  }
53  H5Aclose(attribute_id);
54  return result;
55 }
56 
57 static int hdf5AttributeStartsWith(hid_t group_id, const char* name, char* val) {
58  char buf[1024];
59  if(hdf5AttributeReadString(group_id, name, buf)) {
60  if(strncmp(buf, val, strlen(val)) == 0) {
61  return 1;
62  }
63  }
64  return 0;
65 }
66 
67 
68 static file_format chk_hdf5(char *filename) {
69  file_format ret = {FT_INVALID, -1, -1};
70  hid_t file_id, group_id, group2_id;
71  char buf[1024];
72 
73  /* Save old error handler */
74  H5E_auto_t old_func;
75  void *old_client_data;
76  H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
77 
78  /* Turn off error handling */
79  H5Eset_auto(H5E_DEFAULT, NULL, NULL);
80 
81  file_id = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
82  if(file_id >= 0) {
83 
84  // check for VIIRS SDR
85  if(hdf5AttributeReadString(file_id, "Platform_Short_Name", buf)) {
86  group_id = H5Gopen2(file_id, "Data_Products/VIIRS-M1-SDR", H5P_DEFAULT);
87  if(group_id >= 0) {
88  if(hdf5AttributeStartsWith(group_id, "Instrument_Short_Name", "VIIRS")) {
89  if(strstr(buf, "NPP") || strstr(buf, "NPOESS")) {
90  ret.type = FT_VIIRSL1B;
91  ret.sensor_id = VIIRSN;
92  ret.subsensor_id = VIIRS_NPP;
93  if (want_verbose) {
94  printf("Input file %s is a VIIRS NPP SDR L1B HDF 5 file.\n", filename);
95  }
96  } else if(strstr(buf, "JPSS-1") || strstr(buf, "J01")) {
97  ret.type = FT_VIIRSL1B;
98  ret.sensor_id = VIIRSJ1;
99  ret.subsensor_id = VIIRS_J1;
100  if (want_verbose) {
101  printf("Input file %s is a VIIRS JPSS-1 SDR L1B HDF 5 file.\n", filename);
102  }
103  } else if(strstr(buf, "JPSS-2") || strstr(buf, "J02")) {
104  ret.type = FT_VIIRSL1B;
105  ret.sensor_id = VIIRSJ2;
106  ret.subsensor_id = VIIRS_J2;
107  if (want_verbose) {
108  printf("Input file %s is a VIIRS JPSS-2 SDR L1B HDF 5 file.\n", filename);
109  }
110  }
111  }
112  H5Gclose(group_id);
113  }
114  }
115 
116 
117  // check for HICO
118  if(ret.type == FT_INVALID) {
119  group_id = H5Gopen2(file_id, "metadata/FGDC/Identification_Information/Platform_and_Instrument_Identification", H5P_DEFAULT);
120  if(group_id >= 0) {
121  if(hdf5AttributeStartsWith(group_id, "Instrument_Short_Name", "hico")) {
122  group2_id = H5Gopen2(file_id, "metadata/FGDC/Identification_Information/Processing_Level", H5P_DEFAULT);
123  if(group2_id >= 0) {
124  if(hdf5AttributeStartsWith(group2_id, "Processing_Level_Identifier", "Level-1B")) {
125  ret.type = FT_HICOL1B;
126  ret.sensor_id = HICO;
127  if (want_verbose) {
128  printf("Input file %s is a HICO L1B HDF 5 file.\n", filename);
129  }
130  }
131  H5Gclose(group2_id);
132  }
133  }
134  H5Gclose(group_id);
135  }
136  }
137 
138 
139  // check for GOCI
140  if(ret.type == FT_INVALID) {
141  group_id = H5Gopen2(file_id, "HDFEOS/POINTS/Scene Header", H5P_DEFAULT);
142  if(group_id >= 0) {
143  if(hdf5AttributeStartsWith(group_id, "Scene Title", "GOCI Level-1B Data")) {
144  ret.type = FT_GOCIL1B;
145  ret.sensor_id = GOCI;
146  if (want_verbose) {
147  printf("Input file %s is a GOCI L1B HDF 5 file.\n", filename);
148  }
149  }
150  H5Gclose(group_id);
151  }
152  }
153 
154 
155  // check for SGLI
156  if(ret.type == FT_INVALID) {
157  group_id = H5Gopen2(file_id, "Global_attributes", H5P_DEFAULT);
158  if(group_id >= 0) {
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)")) {
163  ret.type = FT_SGLI;
164  ret.sensor_id = SGLI;
165  if (want_verbose) {
166  printf("Input file %s is a SGLI L1B HDF 5 file.\n", filename);
167  }
168  }
169  }
170  }
171  }
172  H5Gclose(group_id);
173  }
174  }
175 
176 
177  H5Fclose(file_id);
178  }
179 
180  /* Restore previous error handler */
181  H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
182 
183  return ret;
184 }
185 
186 
189  return ret.type;
190 }
191 
193  file_format ret = { FT_INVALID, -1, -1 };
194 
195  int32_t sd_id;
196  char eosmeta[EOSMETALEN] = "";
197  char tempstr[32] = "";
198  idDS ds_id;
199 
200  /* Does the file exist? */
201  if (access(filename, F_OK) || access(filename, R_OK)) {
202  printf("-E- %s: Input file '%s' does not exist or cannot open.\n", __FILE__, filename);
203  return ret;
204  }
205 
206  // need to do HDF5 files before trying NetCDF
207  if ((ret = chk_hdf5(filename)).type != FT_INVALID) {
208  return ret;
209  }
210 
211  /* Is it netCDF */
212  ds_id = openDS(filename);
213  if (ds_id.fid != FAIL) {
214  if (ds_id.fftype == DS_NCDF) {
215  char *titleStr = readAttrStr(ds_id, "title");
216 
217  if (titleStr) {
218  lowcase(titleStr);
219  if (strstr(titleStr, "viirs level-1a")) {
220  char *platformStr = readAttrStr(ds_id, "platform");
221  if (platformStr) {
222  lowcase(platformStr);
223  if (strstr(platformStr, "suomi-npp")) {
224  ret.type = FT_VIIRSL1A;
225  ret.sensor_id = VIIRSN;
226  ret.subsensor_id = VIIRS_NPP;
227  if (want_verbose) {
228  printf("Input file %s is VIIRS NPP L1A NetCDF4.\n", filename);
229  }
230  } else if (strstr(platformStr, "jpss-1")) {
231  ret.type = FT_VIIRSL1A;
232  ret.sensor_id = VIIRSJ1;
233  ret.subsensor_id = VIIRS_J1;
234  if (want_verbose) {
235  printf("Input file %s is VIIRS JPSS-1 L1A NetCDF4.\n", filename);
236  }
237  } else if (strstr(platformStr, "jpss-2")) {
238  ret.type = FT_VIIRSL1A;
239  ret.sensor_id = VIIRSJ2;
240  ret.subsensor_id = VIIRS_J2;
241  if (want_verbose) {
242  printf("Input file %s is VIIRS JPSS-2 L1A NetCDF4.\n", filename);
243  }
244  }
245  free(platformStr);
246  }
247  free(titleStr);
248  endDS(ds_id);
249  return ret;
250  }
251  if (strstr(titleStr, "viirs m-band")) {
252  if (strstr(titleStr, "viirs m-band reflected solar band")) {
253  ret.type = FT_VIIRSL1BNC;
254  if (want_verbose) {
255  printf("Input file %s is VIIRS NPP L1B NetCDF4.\n", filename);
256  }
257  } else if (strstr(titleStr, "viirs m-band geolocation data")) {
258  ret.type = FT_VIIRSGEONC;
259  if (want_verbose) {
260  printf("Input file %s is VIIRS NPP GEO NetCDF4.\n", filename);
261  }
262  }
263  char *platformStr = readAttrStr(ds_id, "platform");
264  if (platformStr) {
265  lowcase(platformStr);
266  if (strstr(platformStr, "suomi-npp")) {
267  ret.sensor_id = VIIRSN;
268  ret.subsensor_id = VIIRS_NPP;
269  } else if (strstr(platformStr, "jpss-1")) {
270  ret.sensor_id = VIIRSJ1;
271  ret.subsensor_id = VIIRS_J1;
272  } else if (strstr(platformStr, "jpss-2")) {
273  ret.sensor_id = VIIRSJ2;
274  ret.subsensor_id = VIIRS_J2;
275  }
276  free(platformStr);
277  }
278  free(titleStr);
279  endDS(ds_id);
280  return ret;
281  }
282  if (strstr(titleStr, "meris l1b")) {
283  ret.type = FT_MERISCC;
284  ret.sensor_id = MERIS;
285  ret.subsensor_id = -1;
286  if (want_verbose) {
287  printf("Input file %s is MERIS CC file.\n", filename);
288  }
289  free(titleStr);
290  endDS(ds_id);
291  return ret;
292  }
293  if (strstr(titleStr, "ocia level-1b")) {
294  ret.type = FT_OCIA;
295  ret.sensor_id = OCIA;
296  ret.subsensor_id = -1;
297  if (want_verbose) {
298  printf("Input file %s is OCIA L1B file.\n", filename);
299  }
300  free(titleStr);
301  endDS(ds_id);
302  return ret;
303  }
304  if (strstr(titleStr, "aviris level-1b")) {
305  ret.type = FT_AVIRIS;
306  ret.sensor_id = AVIRIS;
307  ret.subsensor_id = -1;
308  if (want_verbose) {
309  printf("Input file %s is AVIRIS L1B NetCDF4 file.\n", filename);
310  }
311  free(titleStr);
312  endDS(ds_id);
313  return ret;
314  }
315  if (strstr(titleStr, "olci level 1b product")) {
316  char subtype[4];
317  if (strstr(titleStr, "geo coordinates")) {
318  ret.type = FT_OLCIGEO;
319  strcpy(subtype,"GEO");
320  } else {
321  ret.type = FT_OLCI;
322  strcpy(subtype,"L1B");
323  }
324  char *productNameStr = readAttrStr(ds_id, "product_name");
325  if(!strncmp(productNameStr, "S3A", 3)) {
326  ret.sensor_id = OLCIS3A;
327  ret.subsensor_id = OLCI_S3A;
328  if (want_verbose) {
329  printf("Input file %s is OLCI S3A %s file.\n", filename, subtype);
330  }
331  free(productNameStr);
332  free(titleStr);
333  endDS(ds_id);
334  return ret;
335  } else if(!strncmp(productNameStr, "S3B", 3)) {
336  ret.sensor_id = OLCIS3B;
337  ret.subsensor_id = OLCI_S3B;
338  if (want_verbose) {
339  printf("Input file %s is OLCI S3B %s file.\n", filename, subtype);
340  }
341  free(productNameStr);
342  free(titleStr);
343  endDS(ds_id);
344  return ret;
345  }
346  free(productNameStr);
347  }
348  if (strstr(titleStr, "hawkeye level-1a")) {
349  ret.type = FT_HAWKEYEL1A;
350  ret.sensor_id = HAWKEYE;
351  ret.subsensor_id = -1;
352  if (want_verbose) {
353  printf("Input file %s is HAWKEYE L1A file.\n", filename);
354  }
355  free(titleStr);
356  endDS(ds_id);
357  return ret;
358  }
359  if (strstr(titleStr, "oci level-1b")) {
360  ret.type = FT_OCIL1B;
361  ret.sensor_id = OCI;
362  ret.subsensor_id = -1;
363  if (want_verbose) {
364  printf("Input file %s is PACE L1B file.\n", filename);
365  }
366  free(titleStr);
367  endDS(ds_id);
368  return ret;
369  }
370  if (strstr(titleStr, "ocis level-1b")) {
371  ret.type = FT_OCIS;
372  ret.sensor_id = OCIS;
373  ret.subsensor_id = -1;
374  if (want_verbose) {
375  printf("Input file %s is PACE L1B Simulated file.\n", filename);
376  }
377  free(titleStr);
378  endDS(ds_id);
379  return ret;
380  }
381 
382  if (strstr(titleStr, "hkt level-1a") ||
383  strstr(titleStr, "pace hkt data")) {
384  ret.type = FT_HKT;
385  ret.sensor_id = OCIS;
386  ret.subsensor_id = -1;
387  if (want_verbose) {
388  printf("Input file %s is PACE HKT file.\n", filename);
389  }
390  free(titleStr);
391  endDS(ds_id);
392  return ret;
393  }
394  if (strstr(titleStr, "pace oci level-1c")) {
395  ret.type = FT_L1C;
396  ret.sensor_id = OCI;
397  ret.subsensor_id = -1;
398  if (want_verbose) {
399  printf("Input file %s is PACE OCI L1C file.\n", filename);
400  }
401  free(titleStr);
402  endDS(ds_id);
403  return ret;
404  }
405  if (strstr(titleStr, "pace ocis level-1c")) {
406  ret.type = FT_L1C;
407  ret.sensor_id = OCIS;
408  ret.subsensor_id = -1;
409  if (want_verbose) {
410  printf("Input file %s is PACE OCIS L1C file.\n", filename);
411  }
412  free(titleStr);
413  endDS(ds_id);
414  return ret;
415  }
416  if (strstr(titleStr, "pace harp2 level-1c")) {
417  ret.type = FT_L1C;
418  ret.sensor_id = HARP2;
419  ret.subsensor_id = -1;
420  if (want_verbose) {
421  printf("Input file %s is PACE HARP2 L1C file.\n", filename);
422  }
423  free(titleStr);
424  endDS(ds_id);
425  return ret;
426  }
427  if (strstr(titleStr, "pace spexone level-1c")) {
428  ret.type = FT_L1C;
429  ret.sensor_id = SPEXONE;
430  ret.subsensor_id = -1;
431  if (want_verbose) {
432  printf("Input file %s is PACE SPEXone L1C file.\n", filename);
433  }
434  free(titleStr);
435  endDS(ds_id);
436  return ret;
437  }
438  if (strstr(titleStr, "l1c ancillary file")) {
439  ret.type = FT_L1CANC;
440  ret.sensor_id = OCI;
441  ret.subsensor_id = -1;
442  if (want_verbose) {
443  printf("Input file %s is L1C ancillary file.\n", filename);
444  }
445  free(titleStr);
446  endDS(ds_id);
447  return ret;
448  }
449  if (strstr(titleStr, "spexone level-1b")) {
450  ret.type = FT_SPEXONE;
451  ret.sensor_id = SPEXONE;
452  ret.subsensor_id = -1;
453  if (want_verbose) {
454  printf("Input file %s is PACE SPEXone file.\n", filename);
455  }
456  free(titleStr);
457  endDS(ds_id);
458  return ret;
459  }
460 
461  if (strstr(titleStr, "harp2 level-1b")) {
462  ret.type = FT_HARP2;
463  ret.sensor_id = HARP2;
464  ret.subsensor_id = -1;
465  if (want_verbose) {
466  printf("Input file %s is PACE HARP2 file.\n", filename);
467  }
468  free(titleStr);
469  endDS(ds_id);
470  return ret;
471  }
472 
473  // NetCDF for Seawifs L1A
474  if (strstr(titleStr, "seawifs level-1a data")) {
475  ret.type = FT_SEAWIFSL1ANC;
476  ret.sensor_id = SEAWIFS;
477 
478  char *dataTypeStr = readAttrStr(ds_id, "data_type");
479  if (dataTypeStr) {
480  if (strcmp(dataTypeStr, "GAC") == 0) {
482  if (want_verbose) {
483  printf("Input file %s is SeaWiFS Level-1A GAC.\n", filename);
484  }
485  }
486  else {
488  if (want_verbose) {
489  printf("Input file %s is SeaWiFS Level-1A LAC.\n", filename);
490  }
491  }
492  }
493  free(dataTypeStr);
494  free(titleStr);
495  endDS(ds_id);
496  return ret;
497  }
498  if (strstr(titleStr, "octs level-1a gac data")) {
499  ret.type = FT_OCTSL1ANC;
500  ret.sensor_id = OCTS;
501  ret.subsensor_id = -1;
502  if (want_verbose) {
503  printf("Input file %s is OCTS Level-1A GAC netCDF.\n", filename);
504  }
505  free(titleStr);
506  endDS(ds_id);
507  return ret;
508  }
509 
510  char *platformStr = readAttrStr(ds_id, "platform");
511 
512  if (platformStr) {
513  char *instrumentStr = readAttrStr(ds_id, "instrument");
514  if (instrumentStr) {
515  char *processingLevelStr = readAttrStr(ds_id, "processing_level");
516  if (processingLevelStr) {
517  if (!strcmp(processingLevelStr, "L1B")) {
518  ret.type = FT_L1BNCDF;
519  } else if (!strcmp(processingLevelStr, "L2")) {
520  ret.type = FT_L2NCDF;
521  } else if (!strcmp(processingLevelStr, "L3 Binned")) {
522  ret.type = FT_L3BIN;
523  } else if (!strcmp(processingLevelStr, "L3 Mapped")) {
524  ret.type = FT_L3MAP;
525  }
526  if (ret.type != FT_INVALID) {
527  ret.sensor_id = instrumentPlatform2SensorId(instrumentStr, platformStr);
529  if (want_verbose) {
530  printf("Input file %s is a NetCDF4 %s %s file.\n", filename, instrumentStr, processingLevelStr);
531  }
532  free(processingLevelStr);
533  free(instrumentStr);
534  free(platformStr);
535  free(titleStr);
536  endDS(ds_id);
537  return ret;
538  }
539  free(processingLevelStr);
540  } // processingLevel found
541  free(instrumentStr);
542  } // instrument found
543  free(platformStr);
544  } // platform found
545  free(titleStr);
546  } // title found
547 
548  // unknown netCDF file
549  return ret;
550  } // is a NetCDF file
551  endDS(ds_id);
552  } // data set opened successfully
553 
554  /* Is it HDF? */
555  sd_id = SDstart(filename, DFACC_RDONLY);
556  if (sd_id != FAIL) {
557 
558  /* File is HDF. Is it one of ours? */
559 
560  char title[255];
561  char sensor[80];
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) {
565 
566  // kludge for VIIRS EDR L3
567  if (strcmp(sensor, "VIIRS") == 0) {
568  strncpy(sensor, "VIIRSN", strlen("VIIRSN")+1);
569  }
570 
573  ret.type = FT_L3BIN;
574  if (want_verbose) {
575  printf("Input file %s is %s.\n", filename, title);
576  }
577  } else {
578  fprintf(stderr, "-E- %s Line %d: Unknown sensor name in Level-3 file %s\n", __FILE__, __LINE__, filename);
579  return ret;
580  }
581  } else {
582  fprintf(stderr, "-E- %s Line %d: No sensor name attribute in Level-3 file %s\n", __FILE__, __LINE__, filename);
583  return ret;
584  }
585  } else if (strstr(title, "Level-2 Data") != NULL) {
586  if (SDreadattr(sd_id, SDfindattr(sd_id, "Sensor Name"), (VOIDP) sensor) == 0) {
589  ret.type = FT_L2HDF;
590  if (want_verbose) {
591  printf("Input file %s is %s.\n", filename, title);
592  }
593  } else {
594  fprintf(stderr, "-E- %s Line %d: Unknown sensor name in Level-2 file %s\n", __FILE__, __LINE__, filename);
595  return ret;
596  }
597  } else {
598  fprintf(stderr, "-E- %s Line %d: No sensor name attribute in Level-2 file %s\n", __FILE__, __LINE__, filename);
599  return ret;
600  }
601  } else if (strcmp(title, "SeaWiFS Level-1A Data") == 0) {
602  ret.type = FT_SEAWIFSL1A;
603  ret.sensor_id = SEAWIFS;
604  if (SDreadattr(sd_id, SDfindattr(sd_id, "Data Type"), (VOIDP) tempstr) == 0) {
605  if (strcmp(tempstr, "GAC") == 0) {
607  if (want_verbose) {
608  printf("Input file %s is SeaWiFS Level-1A GAC.\n", filename);
609  }
610  } else if (strcmp(tempstr, "LAC") == 0) {
612  if (want_verbose) {
613  printf("Input file %s is SeaWiFS Level-1A LAC.\n", filename);
614  }
615  } else {
617  if (want_verbose) {
618  printf("Input file %s is assumed to be SeaWiFS Level-1A LAC.\n", filename);
619  }
620  }
621  } else {
623  if (want_verbose) {
624  printf("Input file %s is assumed to be SeaWiFS Level-1A LAC.\n", filename);
625  }
626  }
627  } else if (strcmp(title, "OCTS Level-1A GAC Data") == 0) {
628  ret.type = FT_OCTSL1A;
629  ret.sensor_id = OCTS;
630  ret.subsensor_id = -1;
631  if (want_verbose) {
632  printf("Input file %s is %s.\n", filename, title);
633  }
634  } else if (strcmp(title, "OSMI Level-1A Data") == 0) {
635  ret.type = FT_OSMIL1A;
636  ret.sensor_id = OSMI;
637  ret.subsensor_id = -1;
638  if (want_verbose) {
639  printf("Input file %s is %s.\n", filename, title);
640  }
641  } else if (strcmp(title, "CZCS Level-1A Data") == 0) {
642  ret.type = FT_CZCSL1A;
643  ret.sensor_id = CZCS;
644  ret.subsensor_id = -1;
645  if (want_verbose) {
646  printf("Input file %s is %s.\n", filename, title);
647  }
648  } else if (strcmp(title, "OCM1 Level-1B (OBPG)") == 0) {
649  ret.type = FT_OCML1B;
650  ret.sensor_id = OCM1;
651  ret.subsensor_id = -1;
652  if (want_verbose) {
653  printf("Input file %s is %s.\n", filename, title);
654  }
655  } else if (strncmp(title, "OCM Level-1B", 12) == 0) {
656  ret.type = FT_OCML1BDB;
657  ret.sensor_id = OCM1;
658  ret.subsensor_id = -1;
659  if (want_verbose) {
660  printf("Input file %s is %s.\n", filename, title);
661  }
662  } else if (strcmp(title, "Oceansat OCM2 Level-1B Data") == 0) {
663  ret.type = FT_OCM2L1B;
664  ret.sensor_id = OCM2;
665  ret.subsensor_id = -1;
666  if (want_verbose) {
667  printf("Input file %s is %s.\n", filename, title);
668  }
669 
670  /* generic L1B format support */
671  } else if (strcmp(title, "SeaWiFS Level-1B") == 0) {
672  ret.type = FT_L1HDF;
673  ret.sensor_id = SEAWIFS;
674  ret.subsensor_id = -1;
675  if (want_verbose) {
676  printf("Input file %s is %s.\n", filename, title);
677  }
678 
679  } else if (strcmp(title, "MERIS Level-1B") == 0) {
680  ret.type = FT_L1HDF;
681  ret.sensor_id = MERIS;
682  ret.subsensor_id = -1;
683  if (want_verbose) {
684  printf("Input file %s is %s.\n", filename, title);
685  }
686  } else if (strcmp(title, "VIIRS Level-1B") == 0 || strcmp(title, "VIIRSN Level-1B") == 0) {
687  ret.type = FT_L1HDF;
688  ret.sensor_id = VIIRSN;
689  ret.subsensor_id = VIIRS_NPP;
690  if (want_verbose) {
691  printf("Input file %s is %s.\n", filename, title);
692  }
693  } else if (strcmp(title, "VIIRSJ1 Level-1B") == 0) {
694  ret.type = FT_L1HDF;
695  ret.sensor_id = VIIRSJ1;
696  ret.subsensor_id = VIIRS_J1;
697  if (want_verbose) {
698  printf("Input file %s is %s.\n", filename, title);
699  }
700  } else if (strcmp(title, "VIIRSJ2 Level-1B") == 0) {
701  ret.type = FT_L1HDF;
702  ret.sensor_id = VIIRSJ2;
703  ret.subsensor_id = VIIRS_J2;
704  if (want_verbose) {
705  printf("Input file %s is %s.\n", filename, title);
706  }
707  } else if (strcmp(title, "OCM2 Level-1B") == 0) {
708  ret.type = FT_L1HDF;
709  ret.sensor_id = OCM2;
710  ret.subsensor_id = -1;
711  if (want_verbose) {
712  printf("Input file %s is %s.\n", filename, title);
713  }
714  } else if (strcmp(title, "OCTS Level-1B") == 0) {
715  ret.type = FT_L1HDF;
716  ret.sensor_id = OCTS;
717  ret.subsensor_id = -1;
718  if (want_verbose) {
719  printf("Input file %s is %s.\n", filename, title);
720  }
721  } else if (strcmp(title, "MOS Level-1B") == 0) {
722  ret.type = FT_L1HDF;
723  ret.sensor_id = MOS;
724  ret.subsensor_id = -1;
725  if (want_verbose) {
726  printf("Input file %s is %s.\n", filename, title);
727  }
728  } else if (strcmp(title, "OCTS Level-1B LAC Data") == 0) {
729  ret.type = FT_OCTSL1B;
730  ret.sensor_id = OCTS;
731  ret.subsensor_id = -1;
732  if (want_verbose) {
733  printf("Input file %s is %s.\n", filename, title);
734  }
735  } else if (strcmp(title, "OSMI Level-1B") == 0) {
736  ret.type = FT_L1HDF;
737  ret.sensor_id = OSMI;
738  ret.subsensor_id = -1;
739  if (want_verbose) {
740  printf("Input file %s is %s.\n", filename, title);
741  }
742  } else if (strcmp(title, "HMODIST Level-1B") == 0 || strcmp(title, "MODIST Level-1B") == 0) {
743  ret.type = FT_L1HDF;
744  ret.sensor_id = MODIST;
746  if (want_verbose) {
747  printf("Input file %s is %s.\n", filename, title);
748  printf("\n\n *** WARNING: polarization can not be computed from generic format ***\n\n");
749  }
750  } else if (strcmp(title, "HMODISA Level-1B") == 0 || strcmp(title, "MODISA Level-1B") == 0) {
751  ret.type = FT_L1HDF;
752  ret.sensor_id = MODISA;
753  ret.subsensor_id = MODIS_AQUA;
754  if (want_verbose) {
755  printf("Input file %s is %s.\n", filename, title);
756  printf("\n\n *** WARNING: polarization can not be computed from generic format ***\n\n");
757  }
758  } else if (strcmp(title, "CZCS Level-1B") == 0) {
759  ret.type = FT_L1HDF;
760  ret.sensor_id = CZCS;
761  ret.subsensor_id = -1;
762  if (want_verbose) {
763  printf("Input file %s is %s.\n", filename, title);
764  }
765 
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);
769  return ret;
770  }
771  ret.type = FT_L1XCAL;
772  if (want_verbose) {
773  printf("Input file %s is %s.\n", filename, title);
774  }
775  } else if (strstr(title, "AVHRR") != NULL) {
776  ret.type = FT_CLASSAVHRR;
777  ret.sensor_id = AVHRR;
778  ret.subsensor_id = -1;
779  if (want_verbose) {
780  printf("Input file %s is %s.\n", filename, title);
781  }
782  } else {
783  fprintf(stderr, "-E- %s Line %d: Unrecognized title %s in input HDF file %s\n", __FILE__, __LINE__, title, filename);
784  return ret;
785  }
786 
787  } else if (SDreadattr(sd_id, SDfindattr(sd_id, "title"), (VOIDP) title) == 0) {
788 
789  if (strstr(title, "AVHRR") != NULL) {
790  ret.type = FT_CLASSAVHRR;
791  ret.sensor_id = AVHRR;
792  ret.subsensor_id = -1;
793  if (want_verbose) {
794  printf("Input file %s is %s.\n", filename, title);
795  }
796  }
797 
798  } else if (SDreadattr(sd_id, SDfindattr(sd_id, "satellite"), (VOIDP) title) == 0) {
799 
800  if (strstr(title, "oceansat-1") != NULL) {
801  ret.type = FT_OCML1BDB;
802  ret.sensor_id = OCM1;
803  ret.subsensor_id = -1;
804  if (want_verbose) {
805  printf("Input file %s is %s.\n", filename, "OCM1 DB file");
806  }
807  }
808 
809  /* Is it HDF-EOS L1B format? */
810 
811  } else if (SDreadattr(sd_id, SDfindattr(sd_id, "ArchiveMetadata.0"), (VOIDP) eosmeta) == 0) {
812 
813  if (strstr(eosmeta, "MODIS/Terra Calibrated Radiances 5-Min L1B Swath 1km") != NULL) {
814  ret.type = FT_MODISL1B;
815  ret.sensor_id = MODIST;
817 
818  if (want_verbose) {
819  printf("Input file %s is MODIS Terra Level-1B HDF-EOS product.\n", filename);
820  }
821  return ret;
822  } else if (strstr(eosmeta, "MODIS/Aqua Calibrated Radiances 5-Min L1B Swath 1km") != NULL) {
823  ret.type = FT_MODISL1B;
824  ret.sensor_id = MODISA;
825  ret.subsensor_id = MODIS_AQUA;
826 
827  if (want_verbose) {
828  printf("Input file %s is MODIS Aqua Level-1B HDF-EOS product.\n", filename);
829  }
830  return ret;
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);
833  return ret;
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);
836  return ret;
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);
839  return ret;
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);
842  return ret;
843  } else if (strstr(eosmeta, "MODIS/Aqua Geolocation Fields") != NULL) {
844  ret.type = FT_MODISGEO;
845  ret.sensor_id = MODISA;
846  ret.subsensor_id = MODIS_AQUA;
847  if (want_verbose) {
848  printf("Input file %s is MODIS Aqua Geolocation Fields.\n", filename);
849  }
850  } else if (strstr(eosmeta, "MODIS/Terra Geolocation Fields") != NULL) {
851  ret.type = FT_MODISGEO;
852  ret.sensor_id = MODIST;
854  if (want_verbose) {
855  printf("Input file %s is MODIS Terra Geolocation Fields.\n", filename);
856  }
857  } else {
858  fprintf(stderr, "-E- %s Line %d: Unrecognized HDF-EOS file %s\n", __FILE__, __LINE__, filename);
859  return ret;
860  }
861 
862  /* MISR */
863  } else if ((SDfindattr(sd_id, "Path_number") != -1) && (SDfindattr(sd_id, "SOM_parameters.som_ellipsoid.a") != -1)) {
864  ret.type = FT_MISR;
865  ret.sensor_id = MISR;
866 
867 
868  /* Is it MOS L1B HDF standard product? */
869 
870  } else if (GetFileDesc(filename) != NULL) {
871  ret.type = FT_MOSL1B;
872  ret.sensor_id = MOS;
873  ret.subsensor_id = -1;
874  if (want_verbose) {
875  printf("Input file %s is MOS Level-1B standard product.\n", filename);
876  }
877  } else {
878  fprintf(stderr, "-E- %s Line %d: Unrecognized input HDF file %s\n", __FILE__, __LINE__, filename);
879  return ret;
880  }
881 
882  SDend(sd_id);
883  } else {
884 
885  // check for OLCI, MSI and MERIS SAFE format - in case they specified the xml file
886  if ((ret = chk_safe_xml(filename)).type != FT_INVALID) {
887  return ret;
888  }
889 
890  /* check for SeaBASS? */
891  if ((ret = chk_seabass(filename)).type != FT_INVALID) {
892  if (want_verbose)
893  printf("Input file %s is a SeaBASS text file.\n", filename);
894  return ret;
895  }
896 
897  /* Is it MERIS? */
898  {
899  EPR_SProductId *product_id;
900 
903  if (product_id != NULL) {
904  if (product_id->id_string[8] == '1') { /* it is a level 1 file */
905  ret.type = FT_MERISL1B;
906  ret.sensor_id = MERIS;
907  ret.subsensor_id = -1;
908  if (want_verbose) {
909  printf("Input file %s is MERIS L1 file.\n", filename);
910  }
911  }
913  /*remember to close api (epr_close_api();)*/
914  return ret;
915  }
916  }
917 
918  // check for OLI
919  if ((ret = chk_oli(filename)).type != FT_INVALID) {
920  if (want_verbose) {
921  printf("Input file %s is a Landsat 8/9 OLI L1B GEOTIFF file.\n", filename);
922  }
923  return ret;
924  }
925 
926  // check for AVIRIS
927  char hdrfile[FILENAME_MAX], imgfile[FILENAME_MAX], navfile[FILENAME_MAX], gainfile[FILENAME_MAX];
928  if ((ret = chk_aviris(filename, hdrfile, imgfile, navfile, gainfile)).type != FT_INVALID) {
929  if (want_verbose) {
930  printf("Input file %s is an AVIRIS file.\n", filename);
931  }
932  return ret;
933  }
934 
935  // check for PRISM
936  if ((ret = chk_prism(filename)).type != FT_INVALID) {
937  if (want_verbose) {
938  printf("Input file %s is a PRISM file.\n", filename);
939  }
940  return ret;
941  }
942 
943  // check for Landsat 5 (L5TM)
944  if ((ret = chk_l5tm(filename)).type != FT_INVALID) {
945  if (want_verbose) {
946  printf("Input file %s is a Landsat 5 TM L1B GEOTIFF file.\n", filename);
947  }
948  return ret;
949  }
950 
951  // check for Landsat 7 (L7TM)
952  if ((ret = chk_l7etm(filename)).type != FT_INVALID) {
953  if (want_verbose) {
954  printf("Input file %s is a Landsat 7 TM L1B GEOTIFF file.\n", filename);
955  }
956  return ret;
957  }
958  }
959 
960  return ret;
961 }
962 
963 
964 file_format chk_oli(char *filename) {
965  /* ------------------------------------------------------------------------
966  chk_oli
967 
968  purpose: check a file to see if it is an OLI Landsat8/9 file
969 
970  Returns FT_INVALID if not OLI L1B or the format code
971 
972  Parameters: (in calling order)
973  Type Name I/O Description
974  ---- ---- --- -----------
975  char * filename I file to check
976  filehandle * file I input file information
977 
978  -----------------------------------------------------------------------*/
979  file_format ret = {FT_INVALID, -1, -1};
980  const int lineSize = 500;
981  int i;
982  FILE *fp;
983  char line[lineSize + 1];
984  char *result;
985 
986  /* Open file */
987  if ((fp = fopen(filename, "re")) == NULL) {
988  return ret;
989  }
990 
991  // skip blank lines
992  do {
993  result = fgets(line, lineSize, fp);
994  if (result == NULL) {
995  fclose(fp);
996  return ret;
997  }
998  trimBlanks(line);
999  } while (strlen(line) == 0);
1000 
1001  // first line needs to be "GROUP = L1_METADATA_FILE"
1002  if (strstr(line, "L1_METADATA_FILE") == NULL && strstr(line, "LANDSAT_METADATA_FILE") == NULL) {
1003  fclose(fp);
1004  return ret;
1005  }
1006 
1007  // within 60 lines look for:
1008  // SPACECRAFT_ID = "LANDSAT_8/9"
1009  // SENSOR_ID = "OLI"
1010  int foundSpacecraft = 0;
1011  int foundSensor = 0;
1012  int isLandsat8 = 0;
1013  int isLandsat9 = 0;
1014  for (i = 0; i < 60; i++) {
1015  result = fgets(line, lineSize, fp);
1016  if (result == NULL) {
1017  fclose(fp);
1018  return ret;
1019  }
1020  if (strstr(line, "SPACECRAFT_ID")) {
1021  if (strstr(line, "LANDSAT_8")) {
1022  foundSpacecraft = 1;
1023  isLandsat8 = 1;
1024  }
1025  else if (strstr(line, "LANDSAT_9")) {
1026  foundSpacecraft = 1;
1027  isLandsat9 = 1;
1028  }
1029  } else if (strstr(line, "SENSOR_ID")) {
1030  if (strstr(line, "OLI")) {
1031  foundSensor = 1;
1032  }
1033  }
1034 
1035  if (foundSpacecraft && foundSensor) {
1036  ret.type = FT_OLIL1B;
1037  if (isLandsat8) {
1038  ret.subsensor_id = OLI_L8;
1039  ret.sensor_id = OLIL8;
1040  } else if (isLandsat9) {
1041  ret.subsensor_id = OLI_L9;
1042  ret.sensor_id = OLIL9;
1043  }
1044 
1045  break;
1046  }
1047  }
1048 
1049  fclose(fp);
1050  return ret;
1051 }
1052 
1054  /* ------------------------------------------------------------------------
1055  chk_oli_geo
1056 
1057  purpose: check a file to see if it is an OLI Landsat8/9 GEO file
1058 
1059  Returns FT_INVALID if not OLI L1B or the format code
1060 
1061  Parameters: (in calling order)
1062  Type Name I/O Description
1063  ---- ---- --- -----------
1064  char * filename I file to check
1065  filehandle * file I input file information
1066 
1067  -----------------------------------------------------------------------*/
1068  file_format ret = {FT_INVALID, -1, -1};
1069  const int lineSize = 500;
1070  int i;
1071  FILE *fp;
1072  char line[lineSize + 1];
1073  char *result;
1074 
1075  /* Open file */
1076  if ((fp = fopen(filename, "re")) == NULL) {
1077  return ret;
1078  }
1079 
1080  // skip blank lines
1081  do {
1082  result = fgets(line, lineSize, fp);
1083  if (result == NULL) {
1084  fclose(fp);
1085  return ret;
1086  }
1087  trimBlanks(line);
1088  } while (strlen(line) == 0);
1089 
1090  // first line needs to be "GROUP = FILE_HEADER"
1091  if (strstr(line, "FILE_HEADER") == NULL) {
1092  fclose(fp);
1093  return ret;
1094  }
1095 
1096  // within 60 lines look for:
1097  // SATELLITE = "LANDSAT_8/9"
1098  // BAND_LIST = ...
1099  int foundSpacecraft = 0;
1100  int foundBand = 0;
1101  for (i = 0; i < 60; i++) {
1102  result = fgets(line, lineSize, fp);
1103  if (result == NULL) {
1104  fclose(fp);
1105  return ret;
1106  }
1107  trimBlanks(line);
1108  if (strstr(line, "SATELLITE") || strstr(line, "SPACECRAFT_ID")) {
1109  if (strstr(line, "LANDSAT_8") || strstr(line, "LANDSAT_9")) {
1110  foundSpacecraft = 1;
1111  }
1112  } else if (strstr(line, "BAND_LIST")) {
1113  foundBand = 1;
1114  }
1115 
1116  if (foundSpacecraft && foundBand) {
1117  ret.type = FT_OLIL1B;
1118  break;
1119  }
1120  }
1121 
1122  fclose(fp);
1123  return ret;
1124 }
1125 
1135 file_format chk_prism(char *filename) {
1136  file_format ret = {FT_INVALID, -1, -1};
1137  const int lineSize = 500;
1138  FILE *fp;
1139  char line[lineSize + 1];
1140  char *result;
1141 
1142  if (strstr(filename, "prm") == NULL) {
1143  return ret;
1144  }
1145 
1146  /* Open file */
1147  if ((fp = fopen(filename, "re")) == NULL) {
1148  return ret;
1149  }
1150 
1151  // skip blank lines
1152  do {
1153  result = fgets(line, lineSize, fp);
1154  if (result == NULL) {
1155  fclose(fp);
1156  return ret;
1157  }
1158  trimBlanks(line);
1159  } while (strlen(line) == 0);
1160 
1161  // first line needs to be "ENVI"
1162  if (strstr(line, "ENVI") == NULL) {
1163  fclose(fp);
1164  return ret;
1165  }
1166 
1167  ret.type = FT_PRISM;
1168  ret.sensor_id = PRISM;
1169 
1170  fclose(fp);
1171  return ret;
1172 }
1173 
1183 file_format chk_aviris(char *filename, char *hdrfile, char *imgfile, char *navfile, char *gainfile) {
1184  file_format ret = {FT_INVALID, -1, -1};
1185  const int lineSize = 500;
1186  int i;
1187  FILE *fp;
1188  char line[lineSize + 1];
1189  char *result;
1190 
1191  if (!checkAvProcessFile(filename, hdrfile, imgfile, navfile, gainfile, FILENAME_MAX)) {
1192  strncpy(hdrfile, filename, FILENAME_MAX);
1193  } else {
1194  ret.type = FT_AVIRIS;
1195  ret.sensor_id = AVIRIS;
1196  return ret;
1197  }
1198 
1199  /* Open file */
1200  if ((fp = fopen(hdrfile, "re")) == NULL) {
1201  return ret;
1202  }
1203 
1204  // skip blank lines
1205  do {
1206  result = fgets(line, lineSize, fp);
1207  if (result == NULL) {
1208  fclose(fp);
1209  return ret;
1210  }
1211  trimBlanks(line);
1212  } while (strlen(line) == 0);
1213 
1214  // first line needs to be "ENVI"
1215  if (strstr(line, "ENVI") == NULL) {
1216  fclose(fp);
1217  return ret;
1218  }
1219 
1220  // within 20 lines look for:
1221  // AVIRIS orthocorrected
1222  int foundAviris = 0;
1223  int foundFormat = 0;
1224  int foundOrtho = 0;
1225  for (i = 0; i < 20; i++) {
1226  result = fgets(line, lineSize, fp);
1227  if (result == NULL) {
1228  fclose(fp);
1229  return ret;
1230  }
1231  trimBlanks(line);
1232  if (strstr(line, "AVIRIS")) {
1233  foundAviris = 1;
1234  }
1235  if (strstr(line, "orthocorrected")) {
1236  foundOrtho = 1;
1237  }
1238  if (strstr(line, "interleave")) {
1239  foundFormat = 1;
1240  }
1241 
1242  if (foundAviris && foundFormat && foundOrtho) {
1243  ret.type = FT_AVIRIS;
1244  ret.sensor_id = AVIRIS;
1245  break;
1246  }
1247  }
1248 
1249  fclose(fp);
1250  return ret;
1251 }
1252 
1253 file_format chk_l5tm(char *filename) {
1254  /* ------------------------------------------------------------------------
1255  chk_oli
1256 
1257  purpose: check a file to see if it is an OLI Landsat8 file
1258 
1259  Returns FT_INVALID if not OLI L1B or the format code
1260 
1261  Parameters: (in calling order)
1262  Type Name I/O Description
1263  ---- ---- --- -----------
1264  char * filename I file to check
1265  filehandle * file I input file information
1266 
1267  -----------------------------------------------------------------------*/
1268  file_format ret = {FT_INVALID, -1, -1};
1269  const int lineSize = 500;
1270  int i;
1271  FILE *fp;
1272  char line[lineSize + 1];
1273  char *result;
1274 
1275  /* Open file */
1276  if ((fp = fopen(filename, "re")) == NULL) {
1277  return ret;
1278  }
1279 
1280  // skip blank lines
1281  do {
1282  result = fgets(line, lineSize, fp);
1283  if (result == NULL) {
1284  fclose(fp);
1285  return ret;
1286  }
1287  trimBlanks(line);
1288  } while (strlen(line) == 0);
1289 
1290  // first line needs to be "GROUP = L1_METADATA_FILE"
1291  if (strstr(line, "L1_METADATA_FILE") == NULL) {
1292  fclose(fp);
1293  return ret;
1294  }
1295 
1296  // within 20 lines look for:
1297  // SPACECRAFT_ID = "LANDSAT_5"
1298  // SENSOR_ID = "TM"
1299  int foundSpacecraft = 0;
1300  int foundSensor = 0;
1301  for (i = 0; i < 20; i++) {
1302  result = fgets(line, lineSize, fp);
1303  if (result == NULL) {
1304  fclose(fp);
1305  return ret;
1306  }
1307  trimBlanks(line);
1308  if (strstr(line, "SPACECRAFT_ID")) {
1309  if (strstr(line, "LANDSAT_5")) {
1310  foundSpacecraft = 1;
1311  }
1312  } else if (strstr(line, "SENSOR_ID")){
1313  if (strstr(line, "TM")) {
1314  foundSensor = 1;
1315  }
1316  }
1317 
1318  if (foundSpacecraft && foundSensor) {
1319  ret.type = FT_L5TML1B;
1320  ret.sensor_id = L5TM;
1321  break;
1322  }
1323  }
1324 
1325  fclose(fp);
1326  return ret;
1327 }
1328 
1330  /* ------------------------------------------------------------------------
1331  chk_l5tm_geo
1332 
1333  purpose: check a file to see if it is a Landsat 5 TM GEO file
1334 
1335  Returns FT_INVALID if not LS% L1B or the format code
1336 
1337  Parameters: (in calling order)
1338  Type Name I/O Description
1339  ---- ---- --- -----------
1340  char * filename I file to check
1341  filehandle * file I input file information
1342 
1343  -----------------------------------------------------------------------*/
1344  file_format ret = {FT_INVALID, -1, -1};
1345  const int lineSize = 500;
1346  int i;
1347  FILE *fp;
1348  char line[lineSize + 1];
1349  char *result;
1350 
1351  /* Open file */
1352  if ((fp = fopen(filename, "re")) == NULL) {
1353  return ret;
1354  }
1355 
1356  // skip blank lines
1357  do {
1358  result = fgets(line, lineSize, fp);
1359  if (result == NULL) {
1360  fclose(fp);
1361  return ret;
1362  }
1363  trimBlanks(line);
1364  } while (strlen(line) == 0);
1365 
1366  // first line needs to be "GROUP = FILE_HEADER"
1367  if (strstr(line, "FILE_HEADER") == NULL) {
1368  fclose(fp);
1369  return ret;
1370  }
1371 
1372  // within 20 lines look for:
1373  // SATELLITE = "LANDSAT_5" for now unconfirmed. Need to confirm this from actual
1374  // BAND_LIST = ... geoletry file if such things exists for Landsat 5.
1375  int foundSpacecraft = 0;
1376  int foundBand = 0;
1377  for (i = 0; i < 20; i++) {
1378  result = fgets(line, lineSize, fp);
1379  if (result == NULL) {
1380  fclose(fp);
1381  return ret;
1382  }
1383  trimBlanks(line);
1384  if (strstr(line, "SATELLITE")) {
1385  if (strstr(line, "LANDSAT_5")) {
1386  foundSpacecraft = 1;
1387  }
1388  } else if (strstr(line, "BAND_LIST")) {
1389  foundBand = 1;
1390  }
1391 
1392  if (foundSpacecraft && foundBand) {
1393  ret.type = FT_L5TML1B;
1394  break;
1395  }
1396  }
1397 
1398  fclose(fp);
1399  return ret;
1400 }
1401 
1402 file_format chk_l7etm(char *filename) {
1403  /* ------------------------------------------------------------------------
1404  chk_oli
1405 
1406  purpose: check a file to see if it is an OLI Landsat8 file
1407 
1408  Returns FT_INVALID if not OLI L1B or the format code
1409 
1410  Parameters: (in calling order)
1411  Type Name I/O Description
1412  ---- ---- --- -----------
1413  char * filename I file to check
1414  filehandle * file I input file information
1415 
1416  -----------------------------------------------------------------------*/
1417  file_format ret = {FT_INVALID, -1, -1};
1418  const int lineSize = 500;
1419  int i;
1420  FILE *fp;
1421  char line[lineSize + 1];
1422  char *result;
1423 
1424  /* Open file */
1425  if ((fp = fopen(filename, "re")) == NULL) {
1426  return ret;
1427  }
1428 
1429  // skip blank lines
1430  do {
1431  result = fgets(line, lineSize, fp);
1432  if (result == NULL) {
1433  fclose(fp);
1434  return ret;
1435  }
1436  trimBlanks(line);
1437  } while (strlen(line) == 0);
1438 
1439  // first line needs to be "GROUP = L1_METADATA_FILE"
1440  if (strstr(line, "L1_METADATA_FILE") == NULL) {
1441  fclose(fp);
1442  return ret;
1443  }
1444 
1445  // within 20 lines look for:
1446  // SPACECRAFT_ID = "LANDSAT_5"
1447  // SENSOR_ID = "TM"
1448  int foundSpacecraft = 0;
1449  int foundSensor = 0;
1450  for (i = 0; i < 20; i++) {
1451  result = fgets(line, lineSize, fp);
1452  if (result == NULL) {
1453  fclose(fp);
1454  return ret;
1455  }
1456  trimBlanks(line);
1457  if (strstr(line, "SPACECRAFT_ID")) {
1458  if (strstr(line, "LANDSAT_7")) {
1459  foundSpacecraft = 1;
1460  }
1461  } else if (strstr(line, "SENSOR_ID")){
1462  if (strstr(line, "ETM")) {
1463  foundSensor = 1;
1464  }
1465  }
1466 
1467  if (foundSpacecraft && foundSensor) {
1468  ret.type = FT_L7ETML1B;
1469  ret.sensor_id = L7ETMP;
1470  break;
1471  }
1472  }
1473 
1474  fclose(fp);
1475  return ret;
1476 }
1477 
1486 file_format chk_seabass(char *filename) {
1487 
1488  file_format ret = {FT_INVALID, -1, -1};
1489  FILE *fp;
1490 
1491  if ((fp = fopen(filename, "r")) == NULL) {
1492  fprintf(stderr, "-E- : input file %s does not exist or is read protected.\n", filename);
1493  return ret;
1494  }
1495 
1496 
1497  char buffer[2048];
1498  fgets(buffer, 2048-1, fp);
1499  if (strncmp(buffer, "/begin_header", 13) == 0) {
1500  ret.type = FT_SEABASSRRS;
1501 
1502  // Get delimiter
1503  // while(1) {
1504  // if (fgets(buffer, 2048-1, fp) == NULL) {
1505  // fprintf(stderr, "-E- : input SeaBASS file %s does not contain delimiter.\n", filename);
1506  // fclose(fp);
1507  // exit(1);
1508  // }
1509  // if (strncmp(buffer, "/delimiter=", 11) == 0) {
1510  // buffer[strcspn(buffer, "\n")] = 0;
1511  // strcpy(file->delimiter, &buffer[11]);
1512  // fclose(fp);
1513  // break;
1514  // }
1515  // }
1516 
1517  while (1) {
1518  fgets(buffer, 2048-1, fp);
1519  if (strncmp(buffer, "/end_header", 13) == 0) {
1520  break;
1521  } else if (strncmp(buffer, "/sensor=", 8) == 0) {
1522  for (int i=8;i<64;i++){
1523  if (buffer[i] == '\n'){
1524  buffer[i] = '\0';
1525  break;
1526  }
1527  }
1528  ret.sensor_id = sensorName2SensorId(&buffer[8]);
1530  break;
1531  }
1532  } // while loop
1533  }
1534 
1535  fclose(fp);
1536 
1537  return ret;
1538 }
int32_t subsensor_id
Definition: filetype.h:72
file_type getFormatType(char *filename)
Definition: filetype.c:187
@ FT_L1BNCDF
Definition: filetype.h:19
#define OLCIS3A
Definition: sensorDefs.h:32
char * GetFileDesc(const char *filename)
Definition: hdf_utils.c:752
@ e_log_debug
Definition: epr_api.h:125
@ FT_MISR
Definition: filetype.h:59
#define MODIS_AQUA
Definition: sensorDefs.h:58
int status
Definition: l1_czcs_hdf.c:32
@ FT_OCML1B
Definition: filetype.h:34
#define SPEXONE
Definition: sensorDefs.h:46
int instrumentPlatform2SensorId(const char *instrument, const char *platform)
Definition: sensorInfo.c:405
char * lowcase(char *instr)
Definition: lowcase.c:10
@ FT_OCML1BDB
Definition: filetype.h:35
@ FT_OLCI
Definition: filetype.h:39
#define SGLI
Definition: sensorDefs.h:33
#define AVHRR
Definition: sensorDefs.h:15
#define OCI
Definition: sensorDefs.h:42
idDS openDS(const char *filename)
Definition: wrapper.c:606
#define HARP2
Definition: sensorDefs.h:47
#define FAIL
Definition: ObpgReadGrid.h:18
#define OSMI
Definition: sensorDefs.h:16
@ FT_OLCIGEO
Definition: filetype.h:40
#define NULL
Definition: decode_rs.h:63
@ FT_OCIA
Definition: filetype.h:42
@ FT_L7ETML1B
Definition: filetype.h:56
#define OLIL9
Definition: sensorDefs.h:45
#define VIIRSN
Definition: sensorDefs.h:23
void trimBlanks(char *str)
Definition: trimBlanks.c:10
#define L5TM
Definition: sensorDefs.h:35
@ FT_OCTSL1ANC
Definition: filetype.h:37
int sensorName2SensorId(const char *name)
Definition: sensorInfo.c:371
@ FT_SEAWIFSL1A
Definition: filetype.h:47
#define MERIS
Definition: sensorDefs.h:22
@ FT_VIIRSL1A
Definition: filetype.h:51
@ FT_MODISGEO
Definition: filetype.h:30
#define MODIST
Definition: sensorDefs.h:18
int epr_init_api(EPR_ELogLevel log_level, EPR_FLogHandler log_handler, EPR_FErrHandler err_handler)
Definition: epr_api.c:40
file_type type
Definition: filetype.h:70
int checkAvProcessFile(char *filename, char *hdrfile, char *imgfile, char *navfile, char *gainfile, int itemsize)
Definition: read_aviris.c:831
@ FT_PRISM
Definition: filetype.h:46
@ FT_OCTSL1A
Definition: filetype.h:36
#define OCIA
Definition: sensorDefs.h:29
ds_format_t fftype
Definition: dfutils.h:31
@ FT_L2NCDF
Definition: filetype.h:23
@ FT_VIIRSL1B
Definition: filetype.h:52
@ FT_HICOL1B
Definition: filetype.h:18
int sensorId2SubsensorId(int sensorId)
Definition: sensorInfo.c:438
#define VIIRS_NPP
Definition: sensorDefs.h:59
#define OLIL8
Definition: sensorDefs.h:27
@ FT_AVIRIS
Definition: filetype.h:14
@ FT_L3MAP
Definition: filetype.h:25
@ FT_MERISCC
Definition: filetype.h:26
@ FT_OCTSL1B
Definition: filetype.h:38
@ FT_MERISL1B
Definition: filetype.h:27
file_format chk_safe_xml(char *filename)
Definition: filetypeXml.cpp:43
char * readAttrStr(idDS ds_id, const char *name)
Definition: wrapper.c:99
@ FT_VIIRSL1BNC
Definition: filetype.h:53
file_format getFormat(char *filename)
Definition: filetype.c:192
#define SEAWIFS_GAC
Definition: sensorDefs.h:55
@ FT_OCIS
Definition: filetype.h:44
What value is used by your function when the data value is bad Default is BAD_FLT l2prod product_id[0]
#define HAWKEYE
Definition: sensorDefs.h:39
#define OLI_L8
Definition: sensorDefs.h:66
#define OCIS
Definition: sensorDefs.h:43
#define PRISM
Definition: sensorDefs.h:31
int want_verbose
char filename[FILENAME_MAX]
Definition: atrem_corl1.h:122
@ DS_NCDF
Definition: dfutils.h:20
#define OLI_L9
Definition: sensorDefs.h:67
#define AVIRIS
Definition: sensorDefs.h:30
@ FT_HAWKEYEL1A
Definition: filetype.h:58
@ FT_SPEXONE
Definition: filetype.h:61
#define MOS
Definition: sensorDefs.h:13
#define VIIRS_J1
Definition: sensorDefs.h:60
file_type
Definition: filetype.h:11
#define MISR
Definition: sensorDefs.h:40
@ FT_L5TML1B
Definition: filetype.h:55
#define L7ETMP
Definition: sensorDefs.h:36
@ FT_L1C
Definition: filetype.h:65
int32_t sensor_id
Definition: filetype.h:71
@ FT_HARP2
Definition: filetype.h:62
@ FT_HKT
Definition: filetype.h:64
#define OCTS
Definition: sensorDefs.h:14
@ FT_SEABASSRRS
Definition: filetype.h:60
@ FT_OCM2L1B
Definition: filetype.h:33
#define MODIS_TERRA
Definition: sensorDefs.h:57
@ FT_GOCIL1B
Definition: filetype.h:17
@ FT_VIIRSGEONC
Definition: filetype.h:50
@ FT_MOSL1B
Definition: filetype.h:32
#define OCM1
Definition: sensorDefs.h:20
int32_t fid
Definition: dfutils.h:29
@ FT_INVALID
Definition: filetype.h:12
@ FT_L1HDF
Definition: filetype.h:20
#define CZCS
Definition: sensorDefs.h:17
PARAM_TYPE_NONE Default value No parameter is buried in the product name name_prefix is case insensitive string compared to the product name PARAM_TYPE_VIS_WAVE The visible wavelength bands from the sensor are buried in the product name The product name is compared by appending and name_suffix ie aph_412_giop where prod_ix will be set to PARAM_TYPE_IR_WAVE same search method as PARAM_TYPE_VIS_WAVE except only wavelength above are looped through but prod_ix is still based ie aph_2_giop for the second and prod_ix set to PARAM_TYPE_INT name_prefix is compared with the beginning of the product name If name_suffix is not empty the it must match the end of the product name The characters right after the prefix are read as an integer and prod_ix is set to that number strncpy(l2prod->name_prefix, "myprod", UNITLEN)
Definition: dfutils.h:28
file_format chk_oli_geo(char *filename)
Definition: filetype.c:1053
@ FT_SGLI
Definition: filetype.h:54
@ FT_L1CANC
Definition: filetype.h:66
#define VIIRSJ2
Definition: sensorDefs.h:44
EPR_SProductId * epr_open_product(const char *product_file_path)
Definition: epr_product.c:54
file_format chk_l5tm_geo(char *filename)
Definition: filetype.c:1329
#define OLCIS3B
Definition: sensorDefs.h:41
#define HICO
Definition: sensorDefs.h:25
@ FT_MODISL1B
Definition: filetype.h:31
#define VIIRS_J2
Definition: sensorDefs.h:65
@ FT_OCIL1B
Definition: filetype.h:43
#define SEAWIFS
Definition: sensorDefs.h:12
int endDS(idDS ds_id)
Definition: wrapper.c:624
int i
Definition: decode_rs.h:71
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
#define MODISA
Definition: sensorDefs.h:19
#define EOSMETALEN
Definition: filetype.c:23
#define VIIRSJ1
Definition: sensorDefs.h:37
@ FT_OLIL1B
Definition: filetype.h:41
@ FT_CLASSAVHRR
Definition: filetype.h:15
@ FT_L1XCAL
Definition: filetype.h:21
#define OLCI_S3A
Definition: sensorDefs.h:63
#define SEAWIFS_LAC
Definition: sensorDefs.h:56
#define OCM2
Definition: sensorDefs.h:21
int epr_close_product(EPR_SProductId *product_id)
Definition: epr_product.c:231
@ FT_OSMIL1A
Definition: filetype.h:45
@ FT_SEAWIFSL1ANC
Definition: filetype.h:48
#define OLCI_S3B
Definition: sensorDefs.h:64
@ FT_CZCSL1A
Definition: filetype.h:16
@ FT_L2HDF
Definition: filetype.h:22
@ FT_L3BIN
Definition: filetype.h:24
#define GOCI
Definition: sensorDefs.h:26