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 8/15/2022
4 // lasr version on 12/14/2022
5 //****************************************
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <ctype.h>
11 #include <netcdf>
12 #include <unistd.h>
13 #include <string>
14 #include <vector>
15 #include <boost/algorithm/string.hpp>
16 #include <clo.h>
17 #include <filetype.h>
18 
19 using namespace std;
20 using namespace netCDF;
21 using namespace netCDF::exceptions;
22 
23 #include "l1c_input.h"
24 #include "genutils.h"
25 #include "passthebuck.h"
26 #include "sensorInfo.h"
27 
28 #include "l1c_filehandle.h"
29 #include <iostream>
30 
31 // store the name of program we are running.
32 static char mainProgramName[50];
33 
34 namespace l1c {
35 
36 static char *l1cgen_optionKeys[] = {
37  "-help", "-version", "-dump_options", "-dump_options_paramfile", "-dump_options_xmlfile", "par",
38  "pversion","doi","verbose","ifile","ofile","outlist","l1c_grid", "l1c_anc", "mode", "south", "north", "west",
39  "east", "history","l2prod","ix_l1cprod",
40  "selgran", // selected granules up to 10 files, they are ids not indexes!!
41  "selyear", // selected year
42  "selmon", // selected month
43  "selday", // selected day
44  "grid_resolution", // grid resolution in km
45  "sensor", // SPEX 1, OCI 2 and HARP 3
46  "gransize", "grantype", "bintype", "start_timeflag",
47  "start_time", // initial time as ISO for selecting granules
48  "end_time", // final time as ISO for selecting granules
49  "projection", // projection type,"swath_grid":0 (default-Fred) or "socea=1"
50  "sort_method", // binning sorting type: 0 orbital fred search, 1: SBS
51  "cloud_height", // cloud top height in km
52  "demfile",
53  "terrain_correct", // terrain distortion correction , 1: yes
54  "cloud_correct", // 0: no parallax, L1C at cth=0, 1: L1C at cth = k, 2: L1B at cht=variable
55  "cloud_type",
56  "demcloud_flag",
57  // multi attributes (view, pol, bands)
58  "overlap_vflag", // tells if we want merged views
59  "overlap_pflag", // tells if we want merged polarizations
60  "overlap_bflag", // tells if we want merged spectral bands
61  // uncertainty params l1c merged products
62  "unc_meth", // uncertainity calculation method
63  "unc_thres_v", // uncertainity threshold of angular merged products as %
64  "unc_thres_p", // same but for polarization
65  "unc_thres_b", // sam
66  NULL};
67 
68 L1C_input::L1C_input(){}; // constructor
69 L1C_input::~L1C_input(){};
70 
71 int32_t L1C_input::l1c_usage(const char *prog, const char *ver) {
73 
74  list = clo_createList();
75  l1c_init_options(list, prog, ver);
77 
78  return 0;
79 }
80 
81 int32_t L1C_input::l1c_init_options(clo_optionList_t *list, const char *prog, const char *version) {
82  char tmpStr[2048];
83  clo_option_t *option;
84 
85  if (strcmp(prog, "l1cgen"))
86  clo_setSelectOptionKeys(l1cgen_optionKeys);
87 
88  // set the min program name
89  strcpy(mainProgramName, prog);
90 
91  sprintf(tmpStr, "Usage: %s argument-list\n\n", prog);
92  strcat(tmpStr, " The argument-list is a set of keyword=value pairs. The arguments can\n");
93  strcat(tmpStr, " be specified on the commandline, or put into a parameter file, or the\n");
94  strcat(tmpStr, " two methods can be used together, with commandline over-riding.\n\n");
95  strcat(tmpStr, " return value: 0=ALL GOOD, 1=ERROR, 110=NO PIXELS BINNED\n");
96  strcat(tmpStr, " file data.\n\n");
97  strcat(tmpStr, "The list of valid keywords follows:\n");
98  clo_setHelpStr(tmpStr);
99 
100  // add the parfile alias for backward compatibility
101  clo_addAlias(list, "par", "parfile");
102  strcpy(tmpStr, "input L1b or L2 file name");
103  option = clo_addOption(list, "ifile", CLO_TYPE_IFILE, NULL, tmpStr);
104  clo_addOptionAlias(option, "infile");
105  strcpy(tmpStr, "input L1C file name");
106  option = clo_addOption(list, "l1c_grid", CLO_TYPE_IFILE, NULL, tmpStr);
107  option = clo_addOption(list, "l1c_anc", CLO_TYPE_IFILE, NULL, tmpStr);
108  clo_addOption(list, "ofile", CLO_TYPE_OFILE, "output", "output for 1 file name");
109  clo_addOption(list, "outlist", CLO_TYPE_OFILE, "output", "output list file name");
110  clo_addOption(list, "verbose", CLO_TYPE_BOOL, "off", "Allow more verbose screen messages");
111  clo_addOption(list, "pversion", CLO_TYPE_STRING, NULL, "processing version string");
112  clo_addOption(list, "doi", CLO_TYPE_STRING, NULL, "Digital Object Identifier (DOI) string");
113 
114  strcpy(tmpStr, "flags masked [see /SENSOR/l2bin_defaults.par]");
115  strcpy(tmpStr, "l2prod = bin products [default=all products]\n");
116  strcat(tmpStr, " Set to \"ALL\" or \"all\" for all L2 products in 1st input file.\n");
117  strcat(tmpStr, " Use ',' as delimiters.\n");
118  clo_addOption(list, "l2prod", CLO_TYPE_STRING, "ALL", tmpStr);
119  // l1c options--------------------------
120  //**************L1C options *****************************************
121  strcpy(tmpStr, "L1C processing flag\n");
122  strcat(tmpStr, " 5: L1C grid creation from HKT telemetry\n");
123  strcat(tmpStr,
124  " 7: CTH-corrected L1B (cloud height parallax) and L1C grid at cloud height from L1C "
125  "granules with CTH=0--\n");
126  strcat(tmpStr,
127  " 8: L1C FULL file creation from L1B granules-and input L1C grid SOCEA-L1 readers\n");
128 
129  clo_addOption(list, "mode", CLO_TYPE_INT, "0", tmpStr);
130 
131  // it has a different in l2gen
132  strcpy(tmpStr, "L1C grid min binning latitude");
133  clo_addOption(list, "south", CLO_TYPE_FLOAT, "-90", tmpStr);
134  strcpy(tmpStr, "L1C grid max binning latitude");
135  clo_addOption(list, "north", CLO_TYPE_FLOAT, "+90", tmpStr);
136  strcpy(tmpStr, "L1C grid min binning longitude");
137  clo_addOption(list, "west", CLO_TYPE_FLOAT, "-180", tmpStr);
138  strcpy(tmpStr, "L1C grid max binning longitude");
139  clo_addOption(list, "east", CLO_TYPE_FLOAT, "+180", tmpStr);
140 
141  strcpy(tmpStr, "L1C processing of granules");
142  strcpy(tmpStr, "granule id (1 to 10) note: not indexes!");
143  clo_addOption(list, "selgran", CLO_TYPE_INT, "[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]", tmpStr);
144 
145  // not implemented---
146  strcpy(tmpStr, "Index L1C product [0,0,0]");
147  strcat(tmpStr, " 0: pc");
148  strcat(tmpStr, " 1: vsf");
149  strcat(tmpStr, " 2: dpr");
150  clo_addOption(list, "ix_l1cprod", CLO_TYPE_INT, "[0,0,0]", tmpStr);
151 
152  // fixed bearing projection---
153  strcpy(tmpStr, "Day of the year for processing L1C swath");
154  strcat(tmpStr, " units in day number (1-365/366)");
155  clo_addOption(list, "selday", CLO_TYPE_INT, "-1", tmpStr);
156 
157  strcpy(tmpStr, "Month of the year for processing L1C swath");
158  strcat(tmpStr, " units in month number (1-12)");
159  clo_addOption(list, "selmon", CLO_TYPE_INT, "-1", tmpStr);
160 
161  strcpy(tmpStr, "Year for processing L1C swath");
162  strcat(tmpStr, " units in year");
163  clo_addOption(list, "selyear", CLO_TYPE_INT, "-1", tmpStr);
164 
165  //******************************************************************
166  strcpy(tmpStr, "Common grid resolution");
167  strcat(tmpStr, " units in km");
168  clo_addOption(list, "grid_resolution", CLO_TYPE_FLOAT, "5.2", tmpStr);
169 
170  strcpy(tmpStr, "PACE sensor to be gridded");
171  strcat(tmpStr, " e.g. SPEXONE, OCI, HARP2, MISR");
172  clo_addOption(list, "sensor", CLO_TYPE_STRING, "OCI", tmpStr); // default
173  strcpy(tmpStr, "granule size for telemetry-derived L1C files");
174  strcat(tmpStr, " in minutes--5' by default");
175  clo_addOption(list, "gransize", CLO_TYPE_INT, "5", tmpStr);
176 
177  strcpy(tmpStr, "granule type processing for telemetry-derived L1C files");
178  strcat(tmpStr, " 0: granules, 1: swath, 0 by default");
179  clo_addOption(list, "grantype", CLO_TYPE_INT, "0", tmpStr);
180 
181  strcpy(tmpStr, "binning type for binned L1C products");
182  strcat(tmpStr, " 0: discrete, 1: area-weighting, 0 by default");
183  clo_addOption(list, "bintype", CLO_TYPE_INT, "0", tmpStr);
184 
185  strcpy(tmpStr, "Initial time as ISO for processing HKT granules ->L1C files");
186  strcat(tmpStr, " units as ISO");
187  clo_addOption(list, "start_time", CLO_TYPE_STRING, "2022-03-21T00:00:00", tmpStr);
188 
189  strcpy(tmpStr, "End time as ISO for processing HKT granules ->L1C files");
190  strcat(tmpStr, " units as ISO ");
191  clo_addOption(list, "end_time", CLO_TYPE_STRING, "2022-03-21T00:00:00", tmpStr);
192 
193  strcpy(tmpStr, "log command history");
194  clo_addOption(list, "history", CLO_TYPE_STRING, "l1cgen ifile=xx mode=5 ofile=xx", tmpStr);
195 
196  strcpy(tmpStr, "initial time flag for L1C granule ");
197  strcat(tmpStr,
198  " 0: time zero seconds of the day 00:00:00, 1: starting coverage time for the HKT file by "
199  "default, 0 by default");
200  clo_addOption(list, "start_timeflag", CLO_TYPE_INT, "0", tmpStr);
201 
202  strcpy(tmpStr, "swath # for 1 full orbit processing for telemetry-derived L1C files");
203  strcat(tmpStr, " 1 or 2, ascending or descending");
204  clo_addOption(list, "swath_num", CLO_TYPE_INT, "1", tmpStr);
205 
206  strcpy(tmpStr, "Projection type");
207  strcat(tmpStr, " 0: SOCEA(default)");
208  strcat(tmpStr, " 1: SOCEA-2");
209  clo_addOption(list, "projection", CLO_TYPE_INT, "0", tmpStr);
210 
211  strcpy(tmpStr, "Binning sorting type");
212  strcat(tmpStr, " 0: Orbital-vectorsdefault)");
213  strcat(tmpStr, " 1: SADDLEBACK SEARCH");
214  clo_addOption(list, "sort_method", CLO_TYPE_INT, "0", tmpStr);
215 
216  strcpy(tmpStr, "height type flag");
217  strcat(tmpStr, " 0: geoid or L1C height");
218  strcat(tmpStr, " 1: orthometric or dem height");
219  clo_addOption(list, "demcloud_flag", CLO_TYPE_INT, "0", tmpStr);
220 
221  strcpy(tmpStr, "Cloud top height for L1C corrections");
222  strcat(tmpStr, " (km)");
223  clo_addOption(list, "cloud_height", CLO_TYPE_INT, "0", tmpStr);
224 
225  strcpy(tmpStr, "Terrain correct flag");
226  strcat(tmpStr, " DEM correction");
227  strcat(tmpStr, " 0: off");
228  strcat(tmpStr, " 1: on");
229  clo_addOption(list, "terrain_correct", CLO_TYPE_BOOL, "0", tmpStr);
230 
231  strcpy(tmpStr, "Cloud correct flag for L1C");
232  strcat(tmpStr, " 0: CTH=0 no parallax correction (default)");
233  strcat(tmpStr, " 1: CTH=k, constant CTH from ANC");
234  strcat(tmpStr, " 2: CTH=k, constant CTH from L1C grid height");
235  clo_addOption(list, "cloud_correct", CLO_TYPE_INT, "0", tmpStr);
236 
237  strcpy(tmpStr, "Cloud type for parallax correction");
238  strcat(tmpStr, " 0: water (default)");
239  strcat(tmpStr, " 1: ice");
240  clo_addOption(list, "cloud_type", CLO_TYPE_INT, "0", tmpStr);
241 
242  strcpy(tmpStr, "overlap views flag");
243  strcat(tmpStr, " 0: off");
244  strcat(tmpStr, " 1: on");
245  clo_addOption(list, "overlap_vflag", CLO_TYPE_BOOL, "0", tmpStr);
246 
247  strcpy(tmpStr, "overlap polarizations flag");
248  strcat(tmpStr, " 0: off");
249  strcat(tmpStr, " 1: on");
250  clo_addOption(list, "overlap_pflag", CLO_TYPE_BOOL, "0", tmpStr);
251 
252  strcpy(tmpStr, "overlap spectral bands flag");
253  strcat(tmpStr, " 0: off");
254  strcat(tmpStr, " 1: on");
255  clo_addOption(list, "overlap_bflag", CLO_TYPE_BOOL, "0", tmpStr);
256 
257  strcpy(tmpStr, "Uncertainty calculation method");
258  strcat(tmpStr, " 0: error propagation");
259  strcat(tmpStr, " 1: Monte Carlo");
260  clo_addOption(list, "unc_meth", CLO_TYPE_INT, "0", tmpStr);
261 
262  strcpy(tmpStr, "Uncertainty threshold for angular merged product");
263  strcat(tmpStr, " as percentage");
264  clo_addOption(list, "unc_thres_v", CLO_TYPE_FLOAT, "10", tmpStr);
265 
266  strcpy(tmpStr, "Uncertainty threshold for polarization merged product");
267  strcat(tmpStr, " as percentage");
268  clo_addOption(list, "unc_thres_p", CLO_TYPE_FLOAT, "10", tmpStr);
269 
270  strcpy(tmpStr, "Uncertainty threshold for spectral bands merged product");
271  strcat(tmpStr, " as percentage");
272  clo_addOption(list, "unc_thres_b", CLO_TYPE_FLOAT, "10", tmpStr);
273 
274  strcpy(tmpStr, "Digital Elevation Model file");
275  strcat(tmpStr, " *.nc file");
276  clo_addOption(list, "demfile", CLO_TYPE_STRING, "$OCDATAROOT/common/gebco_ocssw_v2020.nc", tmpStr);
277 
278  //*************************************************************************-
279 
280  clo_setVersion2(prog, version);
281  return 0;
282 }
283 
284 // copy input info from list into instr structure
286  char *tmp_str;
287  char keyword[50];
288  char *parm_str;
289  char tmp_file[FILENAME_MAX];
290  int numOptions, optionId;
291  clo_option_t *option;
292 
293  int *iArray;
294  int count = -1;
295  char **cArray;
296 
297  numOptions = clo_getNumOptions(list);
298  for (optionId = 0; optionId < numOptions; optionId++) {
299  option = clo_getOption(list, optionId);
300 
301  // ignore options of type CLO_TYPE_HELP
302  if (option->dataType == CLO_TYPE_HELP)
303  continue;
304 
305  strcpy(keyword, option->key);
306 
307  /* change keyword to lower case */
308  tmp_str = keyword;
309  while (*tmp_str != '\0') {
310  if (isupper(*tmp_str))
311  *tmp_str = tolower(*tmp_str);
312  tmp_str++;
313  }
314 
315  if (strcmp(keyword, "help") == 0) {
316  } else if (strcmp(keyword, "version") == 0) {
317  } else if (strncmp(keyword, "dump_options", 12) == 0) {
318  } else if (strncmp(keyword, "par", 3) == 0) {
319  } else if (strcmp(keyword, "ifile") == 0) {
320  if (clo_isOptionSet(option)) {
321  parm_str = clo_getOptionString(option);
322  parse_file_name(parm_str, tmp_file);
323  strcpy(l1ccli->infile, tmp_file);
324  }
325  } else if (strcmp(keyword, "ofile") == 0) {
326  if (clo_isOptionSet(option)) {
327  parm_str = clo_getOptionString(option);
328  parse_file_name(parm_str, tmp_file);
329  strcpy(l1ccli->ofile, tmp_file);
330  }
331  } else if (strcmp(keyword, "outlist") == 0) {
332  if (clo_isOptionSet(option)) {
333  parm_str = clo_getOptionString(option);
334  parse_file_name(parm_str, tmp_file);
335  strcpy(l1ccli->outlist, tmp_file);
336  }
337  } else if (strcmp(keyword, "l1c_grid") == 0) {
338  if (clo_isOptionSet(option)) {
339  parm_str = clo_getOptionString(option);
340  parse_file_name(parm_str, tmp_file);
341  strcpy(l1ccli->l1c_grid, tmp_file);
342  }
343 
344  }
345  else if (strcmp(keyword, "l1c_anc") == 0) {
346  if (clo_isOptionSet(option)) {
347  parm_str = clo_getOptionString(option);
348  parse_file_name(parm_str, tmp_file);
349  strcpy(l1ccli->l1c_anc, tmp_file);
350  }
351 
352  } else if (strcmp(keyword, "l2prod") == 0) {
353  parm_str = clo_getOptionRawString(option);
354  strcpy(l1ccli->l2prod, parm_str);
355 
356  } else if (strcmp(keyword, "verbose") == 0) {
357  l1ccli->verbose = clo_getOptionBool(option);
358 
359  } else if (strcmp(keyword, "pversion") == 0) {
360  if (clo_isOptionSet(option)) {
361  strcpy(l1ccli->pversion, clo_getOptionString(option));
362  }
363  } else if (strcmp(keyword, "doi") == 0) {
364  if (clo_isOptionSet(option)) {
365  strcpy(l1ccli->doi, clo_getOptionString(option));
366  }
367  }
368 
369  // L1C new options-----------------------------------------
370  else if (strcmp(keyword, "mode") == 0) {
371  l1ccli->l1c_pflag = clo_getOptionInt(option);
372  } else if (strcmp(keyword, "south") == 0) {
373  l1ccli->south = clo_getOptionFloat(option);
374  } else if (strcmp(keyword, "north") == 0) {
375  l1ccli->north = clo_getOptionFloat(option);
376  } else if (strcmp(keyword, "west") == 0) {
377  l1ccli->west = clo_getOptionFloat(option);
378  } else if (strcmp(keyword, "east") == 0) {
379  l1ccli->east = clo_getOptionFloat(option);
380  } else if (strcmp(keyword, "selgran") == 0) {
381  iArray = clo_getOptionInts(option, &count);
382  if (count <= 10) {
383  for (int i = 0; i < count; i++) {
384  if (iArray[i] <= 10)
385  l1ccli->selgran[i] = iArray[i];
386  else {
387  printf("-E- %s: Granule Id cant be larger than 10.\n", __FILE__);
388  exit(1);
389  }
390  }
391  } else {
392  printf("-E- %s: Max number of granules to be processed is 10.\n", __FILE__);
393  exit(1);
394  }
395  } else if (strcmp(keyword, "ix_l1cprod") == 0) {
396  iArray = clo_getOptionInts(option, &count);
397  for (int i = 0; i < count; i++)
398  l1ccli->ix_l1cprod[i] = iArray[i];
399  }
400 
401  else if (strcmp(keyword, "grid_resolution") == 0) {
402  l1ccli->grid_resolution = clo_getOptionFloat(option);
403  } else if (strcmp(keyword, "sensor") == 0) {
404  if (clo_isOptionSet(option)) {
405  const char *sname = clo_getOptionString(option);
406  l1ccli->sensor = sensorName2SensorId(sname);
407  }
408  } else if (strcmp(keyword, "gransize") == 0) {
409  l1ccli->gransize = clo_getOptionInt(option);
410  } else if (strcmp(keyword, "grantype") == 0) {
411  l1ccli->grantype = clo_getOptionInt(option);
412  } else if (strcmp(keyword, "bintype") == 0) {
413  l1ccli->bintype = clo_getOptionInt(option);
414  } else if (strcmp(keyword, "history") == 0) {
415  if (clo_isOptionSet(option)) {
416  cArray = clo_getOptionStrings(option, &count);
417  string history;
418  for (int i = 0; i < count; i++) {
419  string s1(cArray[i]);
420  history += s1;
421  }
422  strcpy(l1ccli->history, history.c_str());
423  }
424  } else if (strcmp(keyword, "start_time") == 0) {
425  if (clo_isOptionSet(option)) {
426  cArray = clo_getOptionStrings(option, &count);
427  string s1(cArray[0]), s2(cArray[1]), s3(cArray[2]);
428  string start_time = s1 + ":" + s2 + ":" + s3.substr(0, 2) + "Z";
429  strcpy(l1ccli->start_time, start_time.c_str());
430  }
431  } else if (strcmp(keyword, "end_time") == 0) {
432  if (clo_isOptionSet(option)) {
433  cArray = clo_getOptionStrings(option, &count);
434  string s1(cArray[0]), s2(cArray[1]), s3(cArray[2]);
435  string gran_end_time = s1 + ":" + s2 + ":" + s3.substr(0, 2) + "Z";
436  strcpy(l1ccli->end_time, gran_end_time.c_str());
437  }
438  }
439  else if (strcmp(keyword, "demfile") == 0) {
440  if (clo_isOptionSet(option)) {
441  cArray = clo_getOptionStrings(option, &count);
442  string s1(cArray[0]);
443  string gran_demfile = s1;
444  strcpy(l1ccli->demfile, gran_demfile.c_str());
445  }
446  /* else if (strcmp(keyword, "demfile") == 0) {
447  parm_str = clo_getOptionString(option);
448  strcpy(l1ccli->demfile,parm_str);
449  } */
450  }
451  else if (strcmp(keyword, "start_timeflag") == 0) {
452  l1ccli->start_timeflag = clo_getOptionInt(option);
453  } else if (strcmp(keyword, "selday") == 0) {
454  l1ccli->selday = clo_getOptionInt(option);
455  } else if (strcmp(keyword, "selmon") == 0) {
456  l1ccli->selmon = clo_getOptionInt(option);
457  } else if (strcmp(keyword, "selyear") == 0) {
458  l1ccli->selyear = clo_getOptionInt(option);
459  } else if (strcmp(keyword, "swath_num") == 0) {
460  l1ccli->swath_num = clo_getOptionInt(option);
461  } else if (strcmp(keyword, "projection") == 0) {
462  l1ccli->projection = clo_getOptionInt(option);
463  } else if (strcmp(keyword, "sort_method") == 0) {
464  l1ccli->sort_method = clo_getOptionInt(option);
465  } else if (strcmp(keyword, "demcloud_flag") == 0) {
466  l1ccli->demcloud_flag = clo_getOptionInt(option);
467  } else if (strcmp(keyword, "cloud_height") == 0) {
468  l1ccli->cloud_height = clo_getOptionInt(option);
469  } else if (strcmp(keyword, "terrain_correct") == 0) {
470  l1ccli->terrain_correct = clo_getOptionBool(option);
471  } else if (strcmp(keyword, "cloud_correct") == 0) {
472  l1ccli->cloud_correct = clo_getOptionInt(option);
473  } else if (strcmp(keyword, "cloud_type") == 0) {
474  l1ccli->cloud_type = clo_getOptionInt(option);
475  } else if (strcmp(keyword, "overlap_vflag") == 0) {
476  l1ccli->overlap_vflag = clo_getOptionBool(option);
477  } else if (strcmp(keyword, "overlap_pflag") == 0) {
478  l1ccli->overlap_pflag = clo_getOptionBool(option);
479  } else if (strcmp(keyword, "overlap_bflag") == 0) {
480  l1ccli->overlap_bflag = clo_getOptionBool(option);
481  } else if (strcmp(keyword, "unc_meth") == 0) {
482  l1ccli->unc_meth = clo_getOptionInt(option);
483  } else if (strcmp(keyword, "unc_thres_v") == 0) {
484  l1ccli->unc_thres_v = clo_getOptionFloat(option);
485  } else if (strcmp(keyword, "unc_thres_p") == 0) {
486  l1ccli->unc_thres_p = clo_getOptionFloat(option);
487  } else if (strcmp(keyword, "unc_thres_b") == 0) {
488  l1ccli->unc_thres_b = clo_getOptionFloat(option);
489  } else {
490  printf("-E- Invalid argument \"%s\"\n", keyword);
491  clo_dumpOption(option);
492  exit(1);
493  }
494 
495  } // end for
496 
497  return 0;
498 }
499 
500 // it is called by l1c_input method
501 // init defaults, makes sense?
503  l1ccli->infile[0] = '\0';
504  l1ccli->ofile[0] = '\0';
505  l1ccli->outlist[0] = '\0';
506  l1ccli->l1c_grid[0] = '\0';
507  l1ccli->l1c_anc[0] = '\0';
508  l1ccli->verbose = 0;
509  l1ccli->pversion[0] = '\0';
510  l1ccli->doi[0] = '\0';
511  l1ccli->l2prod[0] = '\0';
512  for (int i = 0; i < 3; i++) {
513  l1ccli->ix_l1cprod[i] = i+1;
514  } // 3x1 array with selected l1c products, 1: selected
515  l1ccli->l1c_pflag = 0;
516  l1ccli->south = -90; // latitude in degrees
517  l1ccli->north = 90;
518  l1ccli->west = -180;
519  l1ccli->east = 180;
520 
521  for (int i = 0; i < 10; i++) {
522  l1ccli->selgran[i] = -1; // first file of the list
523  }
524  l1ccli->swath_num = 1;
525  l1ccli->grid_resolution = 5.2; // grid resolution in km
526  l1ccli->sensor = 30; // 30 is OCI, 31 is OCIS
527  l1ccli->gransize = 5; // in minutes
528  l1ccli->grantype = 0;
529  l1ccli->bintype = 0;
530  l1ccli->start_time[0] = '\0';
531  l1ccli->end_time[0] = '\0';
532  l1ccli->demfile[0]='\0'; // as ISO
533  l1ccli->history[0] = '\0';
534  l1ccli->start_timeflag = 0; // flag=0 or to=0 in seconds of the day
535  l1ccli->swath_num = 1; // in minutes
536  l1ccli->selyear = -1;
537  l1ccli->selmon = -1;
538  l1ccli->selday = -1;
539  l1ccli->projection = 0; // projection type,"swath_grid":0 or "socea=1"
540  l1ccli->sort_method = 0;
541  l1ccli->demcloud_flag = 0;
542  l1ccli->cloud_height = 0;
543  l1ccli->terrain_correct = 0; // terrain distortion correction , 1: yes
544  l1ccli->cloud_correct = 0; // cloud distortion correction , 1: yes
545  l1ccli->cloud_type = 0;
546  // multi attributes (view, pol, bands)
547  l1ccli->overlap_vflag = 0; // tells if we want merged views
548  l1ccli->overlap_pflag = 0; // tells if we want merged polarizations
549  l1ccli->overlap_bflag = 0; // tells if we want merged spectral bands
550  // uncertainty params l1c merged products
551  l1ccli->unc_meth = 0; // uncertainity calculation method
552  l1ccli->unc_thres_v = -999.0; // uncertainity threshold of angular merged products as %
553  l1ccli->unc_thres_p = -999.0; // same but for polarization
554  l1ccli->unc_thres_b = -999.0; // same but for multispectral products, same view and polarization
555 
556  return 0;
557 }
558 
559 /*-----------------------------------------------------------------------------
560  Function: l1c_input
561 
562  Returns: int (status)
563  The return code is a negative value if any error occurs, otherwise,
564  returns 0.
565 
566  Description:
567  Convert the arguments from the command line into a structure input
568  variable.
569 
570  Parameters: (in calling order)
571  Type Name I/O Description
572  ---- ---- --- -----------
573  int argc I number of arguments
574  char **argv I list of arguments
575  instr input O structure variable for inputs
576 
577 ----------------------------------------------------------------------------*/
578 
579 int32_t L1C_input::l1c_inputmain(int argc, char **argv, L1C_input *l1cinput, l1c_filehandle *l1cfile,
580  const char *prog, const char *version) {
581  char *dataRoot;
582 
583  char localIfile[FILENAME_MAX], localIfile_l1c[FILENAME_MAX];
584  char *ifile;
585  string ifile_str;
586 
587  /* hold all of the command line options */
589 
590  list = clo_createList();
591 
592  /* initialize the option list with descriptions and default values */
593  l1c_init_options(list, prog, version);
594 
595  if (argc == 1) {
597  exit(1);
598  }
599 
600  // disable the dump option until we have read all of the files
602  clo_readArgs(list, argc, argv);
603 
604  if (l1c_input_init(l1cinput) != 0) {
605  printf("-E- %s: Error initializing l1c input structure.\n", __FILE__);
606  return (-1);
607  }
608 
609  // get list of input files
610  strcpy(localIfile, clo_getString(list, "ifile"));
611  l1cinput->files = readFileList(localIfile); // files stored in a vector container in input struc
612 
613  if (l1cinput->files.size() == 0) {
614  printf("No NetCDF input files found in %s.\n", localIfile);
615  exit(EXIT_FAILURE);
616  }
617 
618  ifile_str = l1cinput->files[0];
619  ifile = (char*)ifile_str.c_str();
620 
621  l1cfile->l1b_name = ifile_str;
622 
623  if(l1cinput->verbose) cout<<"ifile.."<<ifile<<endl;
624  file_format format = getFormat(ifile); // reading from a nc file ---
625  l1cfile->format = format.type;
626 
627  if(l1cinput->verbose)
628  {
629  cout<<"l1cinput->files[0].."<<l1cfile->l1b_name<<endl;
630  printf("format.type....%d..",format.type);
631  printf("sensor id.....%d..",format.sensor_id);
632  }
633 
634  l1cfile->format = format.type;
635 
636  if(l1cinput->verbose) cout<<"sensor id.."<<format.sensor_id<<"sensor name.."<<sensorId2SensorName(format.sensor_id)<<endl;
637 
638  if (format.type == FT_INVALID) {
639  printf("-E- %s Line %d: Could not find type for file %s.\n", __FILE__, __LINE__, ifile);
640  return (-1);
641  }
642 
643  if (format.sensor_id == -1) {
644  printf("-E- Can not look up sensor ID for PLEASE PROVIDE PLATFORM FOR OCIS--!! %s.\n ", localIfile);
645  cout << "forcing to be HARP2 when HARP2 L1B is beta from Meng/Richard" << endl;
646  return (1);
647  }
648 
649  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
650  printf("OCDATAROOT environment variable is not defined.\n");
651  return (1);
652  }
653 
654  // re-load the command line and par file
655 
657  clo_readArgs(list, argc, argv);
658 
659  // re-load the command line and par file
660  if (want_verbose)
661  printf("Loading command line parameters for L1C processing\n\n");
662  // load input struct with command line arguments
663  if (l1c_load_input(list, l1cinput) != 0) {
664  printf("-E- %s: Error loading options into input structure.\n", __FILE__);
665  return (-1);
666  }
667 
668  if (l1cinput->l1c_pflag == 8 || l1cinput->l1c_pflag == 7 || l1cinput->l1c_pflag == 3) {
669  strcpy(localIfile_l1c, clo_getString(list, "l1c_grid"));
670  l1cinput->files_l1c = readFileList(localIfile_l1c); // files stored in a vector container in input struc
671  if(l1cinput->verbose)
672  {
673  cout << localIfile_l1c << endl;
674  cout << l1cinput->files_l1c.size() << endl;
675  }
676 
677  if (l1cinput->files_l1c.size() == 0) {
678  printf("No NetCDF L1C input files found in %s.\n", localIfile_l1c);
679  exit(EXIT_FAILURE);
680  }
681  }
682 
683  if(l1cinput->verbose) cout << "processing mode...." << l1cinput->l1c_pflag << endl;
684 
686 
687  return 0;
688 }
689 
690 } // namespace l1c
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
bool overlap_bflag
Definition: l1c_input.h:80
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
char l2prod[2048]
Definition: l1c_input.h:41
std::string l1b_name
#define NULL
Definition: decode_rs.h:63
char * key
Definition: clo.h:107
void clo_addAlias(clo_optionList_t *list, const char *key, const char *alias)
Definition: clo.c:646
char ** clo_getOptionStrings(clo_option_t *option, int *count)
Definition: clo.c:1226
bool overlap_vflag
Definition: l1c_input.h:78
char * clo_getOptionRawString(clo_option_t *option)
Definition: clo.c:1030
float unc_thres_p
Definition: l1c_input.h:84
int sensorName2SensorId(const char *name)
Definition: sensorInfo.c:371
int clo_getOptionInt(clo_option_t *option)
Definition: clo.c:1113
int32_t selday
Definition: l1c_input.h:65
@ CLO_TYPE_FLOAT
Definition: clo.h:84
int32_t l1c_usage(const char *prog, const char *version)
int clo_isOptionSet(clo_option_t *option)
Definition: clo.c:2257
@ CLO_TYPE_BOOL
Definition: clo.h:81
void clo_setVersion2(const char *programName, const char *versionStr)
Definition: clo.c:464
int32_t cloud_height
Definition: l1c_input.h:72
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:61
char l1c_grid[FILENAME_MAX]
Definition: l1c_input.h:30
int demcloud_flag
Definition: l1c_input.h:76
bool terrain_correct
Definition: l1c_input.h:73
void clo_setEnableDumpOptions(int val)
Definition: clo.c:410
clo_optionList_t * clo_createList()
Definition: clo.c:532
char demfile[100]
Definition: l1c_input.h:34
char infile[FILENAME_MAX]
Definition: l1c_input.h:27
int32_t swath_num
Definition: l1c_input.h:56
char pversion[256]
Definition: l1c_input.h:36
list(APPEND LIBS ${NETCDF_LIBRARIES}) find_package(GSL REQUIRED) include_directories($
Definition: CMakeLists.txt:8
void clo_setHelpStr(const char *str)
Definition: clo.c:487
@ CLO_TYPE_INT
Definition: clo.h:82
file_format getFormat(char *filename)
Definition: filetype.c:192
int32_t sensor
Definition: l1c_input.h:64
char * clo_getOptionString(clo_option_t *option)
Definition: clo.c:1050
char l1c_anc[FILENAME_MAX]
Definition: l1c_input.h:31
int * clo_getOptionInts(clo_option_t *option, int *count)
Definition: clo.c:1273
void clo_printUsage(clo_optionList_t *list)
Definition: clo.c:1988
int want_verbose
@ CLO_TYPE_IFILE
Definition: clo.h:87
@ CLO_TYPE_OFILE
Definition: clo.h:88
clo_option_t * clo_getOption(clo_optionList_t *list, int i)
Definition: clo.c:908
Definition: l1c.cpp:71
void clo_addOptionAlias(clo_option_t *option, const char *alias)
Definition: clo.c:632
int start_timeflag
Definition: l1c_input.h:57
char doi[256]
Definition: l1c_input.h:37
string history
Definition: ncattredit.py:30
std::vector< std::string > files_l1c
Definition: l1c_input.h:45
std::vector< std::string > files
Definition: l1c_input.h:44
int clo_getNumOptions(clo_optionList_t *list)
Definition: clo.c:1017
float grid_resolution
Definition: l1c_input.h:63
void parse_file_name(const char *inpath, char *outpath)
int32_t sort_method
Definition: l1c_input.h:71
@ CLO_TYPE_HELP
Definition: clo.h:89
int32_t selmon
Definition: l1c_input.h:66
int32_t selyear
Definition: l1c_input.h:67
std::vector< std::string > readFileList(std::string fileName)
Definition: readFileList.cpp:9
char ofile[FILENAME_MAX]
Definition: l1c_input.h:28
float unc_thres_v
Definition: l1c_input.h:83
const char * sensorId2SensorName(int sensorId)
Definition: sensorInfo.c:273
char history[200]
Definition: l1c_input.h:35
float unc_thres_b
Definition: l1c_input.h:85
bool overlap_pflag
Definition: l1c_input.h:79
@ FT_INVALID
Definition: filetype.h:12
int cloud_correct
Definition: l1c_input.h:74
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:62
char start_time[50]
Definition: l1c_input.h:32
int32_t unc_meth
Definition: l1c_input.h:82
char outlist[FILENAME_MAX]
Definition: l1c_input.h:29
enum clo_dataType_t dataType
Definition: clo.h:108
int32_t projection
Definition: l1c_input.h:70
int selgran[10]
Definition: l1c_input.h:60
int i
Definition: decode_rs.h:71
@ CLO_TYPE_STRING
Definition: clo.h:86
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
char end_time[50]
Definition: l1c_input.h:33
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
int count
Definition: decode_rs.h:79