| 5 |
|
#endif |
| 6 |
|
|
| 7 |
|
/* |
| 8 |
< |
* Compute Glare Index given by program name: |
| 8 |
> |
* Compute Glare Index given by program name or -t option: |
| 9 |
|
* |
| 10 |
|
* guth_dgr - Guth discomfort glare rating |
| 11 |
|
* guth_vcp - Guth visual comfort probability |
| 12 |
+ |
* cie_cgi - CIE Glare Index (1983, due to Einhorn) |
| 13 |
+ |
* vert_dir - Direct vertical illuminance |
| 14 |
+ |
* vert_ind - Indirect vertical illuminance (from input) |
| 15 |
+ |
* vert_ill - Total vertical illuminance |
| 16 |
|
* |
| 17 |
|
* 12 April 1991 Greg Ward EPFL |
| 18 |
|
*/ |
| 23 |
|
extern double erfc(); |
| 24 |
|
|
| 25 |
|
double posindex(); |
| 22 |
– |
int headline(); |
| 26 |
|
|
| 27 |
< |
double direct(), guth_dgr(), guth_vcp(); |
| 27 |
> |
double direct(), guth_dgr(), guth_vcp(), cie_cgi(), |
| 28 |
> |
indirect(), total(); |
| 29 |
|
|
| 30 |
|
struct named_func { |
| 31 |
|
char *name; |
| 32 |
|
double (*func)(); |
| 33 |
+ |
char *descrip; |
| 34 |
|
} all_funcs[] = { |
| 35 |
< |
{"direct", direct}, |
| 36 |
< |
{"guth_dgr", guth_dgr}, |
| 37 |
< |
{"guth_vcp", guth_vcp}, |
| 35 |
> |
{"guth_vcp", guth_vcp, "Guth Visual Comfort Probability"}, |
| 36 |
> |
{"cie_cgi", cie_cgi, "CIE Glare Index (Einhorn)"}, |
| 37 |
> |
{"guth_dgr", guth_dgr, "Guth Disability Glare Rating"}, |
| 38 |
> |
{"vert_dir", direct, "Direct Vertical Illuminance"}, |
| 39 |
> |
{"vert_ill", total, "Total Vertical Illuminance"}, |
| 40 |
> |
{"vert_ind", indirect, "Indirect Vertical Illuminance"}, |
| 41 |
|
{NULL} |
| 42 |
|
}; |
| 43 |
|
|
| 98 |
|
perror(argv[i]); |
| 99 |
|
exit(1); |
| 100 |
|
} |
| 101 |
< |
/* read header */ |
| 94 |
< |
getheader(stdin, headline, NULL); |
| 95 |
< |
if (wrongformat) { |
| 96 |
< |
fprintf(stderr, "%s: bad input format\n", progname); |
| 97 |
< |
exit(1); |
| 98 |
< |
} |
| 99 |
< |
if (print_header) { /* add to header */ |
| 100 |
< |
printargs(i, argv, stdout); |
| 101 |
< |
putchar('\n'); |
| 102 |
< |
} |
| 103 |
< |
/* set view */ |
| 104 |
< |
if (setview(&midview) != NULL) { |
| 105 |
< |
fprintf(stderr, "%s: bad view information in input\n", |
| 106 |
< |
progname); |
| 107 |
< |
exit(1); |
| 108 |
< |
} |
| 109 |
< |
/* get findglare data */ |
| 110 |
< |
read_input(); |
| 111 |
< |
/* find calculation */ |
| 101 |
> |
/* find and run calculation */ |
| 102 |
|
for (funp = all_funcs; funp->name != NULL; funp++) |
| 103 |
|
if (!strcmp(funp->name, progtail)) { |
| 104 |
+ |
init(); |
| 105 |
+ |
read_input(); |
| 106 |
+ |
if (print_header) { |
| 107 |
+ |
printargs(i, argv, stdout); |
| 108 |
+ |
putchar('\n'); |
| 109 |
+ |
} |
| 110 |
|
print_values(funp->func); |
| 111 |
|
exit(0); /* we're done */ |
| 112 |
|
} |
| 113 |
|
/* invalid function */ |
| 118 |
– |
fprintf(stderr, "%s: unknown function!\n", progtail); |
| 119 |
– |
exit(1); |
| 114 |
|
userr: |
| 115 |
< |
fprintf(stderr, "Usage: %s [-t type][-h] [input]\n", progname); |
| 115 |
> |
fprintf(stderr, "Usage: %s -t type [-h] [input]\n", progname); |
| 116 |
> |
fprintf(stderr, "\twhere 'type' is one of the following:\n"); |
| 117 |
> |
for (funp = all_funcs; funp->name != NULL; funp++) |
| 118 |
> |
fprintf(stderr, "\t%12s\t%s\n", funp->name, funp->descrip); |
| 119 |
|
exit(1); |
| 120 |
|
} |
| 121 |
|
|
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
|
| 139 |
+ |
init() /* initialize calculation */ |
| 140 |
+ |
{ |
| 141 |
+ |
/* read header */ |
| 142 |
+ |
getheader(stdin, headline, NULL); |
| 143 |
+ |
if (wrongformat) { |
| 144 |
+ |
fprintf(stderr, "%s: bad input format\n", progname); |
| 145 |
+ |
exit(1); |
| 146 |
+ |
} |
| 147 |
+ |
/* set view */ |
| 148 |
+ |
if (setview(&midview) != NULL) { |
| 149 |
+ |
fprintf(stderr, "%s: bad view information in input\n", |
| 150 |
+ |
progname); |
| 151 |
+ |
exit(1); |
| 152 |
+ |
} |
| 153 |
+ |
} |
| 154 |
+ |
|
| 155 |
+ |
|
| 156 |
|
read_input() /* read glare sources from stdin */ |
| 157 |
|
{ |
| 158 |
|
#define S_SEARCH 0 |
| 225 |
|
|
| 226 |
|
|
| 227 |
|
double |
| 228 |
< |
direct(gd) /* compute direct illuminance */ |
| 228 |
> |
direct(gd) /* compute direct vertical illuminance */ |
| 229 |
|
struct glare_dir *gd; |
| 230 |
|
{ |
| 231 |
|
FVECT mydir; |
| 243 |
|
} |
| 244 |
|
|
| 245 |
|
|
| 246 |
+ |
double |
| 247 |
+ |
indirect(gd) /* return indirect vertical illuminance */ |
| 248 |
+ |
struct glare_dir *gd; |
| 249 |
+ |
{ |
| 250 |
+ |
return(gd->indirect); |
| 251 |
+ |
} |
| 252 |
+ |
|
| 253 |
+ |
|
| 254 |
+ |
double |
| 255 |
+ |
total(gd) /* return total vertical illuminance */ |
| 256 |
+ |
struct glare_dir *gd; |
| 257 |
+ |
{ |
| 258 |
+ |
return(direct(gd)+gd->indirect); |
| 259 |
+ |
} |
| 260 |
+ |
|
| 261 |
+ |
|
| 262 |
|
/* |
| 263 |
|
* posindex - compute glare position index from: |
| 264 |
|
* |
| 303 |
|
{ |
| 304 |
|
#define q(w) (20.4*w+1.52*pow(w,.2)-.075) |
| 305 |
|
register struct glare_src *gs; |
| 306 |
+ |
FVECT mydir; |
| 307 |
|
double p; |
| 308 |
|
double sum; |
| 309 |
|
double wtot, brsum; |
| 310 |
|
int n; |
| 311 |
|
|
| 312 |
+ |
spinvector(mydir, midview.vdir, midview.vup, gd->ang); |
| 313 |
|
sum = wtot = brsum = 0.0; n = 0; |
| 314 |
|
for (gs = all_srcs; gs != NULL; gs = gs->next) { |
| 315 |
< |
p = posindex(gs->dir, midview.vdir, midview.vup); |
| 315 |
> |
p = posindex(gs->dir, mydir, midview.vup); |
| 316 |
|
if (p <= FTINY) |
| 317 |
|
continue; |
| 318 |
|
sum += gs->lum * q(gs->dom) / p; |
| 322 |
|
} |
| 323 |
|
if (n == 0) |
| 324 |
|
return(0.0); |
| 325 |
< |
else |
| 326 |
< |
return( pow( |
| 295 |
< |
.5*sum/pow((brsum+(5.-wtot)*gd->indirect/PI)/5.,.44), |
| 325 |
> |
|
| 326 |
> |
return( pow(.5*sum/pow((brsum+(5.-wtot)*gd->indirect/PI)/5.,.44), |
| 327 |
|
pow((double)n, -.0914) ) ); |
| 328 |
|
#undef q |
| 329 |
|
} |
| 342 |
|
guth_vcp(gd) /* compute Guth visual comfort probability */ |
| 343 |
|
struct glare_dir *gd; |
| 344 |
|
{ |
| 345 |
< |
return(100.*norm_integral(6.374-1.3227*log(guth_dgr(gd)))); |
| 345 |
> |
double dgr; |
| 346 |
> |
|
| 347 |
> |
dgr = guth_dgr(gd); |
| 348 |
> |
if (dgr <= FTINY) |
| 349 |
> |
return(100.0); |
| 350 |
> |
return(100.*norm_integral(6.374-1.3227*log(dgr))); |
| 351 |
> |
} |
| 352 |
> |
|
| 353 |
> |
|
| 354 |
> |
double |
| 355 |
> |
cie_cgi(gd) /* compute CIE Glare Index */ |
| 356 |
> |
struct glare_dir *gd; |
| 357 |
> |
{ |
| 358 |
> |
register struct glare_src *gs; |
| 359 |
> |
FVECT mydir; |
| 360 |
> |
double dillum; |
| 361 |
> |
double p; |
| 362 |
> |
double sum; |
| 363 |
> |
|
| 364 |
> |
spinvector(mydir, midview.vdir, midview.vup, gd->ang); |
| 365 |
> |
sum = 0.0; |
| 366 |
> |
for (gs = all_srcs; gs != NULL; gs = gs->next) { |
| 367 |
> |
p = posindex(gs->dir, mydir, midview.vup); |
| 368 |
> |
if (p <= FTINY) |
| 369 |
> |
continue; |
| 370 |
> |
sum += gs->lum*gs->lum * gs->dom / (p*p); |
| 371 |
> |
} |
| 372 |
> |
if (sum <= FTINY) |
| 373 |
> |
return(0.0); |
| 374 |
> |
dillum = direct(gd); |
| 375 |
> |
return(8.*log10(2.*sum*(1.+dillum/500.)/(dillum+gd->indirect))); |
| 376 |
|
} |