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 }; |
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"}, |
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 ';' |
71 |
|
/* data file(s) & spectra */ |
72 |
|
enum { DTtransForward, DTtransBackward, DTreflForward, DTreflBackward }; |
73 |
|
|
74 |
< |
enum { DSsolar=-1, DSnir=-2, DSxbar31=-3, DSvisible=-4, DSzbar31=-5 }; |
74 |
> |
enum { DSsolar=-1, DSnir=-2, DSxbar31=-3, DSvisible=-4, DSzbar31=-5, |
75 |
> |
DSuprime=-6, DSvprime=-7 }; |
76 |
|
|
77 |
|
#define MAXFILES 20 |
78 |
|
|
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"; |
167 |
|
fprintf(stderr, "%s: cannot open\n", inpspec); |
168 |
|
return ""; |
169 |
|
} |
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); |
187 |
|
close(fd); |
188 |
|
return str; |
189 |
|
} |
190 |
+ |
#endif |
191 |
|
fp = fdopen(fd, "r"); /* not a regular file */ |
192 |
|
} |
193 |
|
/* reading from stream */ |
305 |
|
if (xml_input == win6_template) |
306 |
|
for (i = 0; XMLfieldID[i].nickName[0]; i++) |
307 |
|
if (XMLfieldID[i].win_need && |
308 |
< |
!ezxml_txt(ezxml_child(wtl,XMLfieldID[i].fullName))[0]) { |
308 |
> |
!ezxml_txt(ezxml_child(wtl,XMLfieldID[i].fullName))[0]) |
309 |
|
fprintf(stderr, |
310 |
< |
"%s: missing required '%s' assignment for WINDOW <%s>\n", |
310 |
> |
"%s: warning - missing '%s' assignment for WINDOW <%s>\n", |
311 |
|
caller, XMLfieldID[i].nickName, |
312 |
|
XMLfieldID[i].fullName); |
313 |
< |
return 0; |
303 |
< |
} |
304 |
< |
return 1; /* no errors */ |
313 |
> |
return 1; |
314 |
|
} |
315 |
|
|
316 |
|
/* Complete angle basis specification */ |
396 |
|
static int |
397 |
|
filter_klems_matrix(FILE *fp) |
398 |
|
{ |
390 |
– |
#define MAX_COLUMNS 145 |
399 |
|
const char *bn = klems_basis_name[angle_basis]; |
392 |
– |
float col_corr[MAX_COLUMNS]; |
400 |
|
int i, j, n = nabases; |
401 |
|
/* get angle basis */ |
402 |
|
while (n-- > 0) |
404 |
|
break; |
405 |
|
if (n < 0) |
406 |
|
return 0; |
400 |
– |
if (abase_list[n].nangles > MAX_COLUMNS) { |
401 |
– |
fputs("Internal error - too many Klems columns!\n", stderr); |
402 |
– |
return 0; |
403 |
– |
} |
404 |
– |
/* get correction factors */ |
405 |
– |
for (j = abase_list[n].nangles; j--; ) |
406 |
– |
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) |
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 |
|
} |
425 |
|
return 0; |
426 |
|
} |
427 |
|
return 1; /* all is good */ |
427 |
– |
#undef MAX_COLUMNS |
428 |
|
} |
429 |
|
|
430 |
|
/* Write out BSDF data block with surrounding tags */ |
444 |
|
break; |
445 |
|
case DSxbar31: |
446 |
|
puts("\t\t<Wavelength unit=\"Integral\">CIE-X</Wavelength>"); |
447 |
< |
puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
447 |
> |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
448 |
|
puts("\t\t<DetectorSpectrum>ASTM E308 1931 X.dsp</DetectorSpectrum>"); |
449 |
|
break; |
450 |
|
case DSzbar31: |
451 |
|
puts("\t\t<Wavelength unit=\"Integral\">CIE-Z</Wavelength>"); |
452 |
< |
puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
452 |
> |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
453 |
|
puts("\t\t<DetectorSpectrum>ASTM E308 1931 Z.dsp</DetectorSpectrum>"); |
454 |
|
break; |
455 |
+ |
case DSuprime: |
456 |
+ |
puts("\t\t<Wavelength unit=\"Integral\">CIE-u</Wavelength>"); |
457 |
+ |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
458 |
+ |
break; |
459 |
+ |
case DSvprime: |
460 |
+ |
puts("\t\t<Wavelength unit=\"Integral\">CIE-v</Wavelength>"); |
461 |
+ |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
462 |
+ |
break; |
463 |
|
case DSsolar: |
464 |
|
puts("\t\t<Wavelength unit=\"Integral\">Solar</Wavelength>"); |
465 |
< |
puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
465 |
> |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
466 |
|
puts("\t\t<DetectorSpectrum>None</DetectorSpectrum>"); |
467 |
|
break; |
468 |
|
case DSnir: |
469 |
|
puts("\t\t<Wavelength unit=\"Integral\">NIR</Wavelength>"); |
470 |
< |
puts("\t\tSourceSpectrum>PLACE_HOLDER</SourceSpectrum>"); |
470 |
> |
puts("\t\t<SourceSpectrum>PLACE_HOLDER</SourceSpectrum>"); |
471 |
|
puts("\t\t<DetectorSpectrum>PLACE_HOLDER</DetectorSpectrum>"); |
472 |
|
break; |
473 |
|
default: |
478 |
|
spectr_file[df->spectrum]); |
479 |
|
if (cp != NULL) |
480 |
|
*cp = '.'; |
481 |
< |
puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
481 |
> |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
482 |
|
printf("\t\t<DetectorSpectrum>%s</DetectorSpectrum>\n", |
483 |
|
spectr_file[df->spectrum]); |
484 |
|
break; |
584 |
|
free(xml); |
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); |
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 */ |
729 |
|
{ |
730 |
|
fputs("Usage: ", stderr); |
731 |
|
fputs(pname, stderr); |
732 |
< |
fputs(" [-W][-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); |
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][-C comm]", stderr); |
734 |
|
fputs(" [input.xml]\n", stderr); |
735 |
|
exit(1); |
736 |
|
} |
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]); |
800 |
|
UsageExit(argv[0]); |
801 |
|
continue; |
802 |
|
case 'c': /* correct solid angle */ |
803 |
< |
correct_solid_angle ^= 1; |
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) |
820 |
|
UsageExit(argv[0]); |
856 |
|
argv[i] = (char *)stdin_name; |
857 |
|
} |
858 |
|
data_file[ndataf].fname = argv[i]; |
859 |
< |
data_file[ndataf++].spectrum = cur_spectrum; |
859 |
> |
data_file[ndataf].spectrum = cur_spectrum; |
860 |
> |
ndataf++; |
861 |
|
continue; |
862 |
|
case 's': /* spectrum name or input file */ |
863 |
|
if (++i >= argc) |
871 |
|
cur_spectrum = DSxbar31; |
872 |
|
else if (!strcasecmp(argv[i], "CIE-Z")) |
873 |
|
cur_spectrum = DSzbar31; |
874 |
+ |
else if (!strcasecmp(argv[i], "CIE-u")) |
875 |
+ |
cur_spectrum = DSuprime; |
876 |
+ |
else if (!strcasecmp(argv[i], "CIE-v")) |
877 |
+ |
cur_spectrum = DSvprime; |
878 |
|
else if (!strcasecmp(argv[i], "NIR")) |
879 |
|
cur_spectrum = DSnir; |
880 |
|
else { |
923 |
|
} else { |
924 |
|
xml_input = argv[i]; |
925 |
|
} |
883 |
– |
if ((xml_input == win6_template) & (angle_basis == ABdefault)) |
884 |
– |
angle_basis = ABklemsFull; |
926 |
|
/* wrap it! */ |
927 |
|
return !wrapBSDF(argv[0]); |
928 |
|
} |