1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
19 |
|
|
20 |
|
#include "color.h" |
21 |
|
|
22 |
– |
#ifndef atof |
23 |
– |
extern double atof(); |
24 |
– |
#endif |
22 |
|
extern char *strcpy(), *strcat(), *malloc(); |
23 |
|
extern double stadj(), sdec(), sazi(), salt(); |
24 |
|
|
33 |
|
extern double s_meridian; |
34 |
|
/* required values */ |
35 |
|
int month, day; /* date */ |
36 |
< |
double hour; /* standard time */ |
36 |
> |
double hour; /* time */ |
37 |
> |
int tsolar; /* 0=standard, 1=solar */ |
38 |
|
double altitude, azimuth; /* or solar angles */ |
39 |
|
/* default values */ |
40 |
|
int cloudy = 0; /* 1=standard, 2=uniform */ |
46 |
|
double sundir[3]; |
47 |
|
double groundbr; |
48 |
|
double F2; |
49 |
< |
double solarbr; |
49 |
> |
double solarbr = -1.0; |
50 |
|
|
51 |
|
char *progname; |
52 |
|
char errmsg[128]; |
56 |
|
int argc; |
57 |
|
char *argv[]; |
58 |
|
{ |
61 |
– |
extern double fabs(); |
59 |
|
int i; |
60 |
|
|
61 |
|
progname = argv[0]; |
71 |
|
month = 0; |
72 |
|
} else { |
73 |
|
month = atoi(argv[1]); |
74 |
+ |
if (month < 1 || month > 12) |
75 |
+ |
userror("bad month"); |
76 |
|
day = atoi(argv[2]); |
77 |
+ |
if (day < 1 || day > 31) |
78 |
+ |
userror("bad day"); |
79 |
|
hour = atof(argv[3]); |
80 |
+ |
if (hour < 0 || hour >= 24) |
81 |
+ |
userror("bad hour"); |
82 |
+ |
tsolar = argv[3][0] == '+'; |
83 |
|
} |
84 |
|
for (i = 4; i < argc; i++) |
85 |
|
if (argv[i][0] == '-' || argv[i][0] == '+') |
88 |
|
cloudy = 0; |
89 |
|
dosun = argv[i][0] == '+'; |
90 |
|
break; |
91 |
+ |
case 'r': |
92 |
+ |
solarbr = atof(argv[++i]); |
93 |
+ |
break; |
94 |
|
case 'c': |
95 |
|
cloudy = argv[i][0] == '+' ? 2 : 1; |
96 |
|
dosun = 0; |
141 |
|
|
142 |
|
jd = jdate(month, day); /* Julian date */ |
143 |
|
sd = sdec(jd); /* solar declination */ |
144 |
< |
st = hour + stadj(jd); /* solar time */ |
144 |
> |
if (tsolar) /* solar time */ |
145 |
> |
st = hour; |
146 |
> |
else |
147 |
> |
st = hour + stadj(jd); |
148 |
|
altitude = salt(sd, st); |
149 |
|
azimuth = sazi(sd, st); |
150 |
+ |
printf("# Solar altitude and azimuth: %f %f\n", |
151 |
+ |
180./PI*altitude, 180./PI*azimuth); |
152 |
|
} |
153 |
+ |
if (!cloudy && altitude > 87.*PI/180.) { |
154 |
+ |
fprintf(stderr, |
155 |
+ |
"%s: warning - sun too close to zenith, reducing altitude to 87 degrees\n", |
156 |
+ |
progname); |
157 |
+ |
printf( |
158 |
+ |
"# warning - sun too close to zenith, reducing altitude to 87 degrees\n"); |
159 |
+ |
altitude = 87.*PI/180.; |
160 |
+ |
} |
161 |
|
sundir[0] = -sin(azimuth)*cos(altitude); |
162 |
|
sundir[1] = -cos(azimuth)*cos(altitude); |
163 |
|
sundir[2] = sin(altitude); |
166 |
|
if (zenithbr <= 0.0) |
167 |
|
if (cloudy) { |
168 |
|
zenithbr = 8.6*sundir[2] + .123; |
169 |
< |
zenithbr *= 1000.0/SKYEFFICACY; |
169 |
> |
zenithbr *= 1000.0/WHTEFFICACY; |
170 |
|
} else { |
171 |
|
zenithbr = (1.376*turbidity-1.81)*tan(altitude)+0.38; |
172 |
|
zenithbr *= 1000.0/SKYEFFICACY; |
183 |
|
} else { |
184 |
|
F2 = 0.274*(0.91 + 10.0*exp(-3.0*(PI/2.0-altitude)) + |
185 |
|
0.45*sundir[2]*sundir[2]); |
186 |
< |
groundbr = zenithbr*normsc(PI/2.0-altitude)/F2/PI; |
186 |
> |
groundbr = zenithbr*normsc(altitude)/F2/PI; |
187 |
|
printf("# Ground ambient level: %f\n", groundbr); |
188 |
< |
if (sundir[2] > 0.0) { |
189 |
< |
if (sundir[2] > .16) |
190 |
< |
solarbr = (1.5e9/SUNEFFICACY) * |
191 |
< |
(1.147 - .147/sundir[2]); |
172 |
< |
else |
173 |
< |
solarbr = 1.5e9/SUNEFFICACY*(1.147-.147/.16); |
188 |
> |
if (sundir[2] > 0.0 && solarbr != 0.0) { |
189 |
> |
if (solarbr < 0.0) |
190 |
> |
solarbr = 1.5e9/SUNEFFICACY * |
191 |
> |
(1.147 - .147/(sundir[2]>.16?sundir[2]:.16)); |
192 |
|
groundbr += solarbr*6e-5*sundir[2]/PI; |
193 |
|
} else |
194 |
|
dosun = 0; |