OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
generate_nc4luts_input.cpp
Go to the documentation of this file.
1 #include "generate_nc4luts.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  "platform",
20  "polar_wander_file",
21  "leapsec_file",
22  "terrain_path",
23  "land_water_mask_path",
24  "verbose",
25  "pversion",
26  "NETCDF_LUT_PATH_LUN",
27  "CMNGEO_PARAM_LUT_LUN",
28  "JPL_EPHEMERIS_LUN",
29  "SAA_COEFFS_LUN",
30  "SOLAR_DIFF_VOLT_LUT_LUN",
31  "SOLAR_DIFF_ROT_MAT_LUT_LUN",
32  "SDR_BB_TEMP_CONSTANTS_LUN",
33  "SDR_COEFF_A_LUT_LUN",
34  "SDR_COEFF_B_LUT_LUN",
35  "SDR_DELTA_C_LUT_LUN",
36  "SDR_DG_ANOMALY_DN_LIMITS_LUT_LUN",
37  "SDR_EB_BT_LUT_LUN",
38  "SDR_EMISSIVE_LUT_LUN",
39  "SDR_GAIN_LUT_LUN",
40  "SDR_HAM_ER_LUT_LUN",
41  "SDR_OBC_ER_LUT_LUN",
42  "SDR_OBC_RR_LUT_LUN",
43  "SDR_OBS_TO_PIXELS_LUT_LUN",
44  "SDR_QA_LUT_LUN",
45  "SDR_RADIOMETRIC_PARAMS_LUN",
46  "SDR_REFLECTIVE_LUT_LUN",
47  "SDR_RTA_ER_LUT_LUN",
48  "SDR_RVS_LUT_LUN",
49  "SDR_SOLAR_IRAD_LUT_LUN",
50  "SDR_TELEM_COEFFS_LUN",
51  "DNB_FRAME_TO_ZONE_LUN",
52  "DNB_RVS_LUT_LUN",
53  "SDR_F_PREDICTED_LUT_LUN",
54  "SDR_RELATIVE_SPECTRAL_RESPONSE_LUT_LUN",
55  "SDR_DNB_LGS_GAINS_LUT_LUN",
56  "SDR_DNB_GAIN_RATIOS_LUT_LUN",
57  "DNB_DN0_LUT_LUN",
58  "SDR_DNB_STRAY_LIGHT_CORRECTION_LUT_LUN",
59  "GEOLOCATION_DNB_PARAMS_LUN",
60  "GEOLOCATION_IMG_PARAMS_LUN",
61  "GEOLOCATION_MOD_PARAMS_LUN",
62  "LANDWATER_PATH_LUN",
63  "pcf_help",
64  NULL
65 };
66 
68 void generate_nc4luts_init_options(clo_optionList_t* list, const char* softwareVersion) {
69  char tmpStr[2048];
70  clo_option_t* option;
71  int i;
72 
73  clo_setVersion2("generate_nc4luts", softwareVersion);
74 
75  sprintf(tmpStr, "Usage: generate_nc4luts argument-list\n\n");
76 
77  strcat(tmpStr, " This program takes a list of binary LUT files and generates a netcdf LUT.\n\n");
78 
79  strcat(tmpStr, " The argument-list is a set of keyword=value pairs. The arguments can\n");
80  strcat(tmpStr, " be specified on the commandline, or put into a parameter file, or the\n");
81  strcat(tmpStr, " two methods can be used together, with commandline over-riding.\n\n");
82  strcat(tmpStr, "The list of valid keywords follows:\n");
83  clo_setHelpStr(tmpStr);
84 
85  // add the parameters common to all VIIRS programs
87 
88  option = clo_addOption(list, "verbose", CLO_TYPE_BOOL, "false", "turn on verbose output");
89  clo_addOptionAlias(option, "v");
90 
91  clo_setSelectOptionKeys((char**) help_optionKeys);
92 }
93 
94 /*
95  Read the command line option and all of the default parameter files.
96 
97  This is the order for loading the options:
98  - load the main program defaults file
99  - load the command line (including specified par files)
100  - re-load the command line disabling file descending so command
101  line arguments will over ride
102 
103  */
104 void generate_nc4luts_read_options(clo_optionList_t* list, int argc, char* argv[]) {
105  char *dataRoot;
106  char tmpStr[FILENAME_MAX];
107  int i;
108 
109  assert(list);
110 
111  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
112  fprintf(stderr, "-E- OCDATAROOT environment variable is not defined.\n");
113  exit(EXIT_FAILURE);
114  }
115 
116  // disable the dump option until we have read all of the files
118 
119  // load program defaults
120  sprintf(tmpStr, "%s/common/generate_nc4luts_defaults.par", dataRoot);
121  clo_readFile(list, tmpStr);
122 
123  // read all arguments including descending par files
124  clo_readArgs(list, argc, argv);
125 
126  // handle PCF file on command line
127  if (clo_getPositionNumOptions(list) > 1) {
128  fprintf(stderr, "-E- Too many command line parameters. Only one par file name allowed.\n");
129  exit(EXIT_FAILURE);
130  }
131 
132  if (clo_getPositionNumOptions(list) == 1) {
134  }
136 
137  if (clo_getPositionNumOptions(list) != 1) {
138 
139  // get sensor directory for this ifile
140  int sensorId = VcstGetSensorId(clo_getString(list, "ifile"));
141  const char* sensorDir = sensorId2SensorDir(sensorId);
142  if (sensorDir == NULL) {
143  fprintf(stderr, "-E- %s:%d - Could not find sensor directory for file %s\n",
144  __FILE__, __LINE__, clo_getString(list, "ifile"));
145  exit(EXIT_FAILURE);
146  }
147 
148  const char* subsensorDir = subsensorId2SubsensorDir(sensorId2SubsensorId(sensorId));
149  if (subsensorDir == NULL) {
150  fprintf(stderr, "-E- %s:%d - Could not find subsensor directory for sensor %s\n",
151  __FILE__, __LINE__, sensorId2SensorName(sensorId));
152  exit(EXIT_FAILURE);
153  }
154 
155  // load the subsensor specific defaults file
156  sprintf(tmpStr, "%s/%s/%s/instrument_defaults.par", dataRoot, sensorDir, subsensorDir);
157  clo_readFile(list, tmpStr);
158  }
159  // enable the dump option
161 
162  clo_readArgs(list, argc, argv);
163 
164 }
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
#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 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
void generate_nc4luts_read_options(clo_optionList_t *list, int argc, char *argv[])
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()
void generate_nc4luts_init_options(clo_optionList_t *list, const char *softwareVersion)