OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1c_input.cpp
Go to the documentation of this file.
1 //******************************************
2 //l1c_input.cpp
3 // Created by Martin Montes on 10/21/20.
4 //****************************************
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <ctype.h>
10 #include <netcdf>
11 #include <unistd.h>
12 #include <string>
13 #include <vector>
14 #include <boost/algorithm/string.hpp>
15 #include <clo.h>
16 #include <filetype.h>
17 
18 using namespace std;
19 using namespace netCDF;
20 using namespace netCDF::exceptions;
21 
22 #include "l1c_input.h"
23 #include "genutils.h"
24 #include "passthebuck.h"
25 #include "sensorInfo.h"
26 #include "ncfileinfo.h"
27 
28 #include "l1c_filehandle.h"
29 
30 
31 // store the name of program we are running.
32 static char mainProgramName[50];
33 
34 
35 namespace l1c{
36 
37  static char *l1cgen_optionKeys[] = {
38  "-help",
39  "-version",
40  "-dump_options",
41  "-dump_options_paramfile",
42  "-dump_options_xmlfile",
43  "par",
44  "pversion",
45  "suite",
46  "l2prod",
47  "ifile",
48  "ofile",
49  "oformat",
50  "fqfile",
51  "parfile",
52  "spixl",
53  "epixl",
54  "sline",
55  "eline",
56  "calfile",
57  "xcalfile",
58  "gain",
59  "offset",
60  "sl_pixl",
61  "sl_frac",
62  "l1c_pflag",//l1c processing flag, 0: no processing, 1: full orbit (1 day),2: specific swath, 3: L1C grid creation, 4: granule processing
63  "binlatmin",
64  "binlatmax",
65  "binlonmin",
66  "binlonmax",
67  "selgran",//selected granules up to 10 files, they are ids not indexes!!
68  "selyear",//selected year
69  "selmon",//selected month
70  "selday", //selected day
71  "swtnum",//swath # for the processing day
72  "gres",//grid resolution in km
73  "nbinx",
74  "sensor",//SPEX 1, OCI 2 and HARP 3
75  "fileix",
76  "gransize",
77  "l1c_proj",//projection type,"swath_grid":0 (default-Fred) or "socea=1"
78  "terrain_correct",//terrain distortion correction , 1: yes
79  "cloud_correct",//cloud distortion correction , 1: yes
80  //multi attributes (view, pol, bands)
81  "overlap_vflag",//tells if we want merged views
82  "overlap_pflag",//tells if we want merged polarizations
83  "overlap_bflag",//tells if we want merged spectral bands
84  //uncertainty params l1c merged products
85  "unc_meth",//uncertainity calculation method
86  "unc_thres_v", //uncertainity threshold of angular merged products as %
87  "unc_thres_p",//same but for polarization
88  "unc_thres_b",//sam
89  NULL
90 };
91 
92 
93  L1C_input::L1C_input(){};//constructor
94  L1C_input::~L1C_input(){};
95 
96 
97 
98 int32_t L1C_input::l1c_usage(const char *prog,const char *ver) {
100 
101  list = clo_createList();
102  l1c_init_options(list, prog,ver);
104 
105  return 0;
106 }
107 
108 
109 int32_t L1C_input::l1c_init_options(clo_optionList_t* list, const char* prog, const char* version) {
110  char tmpStr[2048];
111  clo_option_t* option;
112 
113  if(strcmp(prog, "l1cgen")) clo_setSelectOptionKeys(l1cgen_optionKeys);
114 
115  // set the min program name
116  strcpy(mainProgramName, prog);
117 
118  sprintf(tmpStr, "Usage: %s argument-list\n\n", prog);
119  strcat(tmpStr, " The argument-list is a set of keyword=value pairs. The arguments can\n");
120  strcat(tmpStr, " be specified on the commandline, or put into a parameter file, or the\n");
121  strcat(tmpStr, " two methods can be used together, with commandline over-riding.\n\n");
122  strcat(tmpStr, " return value: 0=OK, 1=error, 110=north,south,east,west does not intersect\n");
123  strcat(tmpStr, " file data.\n\n");
124  strcat(tmpStr, "The list of valid keywords follows:\n");
125  clo_setHelpStr(tmpStr);
126 
127  // add the parfile alias for backward compatibility
128  clo_addOption(list, "parfile", CLO_TYPE_IFILE, NULL, "inititil settings");
129  clo_addAlias(list, "par", "parfile");
130 
131  strcpy(tmpStr, "input L1b file name");
132  option = clo_addOption(list, "ifile", CLO_TYPE_IFILE, NULL, tmpStr);
133  clo_addOptionAlias(option, "infile");
134 
135  clo_addOption(list, "ofile", CLO_TYPE_OFILE, "output", "output file name");
136 // clo_addOption(list, "fileuse", CLO_TYPE_OFILE, NULL, "write the filenames of the the input files used to this file");
137 
138  clo_addOption(list, "suite", CLO_TYPE_STRING, NULL, "suite for default parameters");
139  //clo_addOption(list, "qual_prod", CLO_TYPE_STRING, NULL, "quality product field name");
140 
141 // clo_addOption(list, "deflate", CLO_TYPE_INT, "5", "deflation level. 0=off or 1=low through 9=high");
142 
143  clo_addOption(list, "verbose", CLO_TYPE_BOOL, "off", "Allow more verbose screen messages");
144 // clo_addOption(list, "night", CLO_TYPE_BOOL, "off", "set to 1 for SST night processing");
145  //clo_addOption(list, "qual_max", CLO_TYPE_INT, "2", "maximum acceptable quality");
146  clo_addOption(list, "rowgroup", CLO_TYPE_INT, "-1", "# of bin rows to process at once.");
147  clo_addOption(list, "sday", CLO_TYPE_INT, "1970001", "start datadate (YYYYDDD) [ignored for \"regional\" prodtype]");
148  clo_addOption(list, "eday", CLO_TYPE_INT, "2038018", "end datadate (YYYYDDD) [ignored for \"regional\" prodtype]");
149  //clo_addOption(list, "latnorth", CLO_TYPE_FLOAT, "90", "northern most latitude");
150  //clo_addOption(list, "latsouth", CLO_TYPE_FLOAT, "-90", "southern most latitude");
151  //clo_addOption(list, "loneast", CLO_TYPE_FLOAT, "0", "eastern most longitude");
152  //clo_addOption(list, "lonwest", CLO_TYPE_FLOAT, "0", "western most longitude");
153  //clo_addOption(list, "minobs", CLO_TYPE_FLOAT, "0", "minimum observation to use.");
154 
155  strcpy(tmpStr, "bin resolution\n");
156  strcat(tmpStr, " H: 0.5km\n");
157  strcat(tmpStr, " Q: 250m\n");
158  strcat(tmpStr, " HQ: 100m\n");
159  strcat(tmpStr, " HH: 50m\n");
160  strcat(tmpStr, " 1: 1.1km\n");
161  strcat(tmpStr, " 2: 2.3km\n");
162  strcat(tmpStr, " 4: 4.6km\n");
163  strcat(tmpStr, " 9: 9.2km\n");
164  strcat(tmpStr, " 18: 18.5km\n");
165  strcat(tmpStr, " 36: 36km\n");
166  strcat(tmpStr, " 1D: 1 degree\n");
167  strcat(tmpStr, " HD: 0.5 degree\n");
168  strcat(tmpStr, " QD: 0.25 degree");
169  option = clo_addOption(list, "resolution", CLO_TYPE_STRING, "H", tmpStr);
170  clo_addOptionAlias(option, "resolve");
171 // clo_addOption(list, "prodtype", CLO_TYPE_STRING, "day", "product type (Set to \"regional\" to bin all scans.)");
172 // clo_addOption(list, "pversion", CLO_TYPE_STRING, "unspecified", "production version");
173 
174 // clo_addOption(list, "composite_scheme", CLO_TYPE_STRING, NULL, "composite scheme (min/max)");
175 // clo_addOption(list, "composite_prod", CLO_TYPE_STRING, NULL, "composite product fieldname");
176  strcpy(tmpStr, "flags masked [see /SENSOR/l2bin_defaults.par]");
177  // clo_addOption(list, "flaguse", CLO_TYPE_STRING, DEF_FLAG, tmpStr);
178 
179  strcpy(tmpStr, "l2prod = bin products [default=all products]\n");
180  strcat(tmpStr, " Set to \"ALL\" or \"all\" for all L2 products in 1st input file.\n");
181  strcat(tmpStr, " Use ':' or ',' or ' ' as delimiters.\n");
182  strcat(tmpStr, " Use ';' or '=' to delineate minimum values.\n");
183  clo_addOption(list, "l2prod", CLO_TYPE_STRING, "ALL", tmpStr);
184 
185 // clo_addOption(list, "area_weighting", CLO_TYPE_INT, "0", "Enable area weighting\n 0: off\n 1: pixel box\n 2: pixel bounding box\n 3: pixel polygon");
186 
187 
188 //l1c options--------------------------
189  //**************L1C options *****************************************
190  strcpy(tmpStr, "L1C processing flag\n");
191  strcat(tmpStr, " 1: L1C grid creation from L1B granules\n");
192  strcat(tmpStr, " 2: SBS binning\n");
193  strcat(tmpStr, " 3: weighted binning\n");
194  strcat(tmpStr, " 4: L2 processing\n");
195  strcat(tmpStr, " 5: L1C grid creation from HKT telemetry\n");
196 
197  clo_addOption(list, "l1c_pflag", CLO_TYPE_INT, "0", tmpStr);
198 
199  strcpy(tmpStr, "L1C grid min binning latitude\n");
200  clo_addOption(list, "binlatmin", CLO_TYPE_FLOAT, "-90", tmpStr);
201  strcpy(tmpStr, "L1C grid max binning latitude\n");
202  clo_addOption(list, "binlatmax", CLO_TYPE_FLOAT, "+90", tmpStr);
203  strcpy(tmpStr, "L1C grid min binning longitude\n");
204  clo_addOption(list, "binlonmin", CLO_TYPE_FLOAT, "-180", tmpStr);
205  strcpy(tmpStr, "L1C grid max binning longitude\n");
206  clo_addOption(list, "binlonmax", CLO_TYPE_FLOAT, "+180", tmpStr);
207 
208  strcpy(tmpStr, "L1C processing of granules\n");
209  strcpy(tmpStr, "granule id (1 to 10) note: not indexes!\n");
210  clo_addOption(list, "selgran", CLO_TYPE_INT, "[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]", tmpStr);
211 
212  strcpy(tmpStr, "Index L1C product [0,0,0]\n");
213  strcat(tmpStr, " 0: pc\n");
214  strcat(tmpStr, " 1: vsf\n");
215  strcat(tmpStr, " 2: dpr\n");
216  clo_addOption(list, "ix_l1cprod", CLO_TYPE_INT, "[0,0,0]", tmpStr);
217 
218  strcpy(tmpStr, "Day of the year for processing L1C swath\n");
219  strcat(tmpStr, " units in day number (1-365/366)\n");
220  clo_addOption(list, "selday", CLO_TYPE_INT, "-1", tmpStr);
221 
222  strcpy(tmpStr, "Month of the year for processing L1C swath\n");
223  strcat(tmpStr, " units in month number (1-12)\n");
224  clo_addOption(list, "selmon", CLO_TYPE_INT, "-1", tmpStr);
225 
226  strcpy(tmpStr, "Year for processing L1C swath\n");
227  strcat(tmpStr, " units in year\n");
228  clo_addOption(list, "selyear", CLO_TYPE_INT, "-1", tmpStr);
229 
230  strcpy(tmpStr, "Swath id\n");
231  strcat(tmpStr, " units in swath number\n");
232  clo_addOption(list, "swtnum", CLO_TYPE_INT, "1", tmpStr);
233 //******************************************************************
234  strcpy(tmpStr, "Common grid resolution\n");
235  strcat(tmpStr, " units in km\n");
236  clo_addOption(list, "gres", CLO_TYPE_FLOAT, "5.2", tmpStr);
237 
238  strcpy(tmpStr, "Common grid across bins\n");
239  strcat(tmpStr, " OCI: 514, SPEXone: 40, HARP: 600\n");
240  clo_addOption(list, "nbinx", CLO_TYPE_INT, "514", tmpStr);
241 
242  strcpy(tmpStr, "PACE sensor to be gridded\n");
243  strcat(tmpStr, " SPEXone: 1, OCI: 2, HARP: 3\n");
244  clo_addOption(list, "sensor", CLO_TYPE_INT, "514", tmpStr);
245 
246  strcpy(tmpStr, "file index L1A--HKT\n");
247  strcat(tmpStr, " 0-unlimited\n");
248  clo_addOption(list, "fileix", CLO_TYPE_INT, "0", tmpStr);
249 
250  strcpy(tmpStr, "granule size for telemetry-derived L1C files\n");
251  strcat(tmpStr, " in minutes--5' by default\n");
252  clo_addOption(list, "gransize", CLO_TYPE_INT, "0", tmpStr);
253 
254  strcpy(tmpStr, "Projection type\n");
255  strcat(tmpStr, " 0: SOCEA\n");
256  strcat(tmpStr, " 1: SOCEA-2\n");
257  clo_addOption(list, "l1c_proj", CLO_TYPE_INT, "0", tmpStr);
258 
259  strcpy(tmpStr, "Terrain correct flag\n");
260  strcat(tmpStr, " DEM correction\n");
261  strcat(tmpStr, " 0: off\n");
262  strcat(tmpStr, " 1: on\n");
263  clo_addOption(list, "terrain_correct", CLO_TYPE_INT, "0", tmpStr);
264 
265  strcpy(tmpStr, "Cloud correct flag\n");
266  strcat(tmpStr, " Cloud height correction\n");
267  strcat(tmpStr, " 0: off\n");
268  strcat(tmpStr, " 1: on\n");
269  clo_addOption(list, "cloud_correct", CLO_TYPE_INT, "0", tmpStr);
270 
271  strcpy(tmpStr, "overlap views flag\n");
272  strcat(tmpStr, " 0: off\n");
273  strcat(tmpStr, " 1: on\n");
274  clo_addOption(list, "overlap_vflag", CLO_TYPE_INT, "0", tmpStr);
275 
276  strcpy(tmpStr, "overlap polarizations flag\n");
277  strcat(tmpStr, " 0: off\n");
278  strcat(tmpStr, " 1: on\n");
279  clo_addOption(list, "overlap_pflag", CLO_TYPE_INT, "0", tmpStr);
280 
281  strcpy(tmpStr, "overlap spectral bands flag\n");
282  strcat(tmpStr, " 0: off\n");
283  strcat(tmpStr, " 1: on\n");
284  clo_addOption(list, "overlap_bflag", CLO_TYPE_INT, "0", tmpStr);
285 
286 
287  strcpy(tmpStr, "Uncertainty calculation method\n");
288  strcat(tmpStr, " 0: error propagation\n");
289  strcat(tmpStr, " 1: Monte Carlo\n");
290  clo_addOption(list, "unc_meth", CLO_TYPE_INT, "0", tmpStr);
291 
292  strcpy(tmpStr, "Uncertainty threshold for angular merged product\n");
293  strcat(tmpStr, " as percentage\n");
294  clo_addOption(list, "unc_thres_v", CLO_TYPE_FLOAT, "10", tmpStr);
295 
296  strcpy(tmpStr, "Uncertainty threshold for polarization merged product\n");
297  strcat(tmpStr, " as percentage\n");
298  clo_addOption(list, "unc_thres_p", CLO_TYPE_FLOAT, "10", tmpStr);
299 
300  strcpy(tmpStr, "Uncertainty threshold for spectral bands merged product\n");
301  strcat(tmpStr, " as percentage\n");
302  clo_addOption(list, "unc_thres_b", CLO_TYPE_FLOAT, "10", tmpStr);
303 
304  //*************************************************************************-
305 
306 
308  return 0;
309 }
310 
311 
312 //copy input info from list into instr structure
314  char *tmp_str;
315  char keyword[50];
316  char *parm_str;
317  char tmp_file[FILENAME_MAX];
318  int numOptions, optionId;
319  clo_option_t *option;
320 // L1C_input *l1ccli;
321  int *iArray;
322  int count=-1;
323 
324  numOptions = clo_getNumOptions(list);
325  for (optionId = 0; optionId < numOptions; optionId++) {
326  option = clo_getOption(list, optionId);
327 
328  // ignore options of type CLO_TYPE_HELP
329  if (option->dataType == CLO_TYPE_HELP)
330  continue;
331 
332  strcpy(keyword, option->key);
333 
334  /* change keyword to lower case */
335  tmp_str = keyword;
336  while (*tmp_str != '\0') {
337  if (isupper(*tmp_str)) *tmp_str = tolower(*tmp_str);
338  tmp_str++;
339  }
340 
341  if (strcmp(keyword, "help") == 0) {
342  }
343  else if (strcmp(keyword, "version") == 0) {
344  }
345  else if (strncmp(keyword, "dump_options", 12) == 0) {
346  }
347  else if (strncmp(keyword, "par", 3) == 0) {
348  }
349  else if (strcmp(keyword, "ifile") == 0) {
350  if (clo_isOptionSet(option)) {
351  parm_str = clo_getOptionString(option);
352  parse_file_name(parm_str, tmp_file);
353  strcpy(l1ccli->infile, tmp_file);
354  }
355  } else if (strcmp(keyword, "ofile") == 0) {
356  if (clo_isOptionSet(option)) {
357  parm_str = clo_getOptionString(option);
358  parse_file_name(parm_str, tmp_file);
359  strcpy(l1ccli->ofile, tmp_file);
360  }
361  }
362 
363 /* else if (strcmp(keyword, "fileuse") == 0) {
364  if (clo_isOptionSet(option)) {
365  parm_str = clo_getOptionString(option);
366  parse_file_name(parm_str, tmp_file);
367  strcpy(input->fileuse, tmp_file);
368  }
369  }
370 */
371  else if (strcmp(keyword, "sday") == 0) {
372  if (clo_isOptionSet(option))
373  l1ccli->sday = clo_getOptionInt(option);
374 
375  } else if (strcmp(keyword, "eday") == 0) {
376  if (clo_isOptionSet(option))
377  l1ccli->eday = clo_getOptionInt(option);
378 
379  } else if (strcmp(keyword, "resolution") == 0) {
380  parm_str = clo_getOptionString(option);
381  parse_file_name(parm_str, tmp_file);
382  strcpy(l1ccli->resolve, tmp_file);
383 
384  } else if (strcmp(keyword, "rowgroup") == 0) {
385  l1ccli->rowgroup = clo_getOptionInt(option);
386 
387  }
388 /*
389  else if (strcmp(keyword, "flaguse") == 0) {
390  string flags = clo_getOptionRawString(option);
391  boost::replace_all(flags, "default", DEF_FLAG);
392  strcpy(input->flaguse, flags.c_str());
393  }
394  */
395  else if (strcmp(keyword, "l2prod") == 0) {
396  parm_str = clo_getOptionRawString(option);
397  strcpy(l1ccli->l2prod, parm_str);
398 
399  }
400 
401  /*
402  else if (strcmp(keyword, "prodtype") == 0) {
403  parm_str = clo_getOptionString(option);
404  strcpy(input->prodtype, parm_str);
405  }
406  else if (strcmp(keyword, "pversion") == 0) {
407  parm_str = clo_getOptionString(option);
408  strcpy(input->pversion, parm_str);
409 
410  }
411  */
412  else if (strcmp(keyword, "suite") == 0) {
413  if (clo_isOptionSet(option)) {
414  parm_str = clo_getOptionString(option);
415  strcpy(l1ccli->suite, parm_str);
416  }
417  }
418  /*
419  else if (strcmp(keyword, "latsouth") == 0) {
420  input->latsouth = clo_getOptionFloat(option);
421 
422  } else if (strcmp(keyword, "latnorth") == 0) {
423  input->latnorth = clo_getOptionFloat(option);
424 
425  } else if (strcmp(keyword, "lonwest") == 0) {
426  input->lonwest = clo_getOptionFloat(option);
427 
428  } else if (strcmp(keyword, "loneast") == 0) {
429  input->loneast = clo_getOptionFloat(option);
430 
431  } else if (strcmp(keyword, "meminfo") == 0) {
432  input->meminfo = clo_getOptionInt(option);
433 
434  } else if (strcmp(keyword, "dcinfo") == 0) {
435  input->dcinfo = clo_getOptionInt(option);
436 
437  } else if (strcmp(keyword, "night") == 0) {
438  input->night = clo_getOptionBool(option);
439 
440  }
441 */
442  else if (strcmp(keyword, "verbose") == 0) {
443  l1ccli->verbose = clo_getOptionBool(option);
444 
445  }
446  /* else if (strcmp(keyword, "minobs") == 0) {
447  input->minobs = clo_getOptionFloat(option);
448 
449  } else if (strcmp(keyword, "deflate") == 0) {
450  input->deflate = clo_getOptionInt(option);
451 
452  } else if (strcmp(keyword, "qual_max") == 0) {
453  input->qual_max = (uint8_t) clo_getOptionInt(option);
454 
455  } else if (strcmp(keyword, "qual_prod") == 0) {
456  if (clo_isOptionSet(option)) {
457  parm_str = clo_getOptionString(option);
458  parse_file_name(parm_str, tmp_file);
459  strcpy(input->qual_prod, tmp_file);
460  }
461 
462  } else if (strcmp(keyword, "composite_prod") == 0) {
463  if (clo_isOptionSet(option)) {
464  parm_str = clo_getOptionString(option);
465  parse_file_name(parm_str, tmp_file);
466  strcpy(input->composite_prod, tmp_file);
467  }
468  } else if (strcmp(keyword, "composite_scheme") == 0) {
469  if (clo_isOptionSet(option)) {
470  parm_str = clo_getOptionString(option);
471  parse_file_name(parm_str, tmp_file);
472  strcpy(input->composite_scheme, tmp_file);
473  }
474  } else if (strcmp(keyword, "area_weighting") == 0) {
475  if (clo_isOptionSet(option)) {
476  input->area_weighting = clo_getOptionInt(option);
477  } else {
478  input->area_weighting = 0;
479  }
480  }
481  */
482  //L1C new options-----------------------------------------
483  else if (strcmp(keyword, "l1c_pflag") == 0) {
484  l1ccli->l1c_pflag = clo_getOptionInt(option);
485  }
486  else if (strcmp(keyword, "binlatmin") == 0) {
487  l1ccli->binlatmin = clo_getOptionFloat(option);
488  }
489  else if (strcmp(keyword, "binlatmax") == 0) {
490  l1ccli->binlatmax = clo_getOptionFloat(option);
491  }
492  else if (strcmp(keyword, "binlonmin") == 0) {
493  l1ccli->binlonmin = clo_getOptionFloat(option);
494  }
495  else if (strcmp(keyword, "binlonmax") == 0) {
496  l1ccli->binlonmax = clo_getOptionFloat(option);
497  }
498  else if (strcmp(keyword, "selgran") == 0) {
499  iArray = clo_getOptionInts(option, &count);
500  if (count<=10){
501  for (int i = 0; i < count; i++){
502  if(iArray[i]<=10) l1ccli->selgran[i] = iArray[i];
503  else{ printf("-E- %s: Granule Id cant be larger than 10.\n", __FILE__);exit(1);}
504  }
505  }
506  else{ printf("-E- %s: Max number of granules to be processed is 10.\n", __FILE__);exit(1);}
507  }
508  else if (strcmp(keyword, "ix_l1cprod") == 0) {
509  iArray = clo_getOptionInts(option, &count);
510  for (int i = 0; i < count; i++)
511  l1ccli->ix_l1cprod[i] = iArray[i];
512  }
513 
514  else if (strcmp(keyword, "gres") == 0) {
515  l1ccli->gres = clo_getOptionFloat(option);
516  }
517  else if (strcmp(keyword, "nbinx") == 0) {
518  l1ccli->nbinx = clo_getOptionInt(option);
519  }
520  else if (strcmp(keyword, "fileix") == 0) {
521  l1ccli->fileix = clo_getOptionInt(option);
522  }
523  else if (strcmp(keyword, "sensor") == 0) {
524  l1ccli->sensor = clo_getOptionInt(option);
525  }
526  else if (strcmp(keyword, "gransize") == 0) {
527  l1ccli->gransize = clo_getOptionInt(option);
528  }
529 
530  else if (strcmp(keyword, "selday") == 0) {
531  l1ccli->selday = clo_getOptionInt(option);
532  }
533  else if (strcmp(keyword, "selmon") == 0) {
534  l1ccli->selmon = clo_getOptionInt(option);
535  }
536  else if (strcmp(keyword, "selyear") == 0) {
537  l1ccli->selyear = clo_getOptionInt(option);
538  }
539  else if (strcmp(keyword, "swtnum") == 0) {
540  l1ccli->swtnum = clo_getOptionInt(option);
541  }
542 
543  else if (strcmp(keyword, "l1c_proj") == 0) {
544  l1ccli->l1c_proj = clo_getOptionInt(option);
545  }
546  else if (strcmp(keyword, "terrain_correct") == 0) {
547  l1ccli->terrain_correct = clo_getOptionInt(option);
548  }
549  else if (strcmp(keyword, "cloud_correct") == 0) {
550  l1ccli->cloud_correct = clo_getOptionInt(option);
551  }
552  else if (strcmp(keyword, "overlap_vflag") == 0) {
553  l1ccli->overlap_vflag = clo_getOptionInt(option);
554  }
555  else if (strcmp(keyword, "overlap_pflag") == 0) {
556  l1ccli->overlap_pflag = clo_getOptionInt(option);
557  }
558  else if (strcmp(keyword, "overlap_bflag") == 0) {
559  l1ccli->overlap_bflag = clo_getOptionInt(option);
560  }
561  else if (strcmp(keyword, "unc_meth") == 0) {
562  l1ccli->unc_meth = clo_getOptionInt(option);
563  }
564  else if (strcmp(keyword, "unc_thres_v") == 0) {
565  l1ccli->unc_thres_v = clo_getOptionFloat(option);
566  }
567  else if (strcmp(keyword, "unc_thres_p") == 0) {
568  l1ccli->unc_thres_p = clo_getOptionFloat(option);
569  }
570  else if (strcmp(keyword, "unc_thres_b") == 0) {
571  l1ccli->unc_thres_b = clo_getOptionFloat(option);
572  }
573  else {
574  printf("-E- Invalid argument \"%s\"\n", keyword);
575  clo_dumpOption(option);
576  exit(1);
577  }
578 
579  }//end for
580 
581  return 0;
582 
583 // delete l1ccli;
584 
585 
586 
587 
588 }
589 
590 
591 
592 //it is called by l1c_input method
593 //init defaults, makes sense?
595  // L1C_input *l1ccli;
596 
597  l1ccli->infile[0] = '\0';
598  l1ccli->ofile[0] = '\0';
599 // l1ccli->pfile[0] = '\0';
600 
601 // input_str->fileuse[0] = '\0';
602 // input_str->qual_prod[0] = '\0';
603 // input_str->composite_prod[0] = '\0';
604 // input_str->composite_scheme[0] = '\0';
605 
606 // strcpy(input_str->pversion, "Unspecified");
607 // strcpy(input_str->prodtype, "day");
608 
609 // strcpy(l1ccli->l3bprod, "ALL");
610 
611  l1ccli->sday = 1970001;
612  l1ccli->eday = 2038018;
613 
614  l1ccli->resolve[0] = '\0';
615 
616  l1ccli->rowgroup = -1;
617 
618 // input_str->night = 0;
619  l1ccli->verbose = 0;
620 // input_str->minobs = 0;
621 
622 // input_str->meminfo = 0;
623 // input_str->dcinfo = 0;
624 
625 // input_str->latsouth = -90.0;
626 // input_str->latnorth = +90.0;
627 // input_str->lonwest = 0.0;
628 // input_str->loneast = 0.0;
629 
630 // input_str->qual_max = 255;
631 
632 // l1ccli->deflate = 0;
633 
634  strcpy(l1ccli->suite, "");
635  strcpy(l1ccli->l2prod, "");
636 
637 // l1ccli->area_weighting = 0;
638  //l1c additional input parameters--
639 
640  //all_l1cprod[MAXPRODl1c][50]={"","",""};//string length rather than number of strings
641  for (int i=0;i<3;i++) {
642  l1ccli->ix_l1cprod[i]=0;
643  } //3x1 array with selected l1c products, 1: selected
644  l1ccli->l1c_pflag=0;//l1c processing flag, 0: no, 1: yes
645  l1ccli->binlatmin=-90;//latitude in degrees
646  l1ccli->binlatmax=90;
647  l1ccli->binlonmin=-180;
648  l1ccli->binlonmax=180;
649 
650  for (int i=0;i<10;i++) {
651  l1ccli->selgran[i]=-1;//first file of the list
652  }
653  l1ccli->swtnum=1;
654  l1ccli->gres=5.2;//grid resolution in km
655  l1ccli->nbinx=514;
656  l1ccli->sensor=2;//1 SPEX, 2 OCI and 3 HARP
657  l1ccli->fileix=0;
658  l1ccli->gransize=5;//in minutes
659  l1ccli->selyear=-1;
660  l1ccli->selmon=-1;
661  l1ccli->selday=-1;
662  l1ccli->lat0=0.0;//reference latitude pole rotation SOCEA
663  l1ccli->l1c_proj=-1;//projection type,"swath_grid":0 or "socea=1"
664  l1ccli->terrain_correct=0;//terrain distortion correction , 1: yes
665  l1ccli->cloud_correct=0;//cloud distortion correction , 1: yes
666  //multi attributes (view, pol, bands)
667  l1ccli->overlap_vflag=0;//tells if we want merged views
668  l1ccli->overlap_pflag=0;//tells if we want merged polarizations
669  l1ccli->overlap_bflag=0;//tells if we want merged spectral bands
670  //uncertainty params l1c merged products
671  l1ccli->unc_meth=0;//uncertainity calculation method
672  l1ccli->unc_thres_v=-999.0; //uncertainity threshold of angular merged products as %
673  l1ccli->unc_thres_p=-999.0;//same but for polarization
674  l1ccli->unc_thres_b=-999.0;//same but for multispectral products, same view and polarization
675 
676  return 0;
677 }
678 
679 
680 
681 /*-----------------------------------------------------------------------------
682  Function: l1c_input
683 
684  Returns: int (status)
685  The return code is a negative value if any error occurs, otherwise,
686  returns 0.
687 
688  Description:
689  Convert the arguments from the command line into a structure input
690  variable.
691 
692  Parameters: (in calling order)
693  Type Name I/O Description
694  ---- ---- --- -----------
695  int argc I number of arguments
696  char **argv I list of arguments
697  instr input O structure variable for inputs
698 
699 ----------------------------------------------------------------------------*/
700 
701 int32_t L1C_input::l1c_inputmain(int argc, char **argv, L1C_input *l1cinput,l1c_filehandle *l1cfile,const char* prog, const char* version) {
702 
703 // char str_buf[4096];
704  char *dataRoot;
705  // int sensorId;
706 // int subsensorId = -1;
707 // char localSuite[FILENAME_MAX];
708  char localIfile[FILENAME_MAX];
709  char *ifile;
710  string ifile_str;
711 
712 
713  /* hold all of the command line options */
715 
716  list = clo_createList();
717 
718  /* initialize the option list with descriptions and default values */
719  l1c_init_options(list, prog, version);
720 
721  if (argc == 1) {
723  exit(1);
724  }
725 
726  // disable the dump option until we have read all of the files
728  clo_readArgs(list, argc, argv);
729 
730  if (l1c_input_init(l1cinput) != 0) {
731  printf("-E- %s: Error initializing l1c input structure.\n", __FILE__);
732  return (-1);
733  }
734 
735 
736 
737  // get list of input files
738  strcpy(localIfile, clo_getString(list, "ifile"));
739  l1cinput->files = ncfiles(localIfile); //files stored in a vector container in input struc
740  if (l1cinput->files.size() == 0) {
741  printf("No NetCDF input files found in %s.\n", localIfile);
742  exit(EXIT_FAILURE);
743  }
744 
745  cout<<"l1cinput->files[0].."<<l1cinput->files[0]<<endl;
746 
747  ifile_str = l1cinput->files[0];
748  ifile=&ifile_str[0];
749 
750  //strcpy(l1cfile->name,ifile_str.c_str());
751 
752 
753  cout<<"ifile.."<<ifile<<endl;
754  file_format format = getFormat(ifile);//reading from a nc file ---
755 
756  printf("format.type....%d..",format.type);
757  printf("sensor id.....%d..",format.sensor_id);
758 
759  //harp
760  // format.type=FT_HARP;
761  l1cfile->format=format.type;
762  // format.sensor_id=34;
763 
764  cout<<"sensor id.."<<format.sensor_id<<"sensor name.."<<sensorId2SensorName(format.sensor_id)<<endl;
765 
766  // printf("so far so good after getformat in l2gen_read_options");
767  if (format.type == FT_INVALID) {
768  printf("-E- %s Line %d: Could not find type for file %s.\n", __FILE__, __LINE__, ifile);
769  // cout<<"forcing to be HARP2 when HARP2 L1B is beta from Meng/Richard"<<endl;
770  // format.type=FT_HARP2;
771  // return 0;
772  return (-1);
773  }
774 
775  if (format.sensor_id == -1) {
776  printf("-E- Can not look up sensor ID for PLEASE PROVIDE PLATFORM FOR OCIS--!! %s.\n ", localIfile);
777  cout<<"forcing to be HARP2 when HARP2 L1B is beta from Meng/Richard"<<endl;
778  // format.sensor_id=33;
779  // return 0;
780  return (1);
781  }
782 
783  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
784  printf("OCDATAROOT environment variable is not defined.\n");
785  return (1);
786  }
787 
788 
789  // re-load the command line and par file
790 
792  clo_readArgs(list, argc, argv);
793 
794  // re-load the command line and par file
795  if (want_verbose) printf("Loading command line parameters for L1C processing\n\n");
796  // load input struct with command line arguments
797  if (l1c_load_input(list,l1cinput) != 0) {
798  printf("-E- %s: Error loading options into input structure.\n", __FILE__);
799  return (-1);
800  }
801 
802 
803 
804  //metadata off for now
805 
806 
807  /* */
808  /* Build string of parameters for metadata */
809  /*
810 
811  sprintf(str_buf, "infile = %s\n", input->infile);
812  strcat(input->parms, str_buf);
813  sprintf(str_buf, "ofile = %s\n", input->ofile);
814  strcat(input->parms, str_buf);
815  sprintf(str_buf, "fileuse = %s\n", input->fileuse);
816  strcat(input->parms, str_buf);
817 
818  sprintf(str_buf, "sday = %d\n", input->sday);
819  strcat(input->parms, str_buf);
820  sprintf(str_buf, "eday = %d\n", input->eday);
821  strcat(input->parms, str_buf);
822 
823  sprintf(str_buf, "latnorth = %f\n", input->latnorth);
824  strcat(input->parms, str_buf);
825  sprintf(str_buf, "latsouth = %f\n", input->latsouth);
826  strcat(input->parms, str_buf);
827  sprintf(str_buf, "loneast = %f\n", input->loneast);
828  strcat(input->parms, str_buf);
829  sprintf(str_buf, "lonwest = %f\n", input->lonwest);
830  strcat(input->parms, str_buf);
831 
832  sprintf(str_buf, "resolve = %s\n", input->resolve);
833  strcat(input->parms, str_buf);
834 
835  sprintf(str_buf, "rowgroup = %d\n", input->rowgroup);
836  strcat(input->parms, str_buf);
837 
838  sprintf(str_buf, "flaguse = %s\n", input->flaguse);
839  strcat(input->parms, str_buf);
840 
841  sprintf(str_buf, "l3bprod = %s\n", input->l3bprod);
842  strcat(input->parms, str_buf);
843 
844  sprintf(str_buf, "prodtype = %s\n", input->prodtype);
845  strcat(input->parms, str_buf);
846 
847  sprintf(str_buf, "pversion = %s\n", input->pversion);
848  strcat(input->parms, str_buf);
849 
850  sprintf(str_buf, "suite = %s\n", input->suite);
851  strcat(input->parms, str_buf);
852 
853  sprintf(str_buf, "night = %d\n", input->night);
854  strcat(input->parms, str_buf);
855 
856  sprintf(str_buf, "verbose = %d\n", input->verbose);
857  strcat(input->parms, str_buf);
858 
859  sprintf(str_buf, "minobs = %d\n", input->minobs);
860  strcat(input->parms, str_buf);
861 
862  sprintf(str_buf, "deflate = %d\n", input->deflate);
863  strcat(input->parms, str_buf);
864 
865  sprintf(str_buf, "qual_prod = %s\n", input->qual_prod);
866  strcat(input->parms, str_buf);
867 
868  sprintf(str_buf, "composite_prod = %s\n", input->composite_prod);
869  strcat(input->parms, str_buf);
870 
871  sprintf(str_buf, "composite_scheme = %s\n", input->composite_scheme);
872  strcat(input->parms, str_buf);
873 
874  sprintf(str_buf, "qual_max = %d\n", input->qual_max);
875  strcat(input->parms, str_buf);
876 
877  strcat(input->parms, str_buf);
878 
879  */
880 
881 // delete l1ccli;
883 
884  return 0;
885 }
886 
887 }//close namespace
clo_option_t * clo_addOption(clo_optionList_t *list, const char *key, enum clo_dataType_t dataType, const char *defaultVal, const char *desc)
Definition: clo.c:684
int32_t terrain_correct
Definition: l1c_input.h:101
float clo_getOptionFloat(clo_option_t *option)
Definition: clo.c:1167
int32_t l1c_input_init(L1C_input *l1cinput)
int32_t l1c_load_input(clo_optionList_t *list, L1C_input *l1cinput)
char * clo_getString(clo_optionList_t *list, const char *key)
Definition: clo.c:1357
void clo_readArgs(clo_optionList_t *list, int argc, char *argv[])
Definition: clo.c:2103
list(APPEND LIBS ${PGSTK_LIBRARIES}) add_executable(atteph_info_modis atteph_info_modis.c) target_link_libraries(atteph_info_modis $
Definition: CMakeLists.txt:7
vector< string > ncfiles(const char *filepath)
Definition: ncfileinfo.cpp:21
int32_t eday
Definition: l1c_input.h:53
char l2prod[2048]
Definition: l1c_input.h:42
#define NULL
Definition: decode_rs.h:63
char resolve[4]
Definition: l1c_input.h:54
char * key
Definition: clo.h:104
int32_t sday
Definition: l1c_input.h:52
void clo_addAlias(clo_optionList_t *list, const char *key, const char *alias)
Definition: clo.c:646
int16_t selgran[10]
Definition: l1c_input.h:88
char * clo_getOptionRawString(clo_option_t *option)
Definition: clo.c:1030
float binlonmax
Definition: l1c_input.h:78
float unc_thres_p
Definition: l1c_input.h:110
float binlatmax
Definition: l1c_input.h:76
int32_t fileix
Definition: l1c_input.h:82
int32_t swtnum
Definition: l1c_input.h:97
int clo_getOptionInt(clo_option_t *option)
Definition: clo.c:1113
int32_t selday
Definition: l1c_input.h:94
@ CLO_TYPE_FLOAT
Definition: clo.h:81
int32_t gransize
Definition: l1c_input.h:83
int32_t l1c_usage(const char *prog, const char *version)
int32_t overlap_pflag
Definition: l1c_input.h:105
int clo_isOptionSet(clo_option_t *option)
Definition: clo.c:2257
@ CLO_TYPE_BOOL
Definition: clo.h:78
int32_t l1c_proj
Definition: l1c_input.h:100
int32_t l1c_init_options(clo_optionList_t *list, const char *prog, const char *version)
void clo_setSelectOptionKeys(char **keys)
Definition: clo.c:514
int32_t ix_l1cprod[3]
Definition: l1c_input.h:89
float binlonmin
Definition: l1c_input.h:77
int32_t rowgroup
Definition: l1c_input.h:55
void clo_setEnableDumpOptions(int val)
Definition: clo.c:410
clo_optionList_t * clo_createList()
Definition: clo.c:532
char infile[FILENAME_MAX]
Definition: l1c_input.h:32
void clo_setHelpStr(const char *str)
Definition: clo.c:487
@ CLO_TYPE_INT
Definition: clo.h:79
file_format getFormat(char *filename)
Definition: filetype.c:192
int32_t sensor
Definition: l1c_input.h:93
char * clo_getOptionString(clo_option_t *option)
Definition: clo.c:1050
int * clo_getOptionInts(clo_option_t *option, int *count)
Definition: clo.c:1273
void clo_printUsage(clo_optionList_t *list)
Definition: clo.c:1988
int32_t overlap_vflag
Definition: l1c_input.h:104
int want_verbose
@ CLO_TYPE_IFILE
Definition: clo.h:84
@ CLO_TYPE_OFILE
Definition: clo.h:85
clo_option_t * clo_getOption(clo_optionList_t *list, int i)
Definition: clo.c:908
Definition: l1c.cpp:76
void clo_addOptionAlias(clo_option_t *option, const char *alias)
Definition: clo.c:632
int32_t nbinx
Definition: l1c_input.h:91
std::vector< std::string > files
Definition: l1c_input.h:70
char suite[32]
Definition: l1c_input.h:48
int clo_getNumOptions(clo_optionList_t *list)
Definition: clo.c:1017
void parse_file_name(const char *inpath, char *outpath)
int32_t overlap_bflag
Definition: l1c_input.h:106
@ CLO_TYPE_HELP
Definition: clo.h:86
int32_t selmon
Definition: l1c_input.h:95
int32_t selyear
Definition: l1c_input.h:96
char ofile[FILENAME_MAX]
Definition: l1c_input.h:33
int32_t cloud_correct
Definition: l1c_input.h:102
float unc_thres_v
Definition: l1c_input.h:109
const char * sensorId2SensorName(int sensorId)
Definition: sensorInfo.c:198
void clo_setVersion(const char *str)
Definition: clo.c:448
float unc_thres_b
Definition: l1c_input.h:111
@ FT_INVALID
Definition: filetype.h:12
void clo_deleteList(clo_optionList_t *list)
Definition: clo.c:875
void clo_dumpOption(clo_option_t *option)
Definition: clo.c:1896
int32_t l1c_pflag
Definition: l1c_input.h:90
int32_t unc_meth
Definition: l1c_input.h:108
enum clo_dataType_t dataType
Definition: clo.h:105
int i
Definition: decode_rs.h:71
@ CLO_TYPE_STRING
Definition: clo.h:83
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int32_t verbose
Definition: l1c_input.h:60
int32_t l1c_inputmain(int argc, char **argv, L1C_input *l1cinput, l1c_filehandle *l1cfile, const char *prog, const char *version)
int clo_getOptionBool(clo_option_t *option)
Definition: clo.c:1087
version
Definition: setup.py:15
float binlatmin
Definition: l1c_input.h:75
int count
Definition: decode_rs.h:79