17 |
|
|
18 |
|
#include <math.h> |
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; /* standard time */ |
40 |
> |
double altitude, azimuth; /* or solar angles */ |
41 |
|
/* default values */ |
42 |
|
int cloudy = 0; |
43 |
|
int dosun = 1; |
58 |
|
int argc; |
59 |
|
char *argv[]; |
60 |
|
{ |
61 |
< |
extern double atof(); |
61 |
> |
extern double fabs(); |
62 |
|
int i; |
63 |
|
|
64 |
|
progname = argv[0]; |
68 |
|
} |
69 |
|
if (argc < 4) |
70 |
|
userror("arg count"); |
71 |
< |
month = atoi(argv[1]); |
72 |
< |
day = atoi(argv[2]); |
73 |
< |
hour = atof(argv[3]); |
71 |
> |
if (!strcmp(argv[1], "-ang")) { |
72 |
> |
altitude = atof(argv[2]) * (PI/180); |
73 |
> |
azimuth = atof(argv[3]) * (PI/180); |
74 |
> |
month = 0; |
75 |
> |
} else { |
76 |
> |
month = atoi(argv[1]); |
77 |
> |
day = atoi(argv[2]); |
78 |
> |
hour = atof(argv[3]); |
79 |
> |
} |
80 |
|
for (i = 4; i < argc; i++) |
81 |
|
if (argv[i][0] == '-' || argv[i][0] == '+') |
82 |
|
switch (argv[i][1]) { |
113 |
|
else |
114 |
|
userror("bad option"); |
115 |
|
|
116 |
+ |
if (fabs(s_meridian-s_longitude) > 30*PI/180) |
117 |
+ |
fprintf(stderr, |
118 |
+ |
"%s: warning: %.1f hours btwn. standard meridian and longitude\n", |
119 |
+ |
progname, (s_longitude-s_meridian)*12/PI); |
120 |
+ |
|
121 |
|
printhead(argc, argv); |
122 |
|
|
123 |
|
computesky(); |
127 |
|
|
128 |
|
computesky() /* compute sky parameters */ |
129 |
|
{ |
114 |
– |
int jd; |
115 |
– |
double sd, st; |
116 |
– |
double altitude, azimuth; |
130 |
|
/* compute solar direction */ |
131 |
< |
jd = jdate(month, day); /* Julian date */ |
132 |
< |
sd = sdec(jd); /* solar declination */ |
133 |
< |
st = hour + stadj(jd); /* solar time */ |
134 |
< |
altitude = salt(sd, st); |
135 |
< |
azimuth = sazi(sd, st); |
131 |
> |
if (month) { /* from date and time */ |
132 |
> |
int jd; |
133 |
> |
double sd, st; |
134 |
> |
|
135 |
> |
jd = jdate(month, day); /* Julian date */ |
136 |
> |
sd = sdec(jd); /* solar declination */ |
137 |
> |
st = hour + stadj(jd); /* solar time */ |
138 |
> |
altitude = salt(sd, st); |
139 |
> |
azimuth = sazi(sd, st); |
140 |
> |
} |
141 |
|
sundir[0] = -sin(azimuth)*cos(altitude); |
142 |
|
sundir[1] = -cos(azimuth)*cos(altitude); |
143 |
|
sundir[2] = sin(altitude); |
146 |
|
if (zenithbr <= 0.0) |
147 |
|
if (cloudy) { |
148 |
|
zenithbr = 8.6*sundir[2] + .123; |
149 |
< |
zenithbr *= 1000.0*.0064/3.; |
149 |
> |
zenithbr *= 1000.0/SKYEFFICACY; |
150 |
|
} else { |
151 |
|
zenithbr = (1.376*turbidity-1.81)*tan(altitude)+0.38; |
152 |
< |
zenithbr *= 1000.0*.0064/3.; |
152 |
> |
zenithbr *= 1000.0/SKYEFFICACY; |
153 |
|
} |
154 |
|
if (zenithbr < 0.0) |
155 |
|
zenithbr = 0.0; |
164 |
|
printf("# Ground ambient level: %f\n", groundbr); |
165 |
|
if (sundir[2] > 0.0) { |
166 |
|
if (sundir[2] > .16) |
167 |
< |
solarbr = 2.47e6 - 3.15e5/sundir[2]; |
167 |
> |
solarbr = (1.5e9/SUNEFFICACY) * |
168 |
> |
(1.147 - .147/sundir[2]); |
169 |
|
else |
170 |
< |
solarbr = 5e5; |
170 |
> |
solarbr = 1.5e9/SUNEFFICACY*(1.147-.147/.16); |
171 |
|
groundbr += solarbr*6e-5*sundir[2]/PI; |
172 |
|
} else |
173 |
|
dosun = 0; |
181 |
|
if (dosun) { |
182 |
|
printf("\nvoid light solar\n"); |
183 |
|
printf("0\n0\n"); |
184 |
< |
printf("3 %f %f %f\n", solarbr, solarbr, solarbr); |
184 |
> |
printf("3 %.2e %.2e %.2e\n", solarbr, solarbr, solarbr); |
185 |
|
printf("\nsolar source sun\n"); |
186 |
|
printf("0\n0\n"); |
187 |
|
printf("4 %f %f %f 0.5\n", sundir[0], sundir[1], sundir[2]); |
191 |
|
printf("2 skybright skybright.cal\n"); |
192 |
|
printf("0\n"); |
193 |
|
if (cloudy) |
194 |
< |
printf("3 1 %f %f\n", zenithbr, groundbr); |
194 |
> |
printf("3 1 %.2e %.2e\n", zenithbr, groundbr); |
195 |
|
else |
196 |
< |
printf("7 -1 %f %f %f %f %f %f\n", zenithbr, groundbr, F2, |
197 |
< |
sundir[0], sundir[1], sundir[2]); |
196 |
> |
printf("7 -1 %.2e %.2e %.2e %f %f %f\n", zenithbr, groundbr, |
197 |
> |
F2, sundir[0], sundir[1], sundir[2]); |
198 |
|
} |
199 |
|
|
200 |
|
|
223 |
|
if (msg != NULL) |
224 |
|
fprintf(stderr, "%s: Use error - %s\n", progname, msg); |
225 |
|
fprintf(stderr, "Usage: %s month day hour [options]\n", progname); |
226 |
+ |
fprintf(stderr, " Or: %s -ang altitude azimuth [options]\n", progname); |
227 |
|
fprintf(stderr, " Or: %s -defaults\n", progname); |
228 |
|
exit(1); |
229 |
|
} |