OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
calibrate_viirs_input.cpp
Go to the documentation of this file.
1 #include "calibrate_viirs.h"
2 
3 #include <assert.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 
8 #include <genutils.h>
9 #include <sensorInfo.h>
10 #include <VcstGetSensorId.h>
11 
12 static const char *help_optionKeys[] = {
13  "help",
14  "version",
15  "dump_options",
16  "dump_options_paramfile",
17  "dump_options_xmlfile",
18  "par",
19  "ifile",
20  "l1bfile_img",
21  "l1bfile_mod",
22  "l1bfile_dnb",
23  "l1bfile_cdg",
24  "static_lut_file",
25  "rsb_dynamic_lut_file ",
26  "dnb_dynamic_lut_file",
27  "straylight_lut_file",
28  "cmn_lut_file",
29  "polar_wander_file",
30  "leapsec_file",
31  "geo_lut_file",
32  "terrain_path",
33  "verbose",
34  "pversion",
35  "pcf_help",
36  NULL
37 };
38 
40 void calibrate_viirs_init_options(clo_optionList_t* list, const char* softwareVersion) {
41  char tmpStr[2048];
42  clo_option_t* option;
43  int i;
44 
45  clo_setVersion2("calibrate_viirs", softwareVersion);
46 
47  sprintf(tmpStr, "Usage: calibrate_viirs argument-list\n\n");
48 
49  strcat(tmpStr, " This program takes a VIIRS L1A file and outputs an L1B file.\n\n");
50 
51  strcat(tmpStr, " The argument-list is a set of keyword=value pairs. The arguments can\n");
52  strcat(tmpStr, " be specified on the commandline, or put into a parameter file, or the\n");
53  strcat(tmpStr, " two methods can be used together, with commandline over-riding.\n\n");
54  strcat(tmpStr, "The list of valid keywords follows:\n");
55  clo_setHelpStr(tmpStr);
56 
57  // add the parameters common to all VIIRS programs
59 
60  option = clo_addOption(list, "verbose", CLO_TYPE_BOOL, "false", "turn on verbose output");
61  clo_addOptionAlias(option, "v");
62 
63  clo_setSelectOptionKeys((char**) help_optionKeys);
64 }
65 
66 /*
67  Read the command line option and all of the default parameter files.
68 
69  This is the order for loading the options:
70  - load the main program defaults file
71  - load the command line (including specified par files)
72  - re-load the command line disabling file descending so command
73  line arguments will over ride
74 
75  */
76 void calibrate_viirs_read_options(clo_optionList_t* list, int argc, char* argv[]) {
77  char *dataRoot;
78  char tmpStr[FILENAME_MAX];
79  int i;
80 
81  assert(list);
82 
83  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
84  fprintf(stderr, "-E- OCDATAROOT environment variable is not defined.\n");
85  exit(EXIT_FAILURE);
86  }
87 
88  // disable the dump option until we have read all of the default files
90 
91  // load program defaults
92  sprintf(tmpStr, "%s/common/calibrate_viirs_defaults.par", dataRoot);
93  clo_readFile(list, tmpStr);
94 
95  // read all arguments including descending par files
96  clo_readArgs(list, argc, argv);
97 
98  // handle PCF file on command line
100  fprintf(stderr, "-E- Too many command line parameters. Only one par file name allowed.\n");
101  exit(EXIT_FAILURE);
102  }
103 
104  if (clo_getPositionNumOptions(list) == 1) {
106  }
107 
109 
110  if (clo_getPositionNumOptions(list) != 1) {
111  // get sensor directory for this ifile
112  int sensorId = VcstGetSensorId(clo_getString(list, "ifile"));
113  const char* sensorDir = sensorId2SensorDir(sensorId);
114  if (sensorDir == NULL) {
115  fprintf(stderr, "-E- %s:%d - Could not find sensor directory for file %s\n",
116  __FILE__, __LINE__, clo_getString(list, "ifile"));
117  exit(EXIT_FAILURE);
118  }
119 
120  const char* subsensorDir = subsensorId2SubsensorDir(sensorId2SubsensorId(sensorId));
121  if (subsensorDir == NULL) {
122  fprintf(stderr, "-E- %s:%d - Could not find subsensor directory for sensor %s\n",
123  __FILE__, __LINE__, sensorId2SensorName(sensorId));
124  exit(EXIT_FAILURE);
125  }
126 
127  // load the subsensor specific defaults file
128  sprintf(tmpStr, "%s/%s/%s/instrument_defaults.par", dataRoot, sensorDir, subsensorDir);
129  clo_readFile(list, tmpStr);
130  }
131  // enable the dump option
133 
134  clo_readArgs(list, argc, argv);
135 
136 }
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
const char * sensorId2SensorDir(int sensorId)
Definition: sensorInfo.c:240
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
void calibrate_viirs_read_options(clo_optionList_t *list, int argc, char *argv[])
#define NULL
Definition: decode_rs.h:63
int sensorId2SubsensorId(int sensorId)
Definition: sensorInfo.c:322
@ CLO_TYPE_BOOL
Definition: clo.h:78
void clo_setVersion2(const char *programName, const char *versionStr)
Definition: clo.c:464
void clo_setSelectOptionKeys(char **keys)
Definition: clo.c:514
void clo_setEnableDumpOptions(int val)
Definition: clo.c:410
void clo_setHelpStr(const char *str)
Definition: clo.c:487
void VL1_add_options(clo_optionList_t *list)
char * clo_getPositionString(clo_optionList_t *list, int pos)
Definition: clo.c:1723
void calibrate_viirs_init_options(clo_optionList_t *list, const char *softwareVersion)
void clo_addOptionAlias(clo_option_t *option, const char *alias)
Definition: clo.c:632
void clo_readFile(clo_optionList_t *list, const char *fileName)
Definition: clo.c:2210
const char * sensorId2SensorName(int sensorId)
Definition: sensorInfo.c:198
int VcstGetSensorId(const std::string &l1FileName)
int clo_getPositionNumOptions(clo_optionList_t *list)
Definition: clo.c:1704
const char * subsensorId2SubsensorDir(int subsensorId)
Definition: sensorInfo.c:254
int i
Definition: decode_rs.h:71
void VL1_copy_options()