35 |
|
|
36 |
|
int lin1cnt=0, lin2cnt=0; /* file line position */ |
37 |
|
|
38 |
+ |
int comment_c = '\0'; /* comment delimiter for text files */ |
39 |
+ |
|
40 |
|
const char nsuffix[10][3] = { /* 1st, 2nd, 3rd, etc. */ |
41 |
|
"th","st","nd","rd","th","th","th","th","th","th" |
42 |
|
}; |
101 |
|
const char stdin_name[] = "<stdin>"; |
102 |
|
const char *f1name=NULL, *f2name=NULL; |
103 |
|
FILE *f1in=NULL, *f2in=NULL; |
104 |
+ |
int f1swap=0, f2swap=0; |
105 |
|
|
106 |
|
/* running real differences */ |
107 |
|
double diff2sum = 0; |
113 |
|
{ |
114 |
|
fputs("Usage: ", stderr); |
115 |
|
fputs(progname, stderr); |
116 |
< |
fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", |
116 |
> |
fputs(" [-h][-c#][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", |
117 |
|
stderr); |
118 |
|
exit(2); |
119 |
|
} |
151 |
|
if (!bp->str) |
152 |
|
goto memerr; |
153 |
|
} |
154 |
+ |
if (comment_c) { /* elide comment? */ |
155 |
+ |
char *cp = sskip2(bp->str,0); |
156 |
+ |
if (*cp == comment_c) { |
157 |
+ |
*cp++ = '\n'; |
158 |
+ |
*cp = '\0'; |
159 |
+ |
bp->len = cp - bp->str; |
160 |
+ |
} |
161 |
+ |
} |
162 |
|
return(bp->len); |
163 |
|
memerr: |
164 |
|
fprintf(stderr, |
234 |
|
static int |
235 |
|
norm_check(FVECT nv1, FVECT nv2) |
236 |
|
{ |
237 |
< |
double max2 = nv1[2]*nv1[2]; |
237 |
> |
double max2 = nv1[2]*nv2[2]; |
238 |
|
int imax = 2; |
239 |
|
int i = 2; |
240 |
|
/* identify largest component */ |
241 |
|
while (i--) { |
242 |
< |
double tm2 = nv1[i]*nv1[i]; |
242 |
> |
double tm2 = nv1[i]*nv2[i]; |
243 |
|
if (tm2 > max2) { |
244 |
|
imax = i; |
245 |
|
max2 = tm2; |
327 |
|
static int |
328 |
|
setheadvar(char *val, void *p) |
329 |
|
{ |
330 |
+ |
char newval[128]; |
331 |
|
LUTAB *htp = (LUTAB *)p; |
332 |
|
LUENT *tep; |
333 |
|
char *key; |
337 |
|
adv_linecnt(htp); /* side-effect is to count lines */ |
338 |
|
if (!isalpha(*val)) /* key must start line */ |
339 |
|
return(0); |
340 |
+ |
/* check if we need to swap binary data */ |
341 |
+ |
if ((n = isbigendian(val)) >= 0) { |
342 |
+ |
if (nativebigendian() == n) |
343 |
+ |
return(0); |
344 |
+ |
f1swap += (htp == &hdr1); |
345 |
+ |
f2swap += (htp == &hdr2); |
346 |
+ |
return(0); |
347 |
+ |
} |
348 |
|
key = val++; |
349 |
|
while (*val && !isspace(*val) & (*val != '=')) |
350 |
|
val++; |
370 |
|
return(-1); /* memory allocation error */ |
371 |
|
if (!tep->key) |
372 |
|
tep->key = strcpy(malloc(kln+1), key); |
373 |
< |
if (tep->data) |
373 |
> |
if (tep->data) { /* check for special cases */ |
374 |
> |
if (!strcmp(key, "EXPOSURE")) { |
375 |
> |
sprintf(newval, "%f", atof(tep->data)*atof(val)); |
376 |
> |
vln = strlen(val = newval); |
377 |
> |
} |
378 |
|
free(tep->data); |
379 |
+ |
} |
380 |
|
tep->data = strcpy(malloc(vln+1), val); |
381 |
|
return(1); |
382 |
|
} |
485 |
|
} |
486 |
|
if (c) |
487 |
|
return(TYP_BINARY); |
463 |
– |
SET_FILE_TEXT(fin); /* originally set to binary */ |
488 |
|
return(TYP_TEXT); |
489 |
|
badeof: |
490 |
|
if (report != REP_QUIET) { |
567 |
|
|
568 |
|
if (report >= REP_VERBOSE) { |
569 |
|
fputs(progname, stdout); |
570 |
< |
fputs(": comparing inputs as ASCII text\n", stdout); |
570 |
> |
fputs(": comparing inputs as ASCII text", stdout); |
571 |
> |
if (comment_c) { |
572 |
> |
fputs(", ignoring comments starting with '", stdout); |
573 |
> |
fputc(comment_c, stdout); |
574 |
> |
fputc('\'', stdout); |
575 |
> |
} |
576 |
> |
fputc('\n', stdout); |
577 |
|
} |
578 |
+ |
SET_FILE_TEXT(f1in); /* originally set to binary */ |
579 |
+ |
SET_FILE_TEXT(f2in); |
580 |
|
init_line(&l1buf); init_line(&l2buf); /* compare a line at a time */ |
581 |
|
while (read_line(&l1buf, f1in)) { |
582 |
|
lin1cnt++; |
719 |
|
static char depthvar[] = DEPTHSTR; |
720 |
|
const char *drval; |
721 |
|
|
722 |
< |
depthvar[LDEPTHSTR] = '\0'; |
722 |
> |
depthvar[LDEPTHSTR-1] = '\0'; |
723 |
|
drval = (const char *)lu_find(htp, depthvar)->data; |
724 |
|
if (!drval) |
725 |
|
return(0); |
854 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
855 |
|
goto badeof; |
856 |
|
++nread; |
857 |
+ |
if (f1swap) swap32((char *)&f1, 1); |
858 |
+ |
if (f2swap) swap32((char *)&f2, 1); |
859 |
|
if (real_check(f1, f2)) |
860 |
|
continue; |
861 |
|
if (report != REP_QUIET) |
886 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
887 |
|
goto badeof; |
888 |
|
++nread; |
889 |
+ |
if (f1swap) swap64((char *)&f1, 1); |
890 |
+ |
if (f2swap) swap64((char *)&f2, 1); |
891 |
|
if (real_check(f1, f2)) |
892 |
|
continue; |
893 |
|
if (report != REP_QUIET) |
916 |
|
case 'h': /* ignore header info. */ |
917 |
|
ign_header = !ign_header; |
918 |
|
continue; |
919 |
+ |
case 'c': /* ignore comments */ |
920 |
+ |
comment_c = argv[a][2]; |
921 |
+ |
continue; |
922 |
|
case 's': /* silent operation */ |
923 |
|
report = REP_QUIET; |
924 |
|
continue; |
979 |
|
return(2); |
980 |
|
if (typ1 != typ2) { |
981 |
|
if (report != REP_QUIET) |
982 |
< |
printf("%s: '%s' is %s and '%s' is %s\n", |
982 |
> |
printf("%s: '%s' format is %s and '%s' is %s\n", |
983 |
|
progname, f1name, file_type[typ1], |
984 |
|
f2name, file_type[typ2]); |
985 |
|
return(1); |
995 |
|
printf("%s: warning - unrecognized format\n", |
996 |
|
progname); |
997 |
|
} |
998 |
< |
if (report >= REP_VERBOSE) |
999 |
< |
printf("%s: input file type is %s\n", |
1000 |
< |
progname, file_type[typ1]); |
1001 |
< |
|
998 |
> |
if (report >= REP_VERBOSE) { |
999 |
> |
printf("%s: data format is %s\n", progname, file_type[typ1]); |
1000 |
> |
if ((typ1 == TYP_FLOAT) | (typ1 == TYP_DOUBLE)) { |
1001 |
> |
if (f1swap) |
1002 |
> |
printf("%s: input '%s' is byte-swapped\n", |
1003 |
> |
progname, f1name); |
1004 |
> |
if (f2swap) |
1005 |
> |
printf("%s: input '%s' is byte-swapped\n", |
1006 |
> |
progname, f2name); |
1007 |
> |
} |
1008 |
> |
} |
1009 |
|
switch (typ1) { /* compare based on type */ |
1010 |
|
case TYP_BINARY: |
1011 |
|
case TYP_TMESH: |