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.15 by greg, Fri May 29 07:16:49 2015 UTC vs.
Revision 2.22 by greg, Tue Feb 14 19:58:37 2017 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7   *      G. Ward         February 2015
8   */
9  
10 + #include "platform.h"
11   #include <ctype.h>
12   #include "rtio.h"
13 < #include "rtprocess.h"
13 > #include "paths.h"
14   #include "ezxml.h"
15   #include "bsdf.h"
16   #include "bsdf_m.h"
# Line 25 | Line 26 | const char     *attr_unit = "meter";
26   const char      legal_units[] = "meter|foot|inch|centimeter|millimeter";
27                                          /* system materials & geometry */
28   const char      *mgf_geometry = NULL;
29 <
29 >                                        /* comment list */
30 > #define MAXCOMM         30
31 > const char      *commlist[MAXCOMM];
32 > int             ncomm = 0;
33                                          /* angle bases */
34   enum { ABdefault=-1, ABklemsFull=0, ABklemsHalf, ABklemsQuarter,
35                  ABtensorTree3, ABtensorTree4, ABend };
# Line 48 | Line 52 | struct s_fieldID {
52   } XMLfieldID[] = {
53          {"m", 0, 1, "Manufacturer"},
54          {"n", 0, 1, "Name"},
55 +        {"d", 0, 0, "DeviceType"},
56          {"c", 0, 0, "ThermalConductivity"},
57          {"ef", 0, 0, "EmissivityFront"},
58          {"eb", 0, 0, "EmissivityBack"},
# Line 59 | Line 64 | struct s_fieldID {
64          {"\0", 0, 0, NULL}      /* terminator */
65   };
66                                          /* field assignments */
67 < #define MAXASSIGN       12
67 > #define MAXASSIGN       16
68   const char      *field_assignment[MAXASSIGN];
69   int             nfield_assign = 0;
70   #define FASEP   ';'
# Line 79 | Line 84 | struct s_dfile {
84  
85   int             ndataf = 0;             /* number of data files */
86  
87 + int             unlink_datafiles = 0;   /* unlink data files when done */
88 +
89   const char      *spectr_file[MAXFILES]; /* custom spectral curve input */
90  
91   const char      top_level_name[] = "WindowElement";
# Line 160 | Line 167 | input2str(const char *inpspec)
167                          fprintf(stderr, "%s: cannot open\n", inpspec);
168                          return "";
169                  }
170 < #ifndef _WIN32                          /* XXX somehow broken on Windows */
170 > #if !defined(_WIN32) && !defined(_WIN64)
171 >                                /* XXX somehow broken on Windows */
172                  len = lseek(fd, 0L, SEEK_END);
173                  if (len > 0) {
174                          lseek(fd, 0L, SEEK_SET);
# Line 388 | Line 396 | determine_angle_basis(const char *fn, ezxml_t wtl)
396   static int
397   filter_klems_matrix(FILE *fp)
398   {
391 #define MAX_COLUMNS     145
399          const char      *bn = klems_basis_name[angle_basis];
393        float           col_corr[MAX_COLUMNS];
400          int             i, j, n = nabases;
401                                          /* get angle basis */
402          while (n-- > 0)
# Line 398 | Line 404 | filter_klems_matrix(FILE *fp)
404                          break;
405          if (n < 0)
406                  return 0;
401        if (abase_list[n].nangles > MAX_COLUMNS) {
402                fputs("Internal error - too many Klems columns!\n", stderr);
403                return 0;
404        }
405                                        /* get correction factors */
406        for (j = abase_list[n].nangles; j--; )
407                col_corr[j] = 1.f / io_getohm(j, &abase_list[n]);
407                                          /* read/correct/write matrix */
408          for (i = 0; i < abase_list[n].nangles; i++) {
409 +            const double        corr = 1./io_getohm(i, &abase_list[n]);
410              for (j = 0; j < abase_list[n].nangles; j++) {
411                  double  d;
412                  if (fscanf(fp, "%lf", &d) != 1)
# Line 415 | Line 415 | filter_klems_matrix(FILE *fp)
415                          fputs("Negative BSDF data!\n", stderr);
416                          return 0;
417                  }
418 <                printf(" %.3e", d*col_corr[j]*(d > 0));
418 >                printf(" %.3e", d*corr*(d > 0));
419              }
420              fputc('\n', stdout);
421          }
# Line 425 | Line 425 | filter_klems_matrix(FILE *fp)
425                          return 0;
426                  }
427          return 1;                       /* all is good */
428 #undef MAX_COLUMNS
428   }
429  
430   /* Write out BSDF data block with surrounding tags */
# Line 586 | Line 585 | writeBSDF(const char *caller, ezxml_t fl)
585                  return 0;
586          }
587          puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
588 +        for (i = 0; i < ncomm; i++)
589 +                printf("<!-- %s -->\n", commlist[i]);
590          fflush(stdout);                         /* write previous XML info. */
591          if (write(fileno(stdout), xml, ei) != ei) {
592                  free(xml);
# Line 599 | Line 600 | writeBSDF(const char *caller, ezxml_t fl)
600          fputs(xml+ei, stdout);                  /* write trailer */
601          free(xml);                              /* free string */
602          fputc('\n', stdout);
603 <        return (fflush(stdout) == 0);
603 >        if (fflush(stdout) != 0)
604 >                return 0;
605 >                                                /* unlink data files if req. */
606 >        for (i = ndataf*(unlink_datafiles != 0); i--; )
607 >                if (data_file[i].fname != stdin_name &&
608 >                                data_file[i].fname[0] != '!')
609 >                        unlink(data_file[i].fname);
610 >        if (unlink_datafiles > 1 && mgf_geometry != NULL &&
611 >                        mgf_geometry != stdin_name &&
612 >                        mgf_geometry[0] != '!')
613 >                unlink(mgf_geometry);
614 >        return 1;
615   }
616  
617   /* Insert BSDF data into XML wrapper */
# Line 718 | Line 730 | UsageExit(const char *pname)
730          fputs("Usage: ", stderr);
731          fputs(pname, stderr);
732          fputs(" [-W][-c][-a {kf|kh|kq|t3|t4}][-u unit][-g geom][-f 'x=string;y=string']", stderr);
733 <        fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp]", stderr);
733 >        fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp][-C comm]", stderr);
734          fputs(" [input.xml]\n", stderr);
735          exit(1);
736   }
# Line 763 | Line 775 | main(int argc, char *argv[])
775                          }
776                          attr_unit = argv[i];
777                          continue;
778 +                case 'U':               /* unlink data files when done */
779 +                        unlink_datafiles = 1 + (argv[i][2] == 'U');
780 +                        continue;
781                  case 'a':               /* angle basis */
782                          if (++i >= argc)
783                                  UsageExit(argv[0]);
# Line 786 | Line 801 | main(int argc, char *argv[])
801                          continue;
802                  case 'c':               /* correct solid angle */
803                          correct_solid_angle = 1;
804 +                        continue;
805 +                case 'C':               /* comment */
806 +                        if (ncomm >= MAXCOMM) {
807 +                                fprintf(stderr, "%s: too many comments\n",
808 +                                                argv[0]);
809 +                                return 1;
810 +                        }
811 +                        if (strchr(argv[++i], '>') != NULL) {
812 +                                fprintf(stderr, "%s: illegal character in comment\n",
813 +                                                argv[0]);
814 +                                return 1;
815 +                        }
816 +                        commlist[ncomm++] = argv[i];
817                          continue;
818                  case 't':               /* transmission */
819                          if (i >= argc-1)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines