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 */ |
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 |
|
} |
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]; |