85 |
|
#include <stdlib.h> |
86 |
|
#include <string.h> |
87 |
|
#include <ctype.h> |
88 |
+ |
#include "platform.h" |
89 |
|
#include "rtmath.h" |
90 |
+ |
#include "rtio.h" |
91 |
|
#include "color.h" |
92 |
+ |
#include "sun.h" |
93 |
|
|
94 |
|
char *progname; /* Program name */ |
95 |
|
char errmsg[128]; /* Error message buffer */ |
111 |
|
double solar_rad; /* Solar radiance */ |
112 |
|
double sun_zenith; /* Sun zenith angle (radians) */ |
113 |
|
int input = 0; /* Input type */ |
114 |
+ |
int output = 0; /* Output type */ |
115 |
|
|
116 |
|
extern double dmax( double, double ); |
117 |
|
extern double CalcAirMass(); |
212 |
|
{ 1.950, 2.800 }, |
213 |
|
{ 2.800, 4.500 }, |
214 |
|
{ 4.500, 6.200 }, |
215 |
< |
{ 6.200, 12.00 } /* Clear */ |
215 |
> |
{ 6.200, 12.01 } /* Clear */ |
216 |
|
}; |
217 |
|
|
218 |
|
/* Luminous efficacy model coefficients */ |
250 |
|
{ 101.18, 1.58, -1.10, -8.29 } |
251 |
|
}; |
252 |
|
|
253 |
< |
extern int jdate(int month, int day); |
254 |
< |
extern double stadj(int jd); |
255 |
< |
extern double sdec(int jd); |
252 |
< |
extern double salt(double sd, double st); |
253 |
< |
extern double sazi(double sd, double st); |
254 |
< |
/* sun calculation constants */ |
255 |
< |
extern double s_latitude; |
256 |
< |
extern double s_longitude; |
257 |
< |
extern double s_meridian; |
253 |
> |
#ifndef NSUNPATCH |
254 |
> |
#define NSUNPATCH 4 /* max. # patches to spread sun into */ |
255 |
> |
#endif |
256 |
|
|
257 |
< |
double grefl = 0.2; /* diffuse ground reflectance */ |
257 |
> |
int nsuns = NSUNPATCH; /* number of sun patches to use */ |
258 |
> |
double fixed_sun_sa = -1; /* fixed solid angle per sun? */ |
259 |
|
|
260 |
|
int verbose = 0; /* progress reports to stderr? */ |
261 |
|
|
263 |
|
|
264 |
|
int rhsubdiv = 1; /* Reinhart sky subdivisions */ |
265 |
|
|
266 |
< |
float skycolor[3] = {.96, 1.004, 1.118}; /* sky coloration */ |
266 |
> |
COLOR skycolor = {.96, 1.004, 1.118}; /* sky coloration */ |
267 |
> |
COLOR suncolor = {1., 1., 1.}; /* sun color */ |
268 |
> |
COLOR grefl = {.2, .2, .2}; /* ground reflectance */ |
269 |
|
|
269 |
– |
int do_sun = 1; /* output direct solar contribution? */ |
270 |
– |
|
270 |
|
int nskypatch; /* number of Reinhart patches */ |
271 |
|
float *rh_palt; /* sky patch altitudes (radians) */ |
272 |
|
float *rh_pazi; /* sky patch azimuths (radians) */ |
285 |
|
extern float * resize_dmatrix(float *mtx_data, int nsteps, int npatch); |
286 |
|
extern void AddDirect(float *parr); |
287 |
|
|
288 |
+ |
|
289 |
+ |
static const char * |
290 |
+ |
getfmtname(int fmt) |
291 |
+ |
{ |
292 |
+ |
switch (fmt) { |
293 |
+ |
case 'a': |
294 |
+ |
return("ascii"); |
295 |
+ |
case 'f': |
296 |
+ |
return("float"); |
297 |
+ |
case 'd': |
298 |
+ |
return("double"); |
299 |
+ |
} |
300 |
+ |
return("unknown"); |
301 |
+ |
} |
302 |
+ |
|
303 |
+ |
|
304 |
|
int |
305 |
|
main(int argc, char *argv[]) |
306 |
|
{ |
307 |
|
char buf[256]; |
308 |
+ |
int doheader = 1; /* output header? */ |
309 |
+ |
double rotation = 0; /* site rotation (degrees) */ |
310 |
|
double elevation; /* site elevation (meters) */ |
311 |
|
int dir_is_horiz; /* direct is meas. on horizontal? */ |
312 |
|
float *mtx_data = NULL; /* our matrix data */ |
313 |
< |
int ntsteps = 0; /* number of rows in matrix */ |
313 |
> |
int avgSky = 0; /* compute average sky r.t. matrix? */ |
314 |
> |
int ntsteps = 0; /* number of time steps */ |
315 |
> |
int tstorage = 0; /* number of allocated time steps */ |
316 |
> |
int nstored = 0; /* number of time steps in matrix */ |
317 |
|
int last_monthly = 0; /* month of last report */ |
318 |
+ |
int inconsistent = 0; /* inconsistent options set? */ |
319 |
|
int mo, da; /* month (1-12) and day (1-31) */ |
320 |
|
double hr; /* hour (local standard time) */ |
321 |
|
double dir, dif; /* direct and diffuse values */ |
326 |
|
/* get options */ |
327 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
328 |
|
switch (argv[i][1]) { |
329 |
< |
case 'g': |
330 |
< |
grefl = atof(argv[++i]); |
329 |
> |
case 'g': /* ground reflectance */ |
330 |
> |
grefl[0] = atof(argv[++i]); |
331 |
> |
grefl[1] = atof(argv[++i]); |
332 |
> |
grefl[2] = atof(argv[++i]); |
333 |
|
break; |
334 |
< |
case 'v': |
334 |
> |
case 'v': /* verbose progress reports */ |
335 |
|
verbose++; |
336 |
|
break; |
337 |
< |
case 'o': |
337 |
> |
case 'h': /* turn off header */ |
338 |
> |
doheader = 0; |
339 |
> |
break; |
340 |
> |
case 'o': /* output format */ |
341 |
|
switch (argv[i][2]) { |
342 |
|
case 'f': |
343 |
|
case 'd': |
348 |
|
goto userr; |
349 |
|
} |
350 |
|
break; |
351 |
< |
case 'm': |
351 |
> |
case 'O': /* output type */ |
352 |
> |
switch (argv[i][2]) { |
353 |
> |
case '0': |
354 |
> |
output = 0; |
355 |
> |
break; |
356 |
> |
case '1': |
357 |
> |
output = 1; |
358 |
> |
break; |
359 |
> |
default: |
360 |
> |
goto userr; |
361 |
> |
} |
362 |
> |
if (argv[i][3]) |
363 |
> |
goto userr; |
364 |
> |
break; |
365 |
> |
case 'm': /* Reinhart subdivisions */ |
366 |
|
rhsubdiv = atoi(argv[++i]); |
367 |
|
break; |
368 |
< |
case 'c': |
368 |
> |
case 'c': /* sky color */ |
369 |
> |
inconsistent |= (skycolor[1] <= 1e-4); |
370 |
|
skycolor[0] = atof(argv[++i]); |
371 |
|
skycolor[1] = atof(argv[++i]); |
372 |
|
skycolor[2] = atof(argv[++i]); |
373 |
|
break; |
374 |
< |
case 'd': |
334 |
< |
do_sun = 1; |
374 |
> |
case 'd': /* solar (direct) only */ |
375 |
|
skycolor[0] = skycolor[1] = skycolor[2] = 0; |
376 |
+ |
if (suncolor[1] <= 1e-4) { |
377 |
+ |
inconsistent = 1; |
378 |
+ |
suncolor[0] = suncolor[1] = suncolor[2] = 1; |
379 |
+ |
} |
380 |
|
break; |
381 |
< |
case 's': |
382 |
< |
do_sun = 0; |
383 |
< |
if (skycolor[1] <= 1e-4) |
381 |
> |
case 's': /* sky only (no direct) */ |
382 |
> |
suncolor[0] = suncolor[1] = suncolor[2] = 0; |
383 |
> |
if (skycolor[1] <= 1e-4) { |
384 |
> |
inconsistent = 1; |
385 |
|
skycolor[0] = skycolor[1] = skycolor[2] = 1; |
386 |
+ |
} |
387 |
|
break; |
388 |
+ |
case 'r': /* rotate distribution */ |
389 |
+ |
if (argv[i][2] && argv[i][2] != 'z') |
390 |
+ |
goto userr; |
391 |
+ |
rotation = atof(argv[++i]); |
392 |
+ |
break; |
393 |
+ |
case '5': /* 5-phase calculation */ |
394 |
+ |
nsuns = 1; |
395 |
+ |
fixed_sun_sa = PI/360.*atof(argv[++i]); |
396 |
+ |
if (fixed_sun_sa <= 0) { |
397 |
+ |
fprintf(stderr, "%s: missing solar disk size argument for '-5' option\n", |
398 |
+ |
argv[0]); |
399 |
+ |
exit(1); |
400 |
+ |
} |
401 |
+ |
fixed_sun_sa *= fixed_sun_sa*PI; |
402 |
+ |
break; |
403 |
+ |
case 'A': /* compute average sky */ |
404 |
+ |
avgSky = 1; |
405 |
+ |
break; |
406 |
|
default: |
407 |
|
goto userr; |
408 |
|
} |
409 |
|
if (i < argc-1) |
410 |
|
goto userr; |
411 |
+ |
if (inconsistent) |
412 |
+ |
fprintf(stderr, "%s: WARNING: inconsistent -s, -d, -c options!\n", |
413 |
+ |
progname); |
414 |
|
if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
415 |
|
fprintf(stderr, "%s: cannot open '%s' for input\n", |
416 |
|
progname, argv[i]); |
460 |
|
progname, s_latitude, s_longitude); |
461 |
|
fprintf(stderr, "%s: %d sky patches per time step\n", |
462 |
|
progname, nskypatch); |
463 |
+ |
if (rotation != 0) |
464 |
+ |
fprintf(stderr, "%s: rotating output %.0f degrees\n", |
465 |
+ |
progname, rotation); |
466 |
|
} |
467 |
|
/* convert quantities to radians */ |
468 |
|
s_latitude = DegToRad(s_latitude); |
469 |
|
s_longitude = DegToRad(s_longitude); |
470 |
|
s_meridian = DegToRad(s_meridian); |
471 |
+ |
/* initial allocation */ |
472 |
+ |
mtx_data = resize_dmatrix(mtx_data, tstorage=2, nskypatch); |
473 |
|
/* process each time step in tape */ |
474 |
|
while (scanf("%d %d %lf %lf %lf\n", &mo, &da, &hr, &dir, &dif) == 5) { |
475 |
|
double sda, sta; |
476 |
< |
/* make space for next time step */ |
477 |
< |
mtx_offset = 3*nskypatch*ntsteps++; |
478 |
< |
mtx_data = resize_dmatrix(mtx_data, ntsteps, nskypatch); |
476 |
> |
|
477 |
> |
mtx_offset = 3*nskypatch*nstored; |
478 |
> |
nstored += !avgSky | !nstored; |
479 |
> |
/* make space for next row */ |
480 |
> |
if (nstored > tstorage) { |
481 |
> |
tstorage += (tstorage>>1) + nstored + 7; |
482 |
> |
mtx_data = resize_dmatrix(mtx_data, tstorage, nskypatch); |
483 |
> |
} |
484 |
> |
ntsteps++; /* keep count of time steps */ |
485 |
|
if (dif <= 1e-4) { |
486 |
< |
memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch); |
486 |
> |
if (!avgSky | !mtx_offset) |
487 |
> |
memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch); |
488 |
|
continue; |
489 |
|
} |
490 |
|
if (verbose && mo != last_monthly) |
495 |
|
sda = sdec(julian_date); |
496 |
|
sta = stadj(julian_date); |
497 |
|
altitude = salt(sda, hr+sta); |
498 |
< |
azimuth = sazi(sda, hr+sta) + PI; |
498 |
> |
azimuth = sazi(sda, hr+sta) + PI - DegToRad(rotation); |
499 |
|
/* convert measured values */ |
500 |
|
if (dir_is_horiz && altitude > 0.) |
501 |
|
dir /= sin(altitude); |
508 |
|
} |
509 |
|
/* compute sky patch values */ |
510 |
|
ComputeSky(mtx_data+mtx_offset); |
511 |
< |
if (do_sun) |
512 |
< |
AddDirect(mtx_data+mtx_offset); |
511 |
> |
AddDirect(mtx_data+mtx_offset); |
512 |
> |
/* update cumulative sky? */ |
513 |
> |
for (i = 3*nskypatch*(avgSky&(ntsteps>1)); i--; ) |
514 |
> |
mtx_data[i] += mtx_data[mtx_offset+i]; |
515 |
|
} |
516 |
|
/* check for junk at end */ |
517 |
|
while ((i = fgetc(stdin)) != EOF) |
523 |
|
fputs(buf, stderr); fputc('\n', stderr); |
524 |
|
break; |
525 |
|
} |
526 |
+ |
if (!ntsteps) { |
527 |
+ |
fprintf(stderr, "%s: no valid time steps on input\n", progname); |
528 |
+ |
exit(1); |
529 |
+ |
} |
530 |
+ |
dif = 1./(double)ntsteps; /* average sky? */ |
531 |
+ |
for (i = 3*nskypatch*(avgSky&(ntsteps>1)); i--; ) |
532 |
+ |
mtx_data[i] *= dif; |
533 |
|
/* write out matrix */ |
534 |
+ |
if (outfmt != 'a') |
535 |
+ |
SET_FILE_BINARY(stdout); |
536 |
|
#ifdef getc_unlocked |
537 |
|
flockfile(stdout); |
538 |
|
#endif |
539 |
|
if (verbose) |
540 |
|
fprintf(stderr, "%s: writing %smatrix with %d time steps...\n", |
541 |
< |
progname, outfmt=='a' ? "" : "binary ", ntsteps); |
541 |
> |
progname, outfmt=='a' ? "" : "binary ", nstored); |
542 |
> |
if (doheader) { |
543 |
> |
newheader("RADIANCE", stdout); |
544 |
> |
printargs(argc, argv, stdout); |
545 |
> |
printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude), |
546 |
> |
-RadToDeg(s_longitude)); |
547 |
> |
printf("NROWS=%d\n", nskypatch); |
548 |
> |
printf("NCOLS=%d\n", nstored); |
549 |
> |
printf("NCOMP=3\n"); |
550 |
> |
if ((outfmt == 'f') | (outfmt == 'd')) |
551 |
> |
fputendian(stdout); |
552 |
> |
fputformat((char *)getfmtname(outfmt), stdout); |
553 |
> |
putchar('\n'); |
554 |
> |
} |
555 |
|
/* patches are rows (outer sort) */ |
556 |
|
for (i = 0; i < nskypatch; i++) { |
557 |
|
mtx_offset = 3*i; |
558 |
|
switch (outfmt) { |
559 |
|
case 'a': |
560 |
< |
for (j = 0; j < ntsteps; j++) { |
561 |
< |
printf("%.3e %.3e %.3e\n", mtx_data[mtx_offset], |
560 |
> |
for (j = 0; j < nstored; j++) { |
561 |
> |
printf("%.3g %.3g %.3g\n", mtx_data[mtx_offset], |
562 |
|
mtx_data[mtx_offset+1], |
563 |
|
mtx_data[mtx_offset+2]); |
564 |
|
mtx_offset += 3*nskypatch; |
565 |
|
} |
566 |
< |
if (ntsteps > 1) |
566 |
> |
if (nstored > 1) |
567 |
|
fputc('\n', stdout); |
568 |
|
break; |
569 |
|
case 'f': |
570 |
< |
for (j = 0; j < ntsteps; j++) { |
571 |
< |
fwrite(mtx_data+mtx_offset, sizeof(float), 3, |
570 |
> |
for (j = 0; j < nstored; j++) { |
571 |
> |
putbinary(mtx_data+mtx_offset, sizeof(float), 3, |
572 |
|
stdout); |
573 |
|
mtx_offset += 3*nskypatch; |
574 |
|
} |
575 |
|
break; |
576 |
|
case 'd': |
577 |
< |
for (j = 0; j < ntsteps; j++) { |
577 |
> |
for (j = 0; j < nstored; j++) { |
578 |
|
double ment[3]; |
579 |
|
ment[0] = mtx_data[mtx_offset]; |
580 |
|
ment[1] = mtx_data[mtx_offset+1]; |
581 |
|
ment[2] = mtx_data[mtx_offset+2]; |
582 |
< |
fwrite(ment, sizeof(double), 3, stdout); |
582 |
> |
putbinary(ment, sizeof(double), 3, stdout); |
583 |
|
mtx_offset += 3*nskypatch; |
584 |
|
} |
585 |
|
break; |
593 |
|
fprintf(stderr, "%s: done.\n", progname); |
594 |
|
exit(0); |
595 |
|
userr: |
596 |
< |
fprintf(stderr, "Usage: %s [-v][-d|-s][-m N][-g refl][-c r g b][-o{f|d}] [tape.wea]\n", |
596 |
> |
fprintf(stderr, "Usage: %s [-v][-h][-A][-d|-s][-r deg][-m N][-g r g b][-c r g b][-o{f|d}][-O{0|1}] [tape.wea]\n", |
597 |
|
progname); |
598 |
|
exit(1); |
599 |
|
fmterr: |
614 |
|
{ |
615 |
|
int index; /* Category index */ |
616 |
|
double norm_diff_illum; /* Normalized diffuse illuimnance */ |
514 |
– |
double zlumin; /* Zenith luminance */ |
617 |
|
int i; |
618 |
|
|
619 |
|
/* Calculate atmospheric precipitable water content */ |
620 |
|
apwc = CalcPrecipWater(dew_point); |
621 |
|
|
622 |
< |
/* Limit solar altitude to keep circumsolar off zenith */ |
623 |
< |
if (altitude > DegToRad(87.0)) |
624 |
< |
altitude = DegToRad(87.0); |
622 |
> |
/* Calculate sun zenith angle (don't let it dip below horizon) */ |
623 |
> |
/* Also limit minimum angle to keep circumsolar off zenith */ |
624 |
> |
if (altitude <= 0.0) |
625 |
> |
sun_zenith = DegToRad(90.0); |
626 |
> |
else if (altitude >= DegToRad(87.0)) |
627 |
> |
sun_zenith = DegToRad(3.0); |
628 |
> |
else |
629 |
> |
sun_zenith = DegToRad(90.0) - altitude; |
630 |
|
|
524 |
– |
/* Calculate sun zenith angle */ |
525 |
– |
sun_zenith = DegToRad(90.0) - altitude; |
526 |
– |
|
631 |
|
/* Compute the inputs for the calculation of the sky distribution */ |
632 |
|
|
633 |
|
if (input == 0) /* XXX never used */ |
646 |
|
sky_brightness = CalcSkyBrightness(); |
647 |
|
sky_clearness = CalcSkyClearness(); |
648 |
|
|
649 |
+ |
/* Limit sky clearness */ |
650 |
+ |
if (sky_clearness > 11.9) |
651 |
+ |
sky_clearness = 11.9; |
652 |
+ |
|
653 |
+ |
/* Limit sky brightness */ |
654 |
+ |
if (sky_brightness < 0.01) |
655 |
+ |
sky_brightness = 0.01; |
656 |
+ |
|
657 |
|
/* Calculate illuminance */ |
658 |
|
index = GetCategoryIndex(); |
659 |
|
diff_illum = diff_irrad * CalcDiffuseIllumRatio(index); |
665 |
|
index = CalcSkyParamFromIllum(); |
666 |
|
} |
667 |
|
|
668 |
+ |
if (output == 1) { /* hack for solar radiance */ |
669 |
+ |
diff_illum = diff_irrad * WHTEFFICACY; |
670 |
+ |
dir_illum = dir_irrad * WHTEFFICACY; |
671 |
+ |
} |
672 |
+ |
|
673 |
|
if (bright(skycolor) <= 1e-4) { /* 0 sky component? */ |
674 |
|
memset(parr, 0, sizeof(float)*3*nskypatch); |
675 |
|
return; |
676 |
|
} |
677 |
|
/* Compute ground radiance (include solar contribution if any) */ |
678 |
< |
parr[0] = diff_illum * (1./PI/WHTEFFICACY); |
678 |
> |
parr[0] = diff_illum; |
679 |
|
if (altitude > 0) |
680 |
< |
parr[0] += dir_illum * sin(altitude) * (1./PI/WHTEFFICACY); |
681 |
< |
parr[2] = parr[1] = parr[0]; |
680 |
> |
parr[0] += dir_illum * sin(altitude); |
681 |
> |
parr[2] = parr[1] = parr[0] *= (1./PI/WHTEFFICACY); |
682 |
> |
multcolor(parr, grefl); |
683 |
|
|
684 |
|
/* Calculate Perez sky model parameters */ |
685 |
|
CalcPerezParam(sun_zenith, sky_clearness, sky_brightness, index); |
690 |
|
/* Calculate relative horizontal illuminance */ |
691 |
|
norm_diff_illum = CalcRelHorzIllum(parr); |
692 |
|
|
693 |
+ |
/* Check for zero sky -- make uniform in that case */ |
694 |
+ |
if (norm_diff_illum <= FTINY) { |
695 |
+ |
for (i = 1; i < nskypatch; i++) |
696 |
+ |
setcolor(parr+3*i, 1., 1., 1.); |
697 |
+ |
norm_diff_illum = PI; |
698 |
+ |
} |
699 |
|
/* Normalization coefficient */ |
700 |
|
norm_diff_illum = diff_illum / norm_diff_illum; |
701 |
|
|
578 |
– |
/* Calculate relative zenith luminance */ |
579 |
– |
zlumin = CalcRelLuminance(sun_zenith, 0.0); |
580 |
– |
|
581 |
– |
/* Calculate absolute zenith illuminance */ |
582 |
– |
zlumin *= norm_diff_illum; |
583 |
– |
|
702 |
|
/* Apply to sky patches to get absolute radiance values */ |
703 |
|
for (i = 1; i < nskypatch; i++) { |
704 |
< |
scalecolor(parr+3*i, zlumin*(1./WHTEFFICACY)); |
704 |
> |
scalecolor(parr+3*i, norm_diff_illum*(1./WHTEFFICACY)); |
705 |
|
multcolor(parr+3*i, skycolor); |
706 |
|
} |
707 |
|
} |
711 |
|
AddDirect(float *parr) |
712 |
|
{ |
713 |
|
FVECT svec; |
714 |
< |
double near_dprod[4]; |
715 |
< |
int near_patch[4]; |
716 |
< |
double wta[4], wtot; |
714 |
> |
double near_dprod[NSUNPATCH]; |
715 |
> |
int near_patch[NSUNPATCH]; |
716 |
> |
double wta[NSUNPATCH], wtot; |
717 |
|
int i, j, p; |
718 |
|
|
719 |
< |
if (!do_sun || dir_illum < 1e-4) |
719 |
> |
if (dir_illum <= 1e-4 || bright(suncolor) <= 1e-4) |
720 |
|
return; |
721 |
< |
/* identify 4 closest patches */ |
722 |
< |
for (i = 4; i--; ) |
721 |
> |
/* identify nsuns closest patches */ |
722 |
> |
if (nsuns > NSUNPATCH) |
723 |
> |
nsuns = NSUNPATCH; |
724 |
> |
else if (nsuns <= 0) |
725 |
> |
nsuns = 1; |
726 |
> |
for (i = nsuns; i--; ) |
727 |
|
near_dprod[i] = -1.; |
728 |
|
vector(svec, altitude, azimuth); |
729 |
|
for (p = 1; p < nskypatch; p++) { |
731 |
|
double dprod; |
732 |
|
rh_vector(pvec, p); |
733 |
|
dprod = DOT(pvec, svec); |
734 |
< |
for (i = 0; i < 4; i++) |
734 |
> |
for (i = 0; i < nsuns; i++) |
735 |
|
if (dprod > near_dprod[i]) { |
736 |
< |
for (j = 4; --j > i; ) { |
736 |
> |
for (j = nsuns; --j > i; ) { |
737 |
|
near_dprod[j] = near_dprod[j-1]; |
738 |
|
near_patch[j] = near_patch[j-1]; |
739 |
|
} |
743 |
|
} |
744 |
|
} |
745 |
|
wtot = 0; /* weight by proximity */ |
746 |
< |
for (i = 4; i--; ) |
746 |
> |
for (i = nsuns; i--; ) |
747 |
|
wtot += wta[i] = 1./(1.002 - near_dprod[i]); |
748 |
|
/* add to nearest patch radiances */ |
749 |
< |
for (i = 4; i--; ) { |
749 |
> |
for (i = nsuns; i--; ) { |
750 |
|
float *pdest = parr + 3*near_patch[i]; |
751 |
< |
float val_add = wta[i] * dir_illum / |
752 |
< |
(WHTEFFICACY * wtot * rh_dom[near_patch[i]]); |
753 |
< |
*pdest++ += val_add; |
754 |
< |
*pdest++ += val_add; |
755 |
< |
*pdest++ += val_add; |
751 |
> |
float val_add = wta[i] * dir_illum / (WHTEFFICACY * wtot); |
752 |
> |
|
753 |
> |
val_add /= (fixed_sun_sa > 0) ? fixed_sun_sa |
754 |
> |
: rh_dom[near_patch[i]] ; |
755 |
> |
*pdest++ += val_add*suncolor[0]; |
756 |
> |
*pdest++ += val_add*suncolor[1]; |
757 |
> |
*pdest++ += val_add*suncolor[2]; |
758 |
|
} |
759 |
|
} |
760 |
|
|
789 |
|
for (i = 0; i < NROW*rhsubdiv; i++) { |
790 |
|
const float ralt = alpha*(i + .5); |
791 |
|
const int ninrow = tnaz[i/rhsubdiv]*rhsubdiv; |
792 |
< |
const float dom = (sin(alpha*(i+1)) - sin(alpha*i))/ninrow; |
792 |
> |
const float dom = 2.*PI*(sin(alpha*(i+1)) - sin(alpha*i)) / |
793 |
> |
(double)ninrow; |
794 |
|
for (j = 0; j < ninrow; j++) { |
795 |
|
rh_palt[p] = ralt; |
796 |
|
rh_pazi[p] = 2.*PI * j / (double)ninrow; |
895 |
|
double sz_cubed; /* Sun zenith angle cubed */ |
896 |
|
|
897 |
|
/* Calculate sun zenith angle cubed */ |
898 |
< |
sz_cubed = pow(sun_zenith, 3.0); |
898 |
> |
sz_cubed = sun_zenith*sun_zenith*sun_zenith; |
899 |
|
|
900 |
|
return ((diff_irrad + dir_irrad) / diff_irrad + 1.041 * |
901 |
|
sz_cubed) / (1.0 + 1.041 * sz_cubed); |
926 |
|
double CalcDirectIrradiance() |
927 |
|
{ |
928 |
|
return CalcDiffuseIrradiance() * ((sky_clearness - 1.0) * (1 + 1.041 |
929 |
< |
* pow(sun_zenith, 3.0))); |
929 |
> |
* sun_zenith*sun_zenith*sun_zenith)); |
930 |
|
} |
931 |
|
|
932 |
|
/* Calculate sky brightness and clearness from illuminance values */ |
952 |
|
sky_clearness = 12.0; |
953 |
|
|
954 |
|
/* Limit sky brightness */ |
955 |
< |
if (sky_brightness < 0.05) |
955 |
> |
if (sky_brightness < 0.01) |
956 |
|
sky_brightness = 0.01; |
957 |
|
|
958 |
|
while (((fabs(diff_irrad - test1) > 10.0) || |
965 |
|
/* Convert illuminance to irradiance */ |
966 |
|
index = GetCategoryIndex(); |
967 |
|
diff_irrad = diff_illum / CalcDiffuseIllumRatio(index); |
968 |
< |
dir_irrad = dir_illum / CalcDirectIllumRatio(index); |
968 |
> |
dir_irrad = CalcDirectIllumRatio(index); |
969 |
> |
if (dir_irrad > 0.1) |
970 |
> |
dir_irrad = dir_illum / dir_irrad; |
971 |
|
|
972 |
|
/* Calculate sky brightness and clearness */ |
973 |
|
sky_brightness = CalcSkyBrightness(); |
978 |
|
sky_clearness = 12.0; |
979 |
|
|
980 |
|
/* Limit sky brightness */ |
981 |
< |
if (sky_brightness < 0.05) |
981 |
> |
if (sky_brightness < 0.01) |
982 |
|
sky_brightness = 0.01; |
983 |
|
} |
984 |
|
|
1064 |
|
double rh_illum = 0.0; /* Relative horizontal illuminance */ |
1065 |
|
|
1066 |
|
for (i = 1; i < nskypatch; i++) |
1067 |
< |
rh_illum += parr[3*i+1] * rh_cos(i); |
1067 |
> |
rh_illum += parr[3*i+1] * rh_cos(i) * rh_dom[i]; |
1068 |
|
|
1069 |
< |
return rh_illum * (2.0 * PI / (nskypatch-1)); |
1069 |
> |
return rh_illum; |
1070 |
|
} |
1071 |
|
|
1072 |
|
/* Calculate earth orbit eccentricity correction factor */ |