OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
opt.c
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004-2006,2010,2012 Remik Ziemlinski <first d0t surname att n0aa d0t g0v>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2, or (at your option)
7  any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; see the file COPYING.
16  If not, write to the Free Software Foundation,
17  59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19 
20 #include "opt.h"
21 #define VERSION "2.1.1"
22 
23 static struct option const long_options[] ={
24  {"Attribute", required_argument, 0, 'A'},
25  /*{"cartesian_axis", required_argument, 0, 'c'},*/
26  {"data", no_argument, 0, 'd'},
27  {"debug", no_argument, 0, 'D'},
28  {"exclude", required_argument, 0, 'x'},
29  {"force", no_argument, 0, 'f'},
30  {"fortran", no_argument, 0, 'F'},
31  {"global", no_argument, 0, 'g'},
32  {"globalex", required_argument, 0, 'G'},
33  {"header-pad", no_argument, 0, 'P'},
34  {"history", no_argument, 0, 'h'},
35  {"maxdiff ", required_argument, 0, 'C'},
36  {"metadata", no_argument, 0, 'm'},
37  {"missing", no_argument, 0, 'M'},
38  {"nans-are-equal", no_argument, 0, 'N'},
39  {"precision", required_argument, 0, 'p'},
40  {"quiet", no_argument, 0, 'q'},
41  {"report-identical-files", no_argument, 0, 's'},
42  {"tolerance", required_argument, 0, 't'},
43  {"Tolerance", required_argument, 0, 'T'},
44  {"notolerance", no_argument, 0, 'n'},
45  {"variable", required_argument, 0, 'v'},
46  {"verbose", no_argument, 0, 'b'},
47  {"help", no_argument, 0, 'H'},
48  {"usage", no_argument, 0, 'H'},
49  {"version", no_argument, 0, 'V'},
50  {"warn", required_argument, 0, 'w'},
51  {0, 0, 0, 0}
52 };
53 
54 void freenccmpopts(nccmpopts* popts) {
55  freestringlist(&popts->excludeattlist, popts->nexcludeatt);
56  freestringlist(&popts->globalexclude, popts->nglobalexclude);
57  freestringlist(&popts->excludelist, popts->nexclude);
58  freestringlist(&popts->variablelist, popts->nvariable);
59  freestringlist(&popts->cmpvarlist, popts->ncmpvarlist);
60  XFREE(popts->file1);
61  XFREE(popts->file2);
62  XFREE(popts->precision);
63 }
64 
65 void initnccmpopts(nccmpopts* popts) {
66  if (popts == NULL) return;
67 
68  popts->data = 0;
69  popts->debug = 0;
70  popts->force = 0;
71  popts->fortran = 0;
72  popts->global = 0;
73  popts->history = 0;
74  popts->metadata = 0;
75  popts->missing = 0;
76  popts->nanequal = 0;
77  popts->precision = NULL;
78  popts->quiet = 0;
79  popts->report_identical = 0;
80  popts->verbose = 0;
81  popts->help = 0;
82  popts->tolerance = 0;
83  popts->abstolerance = 0;
84  popts->notolerance = 0;
85  popts->version = 0;
86  popts->maxdiff = 0;
87  popts->diffcount = 0;
88  popts->nexclude = 0;
89  popts->nvariable = 0;
90  popts->exclude = 0;
91  popts->variable = 0;
92  popts->nexcludeatt = 0;
93  popts->excludeattlist = NULL;
94  popts->excludelist = NULL;
95  popts->variablelist = NULL;
96  popts->file1 = NULL;
97  popts->file2 = NULL;
98  popts->nglobalexclude = 0;
99  popts->globalexclude = NULL;
100  popts->cmpvarlist = NULL;
101  popts->ncmpvarlist = 0;
102  popts->tprintf = NULL;
103 
104  memset(popts->warn, 0, NCCMP_W_NUMTAGS);
105 }
106 
107 void printusage() {
108  fprintf(stderr, USAGE);
109 }
110 
111 void printversion() {
112  fprintf(stderr, "nccmp %s\n", VERSION);
113  fprintf(stderr, "Built with NetCDF %s\n", nc_inq_libvers());
114  fprintf(stderr, "Copyright (C) 2004-2007,2009,2010,2012,2013 Remik Ziemlinski\n \
115 \n\
116 This program comes with NO WARRANTY, to the extent permitted by law.\n\
117 You may redistribute copies of this program\n\
118 under the terms of the GNU General Public License.\n");
119 }
120 
121 int getnccmpopts(int argc, char** argv, nccmpopts* popts) {
122  int c;
123  char** warningtags = NULL;
124  int nwarningtags, i;
125  char** valid_warnings = NULL;
126  char tmp[256];
127 
128  /* Create searchable list of defined warning tags.
129  'nwarningtags' is used as a dummy arg here. */
130  newstringlist(&valid_warnings, &nwarningtags, NCCMP_W_NUMTAGS);
131  strcpy(tmp, NCCMP_W_TAGS); /* Necessary evil to prevent segfault. */
132  getstringlist(tmp, &valid_warnings, &nwarningtags);
133  /* printf("%s:%d\n", __FILE__, __LINE__); */
134 
135  if (popts == NULL) return EXIT_FATAL;
136 
137  if (newstringlist(&popts->globalexclude, &popts->nglobalexclude, NC_MAX_VARS) != EXIT_SUCCESS) {
138  printf("ERROR: Failed to allocate memory for global attribute exclusion list.\n");
139  exit(EXIT_FATAL);
140  }
141 
142  if (newstringlist(&popts->excludeattlist, &popts->nexcludeatt, NC_MAX_VARS) != EXIT_SUCCESS) {
143  printf("ERROR: Failed to allocate memory for attribute exclusion list.\n");
144  exit(EXIT_FATAL);
145  }
146 
147  if (newstringlist(&popts->excludelist, &popts->nexclude, NC_MAX_VARS) != EXIT_SUCCESS) {
148  printf("ERROR: Failed to allocate memory for variable exclusion list.\n");
149  exit(EXIT_FATAL);
150  }
151 
152  if (newstringlist(&popts->variablelist, &popts->nvariable, NC_MAX_VARS) != EXIT_SUCCESS) {
153  printf("ERROR: Failed to allocate memory for variable list.\n");
154  exit(EXIT_FATAL);
155  }
156 
157  while ((c = getopt_long(argc, argv, "A:C:dDx:fFghmNnMp:qst:T:v:bHVG:w:", long_options, 0))
158  != -1
159  )
160 
161  switch (c) {
162  case 'd':
163  popts->data = 1;
164  break;
165 
166  case 'D':
167  popts->debug = 1;
168  break;
169 
170  case 'x':
171  popts->exclude = 1;
172  getstringlist(optarg, &popts->excludelist, &popts->nexclude);
173  break;
174 
175  case 'f':
176  popts->force = 1;
177  break;
178 
179  case 'F':
180  popts->fortran = 1;
181  break;
182 
183  case 'g':
184  popts->global = 1;
185  popts->metadata = 1;
186  break;
187 
188  case 'h':
189  popts->history = 1;
190  break;
191 
192  case 'm':
193  popts->metadata = 1;
194  break;
195 
196  case 'M':
197  popts->missing = 1;
198  break;
199 
200  case 'N':
201  popts->nanequal = 1;
202  break;
203 
204  case 'p':
205  popts->precision = XMALLOC(char, strlen(optarg) + 1);
206  strcpy(popts->precision, optarg);
207  break;
208  case 'q':
209  popts->quiet = 1;
210  break;
211  case 's':
212  popts->report_identical = 1;
213  break;
214  case 'n':
215  popts->notolerance = 1;
216  break;
217  case 'C':
218  popts->maxdiff = (long) strtod(optarg, NULL);
219  break;
220  case 't':
221  popts->tolerance = strtod(optarg, NULL);
222  popts->abstolerance = 1;
223  if ((errno == ERANGE) || (errno == EDOM)) {
224  fprintf(stderr, "ERROR: Specified tolerance cannot be used.\n");
225  return EXIT_FATAL;
226  }
227  break;
228  case 'T':
229  popts->tolerance = strtod(optarg, NULL);
230  popts->abstolerance = 0;
231  if ((errno == ERANGE) || (errno == EDOM)) {
232  fprintf(stderr, "ERROR: Specified tolerance cannot be used.\n");
233  return EXIT_FATAL;
234  }
235  break;
236  case 'v':
237  getstringlist(optarg, &popts->variablelist, &popts->nvariable);
238  popts->variable = 1;
239  break;
240  case 'b':
241  popts->verbose = 1;
242  break;
243 
244  case 'V':
245  popts->version = 1;
246  break;
247 
248  case ':':
249  fprintf(stderr, "Error, -%c without argument.\n\n", optopt);
250  popts->help = 1;
251  break;
252 
253  case '?':
254  fprintf(stderr, "Error, Unknown argument %c.\n\n", optopt);
255  popts->help = 1;
256  break;
257 
258  case 'H':
259  popts->help = 1;
260  break;
261 
262  case 'A':
263  getstringlist(optarg, &popts->excludeattlist, &popts->nexcludeatt);
264  break;
265 
266  case 'G':
267  getstringlist(optarg, &popts->globalexclude, &popts->nglobalexclude);
268  break;
269 
270  case 'w':
271  newstringlist(&warningtags, &nwarningtags, NCCMP_W_NUMTAGS);
272  getstringlist(optarg, &warningtags, &nwarningtags);
273 
274  for (i = 0; i < nwarningtags; ++i) {
275  if (instringlist(valid_warnings, warningtags[i], NCCMP_W_NUMTAGS) != 1) {
276  /* Warn user of any invalid warning tags they supplied. */
277  fprintf(stderr, "WARNING: Warning tag \"%s\" is unsupported and will be ignored.\n", warningtags[i]);
278  }
279  }
280 
281  char *sall = (char*) "all", *sfmt = (char*) "format", *seos = (char*) "eos";
282 
283  /* Look for defined tags that are supported. */
284  if (instringlist(warningtags, sall, nwarningtags))
285  popts->warn[NCCMP_W_ALL] = 1;
286  else if (instringlist(warningtags, sfmt, nwarningtags))
287  popts->warn[NCCMP_W_FORMAT] = 1;
288  else if (instringlist(warningtags, seos, nwarningtags))
289  popts->warn[NCCMP_W_EOS] = 1;
290 
291  break;
292  }
293  if (popts->help) {
294  printusage();
295  printversion();
296  return EXIT_FATAL;
297  }
298  if (popts->version) {
299  printversion();
300  return EXIT_FATAL;
301  }
302  if (optind == argc) {
303  fprintf(stderr, "Error, missing operand after `%s'.\n\n", argv[argc - 1]);
304  printusage();
305  return EXIT_FATAL;
306  }
307  if (!(popts->data || popts->metadata)) {
308  fprintf(stderr, "Error, must supply at least one of these options: -d, -m.\n\n");
309  printusage();
310  return EXIT_FATAL;
311  }
312  if (popts->variable && popts->exclude) {
313  fprintf(stderr, "Error, cannot combine -x and -v options.\n\n");
314  printusage();
315  return EXIT_FATAL;
316  }
317  if (popts->precision == NULL) {
318  popts->precision = XMALLOC(char, strlen("%g") + 1);
319  strcpy(popts->precision, "%g");
320  }
321 
322  /* get filename arguments */
323  argc -= optind;
324  argv += optind;
325  if ((argc < 2) ||
326  (argv[0] == NULL) ||
327  (argv[1] == NULL)
328  ) {
329  fprintf(stderr, "Error, 2 file arguments required.\n\n");
330  printusage();
331  popts->file1 = NULL;
332  popts->file2 = NULL;
333  return EXIT_FATAL;
334  } else {
335  /* store filenames */
336  popts->file1 = XMALLOC(char, strlen(argv[0]) + 1);
337  popts->file2 = XMALLOC(char, strlen(argv[1]) + 1);
338  strcpy(popts->file1, argv[0]);
339  strcpy(popts->file2, argv[1]);
340  }
341  /* allocate space to store tprintf based on size of precision option
342  * otherwise set it large enough for a simple format string
343  */
344  if (popts->precision) {
345  popts->tprintf = XMALLOC(char, strlen(popts->precision) + 1);
346  } else {
347  popts->tprintf = XMALLOC(char, 3);
348  }
349  if (popts->history && !popts->global) {
350  fprintf(stderr, "Error, -g required for -h option.\n\n");
351  printusage();
352  return EXIT_FATAL;
353  }
354  if (!popts->metadata && (popts->history || popts->global)) {
355  fprintf(stderr, "Error, -m required for -g and -h options.\n\n");
356  printusage();
357  return EXIT_FATAL;
358  }
359 
360  freestringlist(&warningtags, nwarningtags);
361  freestringlist(&valid_warnings, NCCMP_W_NUMTAGS);
362  /*printf("%s:%d\n", __FILE__, __LINE__);*/
363 
364  return EXIT_SUCCESS;
365 }
#define EXIT_SUCCESS
Definition: GEO_basic.h:72
#define NCCMP_W_NUMTAGS
Definition: opt.h:97
#define VERSION
Definition: opt.c:21
void initnccmpopts(nccmpopts *popts)
Definition: opt.c:65
#define NULL
Definition: decode_rs.h:63
void printversion()
Definition: opt.c:111
int newstringlist(char ***list, int *n, int size)
Definition: strlist.c:22
void freenccmpopts(nccmpopts *popts)
Definition: opt.c:54
#define NCCMP_W_ALL
Definition: opt.h:98
void freestringlist(char ***list, int nitems)
Definition: strlist.c:88
#define NCCMP_W_EOS
Definition: opt.h:100
character(len=1000) if
Definition: names.f90:13
int instringlist(char **list, char *str, int nitems)
Definition: strlist.c:107
#define NCCMP_W_FORMAT
Definition: opt.h:99
data_t tmp
Definition: decode_rs.h:74
int getnccmpopts(int argc, char **argv, nccmpopts *popts)
Definition: opt.c:121
#define USAGE
Definition: bindepths.c:20
void getstringlist(char *optarg, char ***list, int *nitems)
Definition: strlist.c:53
int errno
#define XFREE(stale)
Definition: xmalloc.h:42
void printusage()
Definition: opt.c:107
#define XMALLOC(type, num)
Definition: xmalloc.h:36
#define NCCMP_W_TAGS
Definition: opt.h:96
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed as required for compatibility with version of the SDP toolkit Corrected test output file names to end in per delivery and then split off a new MYD_PR03 pcf file for Aqua Added AssociatedPlatformInstrumentSensor to the inventory metadata in MOD01 mcf and MOD03 mcf Created new versions named MYD01 mcf and MYD03 where AssociatedPlatformShortName is rather than Terra The program itself has been changed to read the Satellite Instrument validate it against the input L1A and LUT and to use it determine the correct files to retrieve the ephemeris and attitude data from Changed to produce a LocalGranuleID starting with MYD03 if run on Aqua data Added the Scan Type file attribute to the Geolocation copied from the L1A and attitude_angels to radians rather than degrees The accumulation of Cumulated gflags was moved from GEO_validate_earth_location c to GEO_locate_one_scan c
Definition: HISTORY.txt:464
#define EXIT_FATAL
Definition: common.h:85
int i
Definition: decode_rs.h:71
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")