9#include "tpcclibConfig.h"
21static char *info[] = {
22 "Check whether specified Interfile-type (IFT) key and value exist in",
23 "the header file, for example:",
25 "Key and value are case-insensitive.",
26 "Program returns 0, if key, and optional value, are found,",
27 "code 10, if key is not found, and 11, if key was found but without",
30 "Usage: @P [options] filename [key [value]]",
33 "-lt | -gt | -abs=<limit>",
34 " Values are tested numerically (not as text), to be less (-lt) or",
35 " greater (-gt) than the given value, or the absolute difference is not",
36 " allowed to exceed the specified limit (-abs=<limit>)",
40 " @P iea345ab.kbq calibrated yes",
42 " @P -abs=0.02 header.dat halflife 2.05",
44 "See also: iftadd, iftdel, iftlist, iftmatch, iftvalc",
46 "Keywords: header, IFT, tool",
65int main(
int argc,
char **argv)
67 int ai, help=0, version=0, verbose=1;
69 double test_abs=-1.0, v1, v2;
70 int test_lt=0, test_gt=0;
71 char *cptr, iftfile[FILENAME_MAX];
78 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
79 iftInit(&ift); iftfile[0]=(char)0; key=value=NULL;
81 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
84 if(strncasecmp(cptr,
"ABS=", 4)==0) {
85 test_abs=
atofVerified(cptr+4);
if(!isnan(test_abs))
continue;
86 }
else if(strcasecmp(cptr,
"LT")==0) {
88 }
else if(strcasecmp(cptr,
"GT")==0) {
91 fprintf(stderr,
"Error: invalid option '%s'\n", argv[ai]);
92 free(key); free(value);
97 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
106 for(; ai<argc; ai++) {
108 strcpy(iftfile, argv[ai]);
continue;
109 }
else if(key==NULL) {
110 key=
strdup(argv[ai]);
continue;
111 }
else if(value==NULL) {
112 value=
strdup(argv[ai]);
continue;
114 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
115 free(key); free(value);
119 if(key==NULL) {
tpcPrintUsage(argv[0], info, stdout);
return(1);}
123 for(ai=0; ai<argc; ai++)
124 printf(
"%s ", argv[ai]);
126 printf(
"iftfile := %s\n", iftfile);
127 printf(
"key := %s\n", key);
128 printf(
"value := %s\n", value);
129 if(test_abs>=0.0) printf(
"test_abs := %g\n", test_abs);
130 printf(
"test_lt := %d\n", test_lt);
131 printf(
"test_gt := %d\n", test_gt);
135 ret=0;
if(test_abs>=0.0) ret++;
if(test_lt) ret++;
if(test_gt) ret++;
137 fprintf(stderr,
"Error: invalid combination of options.\n");
138 free(key); free(value);
return(1);
143 "Error: value must be given with options -lt, -gt, and -abs.\n");
144 free(key);
return(1);
148 fprintf(stderr,
"Error: invalid numerical value for testing.\n");
149 free(key); free(value);
return(1);
151 if(verbose>1) printf(
"numerical_value := %g\n", v1);
157 if(verbose>1) printf(
"reading %s\n", iftfile);
158 FILE *fp=fopen(iftfile,
"r");
if(fp==NULL) {
159 fprintf(stderr,
"Error: cannot open file %s\n", iftfile);
160 free(key); free(value);
return(2);
162 ret=
iftRead(&ift, fp, 1, 1, &status); fclose(fp);
164 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
165 free(key); free(value);
iftFree(&ift);
return(2);
167 if(verbose>2) printf(
"list size: %d item(s)\n", ift.
keyNr);
173 if(verbose>1) printf(
"searching for '%s'\n", key);
178 if(m==0 && verbose>0)
179 fprintf(stderr,
" key \"%s\" was not found.\n", key);
181 iftFree(&ift); free(key); free(value);
return(10);
188 fprintf(stdout,
" key \"%s\" is found in %s\n", key, iftfile);
189 iftFree(&ift); free(key); free(value);
return(0);
195 if(test_abs>=0 || test_lt>0 || test_gt>0) {
199 if(verbose>1) printf(
" keys_numerical_value := %g\n", v2);
204 if(verbose>2) printf(
"testing abs difference between %g and %g\n", v1, v2);
205 if(fabs(v1-v2)<=test_abs) {
208 fprintf(stdout,
" key \"%s\" with matching value %g is found in %s\n",
210 iftFree(&ift); free(key); free(value);
return(0);
217 if(verbose>2) printf(
"testing whether %g < %g\n", v2, v1);
220 if(verbose>0) fprintf(stdout,
221 " key \"%s\" with value %g less than %g is found in %s\n",
222 key, v2, v1, iftfile);
223 iftFree(&ift); free(key); free(value);
return(0);
230 if(verbose>2) printf(
"testing whether %g > %g\n", v2, v1);
233 if(verbose>0) fprintf(stdout,
234 " key \"%s\" with value %g greater than %g is found in %s\n",
235 key, v2, v1, iftfile);
236 iftFree(&ift); free(key); free(value);
return(0);
243 if(strcasecmp(value, ift.
item[li].
value)==0) {
246 fprintf(stdout,
" key \"%s\" with matching value \"%s\" is found in %s\n",
247 key, value, iftfile);
248 iftFree(&ift); free(key); free(value);
return(0);
256 fprintf(stdout,
" key \"%s\" had not value less than \"%s\" in %s\n",
257 key, value, iftfile);
259 fprintf(stdout,
" key \"%s\" had not value larger than \"%s\" in %s\n",
260 key, value, iftfile);
262 fprintf(stdout,
" key \"%s\" with value \"%s\" was not found in %s\n",
263 key, value, iftfile);
266 iftFree(&ift); free(key); free(value);
double atofVerified(const char *s)
int atofCheck(const char *s, double *v)
int doubleGetWithUnit(const char *s, double *v, int *u)
int iftFindKey(IFT *ift, const char *key, int start_index)
int iftRead(IFT *ift, FILE *fp, int is_key_required, int is_comment_accepted, TPCSTATUS *status)
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
int tpcHtmlUsage(const char *program, char *text[], const char *path)
void tpcPrintBuild(const char *program, FILE *fp)
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
void statusInit(TPCSTATUS *s)
char * errorMsg(tpcerror e)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
char * strdup(const char *s)
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
Header file for library libtpcextensions.
Header file for library libtpcift.