135 |
|
/* Radiuans into degrees */ |
136 |
|
#define RadToDeg(rad) ((rad)*(180./PI)) |
137 |
|
|
138 |
– |
|
138 |
|
/* Perez sky model coefficients */ |
139 |
|
|
140 |
|
/* Reference: Perez, R., R. Seals, and J. Michalsky, 1993. "All- */ |
311 |
|
double rotation = 0; /* site rotation (degrees) */ |
312 |
|
double elevation; /* site elevation (meters) */ |
313 |
|
int leap_day = 0; /* add leap day? */ |
314 |
+ |
int sun_hours_only = 0; /* only output sun hours? */ |
315 |
|
int dir_is_horiz; /* direct is meas. on horizontal? */ |
316 |
|
FILE *sunsfp = NULL; /* output file for individual suns */ |
317 |
|
FILE *modsfp = NULL; /* modifier output file */ |
406 |
|
case 's': /* sky only (no direct) */ |
407 |
|
suncolor[0] = suncolor[1] = suncolor[2] = 0; |
408 |
|
break; |
409 |
+ |
case 'u': /* solar hours only */ |
410 |
+ |
sun_hours_only = 1; |
411 |
+ |
break; |
412 |
|
case 'r': /* rotate distribution */ |
413 |
|
if (argv[i][2] && argv[i][2] != 'z') |
414 |
|
goto userr; |
501 |
|
/* process each time step in tape */ |
502 |
|
while (scanf("%d %d %lf %lf %lf\n", &mo, &da, &hr, &dir, &dif) == 5) { |
503 |
|
double sda, sta; |
504 |
< |
|
502 |
< |
mtx_offset = 3*nskypatch*nstored; |
503 |
< |
nstored += !avgSky | !nstored; |
504 |
< |
/* make space for next row */ |
505 |
< |
if (nstored > tstorage) { |
506 |
< |
tstorage += (tstorage>>1) + nstored + 7; |
507 |
< |
mtx_data = resize_dmatrix(mtx_data, tstorage, nskypatch); |
508 |
< |
} |
509 |
< |
ntsteps++; /* keep count of time steps */ |
504 |
> |
int sun_in_sky; |
505 |
|
/* compute solar position */ |
506 |
|
if ((mo == 2) & (da == 29)) { |
507 |
|
julian_date = 60; |
511 |
|
sda = sdec(julian_date); |
512 |
|
sta = stadj(julian_date); |
513 |
|
altitude = salt(sda, hr+sta); |
514 |
+ |
sun_in_sky = (altitude > -DegToRad(SUN_ANG_DEG/2.)); |
515 |
+ |
if (sun_hours_only && !sun_in_sky) |
516 |
+ |
continue; /* skipping nighttime points */ |
517 |
|
azimuth = sazi(sda, hr+sta) + PI - DegToRad(rotation); |
518 |
|
|
519 |
+ |
mtx_offset = 3*nskypatch*nstored; |
520 |
+ |
nstored += !avgSky | !nstored; |
521 |
+ |
/* make space for next row */ |
522 |
+ |
if (nstored > tstorage) { |
523 |
+ |
tstorage += (tstorage>>1) + nstored + 7; |
524 |
+ |
mtx_data = resize_dmatrix(mtx_data, tstorage, nskypatch); |
525 |
+ |
} |
526 |
+ |
ntsteps++; /* keep count of time steps */ |
527 |
+ |
|
528 |
|
if (dir+dif <= 1e-4) { /* effectively nighttime? */ |
529 |
|
if (!avgSky | !mtx_offset) |
530 |
|
memset(mtx_data+mtx_offset, 0, |
531 |
|
sizeof(float)*3*nskypatch); |
532 |
< |
if (sunsfp) /* output black sun */ |
532 |
> |
/* output black sun? */ |
533 |
> |
if (sunsfp && sun_in_sky) |
534 |
|
OutputSun(solar_minute(julian_date,hr), 0, |
535 |
|
sunsfp, modsfp); |
536 |
|
continue; |
547 |
|
} |
548 |
|
/* compute sky patch values */ |
549 |
|
ComputeSky(mtx_data+mtx_offset); |
550 |
< |
|
551 |
< |
if (sunsfp) /* output sun if requested */ |
550 |
> |
/* output sun if requested */ |
551 |
> |
if (sunsfp && sun_in_sky) |
552 |
|
OutputSun(solar_minute(julian_date,hr), 1, |
553 |
|
sunsfp, modsfp); |
554 |
|
|
650 |
|
fprintf(stderr, "%s: done.\n", progname); |
651 |
|
exit(0); |
652 |
|
userr: |
653 |
< |
fprintf(stderr, "Usage: %s [-v][-h][-A][-d|-s|-n][-D file][-r deg][-m N][-g r g b][-c r g b][-o{f|d}][-O{0|1}] [tape.wea]\n", |
653 |
> |
fprintf(stderr, "Usage: %s [-v][-h][-A][-d|-s|-n][-u][-D file [-M modfile]][-r deg][-m N][-g r g b][-c r g b][-o{f|d}][-O{0|1}] [tape.wea]\n", |
654 |
|
progname); |
655 |
|
exit(1); |
656 |
|
fmterr: |
822 |
|
FVECT sv; |
823 |
|
|
824 |
|
srad = DegToRad(SUN_ANG_DEG/2.); |
817 |
– |
|
818 |
– |
if (altitude < -srad) /* well below horizon? */ |
819 |
– |
return; |
820 |
– |
|
825 |
|
srad = goodsun ? dir_illum/(WHTEFFICACY * PI*srad*srad) : 0; |
826 |
|
vector(sv, altitude, azimuth); |
827 |
|
fprintf(fp, "\nvoid light solar%d\n0\n0\n", id); |