NASA Logo
Ocean Color Science Software

ocssw V2022
opt.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004,2009 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 /*
21  Option & argument parsing from command-line.
22  */
23 #ifndef OPT_H
24 #define OPT_H 1
25 
26 #include "common.h"
27 
28 #ifdef HAVE_GETOPT_H
29 #include <getopt.h>
30 #else
31 #include "getopt.h"
32 #endif
33 
34 #include "strlist.h"
35 #include <netcdf.h>
36 
37 /* macro is defined at compile time from within Makefile, not config.h */
38 #define USAGE "\
39 Compare two NetCDF files.\n\
40 nccmp is silent when files are equivalent, otherwise it will echo to STDERR whether metadata or a specific variable differs. By default, comparing stops after the first difference.\n\
41 \n\
42 Exit code 0 is returned for identical files, 1 for different files, and 2 for a fatal error.\n\
43 \n\
44 Usage: nccmp [OPTION...] file1 file2\n\
45 \n\
46  -A, --Attribute=att1[,...] Ignore attribute(s) att1[,...]\n\
47  for all variables.\n\
48  -a, --all Compare all metadata, compare data, forcefully compare\n\
49  Print up to 10 differences per var (can be overridden)\n\
50  -e, --extent=X Compare up to X values per var\n\
51  -b, --verbose Print messages to show progress.\n\
52  -d, --data Compare data (variable values).\n\
53  -C, --maxdiff=CNT Print differences up until CNT messages per var.\n\
54  -D, --debug Prints verbose debug messages.\n\
55  -f, --force Forcefully compare, do not stop after first\n\
56  difference.\n\
57  -F, --fortran Print position indices using Fortran style\n\
58  (1-based reverse order).\n\
59  -g, --global Compare global attributes.\n\
60  (-m required)\n\
61  -G, --globalex att1[,...] Exclude global attributes att1[,...].\n\
62  (-mg required)\n\
63  -h, --history Compare global history attribute.\n\
64  (-mg required)\n\
65  -H, --help Give this usage message.\n\
66  --usage \n\
67  -m, --metadata Compare metadata, excluding global attributes.\n\
68  -M, --missing Ignore difference between values that have\n\
69  different missing_value and/or _FillValue.\n\
70  Attribute differences are still reported.\n\
71  -N, --nans-are-equal Allow NaNs to be equal.\n\
72  -n, --notolerance Turn off 0.0001 percent auto-tolerance for float and double.\n\
73  -p, --precision='%%.17g' Precision of difference printing\n\
74  (default is '%%g').\n\
75  Use '%%x' to print bytes.\n\
76  -s, --report-identical-files\n\
77  Report when files are the same.\n\
78  -t, --tolerance=TOL Compare if absolute difference > TOL.\n\
79  -T, --Tolerance=TOL Compare if relative percent difference > TOL.\n\
80  -v, --variable=var1[,...] Compare variable(s) var1[,...] only.\n\
81  -V, --version Print program version.\n\
82  -x, --exclude=var1[,...] Exclude variable(s) var1[,...].\n\
83  -w, --warn=tag[,...] Selectively make certain differences\n\
84  exceptions, but still print messages.\n\
85  Supported tags and their meanings:\n\
86  all: All differences.\n\
87  format: File formats.\n\
88  eos: Extra attribute end-of-string nulls.\n\
89 \n\
90 Original development by Remik . Ziemlinski @ noaa . gov.\n\
91 \n\
92 Converted to C++ for type generalization by Richard . Healy @ NASA . gov (January 2015)\n\
93 "
94 
95 /* used in allocating a string list */
96 #define NCCMP_MAX_STRINGS 256
97 
98 /* Warning tags supported, which are used as array indices. */
99 #define NCCMP_W_TAGS "all,format,eos"
100 #define NCCMP_W_NUMTAGS 3
101 #define NCCMP_W_ALL 0
102 #define NCCMP_W_FORMAT 1
103 #define NCCMP_W_EOS 2
104 
105 typedef struct NCCMPOPTS {
106  char** excludeattlist; /* variable attributes to exclude from comparisons */
107  int nexcludeatt; /* number of strings in excludeattlist */
108  int data; /* compare variable values? */
109  int debug; /* print additional debug messages */
110  int force; /* continue checking after 1st difference */
111  int fortran; /* fortran style index printing */
112  int global; /* compare global attributes */
113  int nglobalexclude; /* number of global atts to exclude */
114  char** globalexclude; /* list of global atts to exclude */
115  int history; /* compare global history attribute */
116  int metadata; /* compare metadata, excluding global attributes */
117  int missing; /* ignore different missing_value/_FillValues */
118  long maxdiff; /* stop printing differences after maxdiff for each var*/
119  long diffcount; /* current # of differences to compare to maxdiff */
120  int quiet; /* deprecated. prints differences only, no script making for viewing */
121  char* precision; /* print precision of values. */
122  char* tprintf; /* format string to print values. */
123  int verbose; /* print messages to show progress */
124  int help; /* give usage insructions */
125  int version; /* give program version */
126  int exclude; /* exclude list given */
127  double tolerance; /* allowable difference tolerance */
128  char abstolerance; /* flag, 0=percentage (0-100+), 1=absolute tolerance */
129  char notolerance; /* flag, 0=use default tolerance on float and double, 1=turn this off */
130  int variable; /* variable list given */
131  int nexclude; /* how many to exclude */
132  int nvariable; /* how many variables */
133  char** excludelist; /* variables to exclude from comparison */
134  char** variablelist; /* specific variables to compare */
135  char* file1; /* two files to compare */
136  char* file2; /* */
137  char** cmpvarlist; /* list of var names to ultimately compare. */
138  char all; /* equivalent to throwing `-mgdf -C 10` */
139  unsigned int extent; /* how many values to check */
140  unsigned int extentcount; /* how many values have been checked */
141  /* Not user input. Derived by processing inputs. */
142  int ncmpvarlist; /* length of above array. */
143  char warn[NCCMP_W_NUMTAGS]; /* booleans if a warning is on/off */
144  char report_identical; /* Print message if files match. */
145  char nanequal; /* Nans should be considered equal if compared. */
146 } nccmpopts;
147 
148 int getnccmpopts(int argc, char** argv, nccmpopts* popts);
149 void printusage();
150 void printversion();
151 /* frees pointers in struct */
152 void freenccmpopts(nccmpopts* popts);
153 void initnccmpopts(nccmpopts* popts);
154 
155 #endif /* !OPT_H */
char ** globalexclude
Definition: opt.h:114
int nvariable
Definition: opt.h:132
int getnccmpopts(int argc, char **argv, nccmpopts *popts)
Definition: opt.c:131
#define NCCMP_W_NUMTAGS
Definition: opt.h:100
char * file2
Definition: opt.h:136
int quiet
Definition: opt.h:120
unsigned int extent
Definition: opt.h:139
char ** cmpvarlist
Definition: opt.h:137
char ** variablelist
Definition: opt.h:134
char notolerance
Definition: opt.h:129
int verbose
Definition: opt.h:123
int variable
Definition: opt.h:130
unsigned int extentcount
Definition: opt.h:140
int metadata
Definition: opt.h:116
double tolerance
Definition: opt.h:127
int fortran
Definition: opt.h:111
int debug
Definition: opt.h:109
int ncmpvarlist
Definition: opt.h:142
char * precision
Definition: opt.h:121
char * file1
Definition: opt.h:135
char ** excludelist
Definition: opt.h:133
int exclude
Definition: opt.h:126
Definition: opt.h:105
int nexcludeatt
Definition: opt.h:107
void freenccmpopts(nccmpopts *popts)
Definition: opt.c:61
int version
Definition: opt.h:125
char * tprintf
Definition: opt.h:122
void printversion()
Definition: opt.c:121
int global
Definition: opt.h:112
int force
Definition: opt.h:110
long diffcount
Definition: opt.h:119
void initnccmpopts(nccmpopts *popts)
Definition: opt.c:72
char all
Definition: opt.h:138
char report_identical
Definition: opt.h:144
int nglobalexclude
Definition: opt.h:113
char nanequal
Definition: opt.h:145
int nexclude
Definition: opt.h:131
char ** excludeattlist
Definition: opt.h:106
void printusage()
Definition: opt.c:117
char abstolerance
Definition: opt.h:128
int missing
Definition: opt.h:117
char warn[NCCMP_W_NUMTAGS]
Definition: opt.h:143
int history
Definition: opt.h:115
int data
Definition: opt.h:108
long maxdiff
Definition: opt.h:118
int help
Definition: opt.h:124