2 |
|
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
|
/* |
5 |
< |
* Wrap BSDF data in valid WINDOW XML wrapper |
5 |
> |
* Wrap BSDF data in valid WINDOW XML file |
6 |
|
* |
7 |
< |
* G. Ward January 2015 |
7 |
> |
* G. Ward February 2015 |
8 |
|
*/ |
9 |
|
|
10 |
|
#include <ctype.h> |
15 |
|
#include "bsdf_m.h" |
16 |
|
/* XML template file names */ |
17 |
|
const char def_template[] = "minimalBSDFt.xml"; |
18 |
< |
const char win6_template[] = "window6BSDFt.xml"; |
18 |
> |
const char win6_template[] = "WINDOW6BSDFt.xml"; |
19 |
|
|
20 |
|
const char stdin_name[] = "<stdin>"; |
21 |
|
|
22 |
|
/* input files (can be stdin_name) */ |
23 |
|
const char *xml_input = NULL; |
24 |
|
/* unit for materials & geometry */ |
25 |
< |
const char *attr_unit = "millimeter"; |
25 |
> |
const char *attr_unit = "meter"; |
26 |
|
const char legal_units[] = "meter|foot|inch|centimeter|millimeter"; |
27 |
|
/* system materials & geometry */ |
28 |
|
const char *mgf_geometry = NULL; |
29 |
|
|
30 |
< |
/* angle basis */ |
30 |
> |
/* angle bases */ |
31 |
|
enum { ABdefault=-1, ABklemsFull=0, ABklemsHalf, ABklemsQuarter, |
32 |
|
ABtensorTree3, ABtensorTree4, ABend }; |
33 |
|
|
36 |
|
/* field IDs and nicknames */ |
37 |
|
struct s_fieldID { |
38 |
|
char nickName[4]; |
39 |
< |
int has_unit; |
39 |
> |
short has_unit; |
40 |
> |
short win_need; |
41 |
|
const char *fullName; |
42 |
|
} XMLfieldID[] = { |
43 |
< |
{"m", 0, "Manufacturer"}, |
44 |
< |
{"n", 0, "Name"}, |
45 |
< |
{"c", 0, "ThermalConductivity"}, |
46 |
< |
{"ef", 0, "EmissivityFront"}, |
47 |
< |
{"eb", 0, "EmissivityBack"}, |
48 |
< |
{"tir", 0, "TIR"}, |
49 |
< |
{"eo", 0, "EffectiveOpennessFraction"}, |
50 |
< |
{"t", 1, "Thickness"}, |
51 |
< |
{"h", 1, "Height"}, |
52 |
< |
{"w", 1, "Width"}, |
53 |
< |
{"\0", -1, NULL} /* terminator */ |
43 |
> |
{"m", 0, 1, "Manufacturer"}, |
44 |
> |
{"n", 0, 1, "Name"}, |
45 |
> |
{"c", 0, 0, "ThermalConductivity"}, |
46 |
> |
{"ef", 0, 0, "EmissivityFront"}, |
47 |
> |
{"eb", 0, 0, "EmissivityBack"}, |
48 |
> |
{"tir", 0, 0, "TIR"}, |
49 |
> |
{"eo", 0, 0, "EffectiveOpennessFraction"}, |
50 |
> |
{"t", 1, 1, "Thickness"}, |
51 |
> |
{"h", 1, 0, "Height"}, |
52 |
> |
{"w", 1, 0, "Width"}, |
53 |
> |
{"\0", 0, 0, NULL} /* terminator */ |
54 |
|
}; |
55 |
|
/* field assignments */ |
56 |
|
#define MAXASSIGN 12 |
77 |
|
|
78 |
|
const char top_level_name[] = "WindowElement"; |
79 |
|
|
80 |
< |
static char *basis_definition[] = { |
80 |
> |
static char basis_definition[][256] = { |
81 |
|
|
82 |
+ |
"\t<DataDefinition>\n" |
83 |
|
"\t\t<IncidentDataStructure>Columns</IncidentDataStructure>\n" |
84 |
|
"\t\t<AngleBasis>\n" |
85 |
|
"\t\t\t<AngleBasisName>LBNL/Klems Full</AngleBasisName>\n" |
86 |
< |
"\t\t</AngleBasis>\n", |
86 |
> |
"\t\t\t</AngleBasis>\n" |
87 |
> |
"\t</DataDefinition>\n", |
88 |
|
|
89 |
+ |
"\t<DataDefinition>\n" |
90 |
|
"\t\t<IncidentDataStructure>Columns</IncidentDataStructure>\n" |
91 |
|
"\t\t<AngleBasis>\n" |
92 |
|
"\t\t\t<AngleBasisName>LBNL/Klems Half</AngleBasisName>\n" |
93 |
< |
"\t\t</AngleBasis>\n", |
93 |
> |
"\t\t\t</AngleBasis>\n" |
94 |
> |
"\t</DataDefinition>\n", |
95 |
|
|
96 |
+ |
"\t<DataDefinition>\n" |
97 |
|
"\t\t<IncidentDataStructure>Columns</IncidentDataStructure>\n" |
98 |
|
"\t\t<AngleBasis>\n" |
99 |
|
"\t\t\t<AngleBasisName>LBNL/Klems Quarter</AngleBasisName>\n" |
100 |
< |
"\t\t</AngleBasis>\n", |
100 |
> |
"\t\t\t</AngleBasis>\n" |
101 |
> |
"\t</DataDefinition>\n", |
102 |
|
|
103 |
< |
"\t\t<IncidentDataStructure>TensorTree3</IncidentDataStructure>\n", |
103 |
> |
"\t<DataDefinition>\n" |
104 |
> |
"\t\t<IncidentDataStructure>TensorTree3</IncidentDataStructure>\n" |
105 |
> |
"\t</DataDefinition>\n", |
106 |
|
|
107 |
< |
"\t\t<IncidentDataStructure>TensorTree4</IncidentDataStructure>\n", |
107 |
> |
"\t<DataDefinition>\n" |
108 |
> |
"\t\t<IncidentDataStructure>TensorTree4</IncidentDataStructure>\n" |
109 |
> |
"\t</DataDefinition>\n", |
110 |
|
}; |
111 |
|
|
112 |
|
/* Copy data from file descriptor to stdout and close */ |
141 |
|
return ""; |
142 |
|
if (inpspec == stdin_name) { /* read from stdin */ |
143 |
|
fp = stdin; |
144 |
< |
} else if (*inpspec == '!') { /* read from command */ |
144 |
> |
} else if (inpspec[0] == '!') { /* read from command */ |
145 |
|
fp = popen(inpspec+1, "r"); |
146 |
|
if (fp == NULL) { |
147 |
|
fprintf(stderr, "Cannot start process '%s'\n", |
148 |
< |
inpspec+1); |
148 |
> |
inpspec); |
149 |
|
return ""; |
150 |
|
} |
151 |
|
} else { /* else load file */ |
155 |
|
return ""; |
156 |
|
} |
157 |
|
len = lseek(fd, 0L, SEEK_END); |
158 |
< |
if (len < 0) { |
159 |
< |
fprintf(stderr, "%s: seek error\n", inpspec); |
158 |
> |
if (len > 0) { |
159 |
> |
lseek(fd, 0L, SEEK_SET); |
160 |
> |
str = (char *)malloc(len+1); |
161 |
> |
if (str == NULL) { |
162 |
> |
close(fd); |
163 |
> |
goto memerr; |
164 |
> |
} |
165 |
> |
if (read(fd, str, len) != len) { |
166 |
> |
fprintf(stderr, "%s: read error\n", inpspec); |
167 |
> |
free(str); |
168 |
> |
close(fd); |
169 |
> |
return ""; |
170 |
> |
} |
171 |
> |
str[len] = '\0'; |
172 |
|
close(fd); |
173 |
< |
return ""; |
173 |
> |
return str; |
174 |
|
} |
175 |
< |
lseek(fd, 0L, SEEK_SET); |
153 |
< |
str = (char *)malloc(len+1); |
154 |
< |
if (str == NULL) { |
155 |
< |
close(fd); |
156 |
< |
goto memerr; |
157 |
< |
} |
158 |
< |
if (read(fd, str, len) != len) { |
159 |
< |
fprintf(stderr, "%s: read error\n", inpspec); |
160 |
< |
free(str); |
161 |
< |
close(fd); |
162 |
< |
return ""; |
163 |
< |
} |
164 |
< |
str[len] = '\0'; |
165 |
< |
close(fd); |
166 |
< |
return str; |
175 |
> |
fp = fdopen(fd, "r"); /* not a regular file */ |
176 |
|
} |
177 |
|
/* reading from stream */ |
178 |
|
str = (char *)malloc((len=8192)+1); |
195 |
|
if (str == NULL) |
196 |
|
goto memerr; |
197 |
|
} |
198 |
< |
if (*inpspec != '!') |
198 |
> |
if (inpspec[0] != '!') |
199 |
|
fclose(fp); |
200 |
|
else if (pclose(fp)) |
201 |
< |
fprintf(stderr, "Error running command '%s'\n", inpspec+1); |
201 |
> |
fprintf(stderr, "Error running command '%s'\n", inpspec); |
202 |
|
return str; |
203 |
|
memerr: |
204 |
|
fprintf(stderr, "%s: error allocating memory\n", inpspec); |
205 |
|
if (fp != NULL) |
206 |
< |
(*inpspec == '!') ? pclose(fp) : fclose(fp); |
206 |
> |
(inpspec[0] == '!') ? pclose(fp) : fclose(fp); |
207 |
|
return ""; |
208 |
|
} |
209 |
|
|
213 |
|
{ |
214 |
|
int i; |
215 |
|
|
207 |
– |
if (!nfield_assign) |
208 |
– |
return 1; |
216 |
|
wtl = ezxml_child(wtl, "Material"); |
217 |
|
if (wtl == NULL) { |
218 |
|
fprintf(stderr, "%s: missing <Material> tag\n", fn); |
221 |
|
for (i = 0; i < nfield_assign; i++) { |
222 |
|
const char *fnext = field_assignment[i]; |
223 |
|
for ( ; ; ) { |
224 |
+ |
int added = 0; |
225 |
|
ezxml_t fld; |
226 |
|
char sbuf[512]; |
227 |
|
int j; |
230 |
|
++fnext; |
231 |
|
if (!*fnext) |
232 |
|
break; |
233 |
< |
for (j = 0; (*fnext != '=') & !isspace(*fnext); ) { |
233 |
> |
for (j = 0; *fnext != '=' && !isspace(*fnext); ) { |
234 |
|
if (!*fnext | (*fnext == FASEP) | |
235 |
|
(j >= sizeof(sbuf)-1)) { |
236 |
|
fprintf(stderr, |
240 |
|
} |
241 |
|
sbuf[j++] = *fnext++; |
242 |
|
} |
243 |
< |
sbuf[j] = '\0'; /* check nick-names */ |
243 |
> |
sbuf[j] = '\0'; /* check known field */ |
244 |
|
for (j = 0; XMLfieldID[j].nickName[0]; j++) |
245 |
< |
if (!strcasecmp(sbuf, XMLfieldID[j].nickName)) { |
245 |
> |
if (!strcasecmp(sbuf, XMLfieldID[j].nickName) || |
246 |
> |
!strcasecmp(sbuf, XMLfieldID[j].fullName)) { |
247 |
|
strcpy(sbuf, XMLfieldID[j].fullName); |
248 |
|
break; |
249 |
|
} |
250 |
|
/* check if tag exists */ |
251 |
|
fld = ezxml_child(wtl, sbuf); |
252 |
|
if (fld == NULL) { /* otherwise, create one */ |
253 |
< |
fprintf(stderr, "%s: warning - adding tag <%s>\n", |
254 |
< |
fn, sbuf); |
253 |
> |
if (!XMLfieldID[j].nickName[0]) |
254 |
> |
fprintf(stderr, |
255 |
> |
"%s: warning - adding tag <%s>\n", |
256 |
> |
fn, sbuf); |
257 |
> |
ezxml_add_txt(wtl, "\t"); |
258 |
|
fld = ezxml_add_child_d(wtl, sbuf, strlen(wtl->txt)); |
259 |
+ |
++added; |
260 |
|
} |
261 |
|
if (XMLfieldID[j].has_unit) |
262 |
|
ezxml_set_attr(fld, "unit", attr_unit); |
263 |
+ |
XMLfieldID[j].win_need = 0; |
264 |
|
while (isspace(*fnext)) |
265 |
|
++fnext; |
266 |
|
if (*fnext++ != '=') { |
269 |
|
caller, field_assignment[i]); |
270 |
|
return 0; |
271 |
|
} |
272 |
< |
for (j = 0; *fnext & (*fnext != FASEP); ) { |
272 |
> |
for (j = 0; *fnext && *fnext != FASEP; ) { |
273 |
|
if (j >= sizeof(sbuf)-1) { |
274 |
|
fprintf(stderr, |
275 |
|
"%s: field too long in '%s'\n", |
280 |
|
} |
281 |
|
sbuf[j] = '\0'; |
282 |
|
ezxml_set_txt_d(fld, sbuf); |
283 |
+ |
if (added) |
284 |
+ |
ezxml_add_txt(wtl, "\n\t"); |
285 |
|
fnext += (*fnext == FASEP); |
286 |
|
} |
287 |
|
} |
288 |
+ |
/* check required WINDOW settings */ |
289 |
+ |
if (xml_input == win6_template) |
290 |
+ |
for (i = 0; XMLfieldID[i].nickName[0]; i++) |
291 |
+ |
if (XMLfieldID[i].win_need && |
292 |
+ |
!ezxml_txt(ezxml_child(wtl,XMLfieldID[i].fullName))[0]) { |
293 |
+ |
fprintf(stderr, |
294 |
+ |
"%s: missing required '%s' assignment for WINDOW <%s>\n", |
295 |
+ |
caller, XMLfieldID[i].nickName, |
296 |
+ |
XMLfieldID[i].fullName); |
297 |
+ |
return 0; |
298 |
+ |
} |
299 |
|
return 1; /* no errors */ |
300 |
|
} |
301 |
|
|
324 |
|
sprintf(buf, "%g", i ? |
325 |
|
.5*(abase_list[n].lat[i].tmin + abase_list[n].lat[i+1].tmin) : |
326 |
|
.0); |
327 |
+ |
ezxml_add_txt(abb, "\n\t\t\t\t"); |
328 |
|
ezxml_set_txt_d(ezxml_add_child(abb,"Theta",strlen(abb->txt)), buf); |
329 |
|
sprintf(buf, "%d", abase_list[n].lat[i].nphis); |
330 |
+ |
ezxml_add_txt(abb, "\n\t\t\t\t"); |
331 |
|
ezxml_set_txt_d(ezxml_add_child(abb,"nPhis",strlen(abb->txt)), buf); |
332 |
+ |
ezxml_add_txt(abb, "\n\t\t\t\t"); |
333 |
|
tb = ezxml_add_child(abb, "ThetaBounds", strlen(abb->txt)); |
334 |
+ |
ezxml_add_txt(tb, "\n\t\t\t\t\t"); |
335 |
|
sprintf(buf, "%g", abase_list[n].lat[i].tmin); |
336 |
< |
ezxml_set_txt(ezxml_add_child(tb,"LowerTheta",strlen(tb->txt)), buf); |
336 |
> |
ezxml_set_txt_d(ezxml_add_child(tb,"LowerTheta",strlen(tb->txt)), buf); |
337 |
> |
ezxml_add_txt(tb, "\n\t\t\t\t\t"); |
338 |
|
sprintf(buf, "%g", abase_list[n].lat[i+1].tmin); |
339 |
< |
ezxml_set_txt(ezxml_add_child(tb,"UpperTheta",strlen(tb->txt)), buf); |
339 |
> |
ezxml_set_txt_d(ezxml_add_child(tb,"UpperTheta",strlen(tb->txt)), buf); |
340 |
> |
ezxml_add_txt(tb, "\n\t\t\t\t"); |
341 |
> |
ezxml_add_txt(abb, "\n\t\t\t"); |
342 |
> |
ezxml_add_txt(ab, "\n\t\t\t"); |
343 |
|
} |
344 |
|
return 1; |
345 |
|
} |
355 |
|
if (wtl == NULL) |
356 |
|
return -1; |
357 |
|
ids = ezxml_txt(ezxml_child(wtl, "IncidentDataStructure")); |
358 |
< |
if (ids == NULL) |
358 |
> |
if (!ids[0]) |
359 |
|
return -1; |
360 |
|
for (i = 0; i < ABend; i++) { |
361 |
|
ezxml_t parsed = ezxml_parse_str(basis_definition[i], |
378 |
|
return -1; |
379 |
|
} |
380 |
|
|
381 |
+ |
/* Filter Klems angle basis, applying appropriate solid angle correction */ |
382 |
+ |
static int |
383 |
+ |
filter_klems_matrix(FILE *fp) |
384 |
+ |
{ |
385 |
+ |
#define MAX_COLUMNS 145 |
386 |
+ |
float col_corr[MAX_COLUMNS]; |
387 |
+ |
const char *bn; |
388 |
+ |
int i, j, n = nabases; |
389 |
+ |
/* get angle basis */ |
390 |
+ |
switch (angle_basis) { |
391 |
+ |
case ABklemsFull: bn = "LBNL/Klems Full"; break; |
392 |
+ |
case ABklemsHalf: bn = "LBNL/Klems Half"; break; |
393 |
+ |
case ABklemsQuarter: bn = "LBNL/Klems Quarter"; break; |
394 |
+ |
default: |
395 |
+ |
return 0; |
396 |
+ |
} |
397 |
+ |
while (n-- > 0) |
398 |
+ |
if (!strcasecmp(bn, abase_list[n].name)) |
399 |
+ |
break; |
400 |
+ |
if (n < 0) |
401 |
+ |
return 0; |
402 |
+ |
if (abase_list[n].nangles > MAX_COLUMNS) { |
403 |
+ |
fprintf(stderr, "Internal error - too many Klems columns!\n"); |
404 |
+ |
return 0; |
405 |
+ |
} |
406 |
+ |
/* get correction factors */ |
407 |
+ |
for (j = abase_list[n].nangles; j--; ) |
408 |
+ |
col_corr[j] = 1.f / io_getohm(j, &abase_list[n]); |
409 |
+ |
/* read/correct/write matrix */ |
410 |
+ |
for (i = 0; i < abase_list[n].nangles; i++) { |
411 |
+ |
for (j = 0; j < abase_list[n].nangles; j++) { |
412 |
+ |
double d; |
413 |
+ |
if (fscanf(fp, "%lf", &d) != 1) |
414 |
+ |
return 0; |
415 |
+ |
printf(" %f", d*col_corr[j]); |
416 |
+ |
} |
417 |
+ |
fputc('\n', stdout); |
418 |
+ |
} |
419 |
+ |
return 1; |
420 |
+ |
#undef MAX_COLUMNS |
421 |
+ |
} |
422 |
+ |
|
423 |
|
/* Write out BSDF data block with surrounding tags */ |
424 |
|
static int |
425 |
|
writeBSDFblock(const char *caller, struct s_dfile *df) |
426 |
|
{ |
427 |
+ |
int klems_data = 0; |
428 |
|
char *cp; |
429 |
|
|
430 |
|
puts("\t<WavelengthData>"); |
488 |
|
return 0; |
489 |
|
} |
490 |
|
puts("</WavelengthDataDirection>"); |
491 |
+ |
klems_data = 1; |
492 |
|
switch (angle_basis) { |
493 |
|
case ABklemsFull: |
494 |
|
puts("\t\t\t<ColumnAngleBasis>LBNL/Klems Full</ColumnAngleBasis>"); |
502 |
|
case ABtensorTree3: |
503 |
|
case ABtensorTree4: |
504 |
|
puts("\t\t\t<AngleBasis>LBNL/Shirley-Chiu</AngleBasis>"); |
505 |
+ |
klems_data = 0; |
506 |
|
break; |
507 |
|
default: |
508 |
|
fprintf(stderr, "%s: bad angle basis (%d)\n", caller, angle_basis); |
511 |
|
puts("\t\t\t<ScatteringDataType>BTDF</ScatteringDataType>"); |
512 |
|
puts("\t\t\t<ScatteringData>"); |
513 |
|
fflush(stdout); |
514 |
< |
if (df->fname == stdin_name) { |
514 |
> |
if (klems_data) { |
515 |
> |
FILE *fp = stdin; |
516 |
> |
if (df->fname[0] == '!') |
517 |
> |
fp = popen(df->fname+1, "r"); |
518 |
> |
else if (df->fname != stdin_name) |
519 |
> |
fp = fopen(df->fname, "r"); |
520 |
> |
if (fp == NULL) { |
521 |
> |
fprintf(stderr, "%s: cannot open '%s'\n", |
522 |
> |
caller, df->fname); |
523 |
> |
return 0; |
524 |
> |
} |
525 |
> |
if (!filter_klems_matrix(fp)) { |
526 |
> |
fprintf(stderr, "%s: Klems data error from '%s'\n", |
527 |
> |
caller, df->fname); |
528 |
> |
return 0; |
529 |
> |
} |
530 |
> |
if (df->fname[0] != '!') { |
531 |
> |
fclose(fp); |
532 |
> |
} else if (pclose(fp)) { |
533 |
> |
fprintf(stderr, "%s: error running '%s'\n", |
534 |
> |
caller, df->fname); |
535 |
> |
return 0; |
536 |
> |
} |
537 |
> |
} else if (df->fname == stdin_name) { |
538 |
|
copy_and_close(fileno(stdin)); |
539 |
< |
} else if (*df->fname != '!') { |
539 |
> |
} else if (df->fname[0] != '!') { |
540 |
|
if (!copy_and_close(open(df->fname, O_RDONLY))) { |
541 |
|
fprintf(stderr, "%s: error reading from '%s'\n", |
542 |
|
caller, df->fname); |
543 |
|
return 0; |
544 |
|
} |
545 |
|
} else if (system(df->fname+1)) { |
546 |
< |
fprintf(stderr, "%s: error running '%s'\n", caller, df->fname+1); |
546 |
> |
fprintf(stderr, "%s: error running '%s'\n", caller, df->fname); |
547 |
|
return 0; |
548 |
|
} |
549 |
|
puts("\t\t\t</ScatteringData>"); |
556 |
|
static int |
557 |
|
writeBSDF(const char *caller, ezxml_t fl) |
558 |
|
{ |
559 |
< |
char *xml = ezxml_toxml(fl); |
559 |
> |
char *xml = ezxml_toxml(fl); /* store XML in string */ |
560 |
|
int ei, i; |
561 |
|
/* locate trailer */ |
562 |
|
for (ei = strlen(xml)-strlen("</Layer></Optical></WindowElement>"); |
580 |
|
return 0; |
581 |
|
} |
582 |
|
fputs(xml+ei, stdout); /* write trailer */ |
583 |
< |
free(xml); |
583 |
> |
free(xml); /* free string */ |
584 |
> |
fputc('\n', stdout); |
585 |
|
return (fflush(stdout) == 0); |
586 |
|
} |
587 |
|
|
589 |
|
static int |
590 |
|
wrapBSDF(const char *caller) |
591 |
|
{ |
592 |
< |
const char *xml_path = getpath((char *)xml_input, getrlibpath(), R_OK); |
592 |
> |
const char *xml_path = xml_input; |
593 |
|
ezxml_t fl, wtl; |
594 |
|
/* load previous XML/template */ |
595 |
< |
if (xml_path == NULL) { |
596 |
< |
fprintf(stderr, "%s: cannot find XML file named '%s'\n", |
597 |
< |
caller, xml_input==NULL ? "NULL" : xml_input); |
598 |
< |
return 0; |
595 |
> |
if (xml_input == stdin_name) { |
596 |
> |
fl = ezxml_parse_fp(stdin); |
597 |
> |
} else if (xml_input[0] == '!') { |
598 |
> |
FILE *pfp = popen(xml_input+1, "r"); |
599 |
> |
if (pfp == NULL) { |
600 |
> |
fprintf(stderr, "%s: cannot start process '%s'\n", |
601 |
> |
caller, xml_input); |
602 |
> |
return 0; |
603 |
> |
} |
604 |
> |
fl = ezxml_parse_fp(pfp); |
605 |
> |
if (pclose(pfp)) { |
606 |
> |
fprintf(stderr, "%s: error running '%s'\n", |
607 |
> |
caller, xml_input); |
608 |
> |
return 0; |
609 |
> |
} |
610 |
> |
} else { |
611 |
> |
xml_path = getpath((char *)xml_input, getrlibpath(), R_OK); |
612 |
> |
if (xml_path == NULL) { |
613 |
> |
fprintf(stderr, "%s: cannot find XML file named '%s'\n", |
614 |
> |
caller, xml_input==NULL ? "NULL" : xml_input); |
615 |
> |
return 0; |
616 |
> |
} |
617 |
> |
fl = ezxml_parse_file(xml_path); |
618 |
|
} |
496 |
– |
fl = ezxml_parse_file(xml_path); |
619 |
|
if (fl == NULL) { |
620 |
< |
fprintf(stderr, "%s: cannot open XML path '%s'\n", |
499 |
< |
caller, xml_path); |
620 |
> |
fprintf(stderr, "%s: cannot load XML '%s'\n", caller, xml_path); |
621 |
|
return 0; |
622 |
|
} |
623 |
|
if (ezxml_error(fl)[0]) { |
624 |
< |
fprintf(stderr, "%s: error in XML %s: %s\n", caller, xml_path, |
624 |
> |
fprintf(stderr, "%s: error in XML '%s': %s\n", caller, xml_path, |
625 |
|
ezxml_error(fl)); |
626 |
|
goto failure; |
627 |
|
} |
643 |
|
goto failure; |
644 |
|
} |
645 |
|
/* make material assignments */ |
646 |
< |
if (!mat_assignments(caller, xml_path, wtl)) { |
646 |
> |
if (!mat_assignments(caller, xml_path, wtl)) |
647 |
|
goto failure; |
527 |
– |
} |
648 |
|
if (mgf_geometry != NULL) { /* add geometry if specified */ |
649 |
|
ezxml_t geom = ezxml_child(wtl, "Geometry"); |
650 |
|
if (geom == NULL) |
651 |
< |
geom = ezxml_add_child(wtl, "Geometry", 0); |
651 |
> |
geom = ezxml_add_child(wtl, "Geometry", strlen(wtl->txt)); |
652 |
|
ezxml_set_attr(geom, "format", "MGF"); |
653 |
|
geom = ezxml_child(geom, "MGFblock"); |
654 |
|
if (geom == NULL) { |
655 |
|
geom = ezxml_child(wtl, "Geometry"); |
656 |
< |
geom = ezxml_add_child(geom, "MGFblock", strlen(geom->txt)); |
656 |
> |
geom = ezxml_add_child(geom, "MGFblock", 0); |
657 |
|
} |
658 |
|
ezxml_set_attr(geom, "unit", attr_unit); |
659 |
|
ezxml_set_txt(geom, input2str(mgf_geometry)); |
662 |
|
} |
663 |
|
/* check basis */ |
664 |
|
if (angle_basis != ABdefault) { |
665 |
+ |
size_t offset = 0; |
666 |
|
ezxml_t ab, dd = ezxml_child(wtl, "DataDefinition"); |
667 |
< |
if (dd == NULL) { |
668 |
< |
dd = ezxml_add_child(wtl, "DataDefinition", 0); |
669 |
< |
} else { |
549 |
< |
if (ezxml_child(dd, "DataDefinition") != NULL) |
667 |
> |
if (dd != NULL) { |
668 |
> |
offset = dd->off; |
669 |
> |
if (dd->child != NULL) |
670 |
|
fprintf(stderr, |
671 |
|
"%s: warning - replacing existing <DataDefinition> in '%s'\n", |
672 |
|
caller, xml_path); |
673 |
< |
while (dd->child != NULL) |
674 |
< |
ezxml_remove(dd->child); |
675 |
< |
} |
676 |
< |
ezxml_insert(ezxml_parse_str(basis_definition[angle_basis], |
673 |
> |
ezxml_remove(dd); |
674 |
> |
} else |
675 |
> |
offset = strlen(wtl->txt); |
676 |
> |
dd = ezxml_insert(ezxml_parse_str(basis_definition[angle_basis], |
677 |
|
strlen(basis_definition[angle_basis])), |
678 |
< |
dd, 0); |
678 |
> |
wtl, offset); |
679 |
|
if ((ab = ezxml_child(dd, "AngleBasis")) != NULL && |
680 |
|
!finish_angle_basis(ab)) |
681 |
|
goto failure; |
700 |
|
{ |
701 |
|
fputs("Usage: ", stderr); |
702 |
|
fputs(pname, stderr); |
703 |
< |
fputs(" [options] [input.xml]\n", stderr); |
703 |
> |
fputs(" [-W][-a {kf|kh|kq|t3|t4}][-u unit][-g geom][-f 'x=string;y=string']", stderr); |
704 |
> |
fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp]", stderr); |
705 |
> |
fputs(" [input.xml]\n", stderr); |
706 |
|
exit(1); |
707 |
|
} |
708 |
|
|
739 |
|
argv[0]); |
740 |
|
return 1; |
741 |
|
} |
742 |
< |
if (strstr(argv[i], legal_units) == NULL) { |
743 |
< |
fprintf(stderr, "%s: unit must be one of (%s)\n", |
742 |
> |
if (strstr(legal_units, argv[i]) == NULL) { |
743 |
> |
fprintf(stderr, "%s: -u unit must be one of (%s)\n", |
744 |
|
argv[0], legal_units); |
745 |
|
return 1; |
746 |
|
} |