--- ray/src/util/eplus_adduvf.c 2014/02/11 22:01:44 2.6 +++ ray/src/util/eplus_adduvf.c 2014/02/13 17:33:37 2.10 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: eplus_adduvf.c,v 2.6 2014/02/11 22:01:44 greg Exp $"; +static const char RCSid[] = "$Id: eplus_adduvf.c,v 2.10 2014/02/13 17:33:37 greg Exp $"; #endif /* * Add User View Factors to EnergyPlus Input Data File @@ -16,15 +16,17 @@ static const char RCSid[] = "$Id: eplus_adduvf.c,v 2.6 #include "rtprocess.h" #ifndef NSAMPLES -#define NSAMPLES 80000 /* number of samples to use */ +#define NSAMPLES 80000 /* default number of samples */ #endif char *progname; /* global argv[0] */ +int nsamps = NSAMPLES; /* number of samples to use */ + char temp_octree[128]; /* temporary octree */ const char UVF_PNAME[] = - "ZoneProperty:UserViewFactor:bySurfaceName"; + "ZoneProperty:UserViewFactors:bySurfaceName"; const char ADD_HEADER[] = "\n!+++ User View Factors computed by Radiance +++!\n\n"; @@ -32,7 +34,7 @@ const char ADD_HEADER[] = #define NAME_FLD 1 /* name field always first? */ typedef struct { - const char *pname; /* parameter type name */ + const char *pname; /* object type name */ short zone_fld; /* zone field index */ short vert_fld; /* vertex field index */ } SURF_PTYPE; /* surface type we're interested in */ @@ -43,23 +45,31 @@ const SURF_PTYPE surf_type[] = { {"RoofCeiling:Detailed", 3, 9}, {"Wall:Detailed", 3, 9}, {NULL} - }; + }; /* IDF surface types */ typedef struct s_zone { const char *zname; /* zone name */ struct s_zone *next; /* next zone in list */ int nsurf; /* surface count */ - IDF_PARAMETER *pfirst; /* first matching parameter */ - IDF_PARAMETER *plast; /* last matching parameter */ + IDF_OBJECT *pfirst; /* first matching object */ + IDF_OBJECT *plast; /* last matching object */ } ZONE; /* a list of collected zone surfaces */ ZONE *zone_list = NULL; /* our list of zones */ IDF_LOADED *our_idf = NULL; /* loaded/modified IDF */ +typedef struct { + FVECT sdir[3]; /* UVW unit sampling vectors */ + double poff; /* W-offset for plane of polygon */ + double area_left; /* area left to sample */ + int samp_left; /* remaining samples */ + int wd; /* output file descriptor */ +} POLYSAMP; /* structure for polygon sampling */ + /* Create a new zone and push to top of our list */ static ZONE * -new_zone(const char *zname, IDF_PARAMETER *param) +new_zone(const char *zname, IDF_OBJECT *param) { ZONE *znew = (ZONE *)malloc(sizeof(ZONE)); @@ -74,7 +84,7 @@ new_zone(const char *zname, IDF_PARAMETER *param) /* Add the detailed surface (polygon) to the named zone */ static ZONE * -add2zone(IDF_PARAMETER *param, const char *zname) +add2zone(IDF_OBJECT *param, const char *zname) { ZONE *zptr; @@ -84,16 +94,16 @@ add2zone(IDF_PARAMETER *param, const char *zname) if (zptr == NULL) return(new_zone(zname, param)); /* keep surfaces together */ - if (!idf_movparam(our_idf, param, zptr->plast)) + if (!idf_movobject(our_idf, param, zptr->plast)) return(NULL); zptr->plast = param; zptr->nsurf++; return(zptr); } -/* Return field for vertices in the given parameter */ +/* Return field for vertices in the given object */ static IDF_FIELD * -get_vlist(IDF_PARAMETER *param, const char *zname) +get_vlist(IDF_OBJECT *param, const char *zname) { int i = 0; IDF_FIELD *fptr; @@ -113,7 +123,7 @@ get_vlist(IDF_PARAMETER *param, const char *zname) /* Convert surface to Radiance with modifier based on unique name */ static int -rad_surface(IDF_PARAMETER *param, FILE *ofp) +rad_surface(IDF_OBJECT *param, FILE *ofp) { const char *sname = idf_getfield(param,NAME_FLD)->val; IDF_FIELD *fptr = get_vlist(param, NULL); @@ -148,12 +158,12 @@ start_rcontrib(SUBPROC *pd, ZONE *zp) { #define BASE_AC 5 static char *base_av[BASE_AC] = { - "rcontrib", "-ff", "-h", "-x", "1" + "rcontrib", "-fff", "-h", "-x", "1" }; char cbuf[300]; char **av; FILE *ofp; - IDF_PARAMETER *pptr; + IDF_OBJECT *pptr; int i, n; /* start oconv command */ sprintf(cbuf, "oconv - > '%s'", temp_octree); @@ -168,14 +178,14 @@ start_rcontrib(SUBPROC *pd, ZONE *zp) return(0); for (i = 0; i < BASE_AC; i++) av[i] = base_av[i]; - sprintf(cbuf, "%d", NSAMPLES); + sprintf(cbuf, "%d", nsamps); av[i++] = "-c"; av[i++] = cbuf; /* add modifier arguments */ for (n = zp->nsurf, pptr = zp->pfirst; n--; pptr = pptr->dnext) { IDF_FIELD *fptr = idf_getfield(pptr,NAME_FLD); if (fptr == NULL || !fptr->val[0]) { fputs(progname, stderr); - fputs(": missing name for surface parameter\n", stderr); + fputs(": missing name for surface object\n", stderr); return(0); } if (!rad_surface(pptr, ofp)) /* add surface to octree */ @@ -190,7 +200,7 @@ start_rcontrib(SUBPROC *pd, ZONE *zp) } av[i++] = temp_octree; /* add final octree argument */ av[i] = NULL; - if (!open_process(pd, av)) { /* start process */ + if (open_process(pd, av) <= 0) { /* start process */ fputs(progname, stderr); fputs(": cannot start rcontrib process\n", stderr); return(0); @@ -200,14 +210,6 @@ start_rcontrib(SUBPROC *pd, ZONE *zp) #undef BASE_AC } -typedef struct { - FVECT sdir[3]; /* XYZ unit sampling vectors */ - double poff; /* Z-offset for plane of polygon */ - double area_left; /* area left to sample */ - int samp_left; /* remaining samples */ - int wd; /* output file descriptor */ -} POLYSAMP; /* structure for polygon sampling */ - /* Initialize polygon sampling */ static Vert2_list * init_poly(POLYSAMP *ps, IDF_FIELD *f0, int nv) @@ -335,7 +337,7 @@ sample_triangle(const Vert2_list *vl2, int a, int b, i /* Sample the given surface */ static int -sample_surface(IDF_PARAMETER *param, int wd) +sample_surface(IDF_OBJECT *param, int wd) { IDF_FIELD *fptr = get_vlist(param, NULL); POLYSAMP psamp; @@ -349,7 +351,7 @@ sample_surface(IDF_PARAMETER *param, int wd) idf_getfield(param,NAME_FLD)->val); return(0); } - psamp.samp_left = NSAMPLES; /* assign samples & destination */ + psamp.samp_left = nsamps; /* assign samples & destination */ psamp.wd = wd; /* sample each subtriangle */ if (!polyTriangulate(vlist2, &sample_triangle)) @@ -362,16 +364,16 @@ sample_surface(IDF_PARAMETER *param, int wd) static int compute_uvfs(SUBPROC *pd, ZONE *zp) { - IDF_PARAMETER *pptr, *pout, *pptr1; + IDF_OBJECT *pptr, *pout, *pptr1; float *uvfa; char uvfbuf[24]; int n, m; - /* create output parameter */ - pout = idf_newparam(our_idf, UVF_PNAME, + /* create output object */ + pout = idf_newobject(our_idf, UVF_PNAME, " ! computed by Radiance\n ", zp->plast); if (pout == NULL) { fputs(progname, stderr); - fputs(": cannot create new IDF parameter\n", stderr); + fputs(": cannot create new IDF object\n", stderr); return(0); } if (!idf_addfield(pout, zp->zname, @@ -464,22 +466,31 @@ main(int argc, char *argv[]) { int incl_comments = 1; char *origIDF, *revIDF; - IDF_PARAMETER *pptr; + IDF_OBJECT *pptr; int i; - progname = argv[0]; - if (argc > 2 && !strcmp(argv[1], "-c")) { - incl_comments = -1; /* output header only */ - ++argv; --argc; - } - if ((argc < 2) | (argc > 3)) { - fputs("Usage: ", stderr); - fputs(progname, stderr); - fputs(" [-c] Model.idf [Revised.idf]\n", stderr); - return(1); - } - origIDF = argv[1]; - revIDF = (argc == 2) ? argv[1] : argv[2]; + progname = *argv++; argc--; /* get options if any */ + while (argc > 1 && argv[0][0] == '-') + switch (argv[0][1]) { + case 'c': /* elide comments */ + incl_comments = -1; /* header only */ + argv++; argc--; + continue; + case 's': /* samples */ + nsamps = 1000*atoi(*++argv); + argv++; argc -= 2; + continue; + default: + fputs(progname, stderr); + fputs(": unknown option '", stderr); + fputs(argv[0], stderr); + fputs("'\n", stderr); + goto userr; + } + if ((argc < 1) | (argc > 2)) + goto userr; + origIDF = argv[0]; + revIDF = (argc == 1) ? argv[0] : argv[1]; /* load Input Data File */ our_idf = idf_load(origIDF); if (our_idf == NULL) { @@ -490,13 +501,13 @@ main(int argc, char *argv[]) return(1); } /* remove existing UVFs */ - if ((pptr = idf_getparam(our_idf, UVF_PNAME)) != NULL) { - IDF_PARAMETER *pnext; + if ((pptr = idf_getobject(our_idf, UVF_PNAME)) != NULL) { + IDF_OBJECT *pnext; fputs(progname, stderr); fputs(": removing previous User View Factors\n", stderr); do { pnext = pptr->pnext; - idf_delparam(our_idf, pptr); + idf_delobject(our_idf, pptr); } while (pnext != NULL); } /* add to header */ @@ -506,7 +517,7 @@ main(int argc, char *argv[]) idf_add2hdr(our_idf, ADD_HEADER); /* gather zone surfaces */ for (i = 0; surf_type[i].pname != NULL; i++) - for (pptr = idf_getparam(our_idf, surf_type[i].pname); + for (pptr = idf_getobject(our_idf, surf_type[i].pname); pptr != NULL; pptr = pptr->pnext) { IDF_FIELD *fptr = idf_getfield(pptr, surf_type[i].zone_fld); @@ -530,4 +541,9 @@ main(int argc, char *argv[]) return(1); } return(0); /* finito! */ +userr: + fputs("Usage: ", stderr); + fputs(progname, stderr); + fputs(" [-c][-s Ksamps] Model.idf [Revised.idf]\n", stderr); + return(1); }