19 |
|
|
20 |
|
#include "color.h" |
21 |
|
|
22 |
+ |
#ifndef atof |
23 |
+ |
extern double atof(); |
24 |
+ |
#endif |
25 |
|
extern char *strcpy(), *strcat(), *malloc(); |
26 |
|
extern double stadj(), sdec(), sazi(), salt(); |
27 |
|
|
35 |
|
extern double s_longitude; |
36 |
|
extern double s_meridian; |
37 |
|
/* required values */ |
38 |
< |
int month, day; |
39 |
< |
double hour; |
38 |
> |
int month, day; /* date */ |
39 |
> |
double hour; /* time */ |
40 |
> |
int tsolar; /* 0=standard, 1=solar */ |
41 |
> |
double altitude, azimuth; /* or solar angles */ |
42 |
|
/* default values */ |
43 |
< |
int cloudy = 0; |
43 |
> |
int cloudy = 0; /* 1=standard, 2=uniform */ |
44 |
|
int dosun = 1; |
45 |
|
double zenithbr = -1.0; |
46 |
|
double turbidity = 2.75; |
59 |
|
int argc; |
60 |
|
char *argv[]; |
61 |
|
{ |
62 |
< |
extern double atof(), fabs(); |
62 |
> |
extern double fabs(); |
63 |
|
int i; |
64 |
|
|
65 |
|
progname = argv[0]; |
69 |
|
} |
70 |
|
if (argc < 4) |
71 |
|
userror("arg count"); |
72 |
< |
month = atoi(argv[1]); |
73 |
< |
day = atoi(argv[2]); |
74 |
< |
hour = atof(argv[3]); |
72 |
> |
if (!strcmp(argv[1], "-ang")) { |
73 |
> |
altitude = atof(argv[2]) * (PI/180); |
74 |
> |
azimuth = atof(argv[3]) * (PI/180); |
75 |
> |
month = 0; |
76 |
> |
} else { |
77 |
> |
month = atoi(argv[1]); |
78 |
> |
if (month < 1 || month > 12) |
79 |
> |
userror("bad month"); |
80 |
> |
day = atoi(argv[2]); |
81 |
> |
if (day < 1 || day > 31) |
82 |
> |
userror("bad day"); |
83 |
> |
hour = atof(argv[3]); |
84 |
> |
if (hour < 0 || hour >= 24) |
85 |
> |
userror("bad hour"); |
86 |
> |
tsolar = argv[3][0] == '+'; |
87 |
> |
} |
88 |
|
for (i = 4; i < argc; i++) |
89 |
|
if (argv[i][0] == '-' || argv[i][0] == '+') |
90 |
|
switch (argv[i][1]) { |
93 |
|
dosun = argv[i][0] == '+'; |
94 |
|
break; |
95 |
|
case 'c': |
96 |
< |
cloudy = 1; |
96 |
> |
cloudy = argv[i][0] == '+' ? 2 : 1; |
97 |
|
dosun = 0; |
98 |
|
break; |
99 |
|
case 't': |
135 |
|
|
136 |
|
computesky() /* compute sky parameters */ |
137 |
|
{ |
120 |
– |
int jd; |
121 |
– |
double sd, st; |
122 |
– |
double altitude, azimuth; |
138 |
|
/* compute solar direction */ |
139 |
< |
jd = jdate(month, day); /* Julian date */ |
140 |
< |
sd = sdec(jd); /* solar declination */ |
141 |
< |
st = hour + stadj(jd); /* solar time */ |
142 |
< |
altitude = salt(sd, st); |
143 |
< |
azimuth = sazi(sd, st); |
139 |
> |
if (month) { /* from date and time */ |
140 |
> |
int jd; |
141 |
> |
double sd, st; |
142 |
> |
|
143 |
> |
jd = jdate(month, day); /* Julian date */ |
144 |
> |
sd = sdec(jd); /* solar declination */ |
145 |
> |
if (tsolar) /* solar time */ |
146 |
> |
st = hour; |
147 |
> |
else |
148 |
> |
st = hour + stadj(jd); |
149 |
> |
altitude = salt(sd, st); |
150 |
> |
azimuth = sazi(sd, st); |
151 |
> |
} |
152 |
|
sundir[0] = -sin(azimuth)*cos(altitude); |
153 |
|
sundir[1] = -cos(azimuth)*cos(altitude); |
154 |
|
sundir[2] = sin(altitude); |
157 |
|
if (zenithbr <= 0.0) |
158 |
|
if (cloudy) { |
159 |
|
zenithbr = 8.6*sundir[2] + .123; |
160 |
< |
zenithbr *= 1000.0/SKYEFFICACY; |
160 |
> |
zenithbr *= 1000.0/WHTEFFICACY; |
161 |
|
} else { |
162 |
|
zenithbr = (1.376*turbidity-1.81)*tan(altitude)+0.38; |
163 |
|
zenithbr *= 1000.0/SKYEFFICACY; |
166 |
|
zenithbr = 0.0; |
167 |
|
/* Compute horizontal radiance */ |
168 |
|
if (cloudy) { |
169 |
< |
groundbr = zenithbr*0.777778; |
169 |
> |
if (cloudy == 2) |
170 |
> |
groundbr = zenithbr; |
171 |
> |
else |
172 |
> |
groundbr = zenithbr*0.777778; |
173 |
|
printf("# Ground ambient level: %f\n", groundbr); |
174 |
|
} else { |
175 |
|
F2 = 0.274*(0.91 + 10.0*exp(-3.0*(PI/2.0-altitude)) + |
176 |
|
0.45*sundir[2]*sundir[2]); |
177 |
< |
groundbr = zenithbr*normsc(PI/2.0-altitude)/F2/PI; |
177 |
> |
groundbr = zenithbr*normsc(altitude)/F2/PI; |
178 |
|
printf("# Ground ambient level: %f\n", groundbr); |
179 |
|
if (sundir[2] > 0.0) { |
180 |
|
if (sundir[2] > .16) |
205 |
|
printf("2 skybright skybright.cal\n"); |
206 |
|
printf("0\n"); |
207 |
|
if (cloudy) |
208 |
< |
printf("3 1 %.2e %.2e\n", zenithbr, groundbr); |
208 |
> |
printf("3 %d %.2e %.2e\n", cloudy, zenithbr, groundbr); |
209 |
|
else |
210 |
|
printf("7 -1 %.2e %.2e %.2e %f %f %f\n", zenithbr, groundbr, |
211 |
|
F2, sundir[0], sundir[1], sundir[2]); |
214 |
|
|
215 |
|
printdefaults() /* print default values */ |
216 |
|
{ |
217 |
< |
if (cloudy) |
217 |
> |
if (cloudy == 1) |
218 |
|
printf("-c\t\t\t\t# Cloudy sky\n"); |
219 |
+ |
else if (cloudy == 2) |
220 |
+ |
printf("+c\t\t\t\t# Uniform cloudy sky\n"); |
221 |
|
else if (dosun) |
222 |
|
printf("+s\t\t\t\t# Sunny sky with sun\n"); |
223 |
|
else |
239 |
|
if (msg != NULL) |
240 |
|
fprintf(stderr, "%s: Use error - %s\n", progname, msg); |
241 |
|
fprintf(stderr, "Usage: %s month day hour [options]\n", progname); |
242 |
+ |
fprintf(stderr, " Or: %s -ang altitude azimuth [options]\n", progname); |
243 |
|
fprintf(stderr, " Or: %s -defaults\n", progname); |
244 |
|
exit(1); |
245 |
|
} |