OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
TmParamsReader.cpp
Go to the documentation of this file.
1 
2 /**************************************************************************
3 *
4 * NAME: TmParamsReader.cpp
5 *
6 * DESCRIPTION: The TmParamsReader class sets up the items
7 * that are in the program configuration file.
8 * The class provides primitives to read the configurable
9 * information and provide it to other classes as required.
10 *
11 * Created on: April, 2018
12 * Author: Sam Anderson, DT
13 *
14 **************************************************************************/
15 
16 #include <iostream>
17 #include <string>
18 #include <cstdlib>
19 #include <algorithm>
20 #include <vector>
21 #include <map>
22 #include <libgen.h>
23 
24 #include <TmParamsReader.h>
25 #include <TmConstants.h>
26 
27 using namespace std;
28 
29 //---------------------------------------------------------------------------
30 // Static constants
31 //---------------------------------------------------------------------------
32 
33 const std::string INPUT_LAM = "wavelength";
34 const std::string INPUT_EPS_MAX = "axial_ratio_max";
35 const std::string INPUT_EPS_MIN = "axial_ratio_min";
36 const std::string INPUT_EPS_NUM = "axial_ratio_num";
37 const std::string INPUT_MRR_MAX = "mrr_max";
38 const std::string INPUT_MRR_MIN = "mrr_min";
39 const std::string INPUT_MRR_NUM = "mrr_num";
40 const std::string INPUT_MRI_MAX = "mri_max";
41 const std::string INPUT_MRI_MIN = "mri_min";
42 const std::string INPUT_MRI_NUM = "mri_num";
43 const std::string INPUT_B_MAX = "var_max";
44 const std::string INPUT_B_MIN = "var_min";
45 const std::string INPUT_B_NUM = "var_num";
46 const std::string INPUT_NPNAX = "rad_num";
47 const std::string INPUT_AXMAX = "rad_max";
48 const std::string INPUT_NPNA = "scattering_angles";
49 const std::string INPUT_DDELT = "computational_accuracy";
50 const std::string INPUT_NDGS = "division_points";
51 const std::string INPUT_NKMAX = "quadrature_points";
52 const std::string INPUT_NCOEFF = "expansion_coeffs";
53 const std::string INPUT_GAM = "modified_gamma";
54 const std::string INPUT_RAT = "radius_type";
55 const std::string INPUT_NP = "shape_type";
56 const std::string INPUT_NDISTR = "distribution_type";
57 const std::string OUTPUT_NC4 = "ofile";
58 
59 // global variable to hold the command line parameters
60 static clo_optionList_t* tm_global_optionList = NULL;
61 
63  tm_global_optionList = list;
64 }
65 
67  if(tm_global_optionList == NULL) {
68  cerr << "tm_get_optionList: optionList pointer needs to be set before accessing." << endl;
69  exit(EXIT_FAILURE);
70  }
71  return tm_global_optionList;
72 }
73 
75  if(tm_global_optionList == NULL) {
76  cerr << "tm_get_option: optionList pointer needs to be set before accessing." << endl;
77  exit(EXIT_FAILURE);
78  }
79  clo_option_t* option = clo_findOption(tm_global_optionList, name.c_str());
80  if(option == NULL || !clo_isOptionSet(option))
81  return "";
82  string result(clo_getOptionString(option));
83  return result;
84 }
85 
87  if(tm_global_optionList == NULL) {
88  cerr << "tm_get_option: optionList pointer needs to be set before accessing." << endl;
89  exit(EXIT_FAILURE);
90  }
91  clo_option_t* option = clo_findOption(tm_global_optionList, name.c_str());
92  if(option == NULL || !clo_isOptionSet(option))
93  return -999;
94  int result(clo_getOptionInt(option));
95  return result;
96 }
97 
99  if(tm_global_optionList == NULL) {
100  cerr << "tm_get_option: optionList pointer needs to be set before accessing." << endl;
101  exit(EXIT_FAILURE);
102  }
103  clo_option_t* option = clo_findOption(tm_global_optionList, name.c_str());
104  if(option == NULL || !clo_isOptionSet(option))
105  return -999.9;
106  float result(clo_getOptionDouble(option));
107  return result;
108 }
109 
111  if(tm_global_optionList == NULL) {
112  cerr << "tm_get_option: optionList pointer needs to be set before accessing." << endl;
113  exit(EXIT_FAILURE);
114  }
115  clo_option_t* option = clo_findOption(tm_global_optionList, name.c_str());
116  if(option == NULL || !clo_isOptionSet(option))
117  return nullptr;
118  double* result(clo_getOptionDoubles(option, count));
119  return result;
120 }
121 
122 
124  if(tm_global_optionList == NULL)
125  tm_global_optionList = list;
126 
127  clo_addOption(list, OUTPUT_NC4.c_str(), CLO_TYPE_OFILE, NULL, "output t-matrix filename");
128  clo_addOption(list, INPUT_RAT.c_str(), CLO_TYPE_STRING, NULL, "radius type");
129  clo_addOption(list, INPUT_NP.c_str(), CLO_TYPE_STRING, NULL, "shape type");
130  clo_addOption(list, INPUT_LAM.c_str(), CLO_TYPE_DOUBLE, NULL, "wavelengths");
131  clo_addOption(list, INPUT_MRR_MAX.c_str(), CLO_TYPE_DOUBLE, NULL, "maximum real part index of refraction");
132  clo_addOption(list, INPUT_MRR_MIN.c_str(), CLO_TYPE_DOUBLE, NULL, "minimum real part index of refraction");
133  clo_addOption(list, INPUT_MRR_NUM.c_str(), CLO_TYPE_INT, NULL, "number of real part index of refraction");
134  clo_addOption(list, INPUT_MRI_MAX.c_str(), CLO_TYPE_DOUBLE, NULL, "maximum imaginary part index of refraction");
135  clo_addOption(list, INPUT_MRI_MIN.c_str(), CLO_TYPE_DOUBLE, NULL, "minimum imaginary part index of refraction");
136  clo_addOption(list, INPUT_MRI_NUM.c_str(), CLO_TYPE_INT, NULL, "number of imaginary part index of refraction");
137  clo_addOption(list, INPUT_EPS_MAX.c_str(), CLO_TYPE_DOUBLE, NULL, "maximum axial ratio");
138  clo_addOption(list, INPUT_EPS_MIN.c_str(), CLO_TYPE_DOUBLE, NULL, "minimum axial ratio");
139  clo_addOption(list, INPUT_EPS_NUM.c_str(), CLO_TYPE_INT, NULL, "number of axial ratio");
140  clo_addOption(list, INPUT_B_MAX.c_str(), CLO_TYPE_DOUBLE, NULL, "maximum particle size variance");
141  clo_addOption(list, INPUT_B_MIN.c_str(), CLO_TYPE_DOUBLE, NULL, "minimum particle size variance");
142  clo_addOption(list, INPUT_B_NUM.c_str(), CLO_TYPE_INT, NULL, "number of particle size variance");
143  clo_addOption(list, INPUT_AXMAX.c_str(), CLO_TYPE_DOUBLE, NULL, "maximum particle size radius");
144  clo_addOption(list, INPUT_NPNAX.c_str(), CLO_TYPE_INT, NULL, "number of particle size radii");
145  clo_addOption(list, INPUT_GAM.c_str(), CLO_TYPE_DOUBLE, NULL, "gamma distribution parameter");
146  clo_addOption(list, INPUT_DDELT.c_str(), CLO_TYPE_DOUBLE, NULL, "computational accuracy");
147  clo_addOption(list, INPUT_NDGS.c_str(), CLO_TYPE_INT, NULL, "division_points");
148  clo_addOption(list, INPUT_NDISTR.c_str(), CLO_TYPE_STRING, NULL, "size distribution type");
149  clo_addOption(list, INPUT_NKMAX.c_str(), CLO_TYPE_INT, NULL, "quadrature_points");
150  clo_addOption(list, INPUT_NPNA.c_str(), CLO_TYPE_INT, NULL, "scattering_angles");
151  clo_addOption(list, INPUT_NCOEFF.c_str(), CLO_TYPE_INT, NULL, "number of coefficients reported");
152 
153  clo_addOption(list, "pversion", CLO_TYPE_STRING, "Unspecified", "processing version string");
154 
155  string desc = "\n";
156  desc += "This program can also accept a parameters file. The par file option names take\n";
157  desc += "precedence over the standard option parameters even if the standard option\n";
158  desc += "is on the command line. To over ride an option in a parameters file, use the \n";
159  desc += "option name on the command line.\n\n";
160  desc += "use \"-dump_options\" on the command line to see a list of ALL option names.\n";
161  clo_addOption(list, "pcf_help", CLO_TYPE_HELP, NULL, desc.c_str());
162 }
163 
165 }
166 
167 string tm_get_source() {
168  vector<string> sourcesList;
169 
170  string source;
171 
172  for(vector<string>::iterator it = sourcesList.begin(); it < sourcesList.end(); it++) {
173  string str = tm_get_option(*it);
174  if(!str.empty()) {
175  source.append(",");
176  source.append(basename((char*)str.c_str()));
177  }
178  }
179  return source;
180 }
181 
182 string tm_get_history(int argc, char* argv[]) {
183  string history = basename(argv[0]);
184  for (int i=1; i<argc; i++) {
185  history.append(" ");
186  history.append(basename(argv[i]));
187  }
188  return history;
189 }
190 
const std::string INPUT_MRR_NUM
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 std::string INPUT_NPNA
const std::string OUTPUT_NC4
const std::string INPUT_NDISTR
list(APPEND LIBS ${PGSTK_LIBRARIES}) add_executable(atteph_info_modis atteph_info_modis.c) target_link_libraries(atteph_info_modis $
Definition: CMakeLists.txt:7
double clo_getOptionDouble(clo_option_t *option)
Definition: clo.c:1195
double tm_get_option_double(const std::string &name)
double * clo_getOptionDoubles(clo_option_t *option, int *count)
Definition: clo.c:1317
const std::string INPUT_MRI_NUM
#define NULL
Definition: decode_rs.h:63
@ CLO_TYPE_DOUBLE
Definition: clo.h:82
const std::string INPUT_NDGS
clo_option_t * clo_findOption(clo_optionList_t *list, const char *key)
Definition: clo.c:967
int clo_getOptionInt(clo_option_t *option)
Definition: clo.c:1113
const std::string INPUT_GAM
@ string
int clo_isOptionSet(clo_option_t *option)
Definition: clo.c:2257
const std::string INPUT_MRR_MIN
double * tm_get_option_doubles(const std::string &name, int *count)
void tm_add_options(clo_optionList_t *list)
const std::string INPUT_EPS_MAX
@ CLO_TYPE_INT
Definition: clo.h:79
char * clo_getOptionString(clo_option_t *option)
Definition: clo.c:1050
const std::string INPUT_B_NUM
const std::string INPUT_DDELT
const std::string INPUT_MRR_MAX
const std::string INPUT_NP
const std::string INPUT_LAM
clo_optionList_t * tm_get_optionList()
const std::string INPUT_EPS_MIN
@ CLO_TYPE_OFILE
Definition: clo.h:85
string history
Definition: ncattredit.py:30
string tm_get_history(int argc, char *argv[])
string tm_get_source()
const std::string INPUT_RAT
#define basename(s)
Definition: l0chunk_modis.c:29
@ CLO_TYPE_HELP
Definition: clo.h:86
const char * str
Definition: l1c_msi.cpp:35
int tm_get_option_int(const std::string &name)
const std::string INPUT_MRI_MIN
const std::string INPUT_MRI_MAX
const std::string INPUT_NPNAX
const std::string INPUT_B_MAX
const std::string INPUT_B_MIN
int i
Definition: decode_rs.h:71
const std::string INPUT_NCOEFF
@ CLO_TYPE_STRING
Definition: clo.h:83
std::string tm_get_option(const std::string &name)
const std::string INPUT_AXMAX
const std::string INPUT_NKMAX
const std::string INPUT_EPS_NUM
void tm_set_optionList(clo_optionList_t *list)
void tm_copy_options()
int count
Definition: decode_rs.h:79