1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* gensky.c - program to generate sky functions. |
6 |
|
* Our zenith is along the Z-axis, the X-axis |
12 |
|
|
13 |
|
#include <stdio.h> |
14 |
|
|
15 |
+ |
#include <stdlib.h> |
16 |
+ |
|
17 |
+ |
#include <string.h> |
18 |
+ |
|
19 |
|
#include <math.h> |
20 |
|
|
21 |
+ |
#include <ctype.h> |
22 |
+ |
|
23 |
|
#include "color.h" |
24 |
|
|
25 |
< |
extern char *strcpy(), *strcat(), *malloc(); |
23 |
< |
extern double stadj(), sdec(), sazi(), salt(); |
25 |
> |
extern double stadj(), sdec(), sazi(), salt(), tz2mer(); |
26 |
|
|
27 |
< |
#define PI 3.141592654 |
27 |
> |
#ifndef PI |
28 |
> |
#define PI 3.14159265358979323846 |
29 |
> |
#endif |
30 |
|
|
31 |
|
#define DOT(v1,v2) (v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2]) |
32 |
|
|
35 |
|
#define S_UNIF 3 |
36 |
|
#define S_INTER 4 |
37 |
|
|
38 |
< |
#define overcast (skytype==S_OVER|skytype==S_UNIF) |
38 |
> |
#define overcast ((skytype==S_OVER)|(skytype==S_UNIF)) |
39 |
|
|
40 |
|
double normsc(); |
41 |
|
/* sun calculation constants */ |
42 |
|
extern double s_latitude; |
43 |
|
extern double s_longitude; |
44 |
|
extern double s_meridian; |
45 |
+ |
|
46 |
+ |
#undef toupper |
47 |
+ |
#define toupper(c) ((c) & ~0x20) /* ASCII trick to convert case */ |
48 |
+ |
|
49 |
+ |
/* European and North American zones */ |
50 |
+ |
struct { |
51 |
+ |
char zname[8]; /* time zone name (all caps) */ |
52 |
+ |
float zmer; /* standard meridian */ |
53 |
+ |
} tzone[] = { |
54 |
+ |
"YST", 135, "YDT", 120, |
55 |
+ |
"PST", 120, "PDT", 105, |
56 |
+ |
"MST", 105, "MDT", 90, |
57 |
+ |
"CST", 90, "CDT", 75, |
58 |
+ |
"EST", 75, "EDT", 60, |
59 |
+ |
"AST", 60, "ADT", 45, |
60 |
+ |
"NST", 52.5, "NDT", 37.5, |
61 |
+ |
"GMT", 0, "BST", -15, |
62 |
+ |
"CET", -15, "CEST", -30, |
63 |
+ |
"EET", -30, "EEST", -45, |
64 |
+ |
"AST", -45, "ADT", -60, |
65 |
+ |
"GST", -60, "GDT", -75, |
66 |
+ |
"IST", -82.5, "IDT", -97.5, |
67 |
+ |
"JST", -135, "NDT", -150, |
68 |
+ |
"NZST", -180, "NZDT", -195, |
69 |
+ |
"", 0 |
70 |
+ |
}; |
71 |
|
/* required values */ |
72 |
|
int month, day; /* date */ |
73 |
|
double hour; /* time */ |
115 |
|
day = atoi(argv[2]); |
116 |
|
if (day < 1 || day > 31) |
117 |
|
userror("bad day"); |
118 |
< |
hour = atof(argv[3]); |
89 |
< |
if (hour < 0 || hour >= 24) |
90 |
< |
userror("bad hour"); |
91 |
< |
tsolar = argv[3][0] == '+'; |
118 |
> |
cvthour(argv[3]); |
119 |
|
} |
120 |
|
for (i = 4; i < argc; i++) |
121 |
|
if (argv[i][0] == '-' || argv[i][0] == '+') |
166 |
|
else |
167 |
|
userror("bad option"); |
168 |
|
|
169 |
< |
if (fabs(s_meridian-s_longitude) > 30*PI/180) |
169 |
> |
if (fabs(s_meridian-s_longitude) > 45*PI/180) |
170 |
|
fprintf(stderr, |
171 |
|
"%s: warning: %.1f hours btwn. standard meridian and longitude\n", |
172 |
|
progname, (s_longitude-s_meridian)*12/PI); |
175 |
|
|
176 |
|
computesky(); |
177 |
|
printsky(); |
178 |
+ |
|
179 |
+ |
exit(0); |
180 |
|
} |
181 |
|
|
182 |
|
|
196 |
|
st = hour + stadj(jd); |
197 |
|
altitude = salt(sd, st); |
198 |
|
azimuth = sazi(sd, st); |
199 |
+ |
printf("# Local solar time: %.2f\n", st); |
200 |
|
printf("# Solar altitude and azimuth: %.1f %.1f\n", |
201 |
|
180./PI*altitude, 180./PI*azimuth); |
202 |
|
} |
353 |
|
nsc = nsc*x + nf[i]; |
354 |
|
|
355 |
|
return(nsc); |
356 |
+ |
} |
357 |
+ |
|
358 |
+ |
|
359 |
+ |
cvthour(hs) /* convert hour string */ |
360 |
+ |
char *hs; |
361 |
+ |
{ |
362 |
+ |
register char *cp = hs; |
363 |
+ |
register int i, j; |
364 |
+ |
|
365 |
+ |
if ( (tsolar = *cp == '+') ) cp++; /* solar time? */ |
366 |
+ |
while (isdigit(*cp)) cp++; |
367 |
+ |
if (*cp == ':') |
368 |
+ |
hour = atoi(hs) + atoi(++cp)/60.0; |
369 |
+ |
else { |
370 |
+ |
hour = atof(hs); |
371 |
+ |
if (*cp == '.') cp++; |
372 |
+ |
} |
373 |
+ |
while (isdigit(*cp)) cp++; |
374 |
+ |
if (!*cp) |
375 |
+ |
return; |
376 |
+ |
if (tsolar || !isalpha(*cp)) { |
377 |
+ |
fprintf(stderr, "%s: bad time format: %s\n", progname, hs); |
378 |
+ |
exit(1); |
379 |
+ |
} |
380 |
+ |
i = 0; |
381 |
+ |
do { |
382 |
+ |
for (j = 0; cp[j]; j++) |
383 |
+ |
if (toupper(cp[j]) != tzone[i].zname[j]) |
384 |
+ |
break; |
385 |
+ |
if (!cp[j] && !tzone[i].zname[j]) { |
386 |
+ |
s_meridian = tzone[i].zmer * (PI/180); |
387 |
+ |
return; |
388 |
+ |
} |
389 |
+ |
} while (tzone[i++].zname[0]); |
390 |
+ |
|
391 |
+ |
fprintf(stderr, "%s: unknown time zone: %s\n", progname, cp); |
392 |
+ |
fprintf(stderr, "Known time zones:\n\t%s", tzone[0].zname); |
393 |
+ |
for (i = 1; tzone[i].zname[0]; i++) |
394 |
+ |
fprintf(stderr, " %s", tzone[i].zname); |
395 |
+ |
putc('\n', stderr); |
396 |
+ |
exit(1); |
397 |
|
} |
398 |
|
|
399 |
|
|