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 |
|
|
39 |
|
/* default values */ |
40 |
|
int cloudy = 0; /* 1=standard, 2=uniform */ |
41 |
|
int dosun = 1; |
42 |
< |
double zenithbr = -1.0; |
42 |
> |
double zenithbr = 0.0; |
43 |
> |
int u_zenith = 0; /* -1=irradiance, 1=radiance */ |
44 |
|
double turbidity = 2.75; |
45 |
|
double gprefl = 0.2; |
46 |
|
/* computed values */ |
47 |
|
double sundir[3]; |
48 |
|
double groundbr; |
49 |
|
double F2; |
50 |
< |
double solarbr; |
50 |
> |
double solarbr = 0.0; |
51 |
> |
int u_solar = 0; /* -1=irradiance, 1=radiance */ |
52 |
|
|
53 |
|
char *progname; |
54 |
|
char errmsg[128]; |
90 |
|
cloudy = 0; |
91 |
|
dosun = argv[i][0] == '+'; |
92 |
|
break; |
93 |
+ |
case 'r': |
94 |
+ |
case 'R': |
95 |
+ |
u_solar = argv[i][1]=='R' ? -1 : 1; |
96 |
+ |
solarbr = atof(argv[++i]); |
97 |
+ |
break; |
98 |
|
case 'c': |
99 |
|
cloudy = argv[i][0] == '+' ? 2 : 1; |
100 |
|
dosun = 0; |
103 |
|
turbidity = atof(argv[++i]); |
104 |
|
break; |
105 |
|
case 'b': |
106 |
+ |
case 'B': |
107 |
+ |
u_zenith = argv[i][1]=='B' ? -1 : 1; |
108 |
|
zenithbr = atof(argv[++i]); |
109 |
|
break; |
110 |
|
case 'g': |
140 |
|
|
141 |
|
computesky() /* compute sky parameters */ |
142 |
|
{ |
143 |
+ |
double normfactor; |
144 |
|
/* compute solar direction */ |
145 |
|
if (month) { /* from date and time */ |
146 |
|
int jd; |
154 |
|
st = hour + stadj(jd); |
155 |
|
altitude = salt(sd, st); |
156 |
|
azimuth = sazi(sd, st); |
157 |
+ |
printf("# Solar altitude and azimuth: %f %f\n", |
158 |
+ |
180./PI*altitude, 180./PI*azimuth); |
159 |
|
} |
160 |
+ |
if (!cloudy && altitude > 87.*PI/180.) { |
161 |
+ |
fprintf(stderr, |
162 |
+ |
"%s: warning - sun too close to zenith, reducing altitude to 87 degrees\n", |
163 |
+ |
progname); |
164 |
+ |
printf( |
165 |
+ |
"# warning - sun too close to zenith, reducing altitude to 87 degrees\n"); |
166 |
+ |
altitude = 87.*PI/180.; |
167 |
+ |
} |
168 |
|
sundir[0] = -sin(azimuth)*cos(altitude); |
169 |
|
sundir[1] = -cos(azimuth)*cos(altitude); |
170 |
|
sundir[2] = sin(altitude); |
171 |
|
|
172 |
+ |
/* Compute normalization factor */ |
173 |
+ |
if (cloudy == 2) |
174 |
+ |
normfactor = 1.0; |
175 |
+ |
else if (cloudy == 1) |
176 |
+ |
normfactor = 0.777778; |
177 |
+ |
else { |
178 |
+ |
F2 = 0.274*(0.91 + 10.0*exp(-3.0*(PI/2.0-altitude)) + |
179 |
+ |
0.45*sundir[2]*sundir[2]); |
180 |
+ |
normfactor = normsc(altitude)/F2/PI; |
181 |
+ |
} |
182 |
|
/* Compute zenith brightness */ |
183 |
< |
if (zenithbr <= 0.0) |
184 |
< |
if (cloudy) { |
183 |
> |
if (u_zenith == -1) |
184 |
> |
zenithbr /= normfactor*PI; |
185 |
> |
else if (u_zenith == 0) { |
186 |
> |
if (cloudy) |
187 |
|
zenithbr = 8.6*sundir[2] + .123; |
188 |
< |
zenithbr *= 1000.0/WHTEFFICACY; |
160 |
< |
} else { |
188 |
> |
else |
189 |
|
zenithbr = (1.376*turbidity-1.81)*tan(altitude)+0.38; |
190 |
< |
zenithbr *= 1000.0/SKYEFFICACY; |
191 |
< |
} |
164 |
< |
if (zenithbr < 0.0) |
165 |
< |
zenithbr = 0.0; |
166 |
< |
/* Compute horizontal radiance */ |
167 |
< |
if (cloudy) { |
168 |
< |
if (cloudy == 2) |
169 |
< |
groundbr = zenithbr; |
190 |
> |
if (zenithbr < 0.0) |
191 |
> |
zenithbr = 0.0; |
192 |
|
else |
193 |
< |
groundbr = zenithbr*0.777778; |
172 |
< |
printf("# Ground ambient level: %f\n", groundbr); |
173 |
< |
} else { |
174 |
< |
F2 = 0.274*(0.91 + 10.0*exp(-3.0*(PI/2.0-altitude)) + |
175 |
< |
0.45*sundir[2]*sundir[2]); |
176 |
< |
groundbr = zenithbr*normsc(altitude)/F2/PI; |
177 |
< |
printf("# Ground ambient level: %f\n", groundbr); |
178 |
< |
if (sundir[2] > 0.0) { |
179 |
< |
if (sundir[2] > .16) |
180 |
< |
solarbr = (1.5e9/SUNEFFICACY) * |
181 |
< |
(1.147 - .147/sundir[2]); |
182 |
< |
else |
183 |
< |
solarbr = 1.5e9/SUNEFFICACY*(1.147-.147/.16); |
184 |
< |
groundbr += solarbr*6e-5*sundir[2]/PI; |
185 |
< |
} else |
186 |
< |
dosun = 0; |
193 |
> |
zenithbr *= 1000.0/SKYEFFICACY; |
194 |
|
} |
195 |
+ |
/* Compute horizontal radiance */ |
196 |
+ |
groundbr = zenithbr*normfactor; |
197 |
+ |
printf("# Ground ambient level: %f\n", groundbr); |
198 |
+ |
if (sundir[2] > 0.0 && (!u_solar || solarbr > 0.0)) { |
199 |
+ |
if (u_solar == -1) |
200 |
+ |
solarbr /= 6e-5*sundir[2]; |
201 |
+ |
else if (u_solar == 0) |
202 |
+ |
solarbr = 1.5e9/SUNEFFICACY * |
203 |
+ |
(1.147 - .147/(sundir[2]>.16?sundir[2]:.16)); |
204 |
+ |
groundbr += 6e-5/PI*solarbr*sundir[2]; |
205 |
+ |
} else |
206 |
+ |
dosun = 0; |
207 |
|
groundbr *= gprefl; |
208 |
|
} |
209 |
|
|