OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l2qc_viirs_input.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5 #include <assert.h>
6 #include <genutils.h>
7 #include <clo.h>
8 #include <sensorInfo.h>
9 #include "netcdf.h"
10 
11 #include "l2qc_viirs.h"
12 
14 int l2qcviirs_init_options(clo_optionList_t* list, const char* softwareVersion) {
15  char tmpStr[2048];
16  char *dataRoot;
17 
18  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
19  fprintf(stderr, "-E- OCDATAROOT environment variable is not defined.\n");
20  return (-1);
21  }
22 
23  clo_setVersion2("l2qc_viirs", softwareVersion);
24 
25  sprintf(tmpStr, "Usage: l2qc_viirs argument-list\n\n");
26 
27  strcat(tmpStr, " This program checks metadata of a VIIRS L2 data.\n");
28 
29  clo_setHelpStr(tmpStr);
30 
31  clo_addOption(list, "ifile", CLO_TYPE_IFILE, NULL, "input L2 file name");
32 
33  clo_addOption(list, "cfile", CLO_TYPE_IFILE, "default", "input L2qc configuration file name");
34 
35  clo_addOption(list, "ofile", CLO_TYPE_OFILE, NULL, "output filename");
36 
37  return 0;
38 }
39 
40 /*
41  Read the command line option and all of the default parameter files.
42 
43  This is the order for loading the options:
44  - load the main program defaults file
45  - load the command line (including specified par files)
46  - re-load the command line disabling file descending so command
47  line arguments will over ride
48 
49  */
50 int l2qcviirs_read_options(clo_optionList_t* list, int argc, char* argv[]) {
51  char *dataRoot;
52  char tmpStr[FILENAME_MAX];
53 
54  assert(list);
55 
56  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
57  fprintf(stderr, "-E- OCDATAROOT environment variable is not defined.\n");
58  return (-1);
59  }
60 
61  clo_readArgs(list, argc, argv);
62 
63 
64  // find default config file (cfile) if not set in options
65  if (strcmp(clo_getString(list, "cfile"),"default")==0) {
66 
67  // read platform and instrument directories from L2 file metadata
68  int ncid; // netCDF ID
69  char *str_L2file = NULL; // VIIRS L2 file
70  char platformStr[100];
71  char instrumentStr[100];
72  str_L2file = clo_getString(list, "ifile");
73  nc_open(str_L2file, NC_NOWRITE, &ncid);
74  nc_get_att_text(ncid, NC_GLOBAL, "platform", platformStr);
75  nc_get_att_text(ncid, NC_GLOBAL, "instrument", instrumentStr);
76  nc_close(ncid);
77  int sensorId = instrumentPlatform2SensorId(instrumentStr, platformStr);
78  int subsensorId = sensorId2SubsensorId(sensorId);
79 
80  // load the sensor specific default config file
81  sprintf(tmpStr, "%s/%s/%s/l2qc_viirs.conf", dataRoot, sensorId2SensorDir(sensorId),subsensorId2SubsensorDir(subsensorId));
82  clo_setString(list, "cfile", tmpStr, "internal");
83  }
84 
85  return 0;
86 }
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
int instrumentPlatform2SensorId(const char *instrument, const char *platform)
Definition: sensorInfo.c:302
#define NULL
Definition: decode_rs.h:63
int clo_setString(clo_optionList_t *list, const char *key, const char *val, const char *source)
Definition: clo.c:1667
int sensorId2SubsensorId(int sensorId)
Definition: sensorInfo.c:322
void clo_setVersion2(const char *programName, const char *versionStr)
Definition: clo.c:464
void clo_setHelpStr(const char *str)
Definition: clo.c:487
@ CLO_TYPE_IFILE
Definition: clo.h:84
@ CLO_TYPE_OFILE
Definition: clo.h:85
int l2qcviirs_init_options(clo_optionList_t *list, const char *softwareVersion)
int l2qcviirs_read_options(clo_optionList_t *list, int argc, char *argv[])
const char * subsensorId2SubsensorDir(int subsensorId)
Definition: sensorInfo.c:254