27 |
|
|
28 |
|
int ign_header = 0; /* ignore header differences? */ |
29 |
|
|
30 |
+ |
int escape_newlines = 0; /* allow backslash to skip newlines */ |
31 |
+ |
|
32 |
|
double rel_min = 1e-5; /* positive for relative comparisons */ |
33 |
|
|
34 |
|
double rms_lim = 0.01; /* RMS difference limit */ |
37 |
|
|
38 |
|
int lin1cnt=0, lin2cnt=0; /* file line position */ |
39 |
|
|
40 |
+ |
int comment_c = '\0'; /* comment delimiter for text files */ |
41 |
+ |
|
42 |
|
const char nsuffix[10][3] = { /* 1st, 2nd, 3rd, etc. */ |
43 |
|
"th","st","nd","rd","th","th","th","th","th","th" |
44 |
|
}; |
74 |
|
|
75 |
|
/* header variables to always ignore */ |
76 |
|
const char *hdr_ignkey[] = { |
77 |
+ |
"FORMAT", |
78 |
|
"SOFTWARE", |
79 |
|
"CAPDATE", |
80 |
|
"GMT", |
104 |
|
const char stdin_name[] = "<stdin>"; |
105 |
|
const char *f1name=NULL, *f2name=NULL; |
106 |
|
FILE *f1in=NULL, *f2in=NULL; |
107 |
+ |
int f1swap=0, f2swap=0; |
108 |
|
|
109 |
|
/* running real differences */ |
110 |
|
double diff2sum = 0; |
116 |
|
{ |
117 |
|
fputs("Usage: ", stderr); |
118 |
|
fputs(progname, stderr); |
119 |
< |
fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", |
119 |
> |
fputs(" [-h][-c#][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", |
120 |
|
stderr); |
121 |
|
exit(2); |
122 |
|
} |
135 |
|
} |
136 |
|
while (fgets(bp->str + bp->len, bp->siz - bp->len, fp)) { |
137 |
|
bp->len += strlen(bp->str + bp->len); |
138 |
< |
if (bp->str[bp->len-1] == '\n') |
138 |
> |
if (bp->str[bp->len-1] == '\n') { |
139 |
> |
if (bp->len > 1 && bp->str[bp->len-2] == '\r') { |
140 |
> |
bp->str[--bp->len] = '\0'; |
141 |
> |
bp->str[bp->len-1] = '\n'; |
142 |
> |
} |
143 |
> |
if (escape_newlines && bp->len > 1 && |
144 |
> |
bp->str[bp->len-2] == '\\') { |
145 |
> |
bp->str[--bp->len] = '\0'; |
146 |
> |
bp->str[bp->len-1] = ' '; |
147 |
> |
continue; |
148 |
> |
} |
149 |
|
break; /* found EOL */ |
150 |
+ |
} |
151 |
|
if (bp->len < bp->siz - 4) |
152 |
|
continue; /* at EOF? */ |
153 |
|
if (bp->siz >= MAXBUF) { |
165 |
|
if (!bp->str) |
166 |
|
goto memerr; |
167 |
|
} |
168 |
+ |
if (comment_c) { /* elide comment? */ |
169 |
+ |
char *cp = sskip2(bp->str,0); |
170 |
+ |
if (*cp == comment_c) { |
171 |
+ |
*cp++ = '\n'; |
172 |
+ |
*cp = '\0'; |
173 |
+ |
bp->len = cp - bp->str; |
174 |
+ |
} |
175 |
+ |
} |
176 |
|
return(bp->len); |
177 |
|
memerr: |
178 |
|
fprintf(stderr, |
211 |
|
|
212 |
|
if (rel_min > 0) { /* doing relative differences? */ |
213 |
|
double av2 = .25*(r1*r1 + 2.*fabs(r1*r2) + r2*r2); |
214 |
< |
if (av2 > rel_min*rel_min) |
215 |
< |
diff2 /= av2; |
214 |
> |
if (av2 < rel_min*rel_min) |
215 |
> |
av2 = rel_min*rel_min; |
216 |
> |
diff2 /= av2; |
217 |
|
} |
218 |
|
if (max_lim >= 0 && diff2 > max_lim*max_lim) { |
219 |
|
if (report != REP_QUIET) |
249 |
|
static int |
250 |
|
norm_check(FVECT nv1, FVECT nv2) |
251 |
|
{ |
252 |
< |
double max2 = nv1[2]*nv1[2]; |
252 |
> |
double max2 = nv1[2]*nv2[2]; |
253 |
|
int imax = 2; |
254 |
|
int i = 2; |
255 |
|
/* identify largest component */ |
256 |
|
while (i--) { |
257 |
< |
double tm2 = nv1[i]*nv1[i]; |
257 |
> |
double tm2 = nv1[i]*nv2[i]; |
258 |
|
if (tm2 > max2) { |
259 |
|
imax = i; |
260 |
|
max2 = tm2; |
342 |
|
static int |
343 |
|
setheadvar(char *val, void *p) |
344 |
|
{ |
345 |
+ |
char newval[128]; |
346 |
|
LUTAB *htp = (LUTAB *)p; |
347 |
|
LUENT *tep; |
348 |
|
char *key; |
352 |
|
adv_linecnt(htp); /* side-effect is to count lines */ |
353 |
|
if (!isalpha(*val)) /* key must start line */ |
354 |
|
return(0); |
355 |
+ |
/* check if we need to swap binary data */ |
356 |
+ |
if ((n = isbigendian(val)) >= 0) { |
357 |
+ |
if (nativebigendian() == n) |
358 |
+ |
return(0); |
359 |
+ |
f1swap += (htp == &hdr1); |
360 |
+ |
f2swap += (htp == &hdr2); |
361 |
+ |
return(0); |
362 |
+ |
} |
363 |
|
key = val++; |
364 |
|
while (*val && !isspace(*val) & (*val != '=')) |
365 |
|
val++; |
385 |
|
return(-1); /* memory allocation error */ |
386 |
|
if (!tep->key) |
387 |
|
tep->key = strcpy(malloc(kln+1), key); |
388 |
< |
if (tep->data) |
388 |
> |
if (tep->data) { /* check for special cases */ |
389 |
> |
if (!strcmp(key, "EXPOSURE")) { |
390 |
> |
sprintf(newval, "%.6e", atof(tep->data)*atof(val)); |
391 |
> |
vln = strlen(val = newval); |
392 |
> |
} |
393 |
|
free(tep->data); |
394 |
+ |
} |
395 |
|
tep->data = strcpy(malloc(vln+1), val); |
396 |
|
return(1); |
397 |
|
} |
500 |
|
} |
501 |
|
if (c) |
502 |
|
return(TYP_BINARY); |
463 |
– |
SET_FILE_TEXT(fin); /* originally set to binary */ |
503 |
|
return(TYP_TEXT); |
504 |
|
badeof: |
505 |
|
if (report != REP_QUIET) { |
582 |
|
|
583 |
|
if (report >= REP_VERBOSE) { |
584 |
|
fputs(progname, stdout); |
585 |
< |
fputs(": comparing inputs as ASCII text\n", stdout); |
585 |
> |
fputs(": comparing inputs as ASCII text", stdout); |
586 |
> |
if (escape_newlines) |
587 |
> |
fputs(", allowing escaped newlines", stdout); |
588 |
> |
if (comment_c) { |
589 |
> |
fputs(", ignoring comments starting with '", stdout); |
590 |
> |
fputc(comment_c, stdout); |
591 |
> |
fputc('\'', stdout); |
592 |
> |
} |
593 |
> |
fputc('\n', stdout); |
594 |
|
} |
595 |
+ |
SET_FILE_TEXT(f1in); /* originally set to binary */ |
596 |
+ |
SET_FILE_TEXT(f2in); |
597 |
|
init_line(&l1buf); init_line(&l2buf); /* compare a line at a time */ |
598 |
|
while (read_line(&l1buf, f1in)) { |
599 |
|
lin1cnt++; |
736 |
|
static char depthvar[] = DEPTHSTR; |
737 |
|
const char *drval; |
738 |
|
|
739 |
< |
depthvar[LDEPTHSTR] = '\0'; |
739 |
> |
depthvar[LDEPTHSTR-1] = '\0'; |
740 |
|
drval = (const char *)lu_find(htp, depthvar)->data; |
741 |
|
if (!drval) |
742 |
|
return(0); |
871 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
872 |
|
goto badeof; |
873 |
|
++nread; |
874 |
+ |
if (f1swap) swap32((char *)&f1, 1); |
875 |
+ |
if (f2swap) swap32((char *)&f2, 1); |
876 |
|
if (real_check(f1, f2)) |
877 |
|
continue; |
878 |
|
if (report != REP_QUIET) |
903 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
904 |
|
goto badeof; |
905 |
|
++nread; |
906 |
+ |
if (f1swap) swap64((char *)&f1, 1); |
907 |
+ |
if (f2swap) swap64((char *)&f2, 1); |
908 |
|
if (real_check(f1, f2)) |
909 |
|
continue; |
910 |
|
if (report != REP_QUIET) |
933 |
|
case 'h': /* ignore header info. */ |
934 |
|
ign_header = !ign_header; |
935 |
|
continue; |
936 |
+ |
case 'n': /* allow newline escapes */ |
937 |
+ |
escape_newlines = !escape_newlines; |
938 |
+ |
continue; |
939 |
+ |
case 'c': /* ignore comments */ |
940 |
+ |
comment_c = argv[a][2]; |
941 |
+ |
continue; |
942 |
|
case 's': /* silent operation */ |
943 |
|
report = REP_QUIET; |
944 |
|
continue; |
999 |
|
return(2); |
1000 |
|
if (typ1 != typ2) { |
1001 |
|
if (report != REP_QUIET) |
1002 |
< |
printf("%s: '%s' is %s and '%s' is %s\n", |
1002 |
> |
printf("%s: '%s' format is %s and '%s' is %s\n", |
1003 |
|
progname, f1name, file_type[typ1], |
1004 |
|
f2name, file_type[typ2]); |
1005 |
|
return(1); |
1015 |
|
printf("%s: warning - unrecognized format\n", |
1016 |
|
progname); |
1017 |
|
} |
1018 |
< |
if (report >= REP_VERBOSE) |
1019 |
< |
printf("%s: input file type is %s\n", |
1020 |
< |
progname, file_type[typ1]); |
1021 |
< |
|
1018 |
> |
if (report >= REP_VERBOSE) { |
1019 |
> |
printf("%s: data format is %s\n", progname, file_type[typ1]); |
1020 |
> |
if ((typ1 == TYP_FLOAT) | (typ1 == TYP_DOUBLE)) { |
1021 |
> |
if (f1swap) |
1022 |
> |
printf("%s: input '%s' is byte-swapped\n", |
1023 |
> |
progname, f1name); |
1024 |
> |
if (f2swap) |
1025 |
> |
printf("%s: input '%s' is byte-swapped\n", |
1026 |
> |
progname, f2name); |
1027 |
> |
} |
1028 |
> |
} |
1029 |
|
switch (typ1) { /* compare based on type */ |
1030 |
|
case TYP_BINARY: |
1031 |
|
case TYP_TMESH: |