--- ray/src/util/eplus_adduvf.c 2014/02/21 13:17:45 2.12 +++ ray/src/util/eplus_adduvf.c 2025/06/03 21:31:51 2.24 @@ -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.24 2025/06/03 21:31:51 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" @@ -21,8 +23,6 @@ static const char RCSid[] = "$Id: eplus_adduvf.c,v 2.1 #define SURF_EPS 0.0005 /* surface testing epsilon */ -char *progname; /* global argv[0] */ - int nsamps = NSAMPLES; /* number of samples to use */ char temp_octree[128]; /* temporary octree */ @@ -39,7 +39,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 +176,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 +189,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 +324,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 +362,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 +392,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); } @@ -511,7 +532,7 @@ sample_triangle(const Vert2_list *vl2, int a, int b, i dv[2]*ps->sdir[2][j] ; } /* send to our process */ - writebuf(ps->wd, (char *)samp, sizeof(float)*6*ns); + writebuf(ps->wd, samp, sizeof(float)*6*ns); free(samp); /* that's it! */ return(1); } @@ -582,7 +603,7 @@ compute_uvfs(SUBPROC *pd, ZONE *zp) else /* comp. for subsurface area */ adj_factor /= adj_factor - zp->area_redu[n]; /* read results */ - if (readbuf(pd->r, (char *)uvfa, sizeof(float)*3*zp->ntotal) != + if (readbuf(pd->r, uvfa, sizeof(float)*3*zp->ntotal) != sizeof(float)*3*zp->ntotal) { fputs(progname, stderr); fputs(": read error from rcontrib process\n", stderr); @@ -632,6 +653,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 */ @@ -656,7 +678,7 @@ main(int argc, char *argv[]) IDF_OBJECT *pptr; int i; - progname = *argv++; argc--; /* get options if any */ + fixargv0(*argv++); argc--; /* get options if any */ while (argc > 1 && argv[0][0] == '-') switch (argv[0][1]) { case 'c': /* elide comments */ @@ -687,6 +709,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 +726,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 ||