--- ray/src/gen/gensky.c 1996/06/25 20:48:17 2.16 +++ ray/src/gen/gensky.c 2003/07/27 22:12:02 2.21 @@ -1,9 +1,6 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: gensky.c,v 2.21 2003/07/27 22:12:02 schorsch Exp $"; #endif - /* * gensky.c - program to generate sky functions. * Our zenith is along the Z-axis, the X-axis @@ -15,14 +12,21 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#include + +#include + #include +#include + #include "color.h" -extern char *strcpy(), *strcat(), *malloc(); -extern double stadj(), sdec(), sazi(), salt(); +extern double stadj(), sdec(), sazi(), salt(), tz2mer(); -#define PI 3.141592654 +#ifndef PI +#define PI 3.14159265358979323846 +#endif #define DOT(v1,v2) (v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2]) @@ -31,13 +35,39 @@ extern double stadj(), sdec(), sazi(), salt(); #define S_UNIF 3 #define S_INTER 4 -#define overcast (skytype==S_OVER|skytype==S_UNIF) +#define overcast ((skytype==S_OVER)|(skytype==S_UNIF)) double normsc(); /* sun calculation constants */ extern double s_latitude; extern double s_longitude; extern double s_meridian; + +#undef toupper +#define toupper(c) ((c) & ~0x20) /* ASCII trick to convert case */ + + /* European and North American zones */ +struct { + char zname[8]; /* time zone name (all caps) */ + float zmer; /* standard meridian */ +} tzone[] = { + "YST", 135, "YDT", 120, + "PST", 120, "PDT", 105, + "MST", 105, "MDT", 90, + "CST", 90, "CDT", 75, + "EST", 75, "EDT", 60, + "AST", 60, "ADT", 45, + "NST", 52.5, "NDT", 37.5, + "GMT", 0, "BST", -15, + "CET", -15, "CEST", -30, + "EET", -30, "EEST", -45, + "AST", -45, "ADT", -60, + "GST", -60, "GDT", -75, + "IST", -82.5, "IDT", -97.5, + "JST", -135, "NDT", -150, + "NZST", -180, "NZDT", -195, + "", 0 +}; /* required values */ int month, day; /* date */ double hour; /* time */ @@ -136,7 +166,7 @@ char *argv[]; else userror("bad option"); - if (fabs(s_meridian-s_longitude) > 30*PI/180) + if (fabs(s_meridian-s_longitude) > 45*PI/180) fprintf(stderr, "%s: warning: %.1f hours btwn. standard meridian and longitude\n", progname, (s_longitude-s_meridian)*12/PI); @@ -166,6 +196,7 @@ computesky() /* compute sky parameters */ st = hour + stadj(jd); altitude = salt(sd, st); azimuth = sazi(sd, st); + printf("# Local solar time: %.2f\n", st); printf("# Solar altitude and azimuth: %.1f %.1f\n", 180./PI*altitude, 180./PI*azimuth); } @@ -329,14 +360,40 @@ cvthour(hs) /* convert hour string */ char *hs; { register char *cp = hs; + register int i, j; - while (*cp && *cp++ != ':') - ; - if (*cp) - hour = atoi(hs) + atoi(cp)/60.0; - else + if ( (tsolar = *cp == '+') ) cp++; /* solar time? */ + while (isdigit(*cp)) cp++; + if (*cp == ':') + hour = atoi(hs) + atoi(++cp)/60.0; + else { hour = atof(hs); - tsolar = *hs == '+'; + if (*cp == '.') cp++; + } + while (isdigit(*cp)) cp++; + if (!*cp) + return; + if (tsolar || !isalpha(*cp)) { + fprintf(stderr, "%s: bad time format: %s\n", progname, hs); + exit(1); + } + i = 0; + do { + for (j = 0; cp[j]; j++) + if (toupper(cp[j]) != tzone[i].zname[j]) + break; + if (!cp[j] && !tzone[i].zname[j]) { + s_meridian = tzone[i].zmer * (PI/180); + return; + } + } while (tzone[i++].zname[0]); + + fprintf(stderr, "%s: unknown time zone: %s\n", progname, cp); + fprintf(stderr, "Known time zones:\n\t%s", tzone[0].zname); + for (i = 1; tzone[i].zname[0]; i++) + fprintf(stderr, " %s", tzone[i].zname); + putc('\n', stderr); + exit(1); }