246 |
|
{ 101.18, 1.58, -1.10, -8.29 } |
247 |
|
}; |
248 |
|
|
249 |
+ |
#ifndef NSUNPATCH |
250 |
+ |
#define NSUNPATCH 4 /* # patches to spread sun into */ |
251 |
+ |
#endif |
252 |
+ |
|
253 |
|
extern int jdate(int month, int day); |
254 |
|
extern double stadj(int jd); |
255 |
|
extern double sdec(int jd); |
362 |
|
progname); |
363 |
|
} |
364 |
|
/* read weather tape header */ |
365 |
< |
if (scanf("place %[^\n]\n", buf) != 1) |
365 |
> |
if (scanf("place %[^\r\n] ", buf) != 1) |
366 |
|
goto fmterr; |
367 |
|
if (scanf("latitude %lf\n", &s_latitude) != 1) |
368 |
|
goto fmterr; |
398 |
|
fprintf(stderr, "%s: %d sky patches per time step\n", |
399 |
|
progname, nskypatch); |
400 |
|
} |
401 |
+ |
/* convert quantities to radians */ |
402 |
+ |
s_latitude = DegToRad(s_latitude); |
403 |
+ |
s_longitude = DegToRad(s_longitude); |
404 |
+ |
s_meridian = DegToRad(s_meridian); |
405 |
|
/* process each time step in tape */ |
406 |
|
while (scanf("%d %d %lf %lf %lf\n", &mo, &da, &hr, &dir, &dif) == 5) { |
407 |
|
double sda, sta; |
420 |
|
sda = sdec(julian_date); |
421 |
|
sta = stadj(julian_date); |
422 |
|
altitude = salt(sda, hr+sta); |
423 |
< |
azimuth = sazi(sda, hr+sta); |
423 |
> |
azimuth = sazi(sda, hr+sta) + PI; |
424 |
|
/* convert measured values */ |
425 |
|
if (dir_is_horiz && altitude > 0.) |
426 |
|
dir /= sin(altitude); |
459 |
|
switch (outfmt) { |
460 |
|
case 'a': |
461 |
|
for (j = 0; j < ntsteps; j++) { |
462 |
< |
printf("%.3e %.3e %.3e\n", mtx_data[mtx_offset], |
462 |
> |
printf("%.3g %.3g %.3g\n", mtx_data[mtx_offset], |
463 |
|
mtx_data[mtx_offset+1], |
464 |
|
mtx_data[mtx_offset+2]); |
465 |
|
mtx_offset += 3*nskypatch; |
466 |
|
} |
467 |
< |
fputc('\n', stdout); |
467 |
> |
if (ntsteps > 1) |
468 |
> |
fputc('\n', stdout); |
469 |
|
break; |
470 |
|
case 'f': |
471 |
|
for (j = 0; j < ntsteps; j++) { |
517 |
|
double norm_diff_illum; /* Normalized diffuse illuimnance */ |
518 |
|
double zlumin; /* Zenith luminance */ |
519 |
|
int i; |
511 |
– |
|
512 |
– |
if (bright(skycolor) <= 1e-4) { /* 0 sky component? */ |
513 |
– |
memset(parr, 0, sizeof(float)*3*nskypatch); |
514 |
– |
return; |
515 |
– |
} |
520 |
|
|
521 |
|
/* Calculate atmospheric precipitable water content */ |
522 |
|
apwc = CalcPrecipWater(dew_point); |
557 |
|
index = CalcSkyParamFromIllum(); |
558 |
|
} |
559 |
|
|
560 |
+ |
if (bright(skycolor) <= 1e-4) { /* 0 sky component? */ |
561 |
+ |
memset(parr, 0, sizeof(float)*3*nskypatch); |
562 |
+ |
return; |
563 |
+ |
} |
564 |
|
/* Compute ground radiance (include solar contribution if any) */ |
565 |
< |
parr[0] = diff_illum * (1./PI/WHTEFFICACY); |
565 |
> |
parr[0] = diff_illum; |
566 |
|
if (altitude > 0) |
567 |
< |
parr[0] += dir_illum * sin(altitude) * (1./PI/WHTEFFICACY); |
568 |
< |
parr[2] = parr[1] = parr[0]; |
567 |
> |
parr[0] += dir_illum * sin(altitude); |
568 |
> |
parr[2] = parr[1] = parr[0] *= grefl*(1./PI/WHTEFFICACY); |
569 |
|
|
570 |
|
/* Calculate Perez sky model parameters */ |
571 |
|
CalcPerezParam(sun_zenith, sky_clearness, sky_brightness, index); |
597 |
|
AddDirect(float *parr) |
598 |
|
{ |
599 |
|
FVECT svec; |
600 |
< |
double near_dprod[4]; |
601 |
< |
int near_patch[4]; |
602 |
< |
double wta[4], wtot; |
600 |
> |
double near_dprod[NSUNPATCH]; |
601 |
> |
int near_patch[NSUNPATCH]; |
602 |
> |
double wta[NSUNPATCH], wtot; |
603 |
|
int i, j, p; |
604 |
|
|
605 |
|
if (!do_sun || dir_illum < 1e-4) |
606 |
|
return; |
607 |
< |
/* identify 4 closest patches */ |
608 |
< |
for (i = 4; i--; ) |
607 |
> |
/* identify NSUNPATCH closest patches */ |
608 |
> |
for (i = NSUNPATCH; i--; ) |
609 |
|
near_dprod[i] = -1.; |
610 |
|
vector(svec, altitude, azimuth); |
611 |
|
for (p = 1; p < nskypatch; p++) { |
613 |
|
double dprod; |
614 |
|
rh_vector(pvec, p); |
615 |
|
dprod = DOT(pvec, svec); |
616 |
< |
for (i = 0; i < 4; i++) |
616 |
> |
for (i = 0; i < NSUNPATCH; i++) |
617 |
|
if (dprod > near_dprod[i]) { |
618 |
< |
for (j = 4; --j > i; ) { |
618 |
> |
for (j = NSUNPATCH; --j > i; ) { |
619 |
|
near_dprod[j] = near_dprod[j-1]; |
620 |
|
near_patch[j] = near_patch[j-1]; |
621 |
|
} |
625 |
|
} |
626 |
|
} |
627 |
|
wtot = 0; /* weight by proximity */ |
628 |
< |
for (i = 4; i--; ) |
628 |
> |
for (i = NSUNPATCH; i--; ) |
629 |
|
wtot += wta[i] = 1./(1.002 - near_dprod[i]); |
630 |
|
/* add to nearest patch radiances */ |
631 |
< |
for (i = 4; i--; ) |
632 |
< |
parr[near_patch[i]] += wta[i] * dir_illum / |
633 |
< |
(wtot * rh_dom[near_patch[i]]); |
631 |
> |
for (i = NSUNPATCH; i--; ) { |
632 |
> |
float *pdest = parr + 3*near_patch[i]; |
633 |
> |
float val_add = wta[i] * dir_illum / |
634 |
> |
(WHTEFFICACY * wtot * rh_dom[near_patch[i]]); |
635 |
> |
*pdest++ += val_add; |
636 |
> |
*pdest++ += val_add; |
637 |
> |
*pdest++ += val_add; |
638 |
> |
} |
639 |
|
} |
640 |
|
|
641 |
|
/* Initialize Reinhart sky patch positions (GW) */ |
669 |
|
for (i = 0; i < NROW*rhsubdiv; i++) { |
670 |
|
const float ralt = alpha*(i + .5); |
671 |
|
const int ninrow = tnaz[i/rhsubdiv]*rhsubdiv; |
672 |
< |
const float dom = (sin(alpha*(i+1)) - sin(alpha*i))/ninrow; |
672 |
> |
const float dom = 2.*PI*(sin(alpha*(i+1)) - sin(alpha*i)) / |
673 |
> |
(double)ninrow; |
674 |
|
for (j = 0; j < ninrow; j++) { |
675 |
|
rh_palt[p] = ralt; |
676 |
|
rh_pazi[p] = 2.*PI * j / (double)ninrow; |