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

Comparing ray/src/util/wrapBSDF.c (file contents):
Revision 2.22 by greg, Tue Feb 14 19:58:37 2017 UTC vs.
Revision 2.27 by greg, Wed Sep 7 18:55:39 2022 UTC

# Line 27 | Line 27 | const char     legal_units[] = "meter|foot|inch|centimeter
27                                          /* system materials & geometry */
28   const char      *mgf_geometry = NULL;
29                                          /* comment list */
30 < #define MAXCOMM         30
30 > #define MAXCOMM         80
31   const char      *commlist[MAXCOMM];
32   int             ncomm = 0;
33                                          /* angle bases */
# Line 69 | Line 69 | const char     *field_assignment[MAXASSIGN];
69   int             nfield_assign = 0;
70   #define FASEP   ';'
71                                          /* data file(s) & spectra */
72 < enum { DTtransForward, DTtransBackward, DTreflForward, DTreflBackward };
72 > enum { DTransFront, DTransBack, DTreflFront, DTreflBack };
73  
74 + static const char       component_name[4][20] = {
75 +                "Transmission Front",
76 +                "Transmission Back",
77 +                "Reflection Front",
78 +                "Reflection Back"
79 + };
80 +
81   enum { DSsolar=-1, DSnir=-2, DSxbar31=-3, DSvisible=-4, DSzbar31=-5,
82          DSuprime=-6, DSvprime=-7 };
83  
# Line 122 | Line 129 | static char    basis_definition[][256] = {
129          "\t</DataDefinition>\n",
130   };
131  
132 + /* Check that the last-added data file is unique */
133 + static int
134 + check_new_data_file()
135 + {
136 +        int     i = ndataf;
137 +
138 +        while (i-- > 0)
139 +                if ((data_file[i].spectrum == data_file[ndataf].spectrum) &
140 +                                (data_file[i].type == data_file[ndataf].type)) {
141 +                        fprintf(stderr,
142 +                                "%s: warning - ignoring duplicate component %s\n",
143 +                                        data_file[ndataf].fname,
144 +                                        component_name[data_file[i].type]);
145 +                        return 0;
146 +                }
147 +        return 1;
148 + }
149 +
150   /* Copy data from file descriptor to stdout and close */
151   static int
152   copy_and_close(int fd)
# Line 392 | Line 417 | determine_angle_basis(const char *fn, ezxml_t wtl)
417          return -1;
418   }
419  
420 < /* Filter Klems angle basis, factoring out incident projected solid angle */
420 > /* Filter Klems angle data, factoring out incident projected solid angle */
421   static int
422   filter_klems_matrix(FILE *fp)
423   {
424          const char      *bn = klems_basis_name[angle_basis];
425 <        int             i, j, n = nabases;
425 >        int             i, j, c, n = nabases;
426                                          /* get angle basis */
427          while (n-- > 0)
428                  if (!strcasecmp(bn, abase_list[n].name))
# Line 409 | Line 434 | filter_klems_matrix(FILE *fp)
434              const double        corr = 1./io_getohm(i, &abase_list[n]);
435              for (j = 0; j < abase_list[n].nangles; j++) {
436                  double  d;
437 <                if (fscanf(fp, "%lf", &d) != 1)
437 >                if (fscanf(fp, "%lf ", &d) != 1)
438                          return 0;
439 +                if ((c = getc(fp)) != ',')
440 +                        ungetc(c, fp);
441                  if (d < -1e-3) {
442                          fputs("Negative BSDF data!\n", stderr);
443                          return 0;
# Line 419 | Line 446 | filter_klems_matrix(FILE *fp)
446              }
447              fputc('\n', stdout);
448          }
449 <        while ((i = getc(fp)) != EOF)
450 <                if (!isspace(i)) {
449 >        while ((c = getc(fp)) != EOF)
450 >                if (!isspace(c)) {
451                          fputs("Unexpected data past EOF\n", stderr);
452                          return 0;
453                  }
# Line 485 | Line 512 | writeBSDFblock(const char *caller, struct s_dfile *df)
512          }
513          puts("\t\t<WavelengthDataBlock>");
514          fputs("\t\t\t<WavelengthDataDirection>", stdout);
515 <        switch (df->type) {
489 <        case DTtransForward:
490 <                fputs("Transmission Front", stdout);
491 <                break;
492 <        case DTtransBackward:
493 <                fputs("Transmission Back", stdout);
494 <                break;
495 <        case DTreflForward:
496 <                fputs("Reflection Front", stdout);
497 <                break;
498 <        case DTreflBackward:
499 <                fputs("Reflection Back", stdout);
500 <                break;
501 <        default:
502 <                fprintf(stderr, "%s: internal - bad BSDF type (%d)\n", caller, df->type);
503 <                return 0;
504 <        }
515 >        fputs(component_name[df->type], stdout);
516          puts("</WavelengthDataDirection>");
517          switch (angle_basis) {
518          case ABklemsFull:
# Line 808 | Line 819 | main(int argc, char *argv[])
819                                                  argv[0]);
820                                  return 1;
821                          }
822 <                        if (strchr(argv[++i], '>') != NULL) {
822 >                        if (strstr(argv[++i], "-->") != NULL) {
823                                  fprintf(stderr, "%s: illegal character in comment\n",
824                                                  argv[0]);
825                                  return 1;
# Line 824 | Line 835 | main(int argc, char *argv[])
835                                  return 1;
836                          }
837                          if (!strcmp(argv[i], "-tf"))
838 <                                data_file[ndataf].type = DTtransForward;
838 >                                data_file[ndataf].type = DTransFront;
839                          else if (!strcmp(argv[i], "-tb"))
840 <                                data_file[ndataf].type = DTtransBackward;
840 >                                data_file[ndataf].type = DTransBack;
841                          else
842                                  UsageExit(argv[0]);
843                          if (!strcmp(argv[++i], "-")) {
# Line 835 | Line 846 | main(int argc, char *argv[])
846                          }
847                          data_file[ndataf].fname = argv[i];
848                          data_file[ndataf].spectrum = cur_spectrum;
849 <                        ndataf++;
849 >                        ndataf += check_new_data_file();
850                          continue;
851                  case 'r':               /* reflection */
852                          if (i >= argc-1)
# Line 846 | Line 857 | main(int argc, char *argv[])
857                                  return 1;
858                          }
859                          if (!strcmp(argv[i], "-rf"))
860 <                                data_file[ndataf].type = DTreflForward;
860 >                                data_file[ndataf].type = DTreflFront;
861                          else if (!strcmp(argv[i], "-rb"))
862 <                                data_file[ndataf].type = DTreflBackward;
862 >                                data_file[ndataf].type = DTreflBack;
863                          else
864                                  UsageExit(argv[0]);
865                          if (!strcmp(argv[++i], "-")) {
# Line 857 | Line 868 | main(int argc, char *argv[])
868                          }
869                          data_file[ndataf].fname = argv[i];
870                          data_file[ndataf].spectrum = cur_spectrum;
871 <                        ndataf++;
871 >                        ndataf += check_new_data_file();
872                          continue;
873                  case 's':               /* spectrum name or input file */
874                          if (++i >= argc)
# Line 910 | Line 921 | main(int argc, char *argv[])
921                  }
922                  break;
923          }
924 < doneOptions:                                    /* get XML input */
924 >                                                /* get XML input */
925          if (i >= argc) {
926                  if (xml_input == NULL)
927                          xml_input = def_template;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines