99 |
|
const char stdin_name[] = "<stdin>"; |
100 |
|
const char *f1name=NULL, *f2name=NULL; |
101 |
|
FILE *f1in=NULL, *f2in=NULL; |
102 |
+ |
int f1swap=0, f2swap=0; |
103 |
|
|
104 |
|
/* running real differences */ |
105 |
|
double diff2sum = 0; |
224 |
|
static int |
225 |
|
norm_check(FVECT nv1, FVECT nv2) |
226 |
|
{ |
227 |
< |
double max2 = nv1[2]*nv1[2]; |
227 |
> |
double max2 = nv1[2]*nv2[2]; |
228 |
|
int imax = 2; |
229 |
|
int i = 2; |
230 |
|
/* identify largest component */ |
231 |
|
while (i--) { |
232 |
< |
double tm2 = nv1[i]*nv1[i]; |
232 |
> |
double tm2 = nv1[i]*nv2[i]; |
233 |
|
if (tm2 > max2) { |
234 |
|
imax = i; |
235 |
|
max2 = tm2; |
317 |
|
static int |
318 |
|
setheadvar(char *val, void *p) |
319 |
|
{ |
320 |
+ |
char newval[128]; |
321 |
|
LUTAB *htp = (LUTAB *)p; |
322 |
|
LUENT *tep; |
323 |
|
char *key; |
327 |
|
adv_linecnt(htp); /* side-effect is to count lines */ |
328 |
|
if (!isalpha(*val)) /* key must start line */ |
329 |
|
return(0); |
330 |
+ |
/* check if we need to swap binary data */ |
331 |
+ |
if ((n = isbigendian(val)) >= 0) { |
332 |
+ |
if (nativebigendian() == n) |
333 |
+ |
return(0); |
334 |
+ |
f1swap += (htp == &hdr1); |
335 |
+ |
f2swap += (htp == &hdr2); |
336 |
+ |
return(0); |
337 |
+ |
} |
338 |
|
key = val++; |
339 |
|
while (*val && !isspace(*val) & (*val != '=')) |
340 |
|
val++; |
360 |
|
return(-1); /* memory allocation error */ |
361 |
|
if (!tep->key) |
362 |
|
tep->key = strcpy(malloc(kln+1), key); |
363 |
< |
if (tep->data) |
363 |
> |
if (tep->data) { /* check for special cases */ |
364 |
> |
if (!strcmp(key, "EXPOSURE")) { |
365 |
> |
sprintf(newval, "%f", atof(tep->data)*atof(val)); |
366 |
> |
vln = strlen(val = newval); |
367 |
> |
} |
368 |
|
free(tep->data); |
369 |
+ |
} |
370 |
|
tep->data = strcpy(malloc(vln+1), val); |
371 |
|
return(1); |
372 |
|
} |
475 |
|
} |
476 |
|
if (c) |
477 |
|
return(TYP_BINARY); |
463 |
– |
SET_FILE_TEXT(fin); /* originally set to binary */ |
478 |
|
return(TYP_TEXT); |
479 |
|
badeof: |
480 |
|
if (report != REP_QUIET) { |
559 |
|
fputs(progname, stdout); |
560 |
|
fputs(": comparing inputs as ASCII text\n", stdout); |
561 |
|
} |
562 |
+ |
SET_FILE_TEXT(f1in); /* originally set to binary */ |
563 |
+ |
SET_FILE_TEXT(f2in); |
564 |
|
init_line(&l1buf); init_line(&l2buf); /* compare a line at a time */ |
565 |
|
while (read_line(&l1buf, f1in)) { |
566 |
|
lin1cnt++; |
703 |
|
static char depthvar[] = DEPTHSTR; |
704 |
|
const char *drval; |
705 |
|
|
706 |
< |
depthvar[LDEPTHSTR] = '\0'; |
706 |
> |
depthvar[LDEPTHSTR-1] = '\0'; |
707 |
|
drval = (const char *)lu_find(htp, depthvar)->data; |
708 |
|
if (!drval) |
709 |
|
return(0); |
838 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
839 |
|
goto badeof; |
840 |
|
++nread; |
841 |
+ |
if (f1swap) swap32((char *)&f1, 1); |
842 |
+ |
if (f2swap) swap32((char *)&f2, 1); |
843 |
|
if (real_check(f1, f2)) |
844 |
|
continue; |
845 |
|
if (report != REP_QUIET) |
870 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
871 |
|
goto badeof; |
872 |
|
++nread; |
873 |
+ |
if (f1swap) swap64((char *)&f1, 1); |
874 |
+ |
if (f2swap) swap64((char *)&f2, 1); |
875 |
|
if (real_check(f1, f2)) |
876 |
|
continue; |
877 |
|
if (report != REP_QUIET) |
960 |
|
return(2); |
961 |
|
if (typ1 != typ2) { |
962 |
|
if (report != REP_QUIET) |
963 |
< |
printf("%s: '%s' is %s and '%s' is %s\n", |
963 |
> |
printf("%s: '%s' format is %s and '%s' is %s\n", |
964 |
|
progname, f1name, file_type[typ1], |
965 |
|
f2name, file_type[typ2]); |
966 |
|
return(1); |
976 |
|
printf("%s: warning - unrecognized format\n", |
977 |
|
progname); |
978 |
|
} |
979 |
< |
if (report >= REP_VERBOSE) |
980 |
< |
printf("%s: input file type is %s\n", |
981 |
< |
progname, file_type[typ1]); |
982 |
< |
|
979 |
> |
if (report >= REP_VERBOSE) { |
980 |
> |
printf("%s: data format is %s\n", progname, file_type[typ1]); |
981 |
> |
if ((typ1 == TYP_FLOAT) | (typ1 == TYP_DOUBLE)) { |
982 |
> |
if (f1swap) |
983 |
> |
printf("%s: input '%s' is byte-swapped\n", |
984 |
> |
progname, f1name); |
985 |
> |
if (f2swap) |
986 |
> |
printf("%s: input '%s' is byte-swapped\n", |
987 |
> |
progname, f2name); |
988 |
> |
} |
989 |
> |
} |
990 |
|
switch (typ1) { /* compare based on type */ |
991 |
|
case TYP_BINARY: |
992 |
|
case TYP_TMESH: |