7 |
|
* G. Ward February 2015 |
8 |
|
*/ |
9 |
|
|
10 |
+ |
#include "platform.h" |
11 |
|
#include <ctype.h> |
12 |
|
#include "rtio.h" |
13 |
|
#include "paths.h" |
27 |
|
/* system materials & geometry */ |
28 |
|
const char *mgf_geometry = NULL; |
29 |
|
/* comment list */ |
30 |
< |
#define MAXCOMM 30 |
30 |
> |
#define MAXCOMM 80 |
31 |
|
const char *commlist[MAXCOMM]; |
32 |
|
int ncomm = 0; |
33 |
|
/* angle bases */ |
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 }; |
72 |
> |
enum { DTransFront, DTransBack, DTreflFront, DTreflBack }; |
73 |
|
|
74 |
+ |
static const char component_name[4][20] = { |
75 |
+ |
"Transmission Front", |
76 |
+ |
"Transmission Back", |
77 |
+ |
"Reflection Front", |
78 |
+ |
"Reflection Back" |
79 |
+ |
}; |
80 |
+ |
|
81 |
|
enum { DSsolar=-1, DSnir=-2, DSxbar31=-3, DSvisible=-4, DSzbar31=-5, |
82 |
|
DSuprime=-6, DSvprime=-7 }; |
83 |
|
|
129 |
|
"\t</DataDefinition>\n", |
130 |
|
}; |
131 |
|
|
132 |
+ |
/* Check that the last-added data file is unique */ |
133 |
+ |
static int |
134 |
+ |
check_new_data_file() |
135 |
+ |
{ |
136 |
+ |
int i = ndataf; |
137 |
+ |
|
138 |
+ |
while (i-- > 0) |
139 |
+ |
if ((data_file[i].spectrum == data_file[ndataf].spectrum) & |
140 |
+ |
(data_file[i].type == data_file[ndataf].type)) { |
141 |
+ |
fprintf(stderr, |
142 |
+ |
"%s: warning - ignoring duplicate component %s\n", |
143 |
+ |
data_file[ndataf].fname, |
144 |
+ |
component_name[data_file[i].type]); |
145 |
+ |
return 0; |
146 |
+ |
} |
147 |
+ |
return 1; |
148 |
+ |
} |
149 |
+ |
|
150 |
|
/* Copy data from file descriptor to stdout and close */ |
151 |
|
static int |
152 |
|
copy_and_close(int fd) |
192 |
|
fprintf(stderr, "%s: cannot open\n", inpspec); |
193 |
|
return ""; |
194 |
|
} |
195 |
< |
#ifndef _WIN32 /* XXX somehow broken on Windows */ |
195 |
> |
#if !defined(_WIN32) && !defined(_WIN64) |
196 |
> |
/* XXX somehow broken on Windows */ |
197 |
|
len = lseek(fd, 0L, SEEK_END); |
198 |
|
if (len > 0) { |
199 |
|
lseek(fd, 0L, SEEK_SET); |
421 |
|
static int |
422 |
|
filter_klems_matrix(FILE *fp) |
423 |
|
{ |
396 |
– |
#define MAX_COLUMNS 145 |
424 |
|
const char *bn = klems_basis_name[angle_basis]; |
398 |
– |
float col_corr[MAX_COLUMNS]; |
425 |
|
int i, j, n = nabases; |
426 |
|
/* get angle basis */ |
427 |
|
while (n-- > 0) |
429 |
|
break; |
430 |
|
if (n < 0) |
431 |
|
return 0; |
406 |
– |
if (abase_list[n].nangles > MAX_COLUMNS) { |
407 |
– |
fputs("Internal error - too many Klems columns!\n", stderr); |
408 |
– |
return 0; |
409 |
– |
} |
410 |
– |
/* get correction factors */ |
411 |
– |
for (j = abase_list[n].nangles; j--; ) |
412 |
– |
col_corr[j] = 1.f / io_getohm(j, &abase_list[n]); |
432 |
|
/* read/correct/write matrix */ |
433 |
|
for (i = 0; i < abase_list[n].nangles; i++) { |
434 |
+ |
const double corr = 1./io_getohm(i, &abase_list[n]); |
435 |
|
for (j = 0; j < abase_list[n].nangles; j++) { |
436 |
|
double d; |
437 |
|
if (fscanf(fp, "%lf", &d) != 1) |
440 |
|
fputs("Negative BSDF data!\n", stderr); |
441 |
|
return 0; |
442 |
|
} |
443 |
< |
printf(" %.3e", d*col_corr[j]*(d > 0)); |
443 |
> |
printf(" %.3e", d*corr*(d > 0)); |
444 |
|
} |
445 |
|
fputc('\n', stdout); |
446 |
|
} |
450 |
|
return 0; |
451 |
|
} |
452 |
|
return 1; /* all is good */ |
433 |
– |
#undef MAX_COLUMNS |
453 |
|
} |
454 |
|
|
455 |
|
/* Write out BSDF data block with surrounding tags */ |
510 |
|
} |
511 |
|
puts("\t\t<WavelengthDataBlock>"); |
512 |
|
fputs("\t\t\t<WavelengthDataDirection>", stdout); |
513 |
< |
switch (df->type) { |
495 |
< |
case DTtransForward: |
496 |
< |
fputs("Transmission Front", stdout); |
497 |
< |
break; |
498 |
< |
case DTtransBackward: |
499 |
< |
fputs("Transmission Back", stdout); |
500 |
< |
break; |
501 |
< |
case DTreflForward: |
502 |
< |
fputs("Reflection Front", stdout); |
503 |
< |
break; |
504 |
< |
case DTreflBackward: |
505 |
< |
fputs("Reflection Back", stdout); |
506 |
< |
break; |
507 |
< |
default: |
508 |
< |
fprintf(stderr, "%s: internal - bad BSDF type (%d)\n", caller, df->type); |
509 |
< |
return 0; |
510 |
< |
} |
513 |
> |
fputs(component_name[df->type], stdout); |
514 |
|
puts("</WavelengthDataDirection>"); |
515 |
|
switch (angle_basis) { |
516 |
|
case ABklemsFull: |
817 |
|
argv[0]); |
818 |
|
return 1; |
819 |
|
} |
820 |
< |
if (strchr(argv[++i], '>') != NULL) { |
820 |
> |
if (strstr(argv[++i], "-->") != NULL) { |
821 |
|
fprintf(stderr, "%s: illegal character in comment\n", |
822 |
|
argv[0]); |
823 |
|
return 1; |
833 |
|
return 1; |
834 |
|
} |
835 |
|
if (!strcmp(argv[i], "-tf")) |
836 |
< |
data_file[ndataf].type = DTtransForward; |
836 |
> |
data_file[ndataf].type = DTransFront; |
837 |
|
else if (!strcmp(argv[i], "-tb")) |
838 |
< |
data_file[ndataf].type = DTtransBackward; |
838 |
> |
data_file[ndataf].type = DTransBack; |
839 |
|
else |
840 |
|
UsageExit(argv[0]); |
841 |
|
if (!strcmp(argv[++i], "-")) { |
844 |
|
} |
845 |
|
data_file[ndataf].fname = argv[i]; |
846 |
|
data_file[ndataf].spectrum = cur_spectrum; |
847 |
< |
ndataf++; |
847 |
> |
ndataf += check_new_data_file(); |
848 |
|
continue; |
849 |
|
case 'r': /* reflection */ |
850 |
|
if (i >= argc-1) |
855 |
|
return 1; |
856 |
|
} |
857 |
|
if (!strcmp(argv[i], "-rf")) |
858 |
< |
data_file[ndataf].type = DTreflForward; |
858 |
> |
data_file[ndataf].type = DTreflFront; |
859 |
|
else if (!strcmp(argv[i], "-rb")) |
860 |
< |
data_file[ndataf].type = DTreflBackward; |
860 |
> |
data_file[ndataf].type = DTreflBack; |
861 |
|
else |
862 |
|
UsageExit(argv[0]); |
863 |
|
if (!strcmp(argv[++i], "-")) { |
866 |
|
} |
867 |
|
data_file[ndataf].fname = argv[i]; |
868 |
|
data_file[ndataf].spectrum = cur_spectrum; |
869 |
< |
ndataf++; |
869 |
> |
ndataf += check_new_data_file(); |
870 |
|
continue; |
871 |
|
case 's': /* spectrum name or input file */ |
872 |
|
if (++i >= argc) |
919 |
|
} |
920 |
|
break; |
921 |
|
} |
922 |
< |
doneOptions: /* get XML input */ |
922 |
> |
/* get XML input */ |
923 |
|
if (i >= argc) { |
924 |
|
if (xml_input == NULL) |
925 |
|
xml_input = def_template; |