OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
viirs_obc_input.cpp
Go to the documentation of this file.
1 #include "viirs_obc.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 
14  const char* softwareVersion) {
15  char tmpStr[2048];
16  clo_option_t* option;
17  int i;
18 
19  clo_setVersion2("viirs_obc", softwareVersion);
20 
21  sprintf(tmpStr, "Usage: viirs_obc argument-list\n\n");
22 
23  strcat(tmpStr,
24  " This program takes a VIIRS L1A file and outputs an OBC file.\n\n");
25 
26  strcat(tmpStr,
27  " The argument-list is a set of keyword=value pairs. The arguments can\n");
28  strcat(tmpStr,
29  " be specified on the commandline, or put into a parameter file, or the\n");
30  strcat(tmpStr,
31  " two methods can be used together, with commandline over-riding.\n\n");
32  strcat(tmpStr, "The list of valid keywords follows:\n");
33  clo_setHelpStr(tmpStr);
34 
35  // add the parameters common to all VIIRS programs
37 
38  option = clo_addOption(list, "verbose", CLO_TYPE_BOOL, "false",
39  "turn on verbose output");
40  clo_addOptionAlias(option, "v");
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 viirs_obc_read_options(clo_optionList_t* list, int argc, char* argv[]) {
55  char *dataRoot;
56  char tmpStr[FILENAME_MAX];
57  int i;
58 
59  assert(list);
60 
61  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
62  fprintf(stderr,
63  "-E- OCDATAROOT environment variable is not defined.\n");
64  exit(EXIT_FAILURE);
65  }
66 
67  // disable the dump option until we have read all of the files
69 
70  // load program defaults
71  sprintf(tmpStr, "%s/common/viirs_obc_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,
80  "-E- Too many command line parameters. Only one par file name allowed.\n");
81  exit(EXIT_FAILURE);
82  }
83 
84  if (clo_getPositionNumOptions(list) == 1) {
86  }
87 
89 
90  if (clo_getPositionNumOptions(list) != 1) {
91  // get sensor directory for this ifile
92  int sensorId = VcstGetSensorId(clo_getString(list, "ifile"));
93  const char* sensorDir = sensorId2SensorDir(sensorId);
94  if (sensorDir == NULL) {
95  fprintf(stderr, "-E- %s:%d - Could not find sensor directory for file %s\n",
96  __FILE__, __LINE__, clo_getString(list, "ifile"));
97  exit(EXIT_FAILURE);
98  }
99 
100  const char* subsensorDir = subsensorId2SubsensorDir(sensorId2SubsensorId(sensorId));
101  if (subsensorDir == NULL) {
102  fprintf(stderr, "-E- %s:%d - Could not find subsensor directory for sensor %s\n",
103  __FILE__, __LINE__, sensorId2SensorName(sensorId));
104  exit(EXIT_FAILURE);
105  }
106 
107  // load the subsensor specific defaults file
108  sprintf(tmpStr, "%s/%s/%s/instrument_defaults.par", dataRoot, sensorDir, subsensorDir);
109  clo_readFile(list, tmpStr);
110  }
111  // enable the dump option
113 
114  clo_readArgs(list, argc, argv);
115 
116 }
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
void viirs_obc_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_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 viirs_obc_init_options(clo_optionList_t *list, const char *softwareVersion)
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()