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.24 by greg, Tue Jun 30 22:53:05 2020 UTC vs.
Revision 2.32 by greg, Wed Mar 8 19:59:48 2023 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 111 | 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 130 | 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 149 | 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 187 | 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 362 | Line 386 | setheadvar(char *val, void *p)
386                  tep->key = strcpy(malloc(kln+1), key);
387          if (tep->data) {        /* check for special cases */
388                  if (!strcmp(key, "EXPOSURE")) {
389 <                        sprintf(newval, "%f", atof(tep->data)*atof(val));
389 >                        sprintf(newval, "%.6e", atof(tep->data)*atof(val));
390                          vln = strlen(val = newval);
391                  }
392                  free(tep->data);
# Line 475 | Line 499 | identify_type(const char *name, FILE *fin, LUTAB *htp)
499          }
500          if (c)
501                  return(TYP_BINARY);
478        SET_FILE_TEXT(fin);                     /* originally set to binary */
502          return(TYP_TEXT);
503   badeof:
504          if (report != REP_QUIET) {
# Line 558 | 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 582 | Line 615 | compare_text()
615                                                  /* compare non-empty lines */
616                  if (!equiv_string(l1buf.str, l2buf.str)) {
617                          if (report != REP_QUIET) {
618 <                                printf("%s: inputs '%s' and '%s' differ at line %d|%d\n",
619 <                                                progname, f1name, f2name,
620 <                                                lin1cnt, lin2cnt);
618 >                                printf("%s: inputs '%s' and '%s' differ at line %d",
619 >                                                progname, f1name, f2name, lin1cnt);
620 >                                if (lin1cnt != lin2cnt)
621 >                                        printf("|%d\n", lin2cnt);
622 >                                else
623 >                                        putchar('\n');
624                                  if ( report >= REP_VERBOSE &&
625                                                  (l1buf.len < 256) &
626                                                  (l2buf.len < 256) ) {
# Line 898 | Line 934 | main(int argc, char *argv[])
934                  switch (argv[a][1]) {
935                  case 'h':                       /* ignore header info. */
936                          ign_header = !ign_header;
937 +                        continue;
938 +                case 'n':                       /* allow newline escapes */
939 +                        escape_newlines = !escape_newlines;
940 +                        continue;
941 +                case 'c':                       /* ignore comments */
942 +                        comment_c = argv[a][2];
943                          continue;
944                  case 's':                       /* silent operation */
945                          report = REP_QUIET;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines