OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
geolocate_viirs_input.cpp
Go to the documentation of this file.
1 #include "geolocate_viirs.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  "ifile",
20  "geofile_img",
21  "geofile_mod",
22  "geofile_dnb",
23  "static_lut_file",
24  "rsb_dynamic_lut_file ",
25  "dnb_dynamic_lut_file",
26  "straylight_lut_file",
27  "cmn_lut_file",
28  "geo_lut_file",
29  "polar_wander_file",
30  "leapsec_file",
31  "terrain_path",
32  "land_water_mask_path",
33  "verbose",
34  "pversion",
35  "doi",
36  "pcf_help",
37  NULL
38 };
39 
41 void geolocate_viirs_init_options(clo_optionList_t* list, const char* softwareVersion) {
42  char tmpStr[2048];
43  clo_option_t* option;
44  int i;
45 
46  clo_setVersion2("geolocate_viirs", softwareVersion);
47 
48  sprintf(tmpStr, "Usage: geolocate_viirs argument-list\n\n");
49 
50  strcat(tmpStr, " This program takes a VIIRS L1A file and outputs geolocation files.\n\n");
51 
52  strcat(tmpStr, " The argument-list is a set of keyword=value pairs. The arguments can\n");
53  strcat(tmpStr, " be specified on the commandline, or put into a parameter file, or the\n");
54  strcat(tmpStr, " two methods can be used together, with commandline over-riding.\n\n");
55  strcat(tmpStr, "The list of valid keywords follows:\n");
56  clo_setHelpStr(tmpStr);
57 
58  // add the parameters common to all VIIRS programs
60 
61  option = clo_addOption(list, "verbose", CLO_TYPE_BOOL, "false", "turn on verbose output");
62  clo_addOptionAlias(option, "v");
63 
64  clo_setSelectOptionKeys((char**) help_optionKeys);
65 }
66 
67 /*
68  Read the command line option and all of the default parameter files.
69 
70  This is the order for loading the options:
71  - load the main program defaults file
72  - load the command line (including specified par files)
73  - re-load the command line disabling file descending so command
74  line arguments will over ride
75 
76  */
77 void geolocate_viirs_read_options(clo_optionList_t* list, int argc, char* argv[]) {
78  char *dataRoot;
79  char tmpStr[FILENAME_MAX];
80  int i;
81 
82  assert(list);
83 
84  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
85  fprintf(stderr, "-E- OCDATAROOT environment variable is not defined.\n");
86  exit(EXIT_FAILURE);
87  }
88 
89  // disable the dump option until we have read all of the files
91 
92  // load program defaults
93  sprintf(tmpStr, "%s/common/geolocate_viirs_defaults.par", dataRoot);
94  clo_readFile(list, tmpStr);
95 
96  // read all arguments including descending par files
97  clo_readArgs(list, argc, argv);
98 
99  // handle PCF file on command line
100  if (clo_getPositionNumOptions(list) > 1) {
101  fprintf(stderr, "-E- Too many command line parameters. Only one par file name allowed.\n");
102  exit(EXIT_FAILURE);
103  }
104 
105  if (clo_getPositionNumOptions(list) == 1) {
107  }
109 
110  if (clo_getPositionNumOptions(list) != 1) {
111  // get sensor directory for this ifile
112  int sensorId = VcstGetSensorId(clo_getString(list, "ifile"));
113  const char* sensorDir = sensorId2SensorDir(sensorId);
114  if (sensorDir == NULL) {
115  fprintf(stderr, "-E- %s:%d - Could not find sensor directory for file %s\n",
116  __FILE__, __LINE__, clo_getString(list, "ifile"));
117  exit(EXIT_FAILURE);
118  }
119 
120  const char* subsensorDir = subsensorId2SubsensorDir(sensorId2SubsensorId(sensorId));
121  if (subsensorDir == NULL) {
122  fprintf(stderr, "-E- %s:%d - Could not find subsensor directory for sensor %s\n",
123  __FILE__, __LINE__, sensorId2SensorName(sensorId));
124  exit(EXIT_FAILURE);
125  }
126 
127  // load the subsensor specific defaults file
128  sprintf(tmpStr, "%s/%s/%s/instrument_defaults.par", dataRoot, sensorDir, subsensorDir);
129  clo_readFile(list, tmpStr);
130  }
131  // enable the dump option
133 
134  clo_readArgs(list, argc, argv);
135 
136 }
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
void geolocate_viirs_init_options(clo_optionList_t *list, const char *softwareVersion)
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
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
void geolocate_viirs_read_options(clo_optionList_t *list, int argc, char *argv[])
int i
Definition: decode_rs.h:71
void VL1_copy_options()