OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
tmatrix_input.cpp
Go to the documentation of this file.
1 #include <assert.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 
6 #include <tmatrix.h>
7 
8 static const char *help_optionKeys[] = {
9  "-help",
10  "-version",
11  "-dump_options",
12  "-dump_options_paramfile",
13  "-dump_options_xmlfile",
14  "par",
15  "ofile",
16  "verbose",
17  "pversion",
18  "pcf_help",
19  NULL
20 };
21 
22 // should the par file processing descend into other par files
23 static int enableFileDescending = 1;
24 
27 void par_option_cb(struct clo_option_t *option) {
28  if (enableFileDescending)
29  clo_readFile((clo_optionList_t*) option->cb_data, option->valStr);
30 }
31 
33 void tmatrix_init_options(clo_optionList_t* list, const char* softwareVersion) {
34  char tmpStr[2048];
35  clo_option_t* option;
36 
37  clo_setVersion2("tmatrix", softwareVersion);
38 
39  sprintf(tmpStr, "Usage: tmatrix argument-list\n\n");
40 
41  strcat(tmpStr, " This program generates a T-Matrix product.\n\n");
42 
43  strcat(tmpStr, " The argument-list is a set of keyword=value pairs. The arguments can\n");
44  strcat(tmpStr, " be specified on the command line, or put into a parameter file, or the\n");
45  strcat(tmpStr, " two methods can be used together, with command line over-riding.\n\n");
46  strcat(tmpStr, "The list of valid keywords follows:\n");
47  clo_setHelpStr(tmpStr);
48 
49  // add the par option and add the callback function
50 // option = clo_addOption(list, "par", CLO_TYPE_STRING, NULL, "input parameter file");
51 // option->cb_data = (void*) list;
52 // option->cb = par_option_cb;
53 
55 
56  option = clo_addOption(list, "verbose", CLO_TYPE_BOOL, "false", "turn on verbose output");
57  clo_addOptionAlias(option, "v");
58 
59  clo_setSelectOptionKeys((char**)help_optionKeys);
60 }
61 
62 
63 /*
64  Read the command line option and all of the default parameter files.
65 
66  This is the order for loading the options:
67  - load the main program defaults file
68  - load the command line (including specified par files)
69  - re-load the command line disabling file descending so command
70  line arguments will over ride
71 
72  */
73 void tmatrix_read_options(clo_optionList_t* list, int argc, char* argv[]) {
74  char *dataRoot;
75  char tmpStr[FILENAME_MAX];
76 
77  assert(list);
78 
79  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
80  fprintf(stderr, "-E- OCDATAROOT environment variable is not defined.\n");
81  exit(EXIT_FAILURE);
82  }
83 
84  // disable the dump option until we have read all of the files
86 
87  enableFileDescending = 1;
88 
89  // load program defaults
90  sprintf(tmpStr, "%s/common/tmatrix_defaults.par", dataRoot);
91  clo_readFile(list, tmpStr);
92 
93  // read all arguments including descending par files
94  clo_readArgs(list, argc, argv);
95 
96  // if a file was descended, make sure the command args over-rides
97  enableFileDescending = 0;
98  clo_readArgs(list, argc, argv);
99 
100  // get sensor directory for this ifile
101  //const char* sensorDir = getSensorDirectory(clo_getString(optionList, "ifile"));
102  //const char* sensorDir = "viirsn";
103 
104  // load the sensor specific defaults file
105  //sprintf(tmpStr, "%s/%s/instrument_defaults.par", dataRoot, sensorDir);
106  //enableFileDescending = 1;
107  //clo_readFile(list, tmpStr);
108 
109  // read all arguments including descending par files
110  clo_readArgs(list, argc, argv);
111 
112  // enable the dump option
114 
115  // if a file was descended, make sure the command args over-rides
116  enableFileDescending = 0;
117  clo_readArgs(list, argc, argv);
118  enableFileDescending = 1;
119 
120  // handle PCF file on command line
122  fprintf(stderr, "-E- Too many command line parameters. Only one par file name allowed.\n");
123  exit(EXIT_FAILURE);
124  }
125 
126  if(clo_getPositionNumOptions(list) == 1) {
128  }
129 
130  tm_copy_options();
131 }
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
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
void tmatrix_read_options(clo_optionList_t *list, int argc, char *argv[])
@ 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 par_option_cb(struct clo_option_t *option)
void tm_add_options(clo_optionList_t *list)
void clo_setEnableDumpOptions(int val)
Definition: clo.c:410
void clo_setHelpStr(const char *str)
Definition: clo.c:487
char * valStr
Definition: clo.h:108
char * clo_getPositionString(clo_optionList_t *list, int pos)
Definition: clo.c:1723
void tmatrix_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
int clo_getPositionNumOptions(clo_optionList_t *list)
Definition: clo.c:1704
void * cb_data
Definition: clo.h:111
void tm_copy_options()