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.5 by greg, Mon Oct 15 22:21:45 2018 UTC vs.
Revision 2.10 by greg, Wed Oct 17 17:39:23 2018 UTC

# Line 33 | Line 33 | double max_lim = 0.25;         /* difference limit if non-neg
33  
34   int     lin1cnt=0, lin2cnt=0;   /* file line position */
35  
36 + const char      nsuffix[10][3] = {              /* 1st, 2nd, 3rd, etc. */
37 +                        "th","st","nd","rd","th","th","th","th","th","th"
38 +                };
39 + #define num_sfx(n)      nsuffix[(n)%10]
40 +
41                                  /* file types */
42   const char      *file_type[] = {
43                          "Unrecognized",
# Line 48 | Line 53 | const char     *file_type[] = {
53                          "BINARY_unknown",
54                          NULL    /* terminator */
55                  };
56 <
56 >                                /* keep consistent with above */
57   enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE, TYP_FLOAT,
58                  TYP_DOUBLE, TYP_RBFMESH, TYP_OCTREE, TYP_TMESH, TYP_BINARY};
59                  
# Line 77 | Line 82 | FILE           *f1in=NULL, *f2in=NULL;
82  
83                                  /* running real differences */
84   double  diff2sum = 0;
85 < int     nsum = 0;
85 > long    nsum = 0;
86  
87   /* Report usage and exit */
88   static void
# Line 87 | Line 92 | usage()
92          fputs(progname, stderr);
93          fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n",
94                          stderr);
95 <        exit(1);
95 >        exit(2);
96   }
97  
98   /* Get type ID from name (or 0 if not found) */
# Line 129 | Line 134 | real_check(double r1, double r2)
134          return(1);
135   }
136  
137 + /* Compare two color values for equivalence */
138 + static int
139 + color_check(COLOR c1, COLOR c2)
140 + {
141 +        int     p;
142 +
143 +        if (!real_check(colval(c1,RED)+colval(c1,GRN)+colval(c1,BLU)*(1./3.),
144 +                        colval(c2,RED)+colval(c2,GRN)+colval(c2,BLU))*(1./3.))
145 +                return(0);
146 +
147 +        p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED;
148 +        if (colval(c1,BLU) > colval(c1,p)) p = BLU;
149 +        
150 +        return(real_check(colval(c1,p), colval(c2,p)));
151 + }
152 +
153   /* Compare two strings for equivalence */
154   static int
155   equiv_string(char *s1, char *s2)
# Line 223 | Line 244 | setheadvar(char *val, void *p)
244                  val++;
245          if (!*val)              /* nothing set? */
246                  return(0);
226        vln = strlen(val);      /* eliminate space and newline at end */
227        while (--vln > 0 && isspace(val[vln]))
228                ;
229        val[++vln] = '\0';
247                                  /* check if key to ignore */
248          for (n = 0; hdr_ignkey[n]; n++)
249                  if (!strcmp(key, hdr_ignkey[n]))
250                          return(0);
251 +        vln = strlen(val);      /* eliminate space and newline at end */
252 +        while (isspace(val[--vln]))
253 +                ;
254 +        val[++vln] = '\0';
255          if (!(tep = lu_find(htp, key)))
256                  return(-1);     /* memory allocation error */
257          if (!tep->key)
# Line 270 | Line 291 | match_val(const LUENT *ep1, void *p2)
291  
292   /* Compare two sets of header variables */
293   static int
294 < headers_match(LUTAB *hp1, LUTAB *hp2)
294 > headers_match()
295   {
296 <        int     ne = lu_doall(hp1, match_val, hp2);
296 >        int     ne = lu_doall(&hdr1, match_val, &hdr2);
297          if (ne < 0)
298                  return(0);      /* something didn't match! */
299                                  /* non-fatal if second header has extra */
300 <        if (report >= REP_WARN && (ne = lu_doall(hp2, NULL, NULL) - ne))
300 >        if (report >= REP_WARN && (ne = lu_doall(&hdr2, NULL, NULL) - ne))
301                  printf("%s: warning - '%s' has %d extra header setting(s)\n",
302                                          progname, f2name, ne);
303          return(1);              /* good match */
# Line 331 | Line 352 | identify_type(const char *name, FILE *fin, LUTAB *htp)
352                  }
353                  if (getheader(fin, setheadvar, htp) < 0) {
354                          fputs(name, stderr);
355 <                        fputs(": Unknown error reading header\n", stderr);
355 >                        fputs(": unknown error reading header\n", stderr);
356                          return(-1);
357                  }
358                  adv_linecnt(htp);               /* for trailing emtpy line */
# Line 350 | Line 371 | identify_type(const char *name, FILE *fin, LUTAB *htp)
371   badeof:
372          if (report != REP_QUIET) {
373                  fputs(name, stdout);
374 <                fputs(": Unexpected end-of-file\n", stdout);
374 >                fputs(": unexpected end-of-file\n", stdout);
375          }
376          return(-1);
377   }
# Line 396 | Line 417 | compare_binary()
417                                  return(1);      /* success! */
418                          if (report != REP_QUIET) {
419                                  fputs(f1name, stdout);
420 <                                fputs(": Unexpected end-of-file\n", stdout);
420 >                                fputs(": unexpected end-of-file\n", stdout);
421                          }
422                          return(0);
423                  }
424                  if (c2 == EOF) {
425                          if (report != REP_QUIET) {
426                                  fputs(f2name, stdout);
427 <                                fputs(": Unexpected end-of-file\n", stdout);
427 >                                fputs(": unexpected end-of-file\n", stdout);
428                          }
429                          return(0);
430                  }
# Line 443 | Line 464 | compare_text()
464                  if (feof(f2in)) {
465                          if (report != REP_QUIET) {
466                                  fputs(f2name, stdout);
467 <                                fputs(": Unexpected end-of-file\n", stdout);
467 >                                fputs(": unexpected end-of-file\n", stdout);
468                          }
469                          return(0);
470                  }
# Line 470 | Line 491 | compare_text()
491                          continue;
492                  if (report != REP_QUIET) {
493                          fputs(f1name, stdout);
494 <                        fputs(": Unexpected end-of-file\n", stdout);
494 >                        fputs(": unexpected end-of-file\n", stdout);
495                  }
496                  return(0);
497          }
# Line 485 | Line 506 | compare_hdr()
506          COLOR   *scan1, *scan2;
507          int     x, y;
508  
509 +        if (report >= REP_VERBOSE) {
510 +                fputs(progname, stdout);
511 +                fputs(": comparing inputs as HDR images\n", stdout);
512 +        }
513          fgetsresolu(&rs1, f1in);
514          fgetsresolu(&rs2, f2in);
515          if (rs1.rt != rs2.rt) {
# Line 511 | Line 536 | compare_hdr()
536                  if ((freadscan(scan1, scanlen(&rs1), f1in) < 0) |
537                                  (freadscan(scan2, scanlen(&rs2), f2in) < 0)) {
538                          if (report != REP_QUIET)
539 <                                printf("%s: Unexpected end-of-file\n",
539 >                                printf("%s: unexpected end-of-file\n",
540                                                  progname);
541                          free(scan1);
542                          free(scan2);
543                          return(0);
544                  }
545                  for (x = 0; x < scanlen(&rs1); x++) {
546 <                        if (real_check(colval(scan1[x],RED),
522 <                                                colval(scan2[x],RED)) &
523 <                                        real_check(colval(scan1[x],GRN),
524 <                                                colval(scan2[x],GRN)) &
525 <                                        real_check(colval(scan1[x],BLU),
526 <                                                colval(scan2[x],BLU)))
546 >                        if (color_check(scan1[x], scan2[x]))
547                                  continue;
548                          if (report != REP_QUIET) {
549                                  printf(
# Line 550 | Line 570 | compare_hdr()
570          return(good_RMS());                     /* final check of RMS */
571   }
572  
553 const char      nsuffix[10][3] = {              /* 1st, 2nd, 3rd, etc. */
554                        "th","st","nd","rd","th","th","th","th","th","th"
555                };
556
573   /* Compare two inputs that are known to be 32-bit floating-point data */
574   static int
575   compare_float()
# Line 561 | Line 577 | compare_float()
577          long    nread = 0;
578          float   f1, f2;
579  
580 +        if (report >= REP_VERBOSE) {
581 +                fputs(progname, stdout);
582 +                fputs(": comparing inputs as 32-bit IEEE floats\n", stdout);
583 +        }
584          while (getbinary(&f1, sizeof(f1), 1, f1in)) {
585                  if (!getbinary(&f2, sizeof(f2), 1, f2in))
586                          goto badeof;
# Line 569 | Line 589 | compare_float()
589                          continue;
590                  if (report != REP_QUIET)
591                          printf("%s: %ld%s float values differ\n",
592 <                                        progname, nread, nsuffix[nread%10]);
592 >                                        progname, nread, num_sfx(nread));
593                  return(0);
594          }
595          if (!getbinary(&f2, sizeof(f2), 1, f2in))
596                  return(good_RMS());             /* final check of RMS */
597   badeof:
598          if (report != REP_QUIET)
599 <                printf("%s: Unexpected end-of-file\n", progname);
599 >                printf("%s: unexpected end-of-file\n", progname);
600          return(0);
601   }
602  
# Line 587 | Line 607 | compare_double()
607          long    nread = 0;
608          double  f1, f2;
609  
610 +        if (report >= REP_VERBOSE) {
611 +                fputs(progname, stdout);
612 +                fputs(": comparing inputs as 64-bit IEEE doubles\n", stdout);
613 +        }
614          while (getbinary(&f1, sizeof(f1), 1, f1in)) {
615                  if (!getbinary(&f2, sizeof(f2), 1, f2in))
616                          goto badeof;
# Line 594 | Line 618 | compare_double()
618                  if (real_check(f1, f2))
619                          continue;
620                  if (report != REP_QUIET)
621 <                        printf("%s: %ld%s float values differ\n",
622 <                                        progname, nread, nsuffix[nread%10]);
621 >                        printf("%s: %ld%s double values differ\n",
622 >                                        progname, nread, num_sfx(nread));
623                  return(0);
624          }
625          if (!getbinary(&f2, sizeof(f2), 1, f2in))
626                  return(good_RMS());             /* final check of RMS */
627   badeof:
628          if (report != REP_QUIET)
629 <                printf("%s: Unexpected end-of-file\n", progname);
629 >                printf("%s: unexpected end-of-file\n", progname);
630          return(0);
631   }
632  
# Line 649 | Line 673 | main(int argc, char *argv[])
673                  }
674                  break;
675          }
676 <        if (a != argc-2)
676 >        if (a != argc-2)                        /* make sure of two inputs */
677                  usage();
678 <        if (!f1name) f1name = argv[a];
655 <        if (!f2name) f2name = argv[a+1];
656 <
657 <        if (!strcmp(f1name, f2name)) {          /* inputs are same? */
678 >        if (!strcmp(argv[a], argv[a+1])) {      /* inputs are same? */
679                  if (report >= REP_WARN)
680                          printf("%s: warning - identical inputs given\n",
681                                          progname);
682                  return(0);
683          }
684 +        if (!f1name) f1name = argv[a];
685 +        if (!f2name) f2name = argv[a+1];
686                                                  /* open inputs */
687          SET_FILE_BINARY(stdin);                 /* in case we're using it */
688          if (!f1in && !(f1in = fopen(f1name, "rb"))) {
689                  fprintf(stderr, "%s: cannot open for reading\n", f1name);
690 <                return(1);
690 >                return(2);
691          }
692          if (!strcmp(f2name, "-")) {
693                  f2in = stdin;
694                  f2name = stdin_name;
695          } else if (!(f2in = fopen(f2name, "rb"))) {
696                  fprintf(stderr, "%s: cannot open for reading\n", f2name);
697 <                return(1);
697 >                return(2);
698          }
699                                                  /* load headers */
700          if ((typ1 = identify_type(f1name, f1in, &hdr1)) < 0)
701 <                return(1);
701 >                return(2);
702          if ((typ2 = identify_type(f2name, f2in, &hdr2)) < 0)
703 <                return(1);
703 >                return(2);
704          if (typ1 != typ2) {
705                  if (report != REP_QUIET)
706                          printf("%s: '%s' is %s and '%s' is %s\n",
# Line 686 | Line 709 | main(int argc, char *argv[])
709                  return(1);
710          }
711          ign_header |= !has_header(typ1);        /* check headers if indicated */
712 <        if (!ign_header && !headers_match(&hdr1, &hdr2))
712 >        if (!ign_header && !headers_match())
713                  return(1);
714          lu_done(&hdr1); lu_done(&hdr2);
715          if (!ign_header & (report >= REP_WARN)) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines