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" |
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 }; |
83 |
|
|
84 |
|
int ndataf = 0; /* number of data files */ |
85 |
|
|
86 |
+ |
int unlink_datafiles = 0; /* unlink data files when done */ |
87 |
+ |
|
88 |
|
const char *spectr_file[MAXFILES]; /* custom spectral curve input */ |
89 |
|
|
90 |
|
const char top_level_name[] = "WindowElement"; |
166 |
|
fprintf(stderr, "%s: cannot open\n", inpspec); |
167 |
|
return ""; |
168 |
|
} |
169 |
+ |
#if !defined(_WIN32) && !defined(_WIN64) |
170 |
+ |
/* XXX somehow broken on Windows */ |
171 |
|
len = lseek(fd, 0L, SEEK_END); |
172 |
|
if (len > 0) { |
173 |
|
lseek(fd, 0L, SEEK_SET); |
186 |
|
close(fd); |
187 |
|
return str; |
188 |
|
} |
189 |
+ |
#endif |
190 |
|
fp = fdopen(fd, "r"); /* not a regular file */ |
191 |
|
} |
192 |
|
/* reading from stream */ |
452 |
|
break; |
453 |
|
case DSxbar31: |
454 |
|
puts("\t\t<Wavelength unit=\"Integral\">CIE-X</Wavelength>"); |
455 |
< |
puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
455 |
> |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
456 |
|
puts("\t\t<DetectorSpectrum>ASTM E308 1931 X.dsp</DetectorSpectrum>"); |
457 |
|
break; |
458 |
|
case DSzbar31: |
459 |
|
puts("\t\t<Wavelength unit=\"Integral\">CIE-Z</Wavelength>"); |
460 |
< |
puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
460 |
> |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
461 |
|
puts("\t\t<DetectorSpectrum>ASTM E308 1931 Z.dsp</DetectorSpectrum>"); |
462 |
|
break; |
463 |
|
case DSuprime: |
464 |
< |
puts("\t\t<Wavelength unit=\"Integral\">CIE-Z</Wavelength>"); |
465 |
< |
puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
457 |
< |
puts("\t\t<DetectorSpectrum>ASTM E308 1931 u.dsp</DetectorSpectrum>"); |
464 |
> |
puts("\t\t<Wavelength unit=\"Integral\">CIE-u</Wavelength>"); |
465 |
> |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
466 |
|
break; |
467 |
|
case DSvprime: |
468 |
< |
puts("\t\t<Wavelength unit=\"Integral\">CIE-Z</Wavelength>"); |
469 |
< |
puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
462 |
< |
puts("\t\t<DetectorSpectrum>ASTM E308 1931 v.dsp</DetectorSpectrum>"); |
468 |
> |
puts("\t\t<Wavelength unit=\"Integral\">CIE-v</Wavelength>"); |
469 |
> |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
470 |
|
break; |
471 |
|
case DSsolar: |
472 |
|
puts("\t\t<Wavelength unit=\"Integral\">Solar</Wavelength>"); |
473 |
< |
puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
473 |
> |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
474 |
|
puts("\t\t<DetectorSpectrum>None</DetectorSpectrum>"); |
475 |
|
break; |
476 |
|
case DSnir: |
477 |
|
puts("\t\t<Wavelength unit=\"Integral\">NIR</Wavelength>"); |
478 |
< |
puts("\t\tSourceSpectrum>PLACE_HOLDER</SourceSpectrum>"); |
478 |
> |
puts("\t\t<SourceSpectrum>PLACE_HOLDER</SourceSpectrum>"); |
479 |
|
puts("\t\t<DetectorSpectrum>PLACE_HOLDER</DetectorSpectrum>"); |
480 |
|
break; |
481 |
|
default: |
486 |
|
spectr_file[df->spectrum]); |
487 |
|
if (cp != NULL) |
488 |
|
*cp = '.'; |
489 |
< |
puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
489 |
> |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
490 |
|
printf("\t\t<DetectorSpectrum>%s</DetectorSpectrum>\n", |
491 |
|
spectr_file[df->spectrum]); |
492 |
|
break; |
592 |
|
free(xml); |
593 |
|
return 0; |
594 |
|
} |
595 |
+ |
puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
596 |
+ |
for (i = 0; i < ncomm; i++) |
597 |
+ |
printf("<!-- %s -->\n", commlist[i]); |
598 |
|
fflush(stdout); /* write previous XML info. */ |
599 |
|
if (write(fileno(stdout), xml, ei) != ei) { |
600 |
|
free(xml); |
608 |
|
fputs(xml+ei, stdout); /* write trailer */ |
609 |
|
free(xml); /* free string */ |
610 |
|
fputc('\n', stdout); |
611 |
< |
return (fflush(stdout) == 0); |
611 |
> |
if (fflush(stdout) != 0) |
612 |
> |
return 0; |
613 |
> |
/* unlink data files if req. */ |
614 |
> |
for (i = ndataf*(unlink_datafiles != 0); i--; ) |
615 |
> |
if (data_file[i].fname != stdin_name && |
616 |
> |
data_file[i].fname[0] != '!') |
617 |
> |
unlink(data_file[i].fname); |
618 |
> |
if (unlink_datafiles > 1 && mgf_geometry != NULL && |
619 |
> |
mgf_geometry != stdin_name && |
620 |
> |
mgf_geometry[0] != '!') |
621 |
> |
unlink(mgf_geometry); |
622 |
> |
return 1; |
623 |
|
} |
624 |
|
|
625 |
|
/* Insert BSDF data into XML wrapper */ |
738 |
|
fputs("Usage: ", stderr); |
739 |
|
fputs(pname, stderr); |
740 |
|
fputs(" [-W][-c][-a {kf|kh|kq|t3|t4}][-u unit][-g geom][-f 'x=string;y=string']", stderr); |
741 |
< |
fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp]", stderr); |
741 |
> |
fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp][-C comm]", stderr); |
742 |
|
fputs(" [input.xml]\n", stderr); |
743 |
|
exit(1); |
744 |
|
} |
783 |
|
} |
784 |
|
attr_unit = argv[i]; |
785 |
|
continue; |
786 |
+ |
case 'U': /* unlink data files when done */ |
787 |
+ |
unlink_datafiles = 1 + (argv[i][2] == 'U'); |
788 |
+ |
continue; |
789 |
|
case 'a': /* angle basis */ |
790 |
|
if (++i >= argc) |
791 |
|
UsageExit(argv[0]); |
809 |
|
continue; |
810 |
|
case 'c': /* correct solid angle */ |
811 |
|
correct_solid_angle = 1; |
812 |
+ |
continue; |
813 |
+ |
case 'C': /* comment */ |
814 |
+ |
if (ncomm >= MAXCOMM) { |
815 |
+ |
fprintf(stderr, "%s: too many comments\n", |
816 |
+ |
argv[0]); |
817 |
+ |
return 1; |
818 |
+ |
} |
819 |
+ |
if (strchr(argv[++i], '>') != NULL) { |
820 |
+ |
fprintf(stderr, "%s: illegal character in comment\n", |
821 |
+ |
argv[0]); |
822 |
+ |
return 1; |
823 |
+ |
} |
824 |
+ |
commlist[ncomm++] = argv[i]; |
825 |
|
continue; |
826 |
|
case 't': /* transmission */ |
827 |
|
if (i >= argc-1) |