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> |
19 |
– |
|
17 |
|
#include <ctype.h> |
18 |
|
|
19 |
|
#include "color.h" |
20 |
|
|
21 |
< |
extern char *strcpy(), *strcat(), *malloc(); |
22 |
< |
extern double stadj(), sdec(), sazi(), salt(), tz2mer(); |
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 |
|
#ifndef PI |
28 |
|
#define PI 3.14159265358979323846 |
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 */ |
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 |
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 */ |
78 |
|
int dosun = 1; |
79 |
|
double zenithbr = 0.0; |
80 |
|
int u_zenith = 0; /* -1=irradiance, 1=radiance */ |
81 |
< |
double turbidity = 2.75; |
81 |
> |
double turbidity = 2.45; |
82 |
|
double gprefl = 0.2; |
83 |
|
/* computed values */ |
84 |
|
double sundir[3]; |
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 |
+ |
int 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[]; |
106 |
|
{ |
107 |
+ |
int got_meridian = 0; |
108 |
|
int i; |
109 |
|
|
110 |
|
progname = argv[0]; |
125 |
|
day = atoi(argv[2]); |
126 |
|
if (day < 1 || day > 31) |
127 |
|
userror("bad day"); |
128 |
< |
cvthour(argv[3]); |
128 |
> |
got_meridian = cvthour(argv[3]); |
129 |
|
} |
130 |
|
for (i = 4; i < argc; i++) |
131 |
|
if (argv[i][0] == '-' || argv[i][0] == '+') |
167 |
|
s_longitude = atof(argv[++i]) * (PI/180); |
168 |
|
break; |
169 |
|
case 'm': |
170 |
+ |
if (got_meridian) { |
171 |
+ |
++i; |
172 |
+ |
break; /* time overrides */ |
173 |
+ |
} |
174 |
|
s_meridian = atof(argv[++i]) * (PI/180); |
175 |
|
break; |
176 |
|
default: |
194 |
|
} |
195 |
|
|
196 |
|
|
197 |
< |
computesky() /* compute sky parameters */ |
197 |
> |
void |
198 |
> |
computesky(void) /* compute sky parameters */ |
199 |
|
{ |
200 |
|
double normfactor; |
201 |
|
/* compute solar direction */ |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
< |
printsky() /* print out sky */ |
283 |
> |
void |
284 |
> |
printsky(void) /* print out sky */ |
285 |
|
{ |
286 |
|
if (dosun) { |
287 |
|
printf("\nvoid light solar\n"); |
304 |
|
} |
305 |
|
|
306 |
|
|
307 |
< |
printdefaults() /* print default values */ |
307 |
> |
void |
308 |
> |
printdefaults(void) /* print default values */ |
309 |
|
{ |
310 |
|
switch (skytype) { |
311 |
|
case S_OVER: |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
< |
userror(msg) /* print usage error and quit */ |
342 |
< |
char *msg; |
341 |
> |
void |
342 |
> |
userror( /* print usage error and quit */ |
343 |
> |
char *msg |
344 |
> |
) |
345 |
|
{ |
346 |
|
if (msg != NULL) |
347 |
|
fprintf(stderr, "%s: Use error - %s\n", progname, msg); |
353 |
|
|
354 |
|
|
355 |
|
double |
356 |
< |
normsc() /* compute normalization factor (E0*F2/L0) */ |
356 |
> |
normsc(void) /* compute normalization factor (E0*F2/L0) */ |
357 |
|
{ |
358 |
|
static double nfc[2][5] = { |
359 |
|
/* clear sky approx. */ |
375 |
|
} |
376 |
|
|
377 |
|
|
378 |
< |
cvthour(hs) /* convert hour string */ |
379 |
< |
char *hs; |
378 |
> |
int |
379 |
> |
cvthour( /* convert hour string */ |
380 |
> |
char *hs |
381 |
> |
) |
382 |
|
{ |
383 |
|
register char *cp = hs; |
384 |
|
register int i, j; |
385 |
|
|
386 |
< |
if (tsolar = *cp == '+') cp++; /* solar time? */ |
386 |
> |
if ( (tsolar = *cp == '+') ) cp++; /* solar time? */ |
387 |
|
while (isdigit(*cp)) cp++; |
388 |
|
if (*cp == ':') |
389 |
|
hour = atoi(hs) + atoi(++cp)/60.0; |
393 |
|
} |
394 |
|
while (isdigit(*cp)) cp++; |
395 |
|
if (!*cp) |
396 |
< |
return; |
396 |
> |
return(0); |
397 |
|
if (tsolar || !isalpha(*cp)) { |
398 |
|
fprintf(stderr, "%s: bad time format: %s\n", progname, hs); |
399 |
|
exit(1); |
405 |
|
break; |
406 |
|
if (!cp[j] && !tzone[i].zname[j]) { |
407 |
|
s_meridian = tzone[i].zmer * (PI/180); |
408 |
< |
return; |
408 |
> |
return(1); |
409 |
|
} |
410 |
|
} while (tzone[i++].zname[0]); |
411 |
|
|
418 |
|
} |
419 |
|
|
420 |
|
|
421 |
< |
printhead(ac, av) /* print command header */ |
422 |
< |
register int ac; |
423 |
< |
register char **av; |
421 |
> |
void |
422 |
> |
printhead( /* print command header */ |
423 |
> |
register int ac, |
424 |
> |
register char **av |
425 |
> |
) |
426 |
|
{ |
427 |
|
putchar('#'); |
428 |
|
while (ac--) { |