OB.DAAC Logo
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 L1A HKT file.\n", filename);
389  }
390  free(titleStr);
391  endDS(ds_id);
392  return ret;
393  }
394 
395  if (strstr(titleStr, "spexone level-1b")) {
396  ret.type = FT_SPEXONE;
397  ret.sensor_id = SPEXONE;
398  ret.subsensor_id = -1;
399  if (want_verbose) {
400  printf("Input file %s is PACE SPEXone file.\n", filename);
401  }
402  free(titleStr);
403  endDS(ds_id);
404  return ret;
405  }
406 
407  if (strstr(titleStr, "harp2 level-1b")) {
408  ret.type = FT_HARP2;
409  ret.sensor_id = HARP2;
410  ret.subsensor_id = -1;
411  if (want_verbose) {
412  printf("Input file %s is PACE HARP2 file.\n", filename);
413  }
414  free(titleStr);
415  endDS(ds_id);
416  return ret;
417  }
418 
419  char *platformStr = readAttrStr(ds_id, "platform");
420  if (platformStr) {
421  char *instrumentStr = readAttrStr(ds_id, "instrument");
422  if (instrumentStr) {
423  char *processingLevelStr = readAttrStr(ds_id, "processing_level");
424  if (processingLevelStr) {
425  if (!strcmp(processingLevelStr, "L1B")) {
426  ret.type = FT_L1BNCDF;
427  } else if (!strcmp(processingLevelStr, "L2")) {
428  ret.type = FT_L2NCDF;
429  } else if (!strcmp(processingLevelStr, "L3 Binned")) {
430  ret.type = FT_L3BIN;
431  } else if (!strcmp(processingLevelStr, "L3 Mapped")) {
432  ret.type = FT_L3MAP;
433  }
434  if (ret.type != FT_INVALID) {
435  ret.sensor_id = instrumentPlatform2SensorId(instrumentStr, platformStr);
437  if (want_verbose) {
438  printf("Input file %s is a NetCDF4 %s %s file.\n", filename, instrumentStr, processingLevelStr);
439  }
440  free(processingLevelStr);
441  free(instrumentStr);
442  free(platformStr);
443  free(titleStr);
444  endDS(ds_id);
445  return ret;
446  }
447  free(processingLevelStr);
448  } // processingLevel found
449  free(instrumentStr);
450  } // instrument found
451  free(platformStr);
452  } // platform found
453  free(titleStr);
454  } // title found
455 
456  // unknown netCDF file
457  return ret;
458  } // is a NetCDF file
459  endDS(ds_id);
460  } // data set opened successfully
461 
462  /* Is it HDF? */
463  sd_id = SDstart(filename, DFACC_RDONLY);
464  if (sd_id != FAIL) {
465 
466  /* File is HDF. Is it one of ours? */
467 
468  char title[255];
469  char sensor[80];
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) {
473 
474  // kludge for VIIRS EDR L3
475  if (strcmp(sensor, "VIIRS") == 0) {
476  strncpy(sensor, "VIIRSN", strlen("VIIRSN")+1);
477  }
478 
481  ret.type = FT_L3BIN;
482  if (want_verbose) {
483  printf("Input file %s is %s.\n", filename, title);
484  }
485  } else {
486  fprintf(stderr, "-E- %s Line %d: Unknown sensor name in Level-3 file %s\n", __FILE__, __LINE__, filename);
487  return ret;
488  }
489  } else {
490  fprintf(stderr, "-E- %s Line %d: No sensor name attribute in Level-3 file %s\n", __FILE__, __LINE__, filename);
491  return ret;
492  }
493  } else if (strstr(title, "Level-2 Data") != NULL) {
494  if (SDreadattr(sd_id, SDfindattr(sd_id, "Sensor Name"), (VOIDP) sensor) == 0) {
497  ret.type = FT_L2HDF;
498  if (want_verbose) {
499  printf("Input file %s is %s.\n", filename, title);
500  }
501  } else {
502  fprintf(stderr, "-E- %s Line %d: Unknown sensor name in Level-2 file %s\n", __FILE__, __LINE__, filename);
503  return ret;
504  }
505  } else {
506  fprintf(stderr, "-E- %s Line %d: No sensor name attribute in Level-2 file %s\n", __FILE__, __LINE__, filename);
507  return ret;
508  }
509  } else if (strcmp(title, "SeaWiFS Level-1A Data") == 0) {
510  ret.type = FT_SEAWIFSL1A;
511  ret.sensor_id = SEAWIFS;
512  if (SDreadattr(sd_id, SDfindattr(sd_id, "Data Type"), (VOIDP) tempstr) == 0) {
513  if (strcmp(tempstr, "GAC") == 0) {
515  if (want_verbose) {
516  printf("Input file %s is SeaWiFS Level-1A GAC.\n", filename);
517  }
518  } else if (strcmp(tempstr, "LAC") == 0) {
520  if (want_verbose) {
521  printf("Input file %s is SeaWiFS Level-1A LAC.\n", filename);
522  }
523  } else {
525  if (want_verbose) {
526  printf("Input file %s is assumed to be SeaWiFS Level-1A LAC.\n", filename);
527  }
528  }
529  } else {
531  if (want_verbose) {
532  printf("Input file %s is assumed to be SeaWiFS Level-1A LAC.\n", filename);
533  }
534  }
535  } else if (strcmp(title, "OCTS Level-1A GAC Data") == 0) {
536  ret.type = FT_OCTSL1A;
537  ret.sensor_id = OCTS;
538  ret.subsensor_id = -1;
539  if (want_verbose) {
540  printf("Input file %s is %s.\n", filename, title);
541  }
542  } else if (strcmp(title, "OSMI Level-1A Data") == 0) {
543  ret.type = FT_OSMIL1A;
544  ret.sensor_id = OSMI;
545  ret.subsensor_id = -1;
546  if (want_verbose) {
547  printf("Input file %s is %s.\n", filename, title);
548  }
549  } else if (strcmp(title, "CZCS Level-1A Data") == 0) {
550  ret.type = FT_CZCSL1A;
551  ret.sensor_id = CZCS;
552  ret.subsensor_id = -1;
553  if (want_verbose) {
554  printf("Input file %s is %s.\n", filename, title);
555  }
556  } else if (strcmp(title, "OCM1 Level-1B (OBPG)") == 0) {
557  ret.type = FT_OCML1B;
558  ret.sensor_id = OCM1;
559  ret.subsensor_id = -1;
560  if (want_verbose) {
561  printf("Input file %s is %s.\n", filename, title);
562  }
563  } else if (strncmp(title, "OCM Level-1B", 12) == 0) {
564  ret.type = FT_OCML1BDB;
565  ret.sensor_id = OCM1;
566  ret.subsensor_id = -1;
567  if (want_verbose) {
568  printf("Input file %s is %s.\n", filename, title);
569  }
570  } else if (strcmp(title, "Oceansat OCM2 Level-1B Data") == 0) {
571  ret.type = FT_OCM2L1B;
572  ret.sensor_id = OCM2;
573  ret.subsensor_id = -1;
574  if (want_verbose) {
575  printf("Input file %s is %s.\n", filename, title);
576  }
577 
578  /* generic L1B format support */
579  } else if (strcmp(title, "SeaWiFS Level-1B") == 0) {
580  ret.type = FT_L1HDF;
581  ret.sensor_id = SEAWIFS;
582  ret.subsensor_id = -1;
583  if (want_verbose) {
584  printf("Input file %s is %s.\n", filename, title);
585  }
586 
587  } else if (strcmp(title, "MERIS Level-1B") == 0) {
588  ret.type = FT_L1HDF;
589  ret.sensor_id = MERIS;
590  ret.subsensor_id = -1;
591  if (want_verbose) {
592  printf("Input file %s is %s.\n", filename, title);
593  }
594  } else if (strcmp(title, "VIIRS Level-1B") == 0 || strcmp(title, "VIIRSN Level-1B") == 0) {
595  ret.type = FT_L1HDF;
596  ret.sensor_id = VIIRSN;
597  ret.subsensor_id = VIIRS_NPP;
598  if (want_verbose) {
599  printf("Input file %s is %s.\n", filename, title);
600  }
601  } else if (strcmp(title, "OCM2 Level-1B") == 0) {
602  ret.type = FT_L1HDF;
603  ret.sensor_id = OCM2;
604  ret.subsensor_id = -1;
605  if (want_verbose) {
606  printf("Input file %s is %s.\n", filename, title);
607  }
608  } else if (strcmp(title, "OCTS Level-1B") == 0) {
609  ret.type = FT_L1HDF;
610  ret.sensor_id = OCTS;
611  ret.subsensor_id = -1;
612  if (want_verbose) {
613  printf("Input file %s is %s.\n", filename, title);
614  }
615  } else if (strcmp(title, "MOS Level-1B") == 0) {
616  ret.type = FT_L1HDF;
617  ret.sensor_id = MOS;
618  ret.subsensor_id = -1;
619  if (want_verbose) {
620  printf("Input file %s is %s.\n", filename, title);
621  }
622  } else if (strcmp(title, "OCTS Level-1B LAC Data") == 0) {
623  ret.type = FT_OCTSL1B;
624  ret.sensor_id = OCTS;
625  ret.subsensor_id = -1;
626  if (want_verbose) {
627  printf("Input file %s is %s.\n", filename, title);
628  }
629  } else if (strcmp(title, "OSMI Level-1B") == 0) {
630  ret.type = FT_L1HDF;
631  ret.sensor_id = OSMI;
632  ret.subsensor_id = -1;
633  if (want_verbose) {
634  printf("Input file %s is %s.\n", filename, title);
635  }
636  } else if (strcmp(title, "HMODIST Level-1B") == 0 || strcmp(title, "MODIST Level-1B") == 0) {
637  ret.type = FT_L1HDF;
638  ret.sensor_id = MODIST;
640  if (want_verbose) {
641  printf("Input file %s is %s.\n", filename, title);
642  printf("\n\n *** WARNING: polarization can not be computed from generic format ***\n\n");
643  }
644  } else if (strcmp(title, "HMODISA Level-1B") == 0 || strcmp(title, "MODISA Level-1B") == 0) {
645  ret.type = FT_L1HDF;
646  ret.sensor_id = MODISA;
647  ret.subsensor_id = MODIS_AQUA;
648  if (want_verbose) {
649  printf("Input file %s is %s.\n", filename, title);
650  printf("\n\n *** WARNING: polarization can not be computed from generic format ***\n\n");
651  }
652  } else if (strcmp(title, "CZCS Level-1B") == 0) {
653  ret.type = FT_L1HDF;
654  ret.sensor_id = CZCS;
655  ret.subsensor_id = -1;
656  if (want_verbose) {
657  printf("Input file %s is %s.\n", filename, title);
658  }
659 
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);
663  return ret;
664  }
665  ret.type = FT_L1XCAL;
666  if (want_verbose) {
667  printf("Input file %s is %s.\n", filename, title);
668  }
669  } else if (strstr(title, "AVHRR") != NULL) {
670  ret.type = FT_CLASSAVHRR;
671  ret.sensor_id = AVHRR;
672  ret.subsensor_id = -1;
673  if (want_verbose) {
674  printf("Input file %s is %s.\n", filename, title);
675  }
676  } else {
677  fprintf(stderr, "-E- %s Line %d: Unrecognized title %s in input HDF file %s\n", __FILE__, __LINE__, title, filename);
678  return ret;
679  }
680 
681  } else if (SDreadattr(sd_id, SDfindattr(sd_id, "title"), (VOIDP) title) == 0) {
682 
683  if (strstr(title, "AVHRR") != NULL) {
684  ret.type = FT_CLASSAVHRR;
685  ret.sensor_id = AVHRR;
686  ret.subsensor_id = -1;
687  if (want_verbose) {
688  printf("Input file %s is %s.\n", filename, title);
689  }
690  }
691 
692  } else if (SDreadattr(sd_id, SDfindattr(sd_id, "satellite"), (VOIDP) title) == 0) {
693 
694  if (strstr(title, "oceansat-1") != NULL) {
695  ret.type = FT_OCML1BDB;
696  ret.sensor_id = OCM1;
697  ret.subsensor_id = -1;
698  if (want_verbose) {
699  printf("Input file %s is %s.\n", filename, "OCM1 DB file");
700  }
701  }
702 
703  /* Is it HDF-EOS L1B format? */
704 
705  } else if (SDreadattr(sd_id, SDfindattr(sd_id, "ArchiveMetadata.0"), (VOIDP) eosmeta) == 0) {
706 
707  if (strstr(eosmeta, "MODIS/Terra Calibrated Radiances 5-Min L1B Swath 1km") != NULL) {
708  ret.type = FT_HMODISL1B;
709  ret.sensor_id = MODIST;
711 
712  if (want_verbose) {
713  printf("Input file %s is MODIS Terra Level-1B HDF-EOS product.\n", filename);
714  }
715  return ret;
716  } else if (strstr(eosmeta, "MODIS/Aqua Calibrated Radiances 5-Min L1B Swath 1km") != NULL) {
717  ret.type = FT_HMODISL1B;
718  ret.sensor_id = MODISA;
719  ret.subsensor_id = MODIS_AQUA;
720 
721  if (want_verbose) {
722  printf("Input file %s is MODIS Aqua Level-1B HDF-EOS product.\n", filename);
723  }
724  return ret;
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);
727  return ret;
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);
730  return ret;
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);
733  return ret;
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);
736  return ret;
737  } else if (strstr(eosmeta, "MODIS/Aqua Geolocation Fields") != NULL) {
738  ret.type = FT_MODISGEO;
739  ret.sensor_id = MODISA;
740  ret.subsensor_id = MODIS_AQUA;
741  if (want_verbose) {
742  printf("Input file %s is MODIS Aqua Geolocation Fields.\n", filename);
743  }
744  } else if (strstr(eosmeta, "MODIS/Terra Geolocation Fields") != NULL) {
745  ret.type = FT_MODISGEO;
746  ret.sensor_id = MODIST;
748  if (want_verbose) {
749  printf("Input file %s is MODIS Terra Geolocation Fields.\n", filename);
750  }
751  } else {
752  fprintf(stderr, "-E- %s Line %d: Unrecognized HDF-EOS file %s\n", __FILE__, __LINE__, filename);
753  return ret;
754  }
755 
756  /* Is it MODIS IMAPP Direct Broadcast L1B */
757 
758  } else if (SDreadattr(sd_id, SDfindattr(sd_id, "ASSOCIATEDPLATFORMSHORTNAME"), (VOIDP) eosmeta) == 0) {
759  if (strstr(eosmeta, "Aqua") != NULL) {
760  ret.type = FT_MODISL1B;
761  ret.sensor_id = MODISA;
762  ret.subsensor_id = MODIS_AQUA;
763  if (want_verbose) {
764  printf("Input file %s is MODIS Aqua Level-1B IMAPP product.\n", filename);
765  }
766  } else if (strstr(eosmeta, "Terra") != NULL) {
767  ret.type = FT_MODISL1B;
768  ret.sensor_id = MODIST;
770  if (want_verbose) {
771  printf("Input file %s is MODIS Terra Level-1B IMAPP product.\n", filename);
772  }
773  } else {
774  fprintf(stderr, "-E- %s Line %d: Unrecognized IMAPP format %s\n", __FILE__, __LINE__, filename);
775  return ret;
776  }
777 
778  /* MISR */
779  } else if ((SDfindattr(sd_id, "Path_number") != -1) && (SDfindattr(sd_id, "SOM_parameters.som_ellipsoid.a") != -1)) {
780  ret.type = FT_MISR;
781  ret.sensor_id = MISR;
782 
783 
784  /* Is it MOS L1B HDF standard product? */
785 
786  } else if (GetFileDesc(filename) != NULL) {
787  ret.type = FT_MOSL1B;
788  ret.sensor_id = MOS;
789  ret.subsensor_id = -1;
790  if (want_verbose) {
791  printf("Input file %s is MOS Level-1B standard product.\n", filename);
792  }
793  } else {
794  fprintf(stderr, "-E- %s Line %d: Unrecognized input HDF file %s\n", __FILE__, __LINE__, filename);
795  return ret;
796  }
797 
798  SDend(sd_id);
799  } else {
800 
801  // check for OLCI, MSI and MERIS SAFE format - in case they specified the xml file
802  if ((ret = chk_safe_xml(filename)).type != FT_INVALID) {
803  return ret;
804  }
805 
806  /* check for SeaBASS? */
807  if ((ret = chk_seabass(filename)).type != FT_INVALID) {
808  if (want_verbose)
809  printf("Input file %s is a SeaBASS text file.\n", filename);
810  return ret;
811  }
812 
813  /* Is it MERIS? */
814  {
815  EPR_SProductId *product_id;
816 
819  if (product_id != NULL) {
820  if (product_id->id_string[8] == '1') { /* it is a level 1 file */
821  ret.type = FT_MERISL1B;
822  ret.sensor_id = MERIS;
823  ret.subsensor_id = -1;
824  if (want_verbose) {
825  printf("Input file %s is MERIS L1 file.\n", filename);
826  }
827  }
829  /*remember to close api (epr_close_api();)*/
830  return ret;
831  }
832  }
833 
834  // check for OLI
835  if ((ret = chk_oli(filename)).type != FT_INVALID) {
836  if (want_verbose) {
837  printf("Input file %s is a Landsat 8/9 OLI L1B GEOTIFF file.\n", filename);
838  }
839  return ret;
840  }
841 
842  // check for AVIRIS
843  char hdrfile[FILENAME_MAX], imgfile[FILENAME_MAX], navfile[FILENAME_MAX], gainfile[FILENAME_MAX];
844  if ((ret = chk_aviris(filename, hdrfile, imgfile, navfile, gainfile)).type != FT_INVALID) {
845  if (want_verbose) {
846  printf("Input file %s is an AVIRIS file.\n", filename);
847  }
848  return ret;
849  }
850 
851  // check for PRISM
852  if ((ret = chk_prism(filename)).type != FT_INVALID) {
853  if (want_verbose) {
854  printf("Input file %s is a PRISM file.\n", filename);
855  }
856  return ret;
857  }
858 
859  // check for Landsat 5 (L5TM)
860  if ((ret = chk_l5tm(filename)).type != FT_INVALID) {
861  if (want_verbose) {
862  printf("Input file %s is a Landsat 5 TM L1B GEOTIFF file.\n", filename);
863  }
864  return ret;
865  }
866 
867  // check for Landsat 7 (L7TM)
868  if ((ret = chk_l7etm(filename)).type != FT_INVALID) {
869  if (want_verbose) {
870  printf("Input file %s is a Landsat 7 TM L1B GEOTIFF file.\n", filename);
871  }
872  return ret;
873  }
874  }
875 
876  return ret;
877 }
878 
879 
880 file_format chk_oli(char *filename) {
881  /* ------------------------------------------------------------------------
882  chk_oli
883 
884  purpose: check a file to see if it is an OLI Landsat8/9 file
885 
886  Returns FT_INVALID if not OLI L1B or the format code
887 
888  Parameters: (in calling order)
889  Type Name I/O Description
890  ---- ---- --- -----------
891  char * filename I file to check
892  filehandle * file I input file information
893 
894  -----------------------------------------------------------------------*/
895  file_format ret = {FT_INVALID, -1, -1};
896  const int lineSize = 500;
897  int i;
898  FILE *fp;
899  char line[lineSize + 1];
900  char *result;
901 
902  /* Open file */
903  if ((fp = fopen(filename, "re")) == NULL) {
904  return ret;
905  }
906 
907  // skip blank lines
908  do {
909  result = fgets(line, lineSize, fp);
910  if (result == NULL) {
911  fclose(fp);
912  return ret;
913  }
914  trimBlanks(line);
915  } while (strlen(line) == 0);
916 
917  // first line needs to be "GROUP = L1_METADATA_FILE"
918  if (strstr(line, "L1_METADATA_FILE") == NULL && strstr(line, "LANDSAT_METADATA_FILE") == NULL) {
919  fclose(fp);
920  return ret;
921  }
922 
923  // within 60 lines look for:
924  // SPACECRAFT_ID = "LANDSAT_8/9"
925  // SENSOR_ID = "OLI"
926  int foundSpacecraft = 0;
927  int foundSensor = 0;
928  int isLandsat8 = 0;
929  int isLandsat9 = 0;
930  for (i = 0; i < 60; i++) {
931  result = fgets(line, lineSize, fp);
932  if (result == NULL) {
933  fclose(fp);
934  return ret;
935  }
936  if (strstr(line, "SPACECRAFT_ID")) {
937  if (strstr(line, "LANDSAT_8")) {
938  foundSpacecraft = 1;
939  isLandsat8 = 1;
940  }
941  else if (strstr(line, "LANDSAT_9")) {
942  foundSpacecraft = 1;
943  isLandsat9 = 1;
944  }
945  } else if (strstr(line, "SENSOR_ID")) {
946  if (strstr(line, "OLI")) {
947  foundSensor = 1;
948  }
949  }
950 
951  if (foundSpacecraft && foundSensor) {
952  ret.type = FT_OLIL1B;
953  if (isLandsat8) {
954  ret.subsensor_id = OLI_L8;
955  ret.sensor_id = OLIL8;
956  } else if (isLandsat9) {
957  ret.subsensor_id = OLI_L9;
958  ret.sensor_id = OLIL9;
959  }
960 
961  break;
962  }
963  }
964 
965  fclose(fp);
966  return ret;
967 }
968 
970  /* ------------------------------------------------------------------------
971  chk_oli_geo
972 
973  purpose: check a file to see if it is an OLI Landsat8/9 GEO file
974 
975  Returns FT_INVALID if not OLI L1B or the format code
976 
977  Parameters: (in calling order)
978  Type Name I/O Description
979  ---- ---- --- -----------
980  char * filename I file to check
981  filehandle * file I input file information
982 
983  -----------------------------------------------------------------------*/
984  file_format ret = {FT_INVALID, -1, -1};
985  const int lineSize = 500;
986  int i;
987  FILE *fp;
988  char line[lineSize + 1];
989  char *result;
990 
991  /* Open file */
992  if ((fp = fopen(filename, "re")) == NULL) {
993  return ret;
994  }
995 
996  // skip blank lines
997  do {
998  result = fgets(line, lineSize, fp);
999  if (result == NULL) {
1000  fclose(fp);
1001  return ret;
1002  }
1003  trimBlanks(line);
1004  } while (strlen(line) == 0);
1005 
1006  // first line needs to be "GROUP = FILE_HEADER"
1007  if (strstr(line, "FILE_HEADER") == NULL) {
1008  fclose(fp);
1009  return ret;
1010  }
1011 
1012  // within 60 lines look for:
1013  // SATELLITE = "LANDSAT_8/9"
1014  // BAND_LIST = ...
1015  int foundSpacecraft = 0;
1016  int foundBand = 0;
1017  for (i = 0; i < 60; i++) {
1018  result = fgets(line, lineSize, fp);
1019  if (result == NULL) {
1020  fclose(fp);
1021  return ret;
1022  }
1023  trimBlanks(line);
1024  if (strstr(line, "SATELLITE") || strstr(line, "SPACECRAFT_ID")) {
1025  if (strstr(line, "LANDSAT_8") || strstr(line, "LANDSAT_9")) {
1026  foundSpacecraft = 1;
1027  }
1028  } else if (strstr(line, "BAND_LIST")) {
1029  foundBand = 1;
1030  }
1031 
1032  if (foundSpacecraft && foundBand) {
1033  ret.type = FT_OLIL1B;
1034  break;
1035  }
1036  }
1037 
1038  fclose(fp);
1039  return ret;
1040 }
1041 
1051 file_format chk_prism(char *filename) {
1052  file_format ret = {FT_INVALID, -1, -1};
1053  const int lineSize = 500;
1054  FILE *fp;
1055  char line[lineSize + 1];
1056  char *result;
1057 
1058  if (strstr(filename, "prm") == NULL) {
1059  return ret;
1060  }
1061 
1062  /* Open file */
1063  if ((fp = fopen(filename, "re")) == NULL) {
1064  return ret;
1065  }
1066 
1067  // skip blank lines
1068  do {
1069  result = fgets(line, lineSize, fp);
1070  if (result == NULL) {
1071  fclose(fp);
1072  return ret;
1073  }
1074  trimBlanks(line);
1075  } while (strlen(line) == 0);
1076 
1077  // first line needs to be "ENVI"
1078  if (strstr(line, "ENVI") == NULL) {
1079  fclose(fp);
1080  return ret;
1081  }
1082 
1083  ret.type = FT_PRISM;
1084  ret.sensor_id = PRISM;
1085 
1086  fclose(fp);
1087  return ret;
1088 }
1089 
1099 file_format chk_aviris(char *filename, char *hdrfile, char *imgfile, char *navfile, char *gainfile) {
1100  file_format ret = {FT_INVALID, -1, -1};
1101  const int lineSize = 500;
1102  int i;
1103  FILE *fp;
1104  char line[lineSize + 1];
1105  char *result;
1106 
1107  if (!checkAvProcessFile(filename, hdrfile, imgfile, navfile, gainfile, FILENAME_MAX)) {
1108  strncpy(hdrfile, filename, FILENAME_MAX);
1109  } else {
1110  ret.type = FT_AVIRIS;
1111  ret.sensor_id = AVIRIS;
1112  return ret;
1113  }
1114 
1115  /* Open file */
1116  if ((fp = fopen(hdrfile, "re")) == NULL) {
1117  return ret;
1118  }
1119 
1120  // skip blank lines
1121  do {
1122  result = fgets(line, lineSize, fp);
1123  if (result == NULL) {
1124  fclose(fp);
1125  return ret;
1126  }
1127  trimBlanks(line);
1128  } while (strlen(line) == 0);
1129 
1130  // first line needs to be "ENVI"
1131  if (strstr(line, "ENVI") == NULL) {
1132  fclose(fp);
1133  return ret;
1134  }
1135 
1136  // within 20 lines look for:
1137  // AVIRIS orthocorrected
1138  int foundAviris = 0;
1139  int foundFormat = 0;
1140  int foundOrtho = 0;
1141  for (i = 0; i < 20; i++) {
1142  result = fgets(line, lineSize, fp);
1143  if (result == NULL) {
1144  fclose(fp);
1145  return ret;
1146  }
1147  trimBlanks(line);
1148  if (strstr(line, "AVIRIS")) {
1149  foundAviris = 1;
1150  }
1151  if (strstr(line, "orthocorrected")) {
1152  foundOrtho = 1;
1153  }
1154  if (strstr(line, "interleave")) {
1155  foundFormat = 1;
1156  }
1157 
1158  if (foundAviris && foundFormat && foundOrtho) {
1159  ret.type = FT_AVIRIS;
1160  ret.sensor_id = AVIRIS;
1161  break;
1162  }
1163  }
1164 
1165  fclose(fp);
1166  return ret;
1167 }
1168 
1169 file_format chk_l5tm(char *filename) {
1170  /* ------------------------------------------------------------------------
1171  chk_oli
1172 
1173  purpose: check a file to see if it is an OLI Landsat8 file
1174 
1175  Returns FT_INVALID if not OLI L1B or the format code
1176 
1177  Parameters: (in calling order)
1178  Type Name I/O Description
1179  ---- ---- --- -----------
1180  char * filename I file to check
1181  filehandle * file I input file information
1182 
1183  -----------------------------------------------------------------------*/
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  /* Open file */
1192  if ((fp = fopen(filename, "re")) == NULL) {
1193  return ret;
1194  }
1195 
1196  // skip blank lines
1197  do {
1198  result = fgets(line, lineSize, fp);
1199  if (result == NULL) {
1200  fclose(fp);
1201  return ret;
1202  }
1203  trimBlanks(line);
1204  } while (strlen(line) == 0);
1205 
1206  // first line needs to be "GROUP = L1_METADATA_FILE"
1207  if (strstr(line, "L1_METADATA_FILE") == NULL) {
1208  fclose(fp);
1209  return ret;
1210  }
1211 
1212  // within 20 lines look for:
1213  // SPACECRAFT_ID = "LANDSAT_5"
1214  // SENSOR_ID = "TM"
1215  int foundSpacecraft = 0;
1216  int foundSensor = 0;
1217  for (i = 0; i < 20; i++) {
1218  result = fgets(line, lineSize, fp);
1219  if (result == NULL) {
1220  fclose(fp);
1221  return ret;
1222  }
1223  trimBlanks(line);
1224  if (strstr(line, "SPACECRAFT_ID")) {
1225  if (strstr(line, "LANDSAT_5")) {
1226  foundSpacecraft = 1;
1227  }
1228  } else if (strstr(line, "SENSOR_ID")){
1229  if (strstr(line, "TM")) {
1230  foundSensor = 1;
1231  }
1232  }
1233 
1234  if (foundSpacecraft && foundSensor) {
1235  ret.type = FT_L5TML1B;
1236  ret.sensor_id = L5TM;
1237  break;
1238  }
1239  }
1240 
1241  fclose(fp);
1242  return ret;
1243 }
1244 
1246  /* ------------------------------------------------------------------------
1247  chk_l5tm_geo
1248 
1249  purpose: check a file to see if it is a Landsat 5 TM GEO file
1250 
1251  Returns FT_INVALID if not LS% L1B or the format code
1252 
1253  Parameters: (in calling order)
1254  Type Name I/O Description
1255  ---- ---- --- -----------
1256  char * filename I file to check
1257  filehandle * file I input file information
1258 
1259  -----------------------------------------------------------------------*/
1260  file_format ret = {FT_INVALID, -1, -1};
1261  const int lineSize = 500;
1262  int i;
1263  FILE *fp;
1264  char line[lineSize + 1];
1265  char *result;
1266 
1267  /* Open file */
1268  if ((fp = fopen(filename, "re")) == NULL) {
1269  return ret;
1270  }
1271 
1272  // skip blank lines
1273  do {
1274  result = fgets(line, lineSize, fp);
1275  if (result == NULL) {
1276  fclose(fp);
1277  return ret;
1278  }
1279  trimBlanks(line);
1280  } while (strlen(line) == 0);
1281 
1282  // first line needs to be "GROUP = FILE_HEADER"
1283  if (strstr(line, "FILE_HEADER") == NULL) {
1284  fclose(fp);
1285  return ret;
1286  }
1287 
1288  // within 20 lines look for:
1289  // SATELLITE = "LANDSAT_5" for now unconfirmed. Need to confirm this from actual
1290  // BAND_LIST = ... geoletry file if such things exists for Landsat 5.
1291  int foundSpacecraft = 0;
1292  int foundBand = 0;
1293  for (i = 0; i < 20; i++) {
1294  result = fgets(line, lineSize, fp);
1295  if (result == NULL) {
1296  fclose(fp);
1297  return ret;
1298  }
1299  trimBlanks(line);
1300  if (strstr(line, "SATELLITE")) {
1301  if (strstr(line, "LANDSAT_5")) {
1302  foundSpacecraft = 1;
1303  }
1304  } else if (strstr(line, "BAND_LIST")) {
1305  foundBand = 1;
1306  }
1307 
1308  if (foundSpacecraft && foundBand) {
1309  ret.type = FT_L5TML1B;
1310  break;
1311  }
1312  }
1313 
1314  fclose(fp);
1315  return ret;
1316 }
1317 
1318 file_format chk_l7etm(char *filename) {
1319  /* ------------------------------------------------------------------------
1320  chk_oli
1321 
1322  purpose: check a file to see if it is an OLI Landsat8 file
1323 
1324  Returns FT_INVALID if not OLI L1B or the format code
1325 
1326  Parameters: (in calling order)
1327  Type Name I/O Description
1328  ---- ---- --- -----------
1329  char * filename I file to check
1330  filehandle * file I input file information
1331 
1332  -----------------------------------------------------------------------*/
1333  file_format ret = {FT_INVALID, -1, -1};
1334  const int lineSize = 500;
1335  int i;
1336  FILE *fp;
1337  char line[lineSize + 1];
1338  char *result;
1339 
1340  /* Open file */
1341  if ((fp = fopen(filename, "re")) == NULL) {
1342  return ret;
1343  }
1344 
1345  // skip blank lines
1346  do {
1347  result = fgets(line, lineSize, fp);
1348  if (result == NULL) {
1349  fclose(fp);
1350  return ret;
1351  }
1352  trimBlanks(line);
1353  } while (strlen(line) == 0);
1354 
1355  // first line needs to be "GROUP = L1_METADATA_FILE"
1356  if (strstr(line, "L1_METADATA_FILE") == NULL) {
1357  fclose(fp);
1358  return ret;
1359  }
1360 
1361  // within 20 lines look for:
1362  // SPACECRAFT_ID = "LANDSAT_5"
1363  // SENSOR_ID = "TM"
1364  int foundSpacecraft = 0;
1365  int foundSensor = 0;
1366  for (i = 0; i < 20; i++) {
1367  result = fgets(line, lineSize, fp);
1368  if (result == NULL) {
1369  fclose(fp);
1370  return ret;
1371  }
1372  trimBlanks(line);
1373  if (strstr(line, "SPACECRAFT_ID")) {
1374  if (strstr(line, "LANDSAT_7")) {
1375  foundSpacecraft = 1;
1376  }
1377  } else if (strstr(line, "SENSOR_ID")){
1378  if (strstr(line, "ETM")) {
1379  foundSensor = 1;
1380  }
1381  }
1382 
1383  if (foundSpacecraft && foundSensor) {
1384  ret.type = FT_L7ETML1B;
1385  ret.sensor_id = L7ETMP;
1386  break;
1387  }
1388  }
1389 
1390  fclose(fp);
1391  return ret;
1392 }
1393 
1402 file_format chk_seabass(char *filename) {
1403 
1404  file_format ret = {FT_INVALID, -1, -1};
1405  FILE *fp;
1406 
1407  if ((fp = fopen(filename, "r")) == NULL) {
1408  fprintf(stderr, "-E- : input file %s does not exist or is read protected.\n", filename);
1409  return ret;
1410  }
1411 
1412 
1413  char buffer[2048];
1414  fgets(buffer, 2048-1, fp);
1415  if (strncmp(buffer, "/begin_header", 13) == 0) {
1416  ret.type = FT_SEABASSRRS;
1417 
1418  // Get delimiter
1419  // while(1) {
1420  // if (fgets(buffer, 2048-1, fp) == NULL) {
1421  // fprintf(stderr, "-E- : input SeaBASS file %s does not contain delimiter.\n", filename);
1422  // fclose(fp);
1423  // exit(1);
1424  // }
1425  // if (strncmp(buffer, "/delimiter=", 11) == 0) {
1426  // buffer[strcspn(buffer, "\n")] = 0;
1427  // strcpy(file->delimiter, &buffer[11]);
1428  // fclose(fp);
1429  // break;
1430  // }
1431  // }
1432 
1433  while (1) {
1434  fgets(buffer, 2048-1, fp);
1435  if (strncmp(buffer, "/end_header", 13) == 0) {
1436  break;
1437  } else if (strncmp(buffer, "/sensor=", 8) == 0) {
1438  for (int i=8;i<64;i++){
1439  if (buffer[i] == '\n'){
1440  buffer[i] = '\0';
1441  break;
1442  }
1443  }
1444  ret.sensor_id = sensorName2SensorId(&buffer[8]);
1446  break;
1447  }
1448  } // while loop
1449  }
1450 
1451  fclose(fp);
1452 
1453  return ret;
1454 }
int32_t subsensor_id
Definition: filetype.h:69
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:58
#define MODIS_AQUA
Definition: sensorDefs.h:58
int status
Definition: l1_czcs_hdf.c:32
@ FT_OCML1B
Definition: filetype.h:35
#define SPEXONE
Definition: sensorDefs.h:46
int instrumentPlatform2SensorId(const char *instrument, const char *platform)
Definition: sensorInfo.c:302
char * lowcase(char *instr)
Definition: lowcase.c:10
@ FT_OCML1BDB
Definition: filetype.h:36
@ 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:616
#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:55
#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
int sensorName2SensorId(const char *name)
Definition: sensorInfo.c:268
@ FT_SEAWIFSL1A
Definition: filetype.h:47
#define MERIS
Definition: sensorDefs.h:22
@ FT_VIIRSL1A
Definition: filetype.h:50
@ 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:67
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:37
#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:51
@ FT_HICOL1B
Definition: filetype.h:18
int sensorId2SubsensorId(int sensorId)
Definition: sensorInfo.c:322
#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:102
@ FT_VIIRSL1BNC
Definition: filetype.h:52
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:57
@ FT_SPEXONE
Definition: filetype.h:60
#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:54
#define L7ETMP
Definition: sensorDefs.h:36
int32_t sensor_id
Definition: filetype.h:68
@ FT_HARP2
Definition: filetype.h:61
@ FT_HKT
Definition: filetype.h:63
#define OCTS
Definition: sensorDefs.h:14
@ FT_SEABASSRRS
Definition: filetype.h:59
@ FT_OCM2L1B
Definition: filetype.h:34
#define MODIS_TERRA
Definition: sensorDefs.h:57
@ FT_GOCIL1B
Definition: filetype.h:17
@ FT_VIIRSGEONC
Definition: filetype.h:49
@ FT_MOSL1B
Definition: filetype.h:33
#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
@ FT_HMODISL1B
Definition: filetype.h:32
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:969
@ FT_SGLI
Definition: filetype.h:53
#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:1245
#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:634
int i
Definition: decode_rs.h:71
msiBandIdx val
Definition: l1c_msi.cpp:34
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
#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