OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
afrt_input.cpp
Go to the documentation of this file.
1 #include <afrt_input.h>
2 
3 #include <assert.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <stdlib.h>
7 
8 
9 // should the par file processing descend into other par files
10 static int enableFileDescending = 1;
11 
14 void par_option_cb(struct clo_option_t *option) {
15  if (enableFileDescending)
16  clo_readFile((clo_optionList_t*) option->cb_data, option->valStr);
17 }
18 
20 void afrt_init_options(clo_optionList_t* list, const char* softwareVersion) {
21  char tmpStr[2048];
22  clo_option_t* option;
23 
24  clo_setVersion2("afrt", softwareVersion);
25 
26  sprintf(tmpStr, "Usage: afrt argument-list [par file]\n\n");
27 
28  strcat(tmpStr, " This program generates a T-Matrix product.\n\n");
29 
30  strcat(tmpStr, " The argument-list is a set of keyword=value pairs. The arguments can\n");
31  strcat(tmpStr, " be specified on the command line, or put into a parameter file, or the\n");
32  strcat(tmpStr, " two methods can be used together, with command line over-riding.\n\n");
33  strcat(tmpStr, "The list of valid keywords follows:\n");
34  clo_setHelpStr(tmpStr);
35 
36  option = clo_addOption(list, "verbose", CLO_TYPE_BOOL, "false", "turn on verbose output");
37  clo_addOptionAlias(option, "v");
38 
40 
41 }
42 
43 
44 /*
45  Read the command line option and all of the default parameter files.
46 
47  This is the order for loading the options:
48  - load the main program defaults file
49  - load the command line (including specified par files)
50  - re-load the command line disabling file descending so command
51  line arguments will over ride
52 
53  */
54 void afrt_read_options(clo_optionList_t* list, int argc, char* argv[]) {
55  char *dataRoot;
56  char tmpStr[FILENAME_MAX];
57 
58  assert(list);
59 
60  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
61  fprintf(stderr, "-E- OCDATAROOT environment variable is not defined.\n");
62  exit(EXIT_FAILURE);
63  }
64 
65  // disable the dump option until we have read all of the files
67 
68  enableFileDescending = 1;
69 
70  // load program defaults
71  sprintf(tmpStr, "%s/common/afrt_defaults.par", dataRoot);
72  clo_readFile(list, tmpStr);
73 
74  // read all arguments including descending par files
75  clo_readArgs(list, argc, argv);
76 
77  // handle PCF file on command line
79  fprintf(stderr, "-E- Too many command line parameters. Only one par file name allowed.\n");
80  exit(EXIT_FAILURE);
81  }
82 
85  }
86 
87  // if a file was descended, make sure the command args over-rides
88  enableFileDescending = 0;
89  clo_readArgs(list, argc, argv);
90 
91  // read all arguments including descending par files
92  clo_readArgs(list, argc, argv);
93 
94  // enable the dump option
96 
97  // if a file was descended, make sure the command args over-rides
98  enableFileDescending = 0;
99  clo_readArgs(list, argc, argv);
100  enableFileDescending = 1;
101 
102  //afrt_copy_options();
103 }
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 par_option_cb(struct clo_option_t *option)
Definition: afrt_input.cpp:14
@ CLO_TYPE_BOOL
Definition: clo.h:78
void clo_setVersion2(const char *programName, const char *versionStr)
Definition: clo.c:464
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 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 afrt_read_options(clo_optionList_t *list, int argc, char *argv[])
Definition: afrt_input.cpp:54
void afrt_init_options(clo_optionList_t *list, const char *softwareVersion)
Definition: afrt_input.cpp:20
int clo_getPositionNumOptions(clo_optionList_t *list)
Definition: clo.c:1704
void * cb_data
Definition: clo.h:111
void afrt_add_options(clo_optionList_t *list)