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 |
11 |
|
*/ |
12 |
|
|
13 |
|
#include <stdio.h> |
14 |
< |
|
14 |
> |
#include <stdlib.h> |
15 |
> |
#include <string.h> |
16 |
|
#include <math.h> |
17 |
+ |
#include <ctype.h> |
18 |
|
|
19 |
|
#include "color.h" |
20 |
|
|
21 |
< |
extern char *strcpy(), *strcat(), *malloc(); |
22 |
< |
extern double stadj(), sdec(), sazi(), salt(); |
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 |
|
|
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 */ |
90 |
|
char *progname; |
91 |
|
char errmsg[128]; |
92 |
|
|
93 |
+ |
void computesky(void); |
94 |
+ |
void printsky(void); |
95 |
+ |
void printdefaults(void); |
96 |
+ |
void userror(char *msg); |
97 |
+ |
double normsc(void); |
98 |
+ |
void cvthour(char *hs); |
99 |
+ |
void printhead(register int ac, register char **av); |
100 |
|
|
101 |
+ |
|
102 |
+ |
int |
103 |
|
main(argc, argv) |
104 |
|
int argc; |
105 |
|
char *argv[]; |
175 |
|
else |
176 |
|
userror("bad option"); |
177 |
|
|
178 |
< |
if (fabs(s_meridian-s_longitude) > 30*PI/180) |
178 |
> |
if (fabs(s_meridian-s_longitude) > 45*PI/180) |
179 |
|
fprintf(stderr, |
180 |
|
"%s: warning: %.1f hours btwn. standard meridian and longitude\n", |
181 |
|
progname, (s_longitude-s_meridian)*12/PI); |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
< |
computesky() /* compute sky parameters */ |
192 |
> |
void |
193 |
> |
computesky(void) /* compute sky parameters */ |
194 |
|
{ |
195 |
|
double normfactor; |
196 |
|
/* compute solar direction */ |
206 |
|
st = hour + stadj(jd); |
207 |
|
altitude = salt(sd, st); |
208 |
|
azimuth = sazi(sd, st); |
209 |
+ |
printf("# Local solar time: %.2f\n", st); |
210 |
|
printf("# Solar altitude and azimuth: %.1f %.1f\n", |
211 |
|
180./PI*altitude, 180./PI*azimuth); |
212 |
|
} |
275 |
|
} |
276 |
|
|
277 |
|
|
278 |
< |
printsky() /* print out sky */ |
278 |
> |
void |
279 |
> |
printsky(void) /* print out sky */ |
280 |
|
{ |
281 |
|
if (dosun) { |
282 |
|
printf("\nvoid light solar\n"); |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
< |
printdefaults() /* print default values */ |
302 |
> |
void |
303 |
> |
printdefaults(void) /* print default values */ |
304 |
|
{ |
305 |
|
switch (skytype) { |
306 |
|
case S_OVER: |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
< |
userror(msg) /* print usage error and quit */ |
337 |
< |
char *msg; |
336 |
> |
void |
337 |
> |
userror( /* print usage error and quit */ |
338 |
> |
char *msg |
339 |
> |
) |
340 |
|
{ |
341 |
|
if (msg != NULL) |
342 |
|
fprintf(stderr, "%s: Use error - %s\n", progname, msg); |
348 |
|
|
349 |
|
|
350 |
|
double |
351 |
< |
normsc() /* compute normalization factor (E0*F2/L0) */ |
351 |
> |
normsc(void) /* compute normalization factor (E0*F2/L0) */ |
352 |
|
{ |
353 |
|
static double nfc[2][5] = { |
354 |
|
/* clear sky approx. */ |
370 |
|
} |
371 |
|
|
372 |
|
|
373 |
< |
cvthour(hs) /* convert hour string */ |
374 |
< |
char *hs; |
373 |
> |
void |
374 |
> |
cvthour( /* convert hour string */ |
375 |
> |
char *hs |
376 |
> |
) |
377 |
|
{ |
378 |
|
register char *cp = hs; |
379 |
+ |
register int i, j; |
380 |
|
|
381 |
< |
while (*cp && *cp++ != ':') |
382 |
< |
; |
383 |
< |
if (*cp) |
384 |
< |
hour = atoi(hs) + atoi(cp)/60.0; |
385 |
< |
else |
381 |
> |
if ( (tsolar = *cp == '+') ) cp++; /* solar time? */ |
382 |
> |
while (isdigit(*cp)) cp++; |
383 |
> |
if (*cp == ':') |
384 |
> |
hour = atoi(hs) + atoi(++cp)/60.0; |
385 |
> |
else { |
386 |
|
hour = atof(hs); |
387 |
< |
tsolar = *hs == '+'; |
387 |
> |
if (*cp == '.') cp++; |
388 |
> |
} |
389 |
> |
while (isdigit(*cp)) cp++; |
390 |
> |
if (!*cp) |
391 |
> |
return; |
392 |
> |
if (tsolar || !isalpha(*cp)) { |
393 |
> |
fprintf(stderr, "%s: bad time format: %s\n", progname, hs); |
394 |
> |
exit(1); |
395 |
> |
} |
396 |
> |
i = 0; |
397 |
> |
do { |
398 |
> |
for (j = 0; cp[j]; j++) |
399 |
> |
if (toupper(cp[j]) != tzone[i].zname[j]) |
400 |
> |
break; |
401 |
> |
if (!cp[j] && !tzone[i].zname[j]) { |
402 |
> |
s_meridian = tzone[i].zmer * (PI/180); |
403 |
> |
return; |
404 |
> |
} |
405 |
> |
} while (tzone[i++].zname[0]); |
406 |
> |
|
407 |
> |
fprintf(stderr, "%s: unknown time zone: %s\n", progname, cp); |
408 |
> |
fprintf(stderr, "Known time zones:\n\t%s", tzone[0].zname); |
409 |
> |
for (i = 1; tzone[i].zname[0]; i++) |
410 |
> |
fprintf(stderr, " %s", tzone[i].zname); |
411 |
> |
putc('\n', stderr); |
412 |
> |
exit(1); |
413 |
|
} |
414 |
|
|
415 |
|
|
416 |
< |
printhead(ac, av) /* print command header */ |
417 |
< |
register int ac; |
418 |
< |
register char **av; |
416 |
> |
void |
417 |
> |
printhead( /* print command header */ |
418 |
> |
register int ac, |
419 |
> |
register char **av |
420 |
> |
) |
421 |
|
{ |
422 |
|
putchar('#'); |
423 |
|
while (ac--) { |