OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_product_info.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 
5 #include <genutils.h>
6 #include <clo.h>
7 #include <sensorInfo.h>
8 #include <productInfo.h>
9 
10 #define VERSION "3.0"
11 #define PROG_NAME "get_product_info"
12 
14  productInfo_t* productInfo = allocateProductInfo();
15 
16  //printf("chlor_a\n");
17  getFirstProductInfo(productInfo);
18  do {
19  if (strcmp(productInfo->paramDesignator, "none") == 0) {
20  printf("%s%s\n", productInfo->prefix, productInfo->suffix);
21  } else {
22  printf("%snnn%s\n", productInfo->prefix, productInfo->suffix);
23  }
24  } while (getNextProductInfo(productInfo));
25  freeProductInfo(productInfo);
26 }
27 
29 
30  // get sensor wavelengths
31  int32_t* iwave;
32 
33  // stop verbose output
34  int old_verbose = want_verbose;
35  want_verbose = 0;
36  int numWavelengths = rdsensorinfo(sensor, 0, "iwave", (void**) &iwave);
37  want_verbose = old_verbose;
38 
39  if (numWavelengths == -1) {
40  printf("-E- Could not lookup sensor %d wavelengths\n", sensor);
41  exit(1);
42  }
43 
44  //printf("chlor_a\n");
45  productInfo_t* productInfo = allocateProductInfo();
46  getFirstProductInfo(productInfo);
47  do {
48  if (strcmp(productInfo->paramDesignator, "none") == 0) {
49  printf("%s%s\n", productInfo->prefix, productInfo->suffix);
50  } else if (strcmp(productInfo->paramDesignator, "wave") == 0) {
51  int i;
52  for (i = 0; i < numWavelengths; i++) {
53  if((iwave[i] > productInfo->paramWaveMin) && (iwave[i] < productInfo->paramWaveMax)) {
54  printf("%s%d%s\n", productInfo->prefix, iwave[i], productInfo->suffix);
55  }
56  }
57  } else {
58  printf("%snnn%s\n", productInfo->prefix, productInfo->suffix);
59  }
60  } while (getNextProductInfo(productInfo));
61  freeProductInfo(productInfo);
62 }
63 
64 void printProductCSV(productInfo_t* productInfo) {
65  // name
66  if (strcmp(productInfo->paramDesignator, "none") == 0) {
67  printf("%s%s,", productInfo->prefix, productInfo->suffix);
68  } else {
69  printf("%snnn%s,", productInfo->prefix, productInfo->suffix);
70  }
71 
72  printf("%s,", productInfo->paramDesignator);
73  printf("%d,", productInfo->paramWaveMin);
74  printf("%d,", productInfo->paramWaveMax);
75 
76  printf("%s,", productInfo->dataType);
77  printf("%g,", productInfo->scaleFactor);
78  printf("%g,", productInfo->addOffset);
79  printf("%g,", productInfo->fillValue);
80  printf("%g,", productInfo->validMin);
81  printf("%g,", productInfo->validMax);
82 
83  printf("%s,", productInfo->displayScale);
84  printf("%g,", productInfo->displayMin);
85  printf("%g,", productInfo->displayMax);
86 
87  printf("\"%s\",", productInfo->units);
88  printf("%s,", productInfo->standardName);
89  printf("%s,", productInfo->palette);
90  printf("%s,", productInfo->category);
91  printf("\"%s\",", productInfo->reference);
92  printf("\"%s\",", productInfo->description);
93  printf("\"%s\",", productInfo->comment);
94 
95  printf("\n");
96 }
97 
99  productInfo_t* productInfo = allocateProductInfo();
100 
101  // print headings
102  printf("name,");
103  printf("paramDesignator,");
104  printf("paramWaveMin,");
105  printf("paramWaveMax,");
106 
107  printf("dataType,");
108  printf("scaleFactor,");
109  printf("addOffset,");
110  printf("fillValue,");
111  printf("validMin,");
112  printf("validMax,");
113 
114  printf("displayScale,");
115  printf("displayMin,");
116  printf("displayMax,");
117 
118  printf("units,");
119  printf("standardName,");
120  printf("palette,");
121  printf("category,");
122  printf("reference,");
123  printf("description,");
124  printf("comment");
125 
126  printf("\n");
127 
128  getFirstProductInfo(productInfo);
129  do {
130  printProductCSV(productInfo);
131  } while (getNextProductInfo(productInfo));
132  freeProductInfo(productInfo);
133 }
134 
135 int main(int argc, char *argv[]) {
136  // setup clo
140  char helpStr[2048];
141  strcpy(helpStr, "Program to list products or detailed information about a single product\n");
142  strcat(helpStr, "Usage: ");
143  strcat(helpStr, PROG_NAME);
144  strcat(helpStr, " [option=val] <productName>\nOptions:");
145  clo_setHelpStr(helpStr);
147 
148  clo_addOption(list, "l", CLO_TYPE_BOOL, "false", "list all of the products");
149  clo_addOption(list, "r", CLO_TYPE_BOOL, "false", "list all of the products recursing through\n the wavelengths of the sensor specified");
150  clo_addOption(list, "csv", CLO_TYPE_BOOL, "false", "list all of the products, output in CSV format");
151  clo_addOption(list, "sensor", CLO_TYPE_STRING, "MODISA", "sensor name (or ID) to use for wavelength\n expansion or product lookup");
152  clo_addOption(list, "<product>", CLO_TYPE_HELP, NULL, "<productName> product to print detailed information about");
153 
154  clo_readArgs(list, argc, argv);
155  int numPositionOptions = clo_getPositionNumOptions(list);
156  if (numPositionOptions > 1) {
157  printf("-E- Too many parameters on the command line\n");
158  exit(1);
159  }
160 
161  // print usage if no args given
162  if (argc == 1) {
164  exit(0);
165  }
166 
167  // list all products
168  if (clo_getBool(list, "l")) {
170  exit(0);
171  }
172 
173  // get the sensor ID
174  const char* sensorName = clo_getString(list, "sensor");
175  int sensorId = sensorName2SensorId(sensorName);
176  if (sensorId == -1) {
177  printf("-E- Could not find sensor \"%s\"\n", sensorName);
178  exit(1);
179  }
180  // just in case a sensor ID was passed in
181  sensorName = sensorId2SensorName(sensorId);
182 
183  // list all products recursively
184  if (clo_getBool(list, "r")) {
185  printProductListSensor(sensorId);
186  exit(0);
187  }
188 
189  // list all products recursively
190  if (clo_getBool(list, "csv")) {
192  exit(0);
193  }
194 
195  // list detailed info for a single product
196  if (numPositionOptions == 0) {
197  printf("-E- A product name needs to be given on the command line\n");
198  exit(1);
199  }
200 
201  char* productName = clo_getPositionString(list, 0);
202 
203  productInfo_t* productInfo = allocateProductInfo();
204  if (findProductInfo(productName, sensorId, productInfo)) {
205  printf("sensorName=%s\n", sensorName);
206  printProductInfo(productName, productInfo);
207  return 0;
208  }
209 
210  printf("-E- Product \"%s\" is not a valid product\n", productName);
211  return 1;
212 }
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 freeProductInfo(productInfo_t *info)
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
void getFirstProductInfo(productInfo_t *info)
void clo_setEnablePositionOptions(int val)
Definition: clo.c:1685
void printProductInfo(const char *productFullName, const productInfo_t *info)
#define NULL
Definition: decode_rs.h:63
void printProductList()
int sensorName2SensorId(const char *name)
Definition: sensorInfo.c:268
#define VERSION
#define PROG_NAME
@ CLO_TYPE_BOOL
Definition: clo.h:78
void clo_setVersion2(const char *programName, const char *versionStr)
Definition: clo.c:464
clo_optionList_t * clo_createList()
Definition: clo.c:532
void clo_setHelpStr(const char *str)
Definition: clo.c:487
productInfo_t * allocateProductInfo()
char * clo_getPositionString(clo_optionList_t *list, int pos)
Definition: clo.c:1723
void clo_printUsage(clo_optionList_t *list)
Definition: clo.c:1988
void printProductCSV(productInfo_t *productInfo)
int want_verbose
int main(int argc, char *argv[])
int findProductInfo(const char *productName, int sensorId, productInfo_t *info)
@ CLO_TYPE_HELP
Definition: clo.h:86
const char * sensorId2SensorName(int sensorId)
Definition: sensorInfo.c:198
void clo_setEnableParOption(int val)
Definition: clo.c:1738
int clo_getPositionNumOptions(clo_optionList_t *list)
Definition: clo.c:1704
int32_t rdsensorinfo(int32_t, int32_t, const char *, void **)
Definition: rdsensorinfo.c:69
int clo_getBool(clo_optionList_t *list, const char *key)
Definition: clo.c:1375
void printProductListSensor(int sensor)
int i
Definition: decode_rs.h:71
@ 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")
int getNextProductInfo(productInfo_t *info)
void printProductListCSV()