Go to the documentation of this file.
9 #include <boost/algorithm/string.hpp>
12 using namespace netCDF;
13 using namespace netCDF::exceptions;
21 static char mainProgramName[50];
28 strcpy(mainProgramName, prog);
30 sprintf(tmpStr,
"Usage: %s argument-list\n\n", prog);
31 strcat(tmpStr,
" The argument-list is a set of keyword=value pairs. The arguments can\n");
32 strcat(tmpStr,
" be specified on the commandline, or put into a parameter file, or the\n");
33 strcat(tmpStr,
" two methods can be used together, with commandline over-riding.\n\n");
34 strcat(tmpStr,
" return value: 0=OK, 1=error, 110=north,south,east,west does not intersect\n");
35 strcat(tmpStr,
" file data.\n\n");
36 strcat(tmpStr,
"The list of valid keywords follows:\n");
42 strcpy(tmpStr,
"input L2 file name");
66 strcpy(tmpStr,
"equator crossing time delta in\n minutes\n");
67 strcat(tmpStr,
" Caveat...if zero, the sensor default equator crossing time will be used\n");
68 strcat(tmpStr,
" This is not necessarily noon");
71 strcpy(tmpStr,
"bin resolution\n");
72 strcat(tmpStr,
" H: 0.5km\n");
73 strcat(tmpStr,
" Q: 250m\n");
74 strcat(tmpStr,
" HQ: 100m\n");
75 strcat(tmpStr,
" HH: 50m\n");
76 strcat(tmpStr,
" 1: 1.1km\n");
77 strcat(tmpStr,
" 2: 2.3km\n");
78 strcat(tmpStr,
" 4: 4.6km\n");
79 strcat(tmpStr,
" 9: 9.2km\n");
80 strcat(tmpStr,
" 18: 18.5km\n");
81 strcat(tmpStr,
" 36: 36km\n");
82 strcat(tmpStr,
" 1D: 1 degree\n");
83 strcat(tmpStr,
" HD: 0.5 degree\n");
84 strcat(tmpStr,
" QD: 0.25 degree");
92 strcpy(tmpStr,
"flags masked [see /SENSOR/l2bin_defaults.par]");
95 strcpy(tmpStr,
"l3bprod = bin products [default=all products]\n");
96 strcat(tmpStr,
" Set to \"ALL\" or \"all\" for all L2 products in 1st input file.\n");
97 strcat(tmpStr,
" Use ':' or ',' or ' ' as delimiters.\n");
98 strcat(tmpStr,
" Use ';' or '=' to delineate minimum values.");
101 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");
105 strcpy(tmpStr,
"comma separated list of output L3 product names.\n");
106 strcat(tmpStr,
" This option allows the user to specify the output product names which differ from the original l2 product names.\n");
107 strcat(tmpStr,
" Usage: original_l2_name:output_l3_name, i.e. oprodname=cloud_flag:cloud_fraction");
117 char tmp_file[FILENAME_MAX];
118 int numOptions, optionId;
122 for (optionId = 0; optionId < numOptions; optionId++) {
133 while (*tmp_str !=
'\0') {
134 if (isupper(*tmp_str)) *tmp_str = tolower(*tmp_str);
138 if (strcmp(keyword,
"help") == 0) {
140 else if (strcmp(keyword,
"version") == 0) {
142 else if (strncmp(keyword,
"dump_options", 12) == 0) {
144 else if (strncmp(keyword,
"par", 3) == 0) {
146 else if (strcmp(keyword,
"ifile") == 0) {
152 }
else if (strcmp(keyword,
"ofile") == 0) {
158 }
else if (strcmp(keyword,
"fileuse") == 0) {
164 }
else if (strcmp(keyword,
"sday") == 0) {
168 }
else if (strcmp(keyword,
"eday") == 0) {
172 }
else if (strcmp(keyword,
"resolution") == 0) {
177 }
else if (strcmp(keyword,
"rowgroup") == 0) {
180 }
else if (strcmp(keyword,
"flaguse") == 0) {
185 }
else if (strcmp(keyword,
"l3bprod") == 0) {
189 }
else if (strcmp(keyword,
"prodtype") == 0) {
193 }
else if (strcmp(keyword,
"output_wavelengths") == 0) {
197 }
else if (strcmp(keyword,
"pversion") == 0) {
201 }
else if (strcmp(keyword,
"suite") == 0) {
206 }
else if (strcmp(keyword,
"latsouth") == 0) {
209 }
else if (strcmp(keyword,
"latnorth") == 0) {
212 }
else if (strcmp(keyword,
"lonwest") == 0) {
215 }
else if (strcmp(keyword,
"loneast") == 0) {
218 }
else if (strcmp(keyword,
"meminfo") == 0) {
221 }
else if (strcmp(keyword,
"dcinfo") == 0) {
224 }
else if (strcmp(keyword,
"night") == 0) {
227 }
else if (strcmp(keyword,
"verbose") == 0) {
230 }
else if (strcmp(keyword,
"minobs") == 0) {
233 }
else if (strcmp(keyword,
"delta_crossing_time") == 0) {
236 }
else if (strcmp(keyword,
"deflate") == 0) {
239 }
else if (strcmp(keyword,
"qual_max") == 0) {
242 }
else if (strcmp(keyword,
"qual_prod") == 0) {
249 }
else if(strcmp(keyword,
"oprodname") == 0){
254 }
else if (strcmp(keyword,
"composite_prod") == 0) {
260 }
else if (strcmp(keyword,
"composite_scheme") == 0) {
266 }
else if (strcmp(keyword,
"area_weighting") == 0) {
270 input->area_weighting = 0;
272 }
else if (strcmp(keyword,
"doi") == 0) {
277 printf(
"-E- Invalid argument \"%s\"\n", keyword);
287 input_str->infile[0] =
'\0';
288 input_str->ofile[0] =
'\0';
289 input_str->pfile[0] =
'\0';
291 input_str->fileuse[0] =
'\0';
292 input_str->qual_prod[0] =
'\0';
293 input_str->composite_prod[0] =
'\0';
294 input_str->composite_scheme[0] =
'\0';
295 input_str->output_product_names[0] =
'\0';
296 strcpy(input_str->pversion,
"Unspecified");
297 strcpy(input_str->prodtype,
"day");
299 strcpy(input_str->l3bprod,
"ALL");
300 strcpy(input_str->output_wavelengths,
"ALL");
302 input_str->sday = 1970001;
303 input_str->eday = 2038018;
305 input_str->resolve[0] =
'\0';
307 input_str->rowgroup = -1;
309 input_str->night = 0;
310 input_str->verbose = 0;
311 input_str->minobs = 0;
312 input_str->deltaeqcross = 0.0;
314 input_str->meminfo = 0;
315 input_str->dcinfo = 0;
317 input_str->latsouth = -90.0;
318 input_str->latnorth = +90.0;
319 input_str->lonwest = 0.0;
320 input_str->loneast = 0.0;
322 input_str->qual_max = 255;
324 input_str->deflate = 0;
326 strcpy(input_str->suite,
"");
328 input_str->area_weighting = 0;
329 input_str->doi[0] =
'\0';
360 int subsensorId = -1;
361 char localSuite[FILENAME_MAX];
362 char localIfile[FILENAME_MAX];
368 printf(
"-E- %s: Error initializing input structure.\n", __FILE__);
392 if (
input->files.size() == 0) {
393 printf(
"-E- No NetCDF input files found in %s.\n", localIfile);
398 localSuite[0] =
'\0';
406 NcFile nc_input(
input->files[0], NcFile::read);
407 nc_input.getAtt(
"instrument").getValues(
instrument);
408 nc_input.getAtt(
"platform").getValues(
platform);
410 }
catch (NcException
const & e) {
411 printf(
"-E- L2 file %s does not have instrument/platform attributes.\n",
input->files[0].c_str());
417 if (sensorId == -1) {
418 printf(
"-E- Can not look up sensor ID for %s.\n", localIfile);
422 if ((dataRoot = getenv(
"OCDATAROOT")) ==
NULL) {
423 printf(
"OCDATAROOT environment variable is not defined.\n");
428 sprintf(str_buf,
"%s/common/l2bin_defaults.par", dataRoot);
429 if (access(str_buf, R_OK) != -1) {
431 printf(
"Loading default parameters from %s\n", str_buf);
437 if (access(str_buf, R_OK) != -1) {
439 printf(
"Loading default parameters from %s\n", str_buf);
444 if (subsensorId != -1) {
445 sprintf(str_buf,
"%s/%s/%s/l2bin_defaults.par", dataRoot,
447 if (access(str_buf, R_OK) != -1) {
449 printf(
"Loading default parameters from %s\n", str_buf);
455 if (localSuite[0] == 0) {
461 if (localSuite[0] != 0) {
465 sprintf(str_buf,
"%s/common/l2bin_defaults_%s.par", dataRoot, localSuite);
466 if (access(str_buf, R_OK) != -1) {
469 printf(
"Loading default parameters from %s\n", str_buf);
474 sprintf(str_buf,
"%s/%s/l2bin_defaults_%s.par", dataRoot,
476 if (access(str_buf, R_OK) != -1) {
479 printf(
"Loading default parameters from %s\n", str_buf);
484 if (subsensorId != -1) {
485 sprintf(str_buf,
"%s/%s/%s/l2bin_defaults_%s.par", dataRoot,
488 if (access(str_buf, R_OK) != -1) {
491 printf(
"Loading default parameters from %s\n", str_buf);
497 printf(
"-E- Failed to load parameters for suite %s for sensor %s\n", localSuite,
506 printf(
"Loading command line parameters\n\n");
512 printf(
"-E- %s: Error loading options into input structure.\n", __FILE__);
519 sprintf(str_buf,
"infile = %s\n",
input->infile);
520 strcat(
input->parms, str_buf);
521 sprintf(str_buf,
"ofile = %s\n",
input->ofile);
522 strcat(
input->parms, str_buf);
523 sprintf(str_buf,
"fileuse = %s\n",
input->fileuse);
524 strcat(
input->parms, str_buf);
526 sprintf(str_buf,
"sday = %d\n",
input->sday);
527 strcat(
input->parms, str_buf);
528 sprintf(str_buf,
"eday = %d\n",
input->eday);
529 strcat(
input->parms, str_buf);
531 sprintf(str_buf,
"latnorth = %f\n",
input->latnorth);
532 strcat(
input->parms, str_buf);
533 sprintf(str_buf,
"latsouth = %f\n",
input->latsouth);
534 strcat(
input->parms, str_buf);
535 sprintf(str_buf,
"loneast = %f\n",
input->loneast);
536 strcat(
input->parms, str_buf);
537 sprintf(str_buf,
"lonwest = %f\n",
input->lonwest);
538 strcat(
input->parms, str_buf);
540 sprintf(str_buf,
"resolve = %s\n",
input->resolve);
541 strcat(
input->parms, str_buf);
543 sprintf(str_buf,
"rowgroup = %d\n",
input->rowgroup);
544 strcat(
input->parms, str_buf);
546 sprintf(str_buf,
"flaguse = %s\n",
input->flaguse);
547 strcat(
input->parms, str_buf);
549 sprintf(str_buf,
"l3bprod = %s\n",
input->l3bprod);
550 strcat(
input->parms, str_buf);
552 sprintf(str_buf,
"output_wavelengths = %s\n",
input->output_wavelengths);
553 strcat(
input->parms, str_buf);
555 sprintf(str_buf,
"prodtype = %s\n",
input->prodtype);
556 strcat(
input->parms, str_buf);
558 sprintf(str_buf,
"pversion = %s\n",
input->pversion);
559 strcat(
input->parms, str_buf);
561 sprintf(str_buf,
"suite = %s\n",
input->suite);
562 strcat(
input->parms, str_buf);
564 sprintf(str_buf,
"night = %d\n",
input->night);
565 strcat(
input->parms, str_buf);
567 sprintf(str_buf,
"verbose = %d\n",
input->verbose);
568 strcat(
input->parms, str_buf);
570 sprintf(str_buf,
"minobs = %d\n",
input->minobs);
571 strcat(
input->parms, str_buf);
573 sprintf(str_buf,
"delta_crossing_time = %f\n",
input->deltaeqcross);
574 strcat(
input->parms, str_buf);
576 sprintf(str_buf,
"deflate = %d\n",
input->deflate);
577 strcat(
input->parms, str_buf);
579 sprintf(str_buf,
"qual_prod = %s\n",
input->qual_prod);
580 strcat(
input->parms, str_buf);
582 sprintf(str_buf,
"composite_prod = %s\n",
input->composite_prod);
583 strcat(
input->parms, str_buf);
585 sprintf(str_buf,
"composite_scheme = %s\n",
input->composite_scheme);
586 strcat(
input->parms, str_buf);
588 sprintf(str_buf,
"qual_max = %d\n",
input->qual_max);
589 strcat(
input->parms, str_buf);
591 sprintf(str_buf,
"area_weighting = %d\n",
input->area_weighting);
592 strcat(
input->parms, str_buf);
594 sprintf(str_buf,
"doi = %s\n",
input->doi);
595 strcat(
input->parms, str_buf);
597 sprintf(str_buf,
"oprodname = %s\n",
input->output_product_names);
598 strcat(
input->parms, str_buf);
clo_option_t * clo_addOption(clo_optionList_t *list, const char *key, enum clo_dataType_t dataType, const char *defaultVal, const char *desc)
const char * sensorId2SensorDir(int sensorId)
float clo_getOptionFloat(clo_option_t *option)
char * clo_getString(clo_optionList_t *list, const char *key)
void clo_readArgs(clo_optionList_t *list, int argc, char *argv[])
int instrumentPlatform2SensorId(const char *instrument, const char *platform)
void clo_addAlias(clo_optionList_t *list, const char *key, const char *alias)
char * clo_getOptionRawString(clo_option_t *option)
int clo_isSet(clo_optionList_t *list, const char *key)
int clo_getOptionInt(clo_option_t *option)
int sensorId2SubsensorId(int sensorId)
int clo_isOptionSet(clo_option_t *option)
void clo_setEnableDumpOptions(int val)
clo_optionList_t * clo_createList()
list(APPEND LIBS ${NETCDF_LIBRARIES}) find_package(GSL REQUIRED) include_directories($
void clo_setHelpStr(const char *str)
char * clo_getOptionString(clo_option_t *option)
void clo_printUsage(clo_optionList_t *list)
clo_option_t * clo_getOption(clo_optionList_t *list, int i)
void clo_addOptionAlias(clo_option_t *option, const char *alias)
void clo_readFile(clo_optionList_t *list, const char *fileName)
int clo_getNumOptions(clo_optionList_t *list)
void parse_file_name(const char *inpath, char *outpath)
std::vector< std::string > readFileList(std::string fileName)
const char * sensorId2SensorName(int sensorId)
void clo_setVersion(const char *str)
void clo_deleteList(clo_optionList_t *list)
const char * subsensorId2SubsensorDir(int subsensorId)
enum clo_dataType_t dataType
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int clo_getOptionBool(clo_option_t *option)