--- ray/src/util/eplus_adduvf.c 2014/02/21 13:17:45 2.12 +++ ray/src/util/eplus_adduvf.c 2020/02/28 05:18:49 2.22 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: eplus_adduvf.c,v 2.12 2014/02/21 13:17:45 greg Exp $"; +static const char RCSid[] = "$Id: eplus_adduvf.c,v 2.22 2020/02/28 05:18:49 greg Exp $"; #endif /* * Add User View Factors to EnergyPlus Input Data File @@ -8,6 +8,8 @@ static const char RCSid[] = "$Id: eplus_adduvf.c,v 2.1 */ #include +#include +#include "platform.h" #include "rtio.h" #include "rtmath.h" #include "random.h" @@ -39,7 +41,7 @@ const char ADD_HEADER[] = #define NAME_FLD 1 /* name field always first? */ #define SS_BASE_FLD 4 /* subsurface base surface */ -#define SS_VERT_FLD 10 /* subsurface vertex count */ +#define SS_VERT_FLD 9 /* subsurface vertex count */ typedef struct { const char *pname; /* object type name */ @@ -176,7 +178,11 @@ add_subsurf(IDF_OBJECT *param) static IDF_FIELD * get_vlist(IDF_OBJECT *param, const char *zname) { - int i = 0; +#define itm_len (sizeof(IDF_FIELD)+6) + static char fld_buf[4*itm_len]; + static char *next_fbp = fld_buf; + int i; + IDF_FIELD *res; /* check if subsurface */ if (!strcmp(param->pname, SUBSURF_PNAME)) { if (zname != NULL) { @@ -185,20 +191,37 @@ get_vlist(IDF_OBJECT *param, const char *zname) if (strcmp((*(ZONE *)lep->data).zname, zname)) return(NULL); } - return(idf_getfield(param, SS_VERT_FLD)); + res = idf_getfield(param, SS_VERT_FLD); + } else { + i = 0; /* check for surface type */ + while (strcmp(surf_type[i].pname, param->pname)) + if (surf_type[++i].pname == NULL) + return(NULL); + + if (zname != NULL) { /* matches specified zone? */ + IDF_FIELD *fptr = idf_getfield(param, surf_type[i].zone_fld); + if (fptr == NULL || strcmp(fptr->val, zname)) + return(NULL); + } + res = idf_getfield(param, surf_type[i].vert_fld); } - /* check for surface type */ - while (strcmp(surf_type[i].pname, param->pname)) - if (surf_type[++i].pname == NULL) + if (!res->val[0] || tolower(res->val[0]) == 'a') { /* autocalculate */ + IDF_FIELD *fptr; + if (next_fbp >= fld_buf+sizeof(fld_buf)) + next_fbp = fld_buf; + i = 0; /* count vertices */ + for (fptr = res->next; fptr != NULL; fptr = fptr->next) + ++i; + if (i % 3) return(NULL); - - if (zname != NULL) { /* matches specified zone? */ - IDF_FIELD *fptr = idf_getfield(param, surf_type[i].zone_fld); - if (fptr == NULL || strcmp(fptr->val, zname)) - return(NULL); + fptr = res->next; + res = (IDF_FIELD *)next_fbp; next_fbp += itm_len; + res->next = fptr; + res->rem = ""; + sprintf(res->val, "%d", i/3); } - /* return field for #verts */ - return(idf_getfield(param, surf_type[i].vert_fld)); + return(res); +#undef itm_len } /* Get/allocate surface polygon */ @@ -303,7 +326,7 @@ static double rad_subsurface(IDF_OBJECT *param, FILE *ofp) { const char *sname = idf_getfield(param,NAME_FLD)->val; - SURFACE *surf = get_surface(idf_getfield(param,SS_VERT_FLD)); + SURFACE *surf = get_surface(get_vlist(param, NULL)); double area; int i; @@ -341,7 +364,7 @@ start_rcontrib(SUBPROC *pd, ZONE *zp) IDF_FIELD *fptr; int i, j, n; /* start oconv command */ - sprintf(cbuf, "oconv - > '%s'", temp_octree); + sprintf(cbuf, "oconv - > \"%s\"", temp_octree); if ((ofp = popen(cbuf, "w")) == NULL) { fputs(progname, stderr); fputs(": cannot open oconv process\n", stderr); @@ -371,8 +394,8 @@ start_rcontrib(SUBPROC *pd, ZONE *zp) /* now subsurfaces */ if (zp->ntotal > zp->nsurf) { if (zp->area_redu != NULL) - memset(zp->area_redu, 0, sizeof(float)*zp->nsurf); - else if ((zp->area_redu = (float *)calloc(zp->nsurf, + memset(zp->area_redu, 0, sizeof(float)*zp->ntotal); + else if ((zp->area_redu = (float *)calloc(zp->ntotal, sizeof(float))) == NULL) return(0); } @@ -632,6 +655,7 @@ compute_zones(void) for (zptr = zone_list; zptr != NULL; zptr = zptr->next) { SUBPROC rcproc; /* start rcontrib process */ + rcproc = sp_inactive; if (!start_rcontrib(&rcproc, zptr)) return(0); /* compute+add view factors */ @@ -687,6 +711,15 @@ main(int argc, char *argv[]) fputs("'\n", stderr); return(1); } + /* check version (warning) */ + if ((pptr = idf_getobject(our_idf, "Version")) != NULL && + pptr->flist != NULL && pptr->flist->val[0] != '9') { + fputs(progname, stderr); + fputs(": warning - written for IDF version 9.x, not ", + stderr); + fputs(pptr->flist->val, stderr); + fputc('\n', stderr); + } /* remove existing UVFs */ if ((pptr = idf_getobject(our_idf, UVF_PNAME)) != NULL) { IDF_OBJECT *pnext; @@ -695,7 +728,7 @@ main(int argc, char *argv[]) do { pnext = pptr->pnext; idf_delobject(our_idf, pptr); - } while (pnext != NULL); + } while ((pptr = pnext) != NULL); } /* add to header */ if (our_idf->hrem == NULL ||