93 |
|
if (wdb == NULL) /* no geometry section? */ |
94 |
|
return SDEnone; |
95 |
|
sd->dim[0] = sd->dim[1] = sd->dim[2] = .0; |
96 |
+ |
SDerrorDetail[0] = '\0'; |
97 |
|
if ((geom = ezxml_child(wdb, "Width")) != NULL) |
98 |
|
sd->dim[0] = atof(ezxml_txt(geom)) * |
99 |
|
to_meters(ezxml_attr(geom, "unit")); |
104 |
|
sd->dim[2] = atof(ezxml_txt(geom)) * |
105 |
|
to_meters(ezxml_attr(geom, "unit")); |
106 |
|
if ((sd->dim[0] < 0) | (sd->dim[1] < 0) | (sd->dim[2] < 0)) { |
107 |
< |
sprintf(SDerrorDetail, "Negative size in \"%s\"", sd->name); |
107 |
> |
if (!SDerrorDetail[0]) |
108 |
> |
sprintf(SDerrorDetail, "Negative dimension in \"%s\"", |
109 |
> |
sd->name); |
110 |
|
return SDEdata; |
111 |
|
} |
112 |
|
if ((geom = ezxml_child(wdb, "Geometry")) == NULL || |
124 |
|
return SDEsupport; |
125 |
|
} |
126 |
|
cfact = to_meters(ezxml_attr(geom, "unit")); |
127 |
+ |
if (cfact <= 0) |
128 |
+ |
return SDEformat; |
129 |
|
sd->mgf = (char *)malloc(strlen(mgfstr)+32); |
130 |
|
if (sd->mgf == NULL) { |
131 |
|
strcpy(SDerrorDetail, "Out of memory in SDloadGeometry"); |
169 |
|
} |
170 |
|
wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer"); |
171 |
|
if (wtl == NULL) { |
172 |
< |
sprintf(SDerrorDetail, "BSDF \"%s\": no optical layer'", |
172 |
> |
sprintf(SDerrorDetail, "BSDF \"%s\": no optical layers'", |
173 |
|
sd->name); |
174 |
|
ezxml_free(fl); |
175 |
|
return SDEformat; |
176 |
|
} |
177 |
|
/* load geometry if present */ |
178 |
|
lastErr = SDloadGeometry(sd, ezxml_child(wtl, "Material")); |
179 |
< |
if (lastErr) |
179 |
> |
if (lastErr) { |
180 |
> |
ezxml_free(fl); |
181 |
|
return lastErr; |
182 |
+ |
} |
183 |
|
/* try loading variable resolution data */ |
184 |
|
lastErr = SDloadTre(sd, wtl); |
185 |
|
/* check our result */ |
228 |
|
df->maxHemi = .0; |
229 |
|
df->ncomp = nc; |
230 |
|
memset(df->comp, 0, nc*sizeof(SDComponent)); |
231 |
+ |
return df; |
232 |
+ |
} |
233 |
+ |
|
234 |
+ |
/* Add component(s) to spectral distribution function */ |
235 |
+ |
SDSpectralDF * |
236 |
+ |
SDaddComponent(SDSpectralDF *odf, int nadd) |
237 |
+ |
{ |
238 |
+ |
SDSpectralDF *df; |
239 |
+ |
|
240 |
+ |
if (odf == NULL) |
241 |
+ |
return SDnewSpectralDF(nadd); |
242 |
+ |
if (nadd <= 0) |
243 |
+ |
return odf; |
244 |
+ |
df = (SDSpectralDF *)realloc(odf, sizeof(SDSpectralDF) + |
245 |
+ |
(odf->ncomp+nadd-1)*sizeof(SDComponent)); |
246 |
+ |
if (df == NULL) { |
247 |
+ |
sprintf(SDerrorDetail, |
248 |
+ |
"Cannot add %d component(s) to spectral DF", nadd); |
249 |
+ |
SDfreeSpectralDF(odf); |
250 |
+ |
return NULL; |
251 |
+ |
} |
252 |
+ |
memset(df->comp+df->ncomp, 0, nadd*sizeof(SDComponent)); |
253 |
+ |
df->ncomp += nadd; |
254 |
|
return df; |
255 |
|
} |
256 |
|
|