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.13 by greg, Wed Mar 25 22:50:48 2015 UTC vs.
Revision 2.18 by greg, Tue Feb 2 22:34:00 2016 UTC

# Line 9 | Line 9 | static const char RCSid[] = "$Id$";
9  
10   #include <ctype.h>
11   #include "rtio.h"
12 < #include "rtprocess.h"
12 > #include "paths.h"
13   #include "ezxml.h"
14   #include "bsdf.h"
15   #include "bsdf_m.h"
# Line 25 | Line 25 | const char     *attr_unit = "meter";
25   const char      legal_units[] = "meter|foot|inch|centimeter|millimeter";
26                                          /* system materials & geometry */
27   const char      *mgf_geometry = NULL;
28 <
28 >                                        /* comment list */
29 > #define MAXCOMM         30
30 > const char      *commlist[MAXCOMM];
31 > int             ncomm = 0;
32                                          /* angle bases */
33   enum { ABdefault=-1, ABklemsFull=0, ABklemsHalf, ABklemsQuarter,
34                  ABtensorTree3, ABtensorTree4, ABend };
# Line 79 | Line 82 | struct s_dfile {
82  
83   int             ndataf = 0;             /* number of data files */
84  
85 + int             unlink_datafiles = 0;   /* unlink data files when done */
86 +
87   const char      *spectr_file[MAXFILES]; /* custom spectral curve input */
88  
89   const char      top_level_name[] = "WindowElement";
# Line 445 | Line 450 | writeBSDFblock(const char *caller, struct s_dfile *df)
450                  break;
451          case DSxbar31:
452                  puts("\t\t<Wavelength unit=\"Integral\">CIE-X</Wavelength>");
453 <                puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
453 >                puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
454                  puts("\t\t<DetectorSpectrum>ASTM E308 1931 X.dsp</DetectorSpectrum>");
455                  break;
456          case DSzbar31:
457                  puts("\t\t<Wavelength unit=\"Integral\">CIE-Z</Wavelength>");
458 <                puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
458 >                puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
459                  puts("\t\t<DetectorSpectrum>ASTM E308 1931 Z.dsp</DetectorSpectrum>");
460                  break;
461          case DSuprime:
462                  puts("\t\t<Wavelength unit=\"Integral\">CIE-u</Wavelength>");
463 <                puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
459 <                puts("\t\t<DetectorSpectrum>ASTM E308 1931 u.dsp</DetectorSpectrum>");
463 >                puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
464                  break;
465          case DSvprime:
466                  puts("\t\t<Wavelength unit=\"Integral\">CIE-v</Wavelength>");
467 <                puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
464 <                puts("\t\t<DetectorSpectrum>ASTM E308 1931 v.dsp</DetectorSpectrum>");
467 >                puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
468                  break;
469          case DSsolar:
470                  puts("\t\t<Wavelength unit=\"Integral\">Solar</Wavelength>");
471 <                puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
471 >                puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
472                  puts("\t\t<DetectorSpectrum>None</DetectorSpectrum>");
473                  break;
474          case DSnir:
475                  puts("\t\t<Wavelength unit=\"Integral\">NIR</Wavelength>");
476 <                puts("\t\tSourceSpectrum>PLACE_HOLDER</SourceSpectrum>");
476 >                puts("\t\t<SourceSpectrum>PLACE_HOLDER</SourceSpectrum>");
477                  puts("\t\t<DetectorSpectrum>PLACE_HOLDER</DetectorSpectrum>");
478                  break;
479          default:
# Line 481 | Line 484 | writeBSDFblock(const char *caller, struct s_dfile *df)
484                                  spectr_file[df->spectrum]);
485                  if (cp != NULL)
486                          *cp = '.';
487 <                puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
487 >                puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
488                  printf("\t\t<DetectorSpectrum>%s</DetectorSpectrum>\n",
489                                  spectr_file[df->spectrum]);
490                  break;
# Line 587 | Line 590 | writeBSDF(const char *caller, ezxml_t fl)
590                  free(xml);
591                  return 0;
592          }
593 +        puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
594 +        for (i = 0; i < ncomm; i++)
595 +                printf("<!-- %s -->\n", commlist[i]);
596          fflush(stdout);                         /* write previous XML info. */
597          if (write(fileno(stdout), xml, ei) != ei) {
598                  free(xml);
# Line 600 | Line 606 | writeBSDF(const char *caller, ezxml_t fl)
606          fputs(xml+ei, stdout);                  /* write trailer */
607          free(xml);                              /* free string */
608          fputc('\n', stdout);
609 <        return (fflush(stdout) == 0);
609 >        if (fflush(stdout) != 0)
610 >                return 0;
611 >                                                /* unlink data files if req. */
612 >        for (i = ndataf*(unlink_datafiles != 0); i--; )
613 >                if (data_file[i].fname != stdin_name &&
614 >                                data_file[i].fname[0] != '!')
615 >                        unlink(data_file[i].fname);
616 >        return 1;
617   }
618  
619   /* Insert BSDF data into XML wrapper */
# Line 719 | Line 732 | UsageExit(const char *pname)
732          fputs("Usage: ", stderr);
733          fputs(pname, stderr);
734          fputs(" [-W][-c][-a {kf|kh|kq|t3|t4}][-u unit][-g geom][-f 'x=string;y=string']", stderr);
735 <        fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp]", stderr);
735 >        fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp][-C comm]", stderr);
736          fputs(" [input.xml]\n", stderr);
737          exit(1);
738   }
# Line 764 | Line 777 | main(int argc, char *argv[])
777                          }
778                          attr_unit = argv[i];
779                          continue;
780 +                case 'U':               /* unlink data files when done */
781 +                        unlink_datafiles = 1;
782 +                        continue;
783                  case 'a':               /* angle basis */
784                          if (++i >= argc)
785                                  UsageExit(argv[0]);
# Line 787 | Line 803 | main(int argc, char *argv[])
803                          continue;
804                  case 'c':               /* correct solid angle */
805                          correct_solid_angle = 1;
806 +                        continue;
807 +                case 'C':               /* comment */
808 +                        if (ncomm >= MAXCOMM) {
809 +                                fprintf(stderr, "%s: too many comments\n",
810 +                                                argv[0]);
811 +                                return 1;
812 +                        }
813 +                        if (strchr(argv[++i], '>') != NULL) {
814 +                                fprintf(stderr, "%s: illegal character in comment\n",
815 +                                                argv[0]);
816 +                                return 1;
817 +                        }
818 +                        commlist[ncomm++] = argv[i];
819                          continue;
820                  case 't':               /* transmission */
821                          if (i >= argc-1)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines