OB.DAAC Logo
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  -b, --verbose Print messages to show progress.\n\
49  -d, --data Compare data (variable values).\n\
50  -C, --maxdiff=CNT Print differences up until CNT messages per var.\n\
51  -D, --debug Prints verbose debug messages.\n\
52  -f, --force Forcefully compare, do not stop after first\n\
53  difference.\n\
54  -F, --fortran Print position indices using Fortran style\n\
55  (1-based reverse order).\n\
56  -g, --global Compare global attributes.\n\
57  (-m required)\n\
58  -G, --globalex att1[,...] Exclude global attributes att1[,...].\n\
59  (-mg required)\n\
60  -h, --history Compare global history attribute.\n\
61  (-mg required)\n\
62  -H, --help Give this usage message.\n\
63  --usage \n\
64  -m, --metadata Compare metadata, excluding global attributes.\n\
65  -M, --missing Ignore difference between values that have\n\
66  different missing_value and/or _FillValue.\n\
67  Attribute differences are still reported.\n\
68  -N, --nans-are-equal Allow NaNs to be equal.\n\
69  -n, --notolerance Turn off 0.0001 percent auto-tolerance for float and double.\n\
70  -p, --precision='%%.17g' Precision of difference printing\n\
71  (default is '%%g').\n\
72  Use '%%x' to print bytes.\n\
73  -s, --report-identical-files\n\
74  Report when files are the same.\n\
75  -t, --tolerance=TOL Compare if absolute difference > TOL.\n\
76  -T, --Tolerance=TOL Compare if relative percent difference > TOL.\n\
77  -v, --variable=var1[,...] Compare variable(s) var1[,...] only.\n\
78  -V, --version Print program version.\n\
79  -x, --exclude=var1[,...] Exclude variable(s) var1[,...].\n\
80  -w, --warn=tag[,...] Selectively make certain differences\n\
81  exceptions, but still print messages.\n\
82  Supported tags and their meanings:\n\
83  all: All differences.\n\
84  format: File formats.\n\
85  eos: Extra attribute end-of-string nulls.\n\
86 \n\
87 Original development by Remik . Ziemlinski @ noaa . gov.\n\
88 \n\
89 Converted to C++ for type generalization by Richard . Healy @ NASA . gov (January 2015)\n\
90 "
91 
92 /* used in allocating a string list */
93 #define NCCMP_MAX_STRINGS 256
94 
95 /* Warning tags supported, which are used as array indices. */
96 #define NCCMP_W_TAGS "all,format,eos"
97 #define NCCMP_W_NUMTAGS 3
98 #define NCCMP_W_ALL 0
99 #define NCCMP_W_FORMAT 1
100 #define NCCMP_W_EOS 2
101 
102 typedef struct NCCMPOPTS {
103  char** excludeattlist; /* variable attributes to exclude from comparisons */
104  int nexcludeatt; /* number of strings in excludeattlist */
105  int data; /* compare variable values? */
106  int debug; /* print additional debug messages */
107  int force; /* continue checking after 1st difference */
108  int fortran; /* fortran style index printing */
109  int global; /* compare global attributes */
110  int nglobalexclude; /* number of global atts to exclude */
111  char** globalexclude; /* list of global atts to exclude */
112  int history; /* compare global history attribute */
113  int metadata; /* compare metadata, excluding global attributes */
114  int missing; /* ignore different missing_value/_FillValues */
115  long maxdiff; /* stop printing differences after maxdiff for each var*/
116  long diffcount; /* current # of differences to compare to maxdiff */
117  int quiet; /* deprecated. prints differences only, no script making for viewing */
118  char* precision; /* print precision of values. */
119  char* tprintf; /* format string to print values. */
120  int verbose; /* print messages to show progress */
121  int help; /* give usage insructions */
122  int version; /* give program version */
123  int exclude; /* exclude list given */
124  double tolerance; /* allowable difference tolerance */
125  char abstolerance; /* flag, 0=percentage (0-100+), 1=absolute tolerance */
126  char notolerance; /* flag, 0=use default tolerance on float and double, 1=turn this off */
127  int variable; /* variable list given */
128  int nexclude; /* how many to exclude */
129  int nvariable; /* how many variables */
130  char** excludelist; /* variables to exclude from comparison */
131  char** variablelist; /* specific variables to compare */
132  char* file1; /* two files to compare */
133  char* file2; /* */
134  char** cmpvarlist; /* list of var names to ultimately compare. */
135  /* Not user input. Derived by processing inputs. */
136  int ncmpvarlist; /* length of above array. */
137  char warn[NCCMP_W_NUMTAGS]; /* booleans if a warning is on/off */
138  char report_identical; /* Print message if files match. */
139  char nanequal; /* Nans should be considered equal if compared. */
140 } nccmpopts;
141 
142 int getnccmpopts(int argc, char** argv, nccmpopts* popts);
143 void printusage();
144 void printversion();
145 /* frees pointers in struct */
146 void freenccmpopts(nccmpopts* popts);
147 void initnccmpopts(nccmpopts* popts);
148 
149 #endif /* !OPT_H */
char ** globalexclude
Definition: opt.h:111
int nvariable
Definition: opt.h:129
int getnccmpopts(int argc, char **argv, nccmpopts *popts)
Definition: opt.c:121
#define NCCMP_W_NUMTAGS
Definition: opt.h:97
char * file2
Definition: opt.h:133
int quiet
Definition: opt.h:117
char ** cmpvarlist
Definition: opt.h:134
char ** variablelist
Definition: opt.h:131
char notolerance
Definition: opt.h:126
int verbose
Definition: opt.h:120
int variable
Definition: opt.h:127
int metadata
Definition: opt.h:113
double tolerance
Definition: opt.h:124
int fortran
Definition: opt.h:108
int debug
Definition: opt.h:106
int ncmpvarlist
Definition: opt.h:136
char * precision
Definition: opt.h:118
char * file1
Definition: opt.h:132
char ** excludelist
Definition: opt.h:130
int exclude
Definition: opt.h:123
Definition: opt.h:102
int nexcludeatt
Definition: opt.h:104
void freenccmpopts(nccmpopts *popts)
Definition: opt.c:54
int version
Definition: opt.h:122
char * tprintf
Definition: opt.h:119
void printversion()
Definition: opt.c:111
int global
Definition: opt.h:109
int force
Definition: opt.h:107
long diffcount
Definition: opt.h:116
void initnccmpopts(nccmpopts *popts)
Definition: opt.c:65
char report_identical
Definition: opt.h:138
int nglobalexclude
Definition: opt.h:110
char nanequal
Definition: opt.h:139
int nexclude
Definition: opt.h:128
char ** excludeattlist
Definition: opt.h:103
void printusage()
Definition: opt.c:107
char abstolerance
Definition: opt.h:125
int missing
Definition: opt.h:114
char warn[NCCMP_W_NUMTAGS]
Definition: opt.h:137
int history
Definition: opt.h:112
int data
Definition: opt.h:105
long maxdiff
Definition: opt.h:115
int help
Definition: opt.h:121