247 |
|
}; |
248 |
|
|
249 |
|
#ifndef NSUNPATCH |
250 |
< |
#define NSUNPATCH 4 /* # patches to spread sun into */ |
250 |
> |
#define NSUNPATCH 4 /* max. # patches to spread sun into */ |
251 |
|
#endif |
252 |
|
|
253 |
|
extern int jdate(int month, int day); |
260 |
|
extern double s_longitude; |
261 |
|
extern double s_meridian; |
262 |
|
|
263 |
+ |
int nsuns = NSUNPATCH; /* number of sun patches to use */ |
264 |
+ |
double fixed_sun_sa = -1; /* fixed solid angle per sun? */ |
265 |
+ |
|
266 |
|
int verbose = 0; /* progress reports to stderr? */ |
267 |
|
|
268 |
|
int outfmt = 'a'; /* output format */ |
295 |
|
main(int argc, char *argv[]) |
296 |
|
{ |
297 |
|
char buf[256]; |
298 |
+ |
double rotation = 0; /* site rotation (degrees) */ |
299 |
|
double elevation; /* site elevation (meters) */ |
300 |
|
int dir_is_horiz; /* direct is meas. on horizontal? */ |
301 |
|
float *mtx_data = NULL; /* our matrix data */ |
348 |
|
if (skycolor[1] <= 1e-4) |
349 |
|
skycolor[0] = skycolor[1] = skycolor[2] = 1; |
350 |
|
break; |
351 |
+ |
case 'r': /* rotate distribution */ |
352 |
+ |
if (argv[i][2] && argv[i][2] != 'z') |
353 |
+ |
goto userr; |
354 |
+ |
rotation = atof(argv[++i]); |
355 |
+ |
break; |
356 |
+ |
case '5': /* 5-phase calculation */ |
357 |
+ |
nsuns = 1; |
358 |
+ |
fixed_sun_sa = 6.797e-05; |
359 |
+ |
break; |
360 |
|
default: |
361 |
|
goto userr; |
362 |
|
} |
411 |
|
progname, s_latitude, s_longitude); |
412 |
|
fprintf(stderr, "%s: %d sky patches per time step\n", |
413 |
|
progname, nskypatch); |
414 |
+ |
if (rotation != 0) |
415 |
+ |
fprintf(stderr, "%s: rotating output %.0f degrees\n", |
416 |
+ |
progname, rotation); |
417 |
|
} |
418 |
|
/* convert quantities to radians */ |
419 |
|
s_latitude = DegToRad(s_latitude); |
437 |
|
sda = sdec(julian_date); |
438 |
|
sta = stadj(julian_date); |
439 |
|
altitude = salt(sda, hr+sta); |
440 |
< |
azimuth = sazi(sda, hr+sta) + PI; |
440 |
> |
azimuth = sazi(sda, hr+sta) + PI - DegToRad(rotation); |
441 |
|
/* convert measured values */ |
442 |
|
if (dir_is_horiz && altitude > 0.) |
443 |
|
dir /= sin(altitude); |
510 |
|
fprintf(stderr, "%s: done.\n", progname); |
511 |
|
exit(0); |
512 |
|
userr: |
513 |
< |
fprintf(stderr, "Usage: %s [-v][-d|-s][-m N][-g r g b][-c r g b][-o{f|d}] [tape.wea]\n", |
513 |
> |
fprintf(stderr, "Usage: %s [-v][-d|-s][-r deg][-m N][-g r g b][-c r g b][-o{f|d}] [tape.wea]\n", |
514 |
|
progname); |
515 |
|
exit(1); |
516 |
|
fmterr: |
531 |
|
{ |
532 |
|
int index; /* Category index */ |
533 |
|
double norm_diff_illum; /* Normalized diffuse illuimnance */ |
518 |
– |
double zlumin; /* Zenith luminance */ |
534 |
|
int i; |
535 |
|
|
536 |
|
/* Calculate atmospheric precipitable water content */ |
563 |
|
sky_brightness = CalcSkyBrightness(); |
564 |
|
sky_clearness = CalcSkyClearness(); |
565 |
|
|
566 |
+ |
/* Limit sky clearness */ |
567 |
+ |
if (sky_clearness > 11.9) |
568 |
+ |
sky_clearness = 11.9; |
569 |
+ |
|
570 |
+ |
/* Limit sky brightness */ |
571 |
+ |
if (sky_brightness < 0.01) |
572 |
+ |
sky_brightness = 0.01; |
573 |
+ |
|
574 |
|
/* Calculate illuminance */ |
575 |
|
index = GetCategoryIndex(); |
576 |
|
diff_illum = diff_irrad * CalcDiffuseIllumRatio(index); |
605 |
|
/* Normalization coefficient */ |
606 |
|
norm_diff_illum = diff_illum / norm_diff_illum; |
607 |
|
|
585 |
– |
/* Calculate relative zenith luminance */ |
586 |
– |
zlumin = CalcRelLuminance(sun_zenith, 0.0); |
587 |
– |
|
588 |
– |
/* Calculate absolute zenith illuminance */ |
589 |
– |
zlumin *= norm_diff_illum; |
590 |
– |
|
608 |
|
/* Apply to sky patches to get absolute radiance values */ |
609 |
|
for (i = 1; i < nskypatch; i++) { |
610 |
< |
scalecolor(parr+3*i, zlumin*(1./WHTEFFICACY)); |
610 |
> |
scalecolor(parr+3*i, norm_diff_illum*(1./WHTEFFICACY)); |
611 |
|
multcolor(parr+3*i, skycolor); |
612 |
|
} |
613 |
|
} |
624 |
|
|
625 |
|
if (dir_illum <= 1e-4 || bright(suncolor) <= 1e-4) |
626 |
|
return; |
627 |
< |
/* identify NSUNPATCH closest patches */ |
628 |
< |
for (i = NSUNPATCH; i--; ) |
627 |
> |
/* identify nsuns closest patches */ |
628 |
> |
if (nsuns > NSUNPATCH) |
629 |
> |
nsuns = NSUNPATCH; |
630 |
> |
else if (nsuns <= 0) |
631 |
> |
nsuns = 1; |
632 |
> |
for (i = nsuns; i--; ) |
633 |
|
near_dprod[i] = -1.; |
634 |
|
vector(svec, altitude, azimuth); |
635 |
|
for (p = 1; p < nskypatch; p++) { |
637 |
|
double dprod; |
638 |
|
rh_vector(pvec, p); |
639 |
|
dprod = DOT(pvec, svec); |
640 |
< |
for (i = 0; i < NSUNPATCH; i++) |
640 |
> |
for (i = 0; i < nsuns; i++) |
641 |
|
if (dprod > near_dprod[i]) { |
642 |
< |
for (j = NSUNPATCH; --j > i; ) { |
642 |
> |
for (j = nsuns; --j > i; ) { |
643 |
|
near_dprod[j] = near_dprod[j-1]; |
644 |
|
near_patch[j] = near_patch[j-1]; |
645 |
|
} |
649 |
|
} |
650 |
|
} |
651 |
|
wtot = 0; /* weight by proximity */ |
652 |
< |
for (i = NSUNPATCH; i--; ) |
652 |
> |
for (i = nsuns; i--; ) |
653 |
|
wtot += wta[i] = 1./(1.002 - near_dprod[i]); |
654 |
|
/* add to nearest patch radiances */ |
655 |
< |
for (i = NSUNPATCH; i--; ) { |
655 |
> |
for (i = nsuns; i--; ) { |
656 |
|
float *pdest = parr + 3*near_patch[i]; |
657 |
< |
float val_add = wta[i] * dir_illum / |
658 |
< |
(WHTEFFICACY * wtot * rh_dom[near_patch[i]]); |
657 |
> |
float val_add = wta[i] * dir_illum / (WHTEFFICACY * wtot); |
658 |
> |
|
659 |
> |
val_add /= (fixed_sun_sa > 0) ? fixed_sun_sa |
660 |
> |
: rh_dom[near_patch[i]] ; |
661 |
|
*pdest++ += val_add*suncolor[0]; |
662 |
|
*pdest++ += val_add*suncolor[1]; |
663 |
|
*pdest++ += val_add*suncolor[2]; |
858 |
|
sky_clearness = 12.0; |
859 |
|
|
860 |
|
/* Limit sky brightness */ |
861 |
< |
if (sky_brightness < 0.05) |
861 |
> |
if (sky_brightness < 0.01) |
862 |
|
sky_brightness = 0.01; |
863 |
|
|
864 |
|
while (((fabs(diff_irrad - test1) > 10.0) || |
882 |
|
sky_clearness = 12.0; |
883 |
|
|
884 |
|
/* Limit sky brightness */ |
885 |
< |
if (sky_brightness < 0.05) |
885 |
> |
if (sky_brightness < 0.01) |
886 |
|
sky_brightness = 0.01; |
887 |
|
} |
888 |
|
|
968 |
|
double rh_illum = 0.0; /* Relative horizontal illuminance */ |
969 |
|
|
970 |
|
for (i = 1; i < nskypatch; i++) |
971 |
< |
rh_illum += parr[3*i+1] * rh_cos(i); |
971 |
> |
rh_illum += parr[3*i+1] * rh_cos(i) * rh_dom[i]; |
972 |
|
|
973 |
< |
return rh_illum * (2.0 * PI / (nskypatch-1)); |
973 |
> |
return rh_illum; |
974 |
|
} |
975 |
|
|
976 |
|
/* Calculate earth orbit eccentricity correction factor */ |