OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l2brsgen_input.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <ctype.h>
6 #include <assert.h>
7 #include <genutils.h>
8 #include <clo.h>
9 #include <sensorInfo.h>
10 
11 #include "l2brsgen.h"
12 
13 //-----------------------------------------------------------------------
14 
17  char tmpStr[2048];
18 
19  sprintf(tmpStr, "l2brsgen %s (%s %s)", VERSION, __DATE__, __TIME__);
20  clo_setVersion(tmpStr);
21 
22  sprintf(tmpStr, "Usage: l2brsgen argument-list\n\n");
23 
24  strcat(tmpStr, " This program takes a product from a L2 file, subsamples the file\n");
25  strcat(tmpStr, " and writes a browse file\n\n");
26 
27  strcat(tmpStr, " The argument-list is a set of keyword=value pairs. The arguments can\n");
28  strcat(tmpStr, " be specified on the commandline, or put into a parameter file, or the\n");
29  strcat(tmpStr, " two methods can be used together, with commandline over-riding.\n\n");
30  strcat(tmpStr, "The list of valid keywords follows:\n");
31  clo_setHelpStr(tmpStr);
32 
33  clo_addOption(list, "ifile", CLO_TYPE_IFILE, NULL, "input L2 file name");
34  clo_addOption(list, "ofile", CLO_TYPE_OFILE, "output", "output filename");
35  clo_addOption(list, "prod", CLO_TYPE_STRING, "chlor_a", "product name");
36  clo_addOption(list, "quality", CLO_TYPE_INT, "999", "highest quality value acceptable");
37  clo_addOption(list, "rflag", CLO_TYPE_STRING, "ORIGINAL", "replacement flag");
38  clo_addOption(list, "flaguse", CLO_TYPE_STRING, NULL, "Flags used to mask data");
39  clo_addOption(list, "chl_flags", CLO_TYPE_STRING, "ATMFAIL,HILT,STRAYLIGHT,CLDICE,LOWLW,CHLWARN,CHLFAIL,NAVWARN,MAXAERITER,NAVFAIL,FILTER,HIGLINT",
40  "Flags used to mask data for chl product if flaguse not set");
41  clo_addOption(list, "sst_flags", CLO_TYPE_STRING, "SSTFAIL",
42  "Flags used to mask data for sst product if flaguse not set");
43 
44  clo_addOption(list, "spixl", CLO_TYPE_INT, "1", "start pixel number");
45  clo_addOption(list, "epixl", CLO_TYPE_INT, "-1", "end pixel number (-1=the last pixel)");
46  clo_addOption(list, "dpixl", CLO_TYPE_INT, "1", "pixel subsampling interval");
47  clo_addOption(list, "sline", CLO_TYPE_INT, "1", "start line number");
48  clo_addOption(list, "eline", CLO_TYPE_INT, "-1", "end line number (-1=the last line)");
49  clo_addOption(list, "dline", CLO_TYPE_INT, "1", "line subsampling interval");
50 
51  clo_addOption(list, "apply_pal", CLO_TYPE_BOOL, "no", "apply color palette, false = grayscale");
52  clo_addOption(list, "palfile", CLO_TYPE_IFILE, "default", "palette filename. \"default\" means the\n palette is chosen using the product table file");
53  clo_addOption(list, "palette_dir", CLO_TYPE_IFILE, "$OCDATAROOT/common/palette", "directory\n containing the palette files");
54  clo_addOption(list, "product_table", CLO_TYPE_IFILE, "$OCDATAROOT/common/l2brsgen_product_table.dat", "product table");
55 
56  clo_addOption(list, "datamin", CLO_TYPE_FLOAT, "0.0", "minimum value for data scaling\n (default see product_table)");
57  clo_addOption(list, "datamax", CLO_TYPE_FLOAT, "0.0", "maximum value for data scaling\n (default see product_table)");
58  clo_addOption(list, "stype", CLO_TYPE_INT, "0", "scaling type (default see product_table)\n 1: LINEAR\n 2: LOG");
59 
60  strcpy(tmpStr, "format of the output file\n");
61  strcat(tmpStr, " hdf4: (1) HDF browse file\n");
62  strcat(tmpStr, " png: (5) PNG color or grayscale image file\n");
63  strcat(tmpStr, " ppm: (7) PPM color or PGM grayscale image file\n");
64  clo_addOption(list, "oformat", CLO_TYPE_STRING, "HDF4", tmpStr);
65 
66  return 0;
67 }
68 
69 //-----------------------------------------------------------------------
70 
84 int l2brsgen_read_options(clo_optionList_t* list, int argc, char* argv[],
85  l2_prod *l2_str, meta_l2Type *meta_l2) {
86  char *dataRoot;
87  char tmpStr[FILENAME_MAX];
88  int sensorId;
89 
90  assert(list);
91 
92  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
93  fprintf(stderr, "-E- OCDATAROOT environment variable is not defined.\n");
94  return (-1);
95  }
96 
97  // disable the dump option until we have read all of the files
99  clo_readArgs(list, argc, argv);
100 
101  // open ifile to get sensor info
102  parse_file_name(clo_getString(list, "ifile"), tmpStr);
103  openL2(tmpStr, 0x0, l2_str);
104  readL2meta(meta_l2, l2_str->fileindex);
105  sscanf(meta_l2->title, "%s", tmpStr);
106  sensorId = sensorName2SensorId(tmpStr);
107  if (sensorId == -1) {
108  fprintf(stderr, "-E- Could not find sensor %s in sensorName list.\n", tmpStr);
109  return (-1);
110  }
111 
112  // load program defaults
113  sprintf(tmpStr, "%s/common/l2brsgen_defaults.par", dataRoot);
114  if (want_verbose) {
115  fprintf(stderr, "Loading default parameters from %s\n", tmpStr);
116  }
117  clo_readFile(list, tmpStr);
118 
119  // load the sensor specific defaults file
120  if (sensorId != -1) {
121  sprintf(tmpStr, "%s/%s/l2brsgen_defaults.par", dataRoot, sensorId2SensorDir(sensorId));
122 
123  // see if the file exists
124  if (!access(tmpStr, R_OK)) {
125  if (want_verbose)
126  printf("Loading default parameters for %s from %s\n",
127  sensorId2SensorName(sensorId), tmpStr);
128  clo_readFile(list, tmpStr);
129  }
130  }
131 
133  clo_readArgs(list, argc, argv);
134 
135  return 0;
136 }
int32_t openL2(const char *fname, char *plist, l2_prod *l2_str)
Definition: readL2scan.c:296
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 l2brsgen_init_options(clo_optionList_t *list)
#define NULL
Definition: decode_rs.h:63
int32_t readL2meta(meta_l2Type *meta_l2, int32_t ifile)
Definition: readL2scan.c:2081
int sensorName2SensorId(const char *name)
Definition: sensorInfo.c:268
@ CLO_TYPE_FLOAT
Definition: clo.h:81
@ CLO_TYPE_BOOL
Definition: clo.h:78
#define VERSION
void clo_setEnableDumpOptions(int val)
Definition: clo.c:410
void clo_setHelpStr(const char *str)
Definition: clo.c:487
@ CLO_TYPE_INT
Definition: clo.h:79
int want_verbose
@ CLO_TYPE_IFILE
Definition: clo.h:84
@ CLO_TYPE_OFILE
Definition: clo.h:85
void clo_readFile(clo_optionList_t *list, const char *fileName)
Definition: clo.c:2210
void parse_file_name(const char *inpath, char *outpath)
const char * sensorId2SensorName(int sensorId)
Definition: sensorInfo.c:198
void clo_setVersion(const char *str)
Definition: clo.c:448
int l2brsgen_read_options(clo_optionList_t *list, int argc, char *argv[], l2_prod *l2_str, meta_l2Type *meta_l2)
@ CLO_TYPE_STRING
Definition: clo.h:83
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")