15 |
|
#include <string.h> |
16 |
|
#include <math.h> |
17 |
|
#include <ctype.h> |
18 |
< |
|
18 |
> |
#include "sun.h" |
19 |
|
#include "color.h" |
20 |
|
|
21 |
– |
extern int jdate(int month, int day); |
22 |
– |
extern double stadj(int jd); |
23 |
– |
extern double sdec(int jd); |
24 |
– |
extern double salt(double sd, double st); |
25 |
– |
extern double sazi(double sd, double st); |
26 |
– |
|
21 |
|
#ifndef PI |
22 |
|
#define PI 3.14159265358979323846 |
23 |
|
#endif |
32 |
|
#define overcast ((skytype==S_OVER)|(skytype==S_UNIF)) |
33 |
|
|
34 |
|
double normsc(); |
41 |
– |
/* sun calculation constants */ |
42 |
– |
extern double s_latitude; |
43 |
– |
extern double s_longitude; |
44 |
– |
extern double s_meridian; |
35 |
|
|
36 |
|
#undef toupper |
37 |
|
#define toupper(c) ((c) & ~0x20) /* ASCII trick to convert case */ |
59 |
|
{"", 0} |
60 |
|
}; |
61 |
|
/* required values */ |
62 |
+ |
int year = 0; /* year (optional) */ |
63 |
|
int month, day; /* date */ |
64 |
|
double hour; /* time */ |
65 |
|
int tsolar; /* 0=standard, 1=solar */ |
69 |
|
int dosun = 1; |
70 |
|
double zenithbr = 0.0; |
71 |
|
int u_zenith = 0; /* -1=irradiance, 1=radiance */ |
72 |
< |
double turbidity = 2.75; |
72 |
> |
double turbidity = 2.45; |
73 |
|
double gprefl = 0.2; |
74 |
|
/* computed values */ |
75 |
|
double sundir[3]; |
87 |
|
void userror(char *msg); |
88 |
|
double normsc(void); |
89 |
|
int cvthour(char *hs); |
90 |
< |
void printhead(register int ac, register char **av); |
90 |
> |
void printhead(int ac, char **av); |
91 |
|
|
92 |
|
|
93 |
|
int |
94 |
< |
main(argc, argv) |
95 |
< |
int argc; |
96 |
< |
char *argv[]; |
94 |
> |
main( |
95 |
> |
int argc, |
96 |
> |
char *argv[] |
97 |
> |
) |
98 |
|
{ |
99 |
|
int got_meridian = 0; |
100 |
|
int i; |
126 |
|
skytype = S_CLEAR; |
127 |
|
dosun = argv[i][0] == '+'; |
128 |
|
break; |
129 |
+ |
case 'y': |
130 |
+ |
year = atoi(argv[++i]); |
131 |
+ |
break; |
132 |
|
case 'r': |
133 |
|
case 'R': |
134 |
|
u_solar = argv[i][1]=='R' ? -1 : 1; |
175 |
|
else |
176 |
|
userror("bad option"); |
177 |
|
|
178 |
< |
if (fabs(s_meridian-s_longitude) > 45*PI/180) |
178 |
> |
if (year && (year < 1950) | (year > 2050)) |
179 |
|
fprintf(stderr, |
180 |
< |
"%s: warning: %.1f hours btwn. standard meridian and longitude\n", |
180 |
> |
"%s: warning - year should be in range 1950-2050\n", |
181 |
> |
progname); |
182 |
> |
if (month && !tsolar && fabs(s_meridian-s_longitude) > 45*PI/180) |
183 |
> |
fprintf(stderr, |
184 |
> |
"%s: warning - %.1f hours btwn. standard meridian and longitude\n", |
185 |
|
progname, (s_longitude-s_meridian)*12/PI); |
186 |
|
|
187 |
|
printhead(argc, argv); |
199 |
|
double normfactor; |
200 |
|
/* compute solar direction */ |
201 |
|
if (month) { /* from date and time */ |
202 |
< |
int jd; |
204 |
< |
double sd, st; |
202 |
> |
double sd, st = hour; |
203 |
|
|
204 |
< |
jd = jdate(month, day); /* Julian date */ |
205 |
< |
sd = sdec(jd); /* solar declination */ |
206 |
< |
if (tsolar) /* solar time */ |
207 |
< |
st = hour; |
208 |
< |
else |
209 |
< |
st = hour + stadj(jd); |
204 |
> |
if (year) { /* Michalsky algorithm? */ |
205 |
> |
double mjd = mjdate(year, month, day, hour); |
206 |
> |
if (tsolar) |
207 |
> |
sd = msdec(mjd, NULL); |
208 |
> |
else |
209 |
> |
sd = msdec(mjd, &st); |
210 |
> |
} else { |
211 |
> |
int jd = jdate(month, day); /* Julian date */ |
212 |
> |
sd = sdec(jd); /* solar declination */ |
213 |
> |
if (!tsolar) /* get solar time? */ |
214 |
> |
st = hour + stadj(jd); |
215 |
> |
} |
216 |
|
altitude = salt(sd, st); |
217 |
|
azimuth = sazi(sd, st); |
218 |
|
printf("# Local solar time: %.2f\n", st); |
365 |
|
/* intermediate sky approx. */ |
366 |
|
{3.5556, -2.7152, -1.3081, 1.0660, 0.60227}, |
367 |
|
}; |
368 |
< |
register double *nf; |
368 |
> |
double *nf; |
369 |
|
double x, nsc; |
370 |
< |
register int i; |
370 |
> |
int i; |
371 |
|
/* polynomial approximation */ |
372 |
|
nf = nfc[skytype==S_INTER]; |
373 |
|
x = (altitude - PI/4.0)/(PI/4.0); |
384 |
|
char *hs |
385 |
|
) |
386 |
|
{ |
387 |
< |
register char *cp = hs; |
388 |
< |
register int i, j; |
387 |
> |
char *cp = hs; |
388 |
> |
int i, j; |
389 |
|
|
390 |
|
if ( (tsolar = *cp == '+') ) cp++; /* solar time? */ |
391 |
|
while (isdigit(*cp)) cp++; |
424 |
|
|
425 |
|
void |
426 |
|
printhead( /* print command header */ |
427 |
< |
register int ac, |
428 |
< |
register char **av |
427 |
> |
int ac, |
428 |
> |
char **av |
429 |
|
) |
430 |
|
{ |
431 |
|
putchar('#'); |