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" |
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 }; |
69 |
|
/* data file(s) & spectra */ |
70 |
|
enum { DTtransForward, DTtransBackward, DTreflForward, DTreflBackward }; |
71 |
|
|
72 |
< |
enum { DSsolar=-1, DSnir=-2, DSxbar31=-3, DSvisible=-4, DSzbar31=-5 }; |
72 |
> |
enum { DSsolar=-1, DSnir=-2, DSxbar31=-3, DSvisible=-4, DSzbar31=-5, |
73 |
> |
DSuprime=-6, DSvprime=-7 }; |
74 |
|
|
75 |
|
#define MAXFILES 20 |
76 |
|
|
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"; |
165 |
|
fprintf(stderr, "%s: cannot open\n", inpspec); |
166 |
|
return ""; |
167 |
|
} |
168 |
+ |
#ifndef _WIN32 /* XXX somehow broken on Windows */ |
169 |
|
len = lseek(fd, 0L, SEEK_END); |
170 |
|
if (len > 0) { |
171 |
|
lseek(fd, 0L, SEEK_SET); |
184 |
|
close(fd); |
185 |
|
return str; |
186 |
|
} |
187 |
+ |
#endif |
188 |
|
fp = fdopen(fd, "r"); /* not a regular file */ |
189 |
|
} |
190 |
|
/* reading from stream */ |
302 |
|
if (xml_input == win6_template) |
303 |
|
for (i = 0; XMLfieldID[i].nickName[0]; i++) |
304 |
|
if (XMLfieldID[i].win_need && |
305 |
< |
!ezxml_txt(ezxml_child(wtl,XMLfieldID[i].fullName))[0]) { |
305 |
> |
!ezxml_txt(ezxml_child(wtl,XMLfieldID[i].fullName))[0]) |
306 |
|
fprintf(stderr, |
307 |
< |
"%s: missing required '%s' assignment for WINDOW <%s>\n", |
307 |
> |
"%s: warning - missing '%s' assignment for WINDOW <%s>\n", |
308 |
|
caller, XMLfieldID[i].nickName, |
309 |
|
XMLfieldID[i].fullName); |
310 |
< |
return 0; |
303 |
< |
} |
304 |
< |
return 1; /* no errors */ |
310 |
> |
return 1; |
311 |
|
} |
312 |
|
|
313 |
|
/* Complete angle basis specification */ |
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\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\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: |
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; |
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); |
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 */ |
731 |
|
{ |
732 |
|
fputs("Usage: ", stderr); |
733 |
|
fputs(pname, stderr); |
734 |
< |
fputs(" [-W][-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); |
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][-C comm]", stderr); |
736 |
|
fputs(" [input.xml]\n", stderr); |
737 |
|
exit(1); |
738 |
|
} |
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]); |
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) |
822 |
|
UsageExit(argv[0]); |
873 |
|
cur_spectrum = DSxbar31; |
874 |
|
else if (!strcasecmp(argv[i], "CIE-Z")) |
875 |
|
cur_spectrum = DSzbar31; |
876 |
+ |
else if (!strcasecmp(argv[i], "CIE-u")) |
877 |
+ |
cur_spectrum = DSuprime; |
878 |
+ |
else if (!strcasecmp(argv[i], "CIE-v")) |
879 |
+ |
cur_spectrum = DSvprime; |
880 |
|
else if (!strcasecmp(argv[i], "NIR")) |
881 |
|
cur_spectrum = DSnir; |
882 |
|
else { |