10 |
|
* 3/26/86 |
11 |
|
*/ |
12 |
|
|
13 |
< |
#include <stdio.h> |
13 |
> |
#include "rtio.h" |
14 |
|
#include <stdlib.h> |
15 |
– |
#include <string.h> |
15 |
|
#include <math.h> |
16 |
|
#include <ctype.h> |
17 |
< |
|
17 |
> |
#include "sun.h" |
18 |
|
#include "color.h" |
19 |
|
|
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 |
– |
|
20 |
|
#ifndef PI |
21 |
|
#define PI 3.14159265358979323846 |
22 |
|
#endif |
31 |
|
#define overcast ((skytype==S_OVER)|(skytype==S_UNIF)) |
32 |
|
|
33 |
|
double normsc(); |
41 |
– |
/* sun calculation constants */ |
42 |
– |
extern double s_latitude; |
43 |
– |
extern double s_longitude; |
44 |
– |
extern double s_meridian; |
34 |
|
|
35 |
|
#undef toupper |
36 |
|
#define toupper(c) ((c) & ~0x20) /* ASCII trick to convert case */ |
58 |
|
{"", 0} |
59 |
|
}; |
60 |
|
/* required values */ |
61 |
+ |
int year = 0; /* year (optional) */ |
62 |
|
int month, day; /* date */ |
63 |
|
double hour; /* time */ |
64 |
|
int tsolar; /* 0=standard, 1=solar */ |
86 |
|
void userror(char *msg); |
87 |
|
double normsc(void); |
88 |
|
int cvthour(char *hs); |
99 |
– |
void printhead(register int ac, register char **av); |
89 |
|
|
90 |
|
|
91 |
|
int |
92 |
< |
main(argc, argv) |
93 |
< |
int argc; |
94 |
< |
char *argv[]; |
92 |
> |
main( |
93 |
> |
int argc, |
94 |
> |
char *argv[] |
95 |
> |
) |
96 |
|
{ |
97 |
|
int got_meridian = 0; |
98 |
|
int i; |
124 |
|
skytype = S_CLEAR; |
125 |
|
dosun = argv[i][0] == '+'; |
126 |
|
break; |
127 |
+ |
case 'y': |
128 |
+ |
year = atoi(argv[++i]); |
129 |
+ |
break; |
130 |
|
case 'r': |
131 |
|
case 'R': |
132 |
|
u_solar = argv[i][1]=='R' ? -1 : 1; |
173 |
|
else |
174 |
|
userror("bad option"); |
175 |
|
|
176 |
+ |
if (year && (year < 1950) | (year > 2050)) |
177 |
+ |
fprintf(stderr, |
178 |
+ |
"%s: warning - year should be in range 1950-2050\n", |
179 |
+ |
progname); |
180 |
|
if (month && !tsolar && fabs(s_meridian-s_longitude) > 45*PI/180) |
181 |
|
fprintf(stderr, |
182 |
|
"%s: warning - %.1f hours btwn. standard meridian and longitude\n", |
183 |
|
progname, (s_longitude-s_meridian)*12/PI); |
184 |
|
|
185 |
< |
printhead(argc, argv); |
185 |
> |
fputs("# ", stdout); |
186 |
> |
printargs(argc, argv, stdout); |
187 |
|
|
188 |
|
computesky(); |
189 |
|
printsky(); |
198 |
|
double normfactor; |
199 |
|
/* compute solar direction */ |
200 |
|
if (month) { /* from date and time */ |
201 |
< |
int jd; |
204 |
< |
double sd, st; |
201 |
> |
double sd, st = hour; |
202 |
|
|
203 |
< |
jd = jdate(month, day); /* Julian date */ |
204 |
< |
sd = sdec(jd); /* solar declination */ |
205 |
< |
if (tsolar) /* solar time */ |
206 |
< |
st = hour; |
207 |
< |
else |
208 |
< |
st = hour + stadj(jd); |
203 |
> |
if (year) { /* Michalsky algorithm? */ |
204 |
> |
double mjd = mjdate(year, month, day, hour); |
205 |
> |
if (tsolar) |
206 |
> |
sd = msdec(mjd, NULL); |
207 |
> |
else |
208 |
> |
sd = msdec(mjd, &st); |
209 |
> |
} else { |
210 |
> |
int jd = jdate(month, day); /* Julian date */ |
211 |
> |
sd = sdec(jd); /* solar declination */ |
212 |
> |
if (!tsolar) /* get solar time? */ |
213 |
> |
st = hour + stadj(jd); |
214 |
> |
} |
215 |
|
altitude = salt(sd, st); |
216 |
|
azimuth = sazi(sd, st); |
217 |
|
printf("# Local solar time: %.2f\n", st); |
364 |
|
/* intermediate sky approx. */ |
365 |
|
{3.5556, -2.7152, -1.3081, 1.0660, 0.60227}, |
366 |
|
}; |
367 |
< |
register double *nf; |
367 |
> |
double *nf; |
368 |
|
double x, nsc; |
369 |
< |
register int i; |
369 |
> |
int i; |
370 |
|
/* polynomial approximation */ |
371 |
|
nf = nfc[skytype==S_INTER]; |
372 |
|
x = (altitude - PI/4.0)/(PI/4.0); |
383 |
|
char *hs |
384 |
|
) |
385 |
|
{ |
386 |
< |
register char *cp = hs; |
387 |
< |
register int i, j; |
386 |
> |
char *cp = hs; |
387 |
> |
int i, j; |
388 |
|
|
389 |
|
if ( (tsolar = *cp == '+') ) cp++; /* solar time? */ |
390 |
|
while (isdigit(*cp)) cp++; |
418 |
|
fprintf(stderr, " %s", tzone[i].zname); |
419 |
|
putc('\n', stderr); |
420 |
|
exit(1); |
418 |
– |
} |
419 |
– |
|
420 |
– |
|
421 |
– |
void |
422 |
– |
printhead( /* print command header */ |
423 |
– |
register int ac, |
424 |
– |
register char **av |
425 |
– |
) |
426 |
– |
{ |
427 |
– |
putchar('#'); |
428 |
– |
while (ac--) { |
429 |
– |
putchar(' '); |
430 |
– |
fputs(*av++, stdout); |
431 |
– |
} |
432 |
– |
putchar('\n'); |
421 |
|
} |