| 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 |
|
|
| 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", 0, 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 */ |
| 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); |
| 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); |
| 229 |
|
++fnext; |
| 230 |
|
if (!*fnext) |
| 231 |
|
break; |
| 232 |
< |
for (j = 0; (*fnext != '=') & !isspace(*fnext); ) { |
| 232 |
> |
for (j = 0; *fnext != '=' && !isspace(*fnext); ) { |
| 233 |
|
if (!*fnext | (*fnext == FASEP) | |
| 234 |
|
(j >= sizeof(sbuf)-1)) { |
| 235 |
|
fprintf(stderr, |
| 249 |
|
/* check if tag exists */ |
| 250 |
|
fld = ezxml_child(wtl, sbuf); |
| 251 |
|
if (fld == NULL) { /* otherwise, create one */ |
| 252 |
< |
fprintf(stderr, "%s: warning - adding tag <%s>\n", |
| 253 |
< |
fn, sbuf); |
| 252 |
> |
if (!XMLfieldID[j].nickName[0]) |
| 253 |
> |
fprintf(stderr, |
| 254 |
> |
"%s: warning - adding tag <%s>\n", |
| 255 |
> |
fn, sbuf); |
| 256 |
|
fld = ezxml_add_child_d(wtl, sbuf, strlen(wtl->txt)); |
| 257 |
|
} |
| 258 |
|
if (XMLfieldID[j].has_unit) |
| 259 |
|
ezxml_set_attr(fld, "unit", attr_unit); |
| 260 |
+ |
XMLfieldID[j].win_need = 0; |
| 261 |
|
while (isspace(*fnext)) |
| 262 |
|
++fnext; |
| 263 |
|
if (*fnext++ != '=') { |
| 266 |
|
caller, field_assignment[i]); |
| 267 |
|
return 0; |
| 268 |
|
} |
| 269 |
< |
for (j = 0; *fnext & (*fnext != FASEP); ) { |
| 269 |
> |
for (j = 0; *fnext && *fnext != FASEP; ) { |
| 270 |
|
if (j >= sizeof(sbuf)-1) { |
| 271 |
|
fprintf(stderr, |
| 272 |
|
"%s: field too long in '%s'\n", |
| 280 |
|
fnext += (*fnext == FASEP); |
| 281 |
|
} |
| 282 |
|
} |
| 283 |
+ |
/* check required WINDOW settings */ |
| 284 |
+ |
if (xml_input == win6_template) |
| 285 |
+ |
for (i = 0; XMLfieldID[i].nickName[0]; i++) |
| 286 |
+ |
if (XMLfieldID[i].win_need && |
| 287 |
+ |
!ezxml_txt(ezxml_child(wtl,XMLfieldID[i].fullName))[0]) { |
| 288 |
+ |
fprintf(stderr, |
| 289 |
+ |
"%s: missing required '%s' assignment for WINDOW <%s>\n", |
| 290 |
+ |
caller, XMLfieldID[i].nickName, |
| 291 |
+ |
XMLfieldID[i].fullName); |
| 292 |
+ |
return 0; |
| 293 |
+ |
} |
| 294 |
|
return 1; /* no errors */ |
| 295 |
|
} |
| 296 |
|
|
| 319 |
|
sprintf(buf, "%g", i ? |
| 320 |
|
.5*(abase_list[n].lat[i].tmin + abase_list[n].lat[i+1].tmin) : |
| 321 |
|
.0); |
| 322 |
+ |
ezxml_add_txt(abb, "\n\t\t\t\t"); |
| 323 |
|
ezxml_set_txt_d(ezxml_add_child(abb,"Theta",strlen(abb->txt)), buf); |
| 324 |
|
sprintf(buf, "%d", abase_list[n].lat[i].nphis); |
| 325 |
+ |
ezxml_add_txt(abb, "\n\t\t\t\t"); |
| 326 |
|
ezxml_set_txt_d(ezxml_add_child(abb,"nPhis",strlen(abb->txt)), buf); |
| 327 |
+ |
ezxml_add_txt(abb, "\n\t\t\t\t"); |
| 328 |
|
tb = ezxml_add_child(abb, "ThetaBounds", strlen(abb->txt)); |
| 329 |
+ |
ezxml_add_txt(tb, "\n\t\t\t\t\t"); |
| 330 |
|
sprintf(buf, "%g", abase_list[n].lat[i].tmin); |
| 331 |
< |
ezxml_set_txt(ezxml_add_child(tb,"LowerTheta",strlen(tb->txt)), buf); |
| 331 |
> |
ezxml_set_txt_d(ezxml_add_child(tb,"LowerTheta",strlen(tb->txt)), buf); |
| 332 |
> |
ezxml_add_txt(tb, "\n\t\t\t\t\t"); |
| 333 |
|
sprintf(buf, "%g", abase_list[n].lat[i+1].tmin); |
| 334 |
< |
ezxml_set_txt(ezxml_add_child(tb,"UpperTheta",strlen(tb->txt)), buf); |
| 334 |
> |
ezxml_set_txt_d(ezxml_add_child(tb,"UpperTheta",strlen(tb->txt)), buf); |
| 335 |
> |
ezxml_add_txt(tb, "\n\t\t\t\t"); |
| 336 |
> |
ezxml_add_txt(abb, "\n\t\t\t"); |
| 337 |
> |
ezxml_add_txt(ab, "\n\t\t\t"); |
| 338 |
|
} |
| 339 |
|
return 1; |
| 340 |
|
} |
| 350 |
|
if (wtl == NULL) |
| 351 |
|
return -1; |
| 352 |
|
ids = ezxml_txt(ezxml_child(wtl, "IncidentDataStructure")); |
| 353 |
< |
if (ids == NULL) |
| 353 |
> |
if (!ids[0]) |
| 354 |
|
return -1; |
| 355 |
|
for (i = 0; i < ABend; i++) { |
| 356 |
|
ezxml_t parsed = ezxml_parse_str(basis_definition[i], |
| 508 |
|
} |
| 509 |
|
fputs(xml+ei, stdout); /* write trailer */ |
| 510 |
|
free(xml); /* free string */ |
| 511 |
+ |
fputc('\n', stdout); |
| 512 |
|
return (fflush(stdout) == 0); |
| 513 |
|
} |
| 514 |
|
|
| 570 |
|
goto failure; |
| 571 |
|
} |
| 572 |
|
/* make material assignments */ |
| 573 |
< |
if (!mat_assignments(caller, xml_path, wtl)) { |
| 573 |
> |
if (!mat_assignments(caller, xml_path, wtl)) |
| 574 |
|
goto failure; |
| 545 |
– |
} |
| 575 |
|
if (mgf_geometry != NULL) { /* add geometry if specified */ |
| 576 |
|
ezxml_t geom = ezxml_child(wtl, "Geometry"); |
| 577 |
|
if (geom == NULL) |
| 578 |
< |
geom = ezxml_add_child(wtl, "Geometry", 0); |
| 578 |
> |
geom = ezxml_add_child(wtl, "Geometry", strlen(wtl->txt)); |
| 579 |
|
ezxml_set_attr(geom, "format", "MGF"); |
| 580 |
|
geom = ezxml_child(geom, "MGFblock"); |
| 581 |
|
if (geom == NULL) { |
| 582 |
|
geom = ezxml_child(wtl, "Geometry"); |
| 583 |
< |
geom = ezxml_add_child(geom, "MGFblock", strlen(geom->txt)); |
| 583 |
> |
geom = ezxml_add_child(geom, "MGFblock", 0); |
| 584 |
|
} |
| 585 |
|
ezxml_set_attr(geom, "unit", attr_unit); |
| 586 |
|
ezxml_set_txt(geom, input2str(mgf_geometry)); |
| 589 |
|
} |
| 590 |
|
/* check basis */ |
| 591 |
|
if (angle_basis != ABdefault) { |
| 592 |
+ |
size_t offset = 0; |
| 593 |
|
ezxml_t ab, dd = ezxml_child(wtl, "DataDefinition"); |
| 594 |
< |
if (dd == NULL) { |
| 595 |
< |
dd = ezxml_add_child(wtl, "DataDefinition", 0); |
| 596 |
< |
} else { |
| 567 |
< |
if (ezxml_child(dd, "DataDefinition") != NULL) |
| 568 |
< |
fprintf(stderr, |
| 594 |
> |
if (dd != NULL) { |
| 595 |
> |
offset = dd->off; |
| 596 |
> |
fprintf(stderr, |
| 597 |
|
"%s: warning - replacing existing <DataDefinition> in '%s'\n", |
| 598 |
|
caller, xml_path); |
| 599 |
< |
while (dd->child != NULL) |
| 600 |
< |
ezxml_remove(dd->child); |
| 601 |
< |
} |
| 602 |
< |
ezxml_insert(ezxml_parse_str(basis_definition[angle_basis], |
| 599 |
> |
ezxml_remove(dd); |
| 600 |
> |
} else |
| 601 |
> |
offset = strlen(wtl->txt); |
| 602 |
> |
dd = ezxml_insert(ezxml_parse_str(basis_definition[angle_basis], |
| 603 |
|
strlen(basis_definition[angle_basis])), |
| 604 |
< |
dd, 0); |
| 604 |
> |
wtl, offset); |
| 605 |
|
if ((ab = ezxml_child(dd, "AngleBasis")) != NULL && |
| 606 |
|
!finish_angle_basis(ab)) |
| 607 |
|
goto failure; |