ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/wrapBSDF.c
(Generate patch)

Comparing ray/src/util/wrapBSDF.c (file contents):
Revision 2.2 by greg, Wed Feb 11 19:38:18 2015 UTC vs.
Revision 2.3 by greg, Fri Feb 13 20:49:59 2015 UTC

# Line 15 | Line 15 | static const char RCSid[] = "$Id$";
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  
# Line 36 | Line 36 | int            angle_basis = ABdefault;
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
# Line 76 | Line 77 | const char     *spectr_file[MAXFILES]; /* custom spectral
77  
78   const char      top_level_name[] = "WindowElement";
79  
80 < static char     *basis_definition[] = {
80 > static char     basis_definition[][256] = {
81  
82          "\t\t<IncidentDataStructure>Columns</IncidentDataStructure>\n"
83          "\t\t<AngleBasis>\n"
# Line 144 | Line 145 | input2str(const char *inpspec)
145                          return "";
146                  }
147                  len = lseek(fd, 0L, SEEK_END);
148 <                if (len < 0) {
149 <                        fprintf(stderr, "%s: seek error\n", inpspec);
148 >                if (len > 0) {
149 >                        lseek(fd, 0L, SEEK_SET);
150 >                        str = (char *)malloc(len+1);
151 >                        if (str == NULL) {
152 >                                close(fd);
153 >                                goto memerr;
154 >                        }
155 >                        if (read(fd, str, len) != len) {
156 >                                fprintf(stderr, "%s: read error\n", inpspec);
157 >                                free(str);
158 >                                close(fd);
159 >                                return "";
160 >                        }
161 >                        str[len] = '\0';
162                          close(fd);
163 <                        return "";
163 >                        return str;
164                  }
165 <                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;
165 >                fp = fdopen(fd, "r");           /* not a regular file */
166          }
167                                                  /* reading from stream */
168          str = (char *)malloc((len=8192)+1);
# Line 204 | Line 203 | mat_assignments(const char *caller, const char *fn, ez
203   {
204          int     i;
205  
207        if (!nfield_assign)
208                return 1;
206          wtl = ezxml_child(wtl, "Material");
207          if (wtl == NULL) {
208                  fprintf(stderr, "%s: missing <Material> tag\n", fn);
# Line 222 | Line 219 | mat_assignments(const char *caller, const char *fn, ez
219                                  ++fnext;
220                          if (!*fnext)
221                                  break;
222 <                        for (j = 0; (*fnext != '=') & !isspace(*fnext); ) {
222 >                        for (j = 0; *fnext != '=' && !isspace(*fnext); ) {
223                                  if (!*fnext | (*fnext == FASEP) |
224                                                  (j >= sizeof(sbuf)-1)) {
225                                          fprintf(stderr,
# Line 242 | Line 239 | mat_assignments(const char *caller, const char *fn, ez
239                                                  /* check if tag exists */
240                          fld = ezxml_child(wtl, sbuf);
241                          if (fld == NULL) {      /* otherwise, create one */
242 <                                fprintf(stderr, "%s: warning - adding tag <%s>\n",
243 <                                        fn, sbuf);
242 >                                if (!XMLfieldID[j].nickName[0])
243 >                                        fprintf(stderr,
244 >                                                "%s: warning - adding tag <%s>\n",
245 >                                                        fn, sbuf);
246                                  fld = ezxml_add_child_d(wtl, sbuf, strlen(wtl->txt));
247                          }
248                          if (XMLfieldID[j].has_unit)
249                                  ezxml_set_attr(fld, "unit", attr_unit);
250 +                        XMLfieldID[j].win_need = 0;
251                          while (isspace(*fnext))
252                                  ++fnext;
253                          if (*fnext++ != '=') {
# Line 256 | Line 256 | mat_assignments(const char *caller, const char *fn, ez
256                                                  caller, field_assignment[i]);
257                                  return 0;
258                          }
259 <                        for (j = 0; *fnext & (*fnext != FASEP); ) {
259 >                        for (j = 0; *fnext && *fnext != FASEP; ) {
260                                  if (j >= sizeof(sbuf)-1) {
261                                          fprintf(stderr,
262                                          "%s: field too long in '%s'\n",
# Line 270 | Line 270 | mat_assignments(const char *caller, const char *fn, ez
270                          fnext += (*fnext == FASEP);
271                  }
272          }
273 +                                        /* check required WINDOW settings */
274 +        if (xml_input == win6_template)
275 +            for (i = 0; XMLfieldID[i].nickName[0]; i++)
276 +                if (XMLfieldID[i].win_need &&
277 +                        !ezxml_txt(ezxml_child(wtl,XMLfieldID[i].fullName))[0]) {
278 +                        fprintf(stderr,
279 +                        "%s: missing required '%s' assignment for WINDOW <%s>\n",
280 +                                        caller, XMLfieldID[i].nickName,
281 +                                        XMLfieldID[i].fullName);
282 +                        return 0;
283 +                }
284          return 1;               /* no errors */
285   }
286  
# Line 540 | Line 551 | wrapBSDF(const char *caller)
551                  goto failure;
552          }
553                                          /* make material assignments */
554 <        if (!mat_assignments(caller, xml_path, wtl)) {
554 >        if (!mat_assignments(caller, xml_path, wtl))
555                  goto failure;
545        }
556          if (mgf_geometry != NULL) {     /* add geometry if specified */
557                  ezxml_t geom = ezxml_child(wtl, "Geometry");
558                  if (geom == NULL)
559 <                        geom = ezxml_add_child(wtl, "Geometry", 0);
559 >                        geom = ezxml_add_child(wtl, "Geometry", strlen(wtl->txt));
560                  ezxml_set_attr(geom, "format", "MGF");
561                  geom = ezxml_child(geom, "MGFblock");
562                  if (geom == NULL) {
563                          geom = ezxml_child(wtl, "Geometry");
564 <                        geom = ezxml_add_child(geom, "MGFblock", strlen(geom->txt));
564 >                        geom = ezxml_add_child(geom, "MGFblock", 0);
565                  }
566                  ezxml_set_attr(geom, "unit", attr_unit);
567                  ezxml_set_txt(geom, input2str(mgf_geometry));
# Line 562 | Line 572 | wrapBSDF(const char *caller)
572          if (angle_basis != ABdefault) {
573                  ezxml_t ab, dd = ezxml_child(wtl, "DataDefinition");
574                  if (dd == NULL) {
575 <                        dd = ezxml_add_child(wtl, "DataDefinition", 0);
576 <                } else {
577 <                        if (ezxml_child(dd, "DataDefinition") != NULL)
568 <                                fprintf(stderr,
575 >                        dd = ezxml_add_child(wtl, "DataDefinition", strlen(wtl->txt));
576 >                } else if (dd->child != NULL) {
577 >                        fprintf(stderr,
578                  "%s: warning - replacing existing <DataDefinition> in '%s'\n",
579                                                  caller, xml_path);
580 <                        while (dd->child != NULL)
580 >                        do
581                                  ezxml_remove(dd->child);
582 +                        while (dd->child != NULL);
583                  }
584                  ezxml_insert(ezxml_parse_str(basis_definition[angle_basis],
585                                          strlen(basis_definition[angle_basis])),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines