ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/radcompare.c
(Generate patch)

Comparing ray/src/util/radcompare.c (file contents):
Revision 2.19 by greg, Wed Aug 14 04:18:12 2019 UTC vs.
Revision 2.31 by greg, Fri May 27 17:27:53 2022 UTC

# Line 27 | Line 27 | int    report = REP_WARN;      /* reporting level */
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 */
# Line 35 | Line 37 | double max_lim = 0.25;         /* difference limit if non-neg
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                  };
# Line 99 | Line 103 | char           *progname = NULL;
103   const char      stdin_name[] = "<stdin>";
104   const char      *f1name=NULL, *f2name=NULL;
105   FILE            *f1in=NULL, *f2in=NULL;
106 + int             f1swap=0, f2swap=0;
107  
108                                  /* running real differences */
109   double  diff2sum = 0;
# Line 110 | Line 115 | usage()
115   {
116          fputs("Usage: ", stderr);
117          fputs(progname, stderr);
118 <        fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n",
118 >        fputs(" [-h][-c#][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n",
119                          stderr);
120          exit(2);
121   }
# Line 129 | Line 134 | read_line(LINEBUF *bp, FILE *fp)
134          }
135          while (fgets(bp->str + bp->len, bp->siz - bp->len, fp)) {
136                  bp->len += strlen(bp->str + bp->len);
137 <                if (bp->str[bp->len-1] == '\n')
137 >                if (bp->str[bp->len-1] == '\n') {
138 >                        if (bp->len > 1 && bp->str[bp->len-2] == '\r') {
139 >                                bp->str[--bp->len] = '\0';
140 >                                bp->str[bp->len-1] = '\n';
141 >                        }
142 >                        if (escape_newlines && bp->len > 1 &&
143 >                                        bp->str[bp->len-2] == '\\') {
144 >                                bp->str[--bp->len] = '\0';
145 >                                bp->str[bp->len-1] = ' ';
146 >                                continue;
147 >                        }
148                          break;          /* found EOL */
149 +                }
150                  if (bp->len < bp->siz - 4)
151                          continue;       /* at EOF? */
152                  if (bp->siz >= MAXBUF) {
# Line 148 | Line 164 | read_line(LINEBUF *bp, FILE *fp)
164                  if (!bp->str)
165                          goto memerr;
166          }
167 +        if (comment_c) {                /* elide comment? */
168 +                char    *cp = sskip2(bp->str,0);
169 +                if (*cp == comment_c) {
170 +                        *cp++ = '\n';
171 +                        *cp = '\0';
172 +                        bp->len = cp - bp->str;
173 +                }
174 +        }
175          return(bp->len);
176   memerr:
177          fprintf(stderr,
# Line 186 | Line 210 | real_check(double r1, double r2)
210  
211          if (rel_min > 0) {      /* doing relative differences? */
212                  double  av2 = .25*(r1*r1 + 2.*fabs(r1*r2) + r2*r2);
213 <                if (av2 > rel_min*rel_min)
214 <                        diff2 /= av2;
213 >                if (av2 < rel_min*rel_min)
214 >                        av2 = rel_min*rel_min;
215 >                diff2 /= av2;
216          }
217          if (max_lim >= 0 && diff2 > max_lim*max_lim) {
218                  if (report != REP_QUIET)
# Line 223 | Line 248 | color_check(COLOR c1, COLOR c2)
248   static int
249   norm_check(FVECT nv1, FVECT nv2)
250   {
251 <        double  max2 = nv1[2]*nv1[2];
251 >        double  max2 = nv1[2]*nv2[2];
252          int     imax = 2;
253          int     i = 2;
254                                          /* identify largest component */
255          while (i--) {
256 <                double  tm2 = nv1[i]*nv1[i];
256 >                double  tm2 = nv1[i]*nv2[i];
257                  if (tm2 > max2) {
258                          imax = i;
259                          max2 = tm2;
# Line 316 | Line 341 | equiv_string(char *s1, char *s2)
341   static int
342   setheadvar(char *val, void *p)
343   {
344 +        char    newval[128];
345          LUTAB   *htp = (LUTAB *)p;
346          LUENT   *tep;
347          char    *key;
# Line 325 | Line 351 | setheadvar(char *val, void *p)
351          adv_linecnt(htp);       /* side-effect is to count lines */
352          if (!isalpha(*val))     /* key must start line */
353                  return(0);
354 +                                /* check if we need to swap binary data */
355 +        if ((n = isbigendian(val)) >= 0) {
356 +                if (nativebigendian() == n)
357 +                        return(0);
358 +                f1swap += (htp == &hdr1);
359 +                f2swap += (htp == &hdr2);
360 +                return(0);
361 +        }
362          key = val++;
363          while (*val && !isspace(*val) & (*val != '='))
364                  val++;
# Line 350 | Line 384 | setheadvar(char *val, void *p)
384                  return(-1);     /* memory allocation error */
385          if (!tep->key)
386                  tep->key = strcpy(malloc(kln+1), key);
387 <        if (tep->data)
387 >        if (tep->data) {        /* check for special cases */
388 >                if (!strcmp(key, "EXPOSURE")) {
389 >                        sprintf(newval, "%.6e", atof(tep->data)*atof(val));
390 >                        vln = strlen(val = newval);
391 >                }
392                  free(tep->data);
393 +        }
394          tep->data = strcpy(malloc(vln+1), val);
395          return(1);
396   }
# Line 460 | Line 499 | identify_type(const char *name, FILE *fin, LUTAB *htp)
499          }
500          if (c)
501                  return(TYP_BINARY);
463        SET_FILE_TEXT(fin);                     /* originally set to binary */
502          return(TYP_TEXT);
503   badeof:
504          if (report != REP_QUIET) {
# Line 543 | Line 581 | compare_text()
581  
582          if (report >= REP_VERBOSE) {
583                  fputs(progname, stdout);
584 <                fputs(": comparing inputs as ASCII text\n", stdout);
584 >                fputs(": comparing inputs as ASCII text", stdout);
585 >                if (escape_newlines)
586 >                        fputs(", allowing escaped newlines", stdout);
587 >                if (comment_c) {
588 >                        fputs(", ignoring comments starting with '", stdout);
589 >                        fputc(comment_c, stdout);
590 >                        fputc('\'', stdout);
591 >                }
592 >                fputc('\n', stdout);
593          }
594 +        SET_FILE_TEXT(f1in);                    /* originally set to binary */
595 +        SET_FILE_TEXT(f2in);
596          init_line(&l1buf); init_line(&l2buf);   /* compare a line at a time */
597          while (read_line(&l1buf, f1in)) {
598                  lin1cnt++;
# Line 687 | Line 735 | set_refdepth(DEPTHCODEC *dcp, LUTAB *htp)
735          static char     depthvar[] = DEPTHSTR;
736          const char      *drval;
737  
738 <        depthvar[LDEPTHSTR] = '\0';
738 >        depthvar[LDEPTHSTR-1] = '\0';
739          drval = (const char *)lu_find(htp, depthvar)->data;
740          if (!drval)
741                  return(0);
# Line 822 | Line 870 | compare_float()
870                  if (!getbinary(&f2, sizeof(f2), 1, f2in))
871                          goto badeof;
872                  ++nread;
873 +                if (f1swap) swap32((char *)&f1, 1);
874 +                if (f2swap) swap32((char *)&f2, 1);
875                  if (real_check(f1, f2))
876                          continue;
877                  if (report != REP_QUIET)
# Line 852 | Line 902 | compare_double()
902                  if (!getbinary(&f2, sizeof(f2), 1, f2in))
903                          goto badeof;
904                  ++nread;
905 +                if (f1swap) swap64((char *)&f1, 1);
906 +                if (f2swap) swap64((char *)&f2, 1);
907                  if (real_check(f1, f2))
908                          continue;
909                  if (report != REP_QUIET)
# Line 880 | Line 932 | main(int argc, char *argv[])
932                  case 'h':                       /* ignore header info. */
933                          ign_header = !ign_header;
934                          continue;
935 +                case 'n':                       /* allow newline escapes */
936 +                        escape_newlines = !escape_newlines;
937 +                        continue;
938 +                case 'c':                       /* ignore comments */
939 +                        comment_c = argv[a][2];
940 +                        continue;
941                  case 's':                       /* silent operation */
942                          report = REP_QUIET;
943                          continue;
# Line 940 | Line 998 | main(int argc, char *argv[])
998                  return(2);
999          if (typ1 != typ2) {
1000                  if (report != REP_QUIET)
1001 <                        printf("%s: '%s' is %s and '%s' is %s\n",
1001 >                        printf("%s: '%s' format is %s and '%s' is %s\n",
1002                                          progname, f1name, file_type[typ1],
1003                                          f2name, file_type[typ2]);
1004                  return(1);
# Line 956 | Line 1014 | main(int argc, char *argv[])
1014                          printf("%s: warning - unrecognized format\n",
1015                                          progname);
1016          }
1017 <        if (report >= REP_VERBOSE)
1018 <                printf("%s: input file type is %s\n",
1019 <                                progname, file_type[typ1]);
1020 <
1017 >        if (report >= REP_VERBOSE) {
1018 >                printf("%s: data format is %s\n", progname, file_type[typ1]);
1019 >                if ((typ1 == TYP_FLOAT) | (typ1 == TYP_DOUBLE)) {
1020 >                        if (f1swap)
1021 >                                printf("%s: input '%s' is byte-swapped\n",
1022 >                                                progname, f1name);
1023 >                        if (f2swap)
1024 >                                printf("%s: input '%s' is byte-swapped\n",
1025 >                                                progname, f2name);
1026 >                }
1027 >        }
1028          switch (typ1) {                         /* compare based on type */
1029          case TYP_BINARY:
1030          case TYP_TMESH:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines