--- ray/src/gen/gensky.c 2003/02/22 02:07:23 2.20 +++ ray/src/gen/gensky.c 2004/09/10 18:19:24 2.23 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: gensky.c,v 2.20 2003/02/22 02:07:23 greg Exp $"; +static const char RCSid[] = "$Id: gensky.c,v 2.23 2004/09/10 18:19:24 greg Exp $"; #endif /* * gensky.c - program to generate sky functions. @@ -11,18 +11,18 @@ static const char RCSid[] = "$Id: gensky.c,v 2.20 2003 */ #include - #include - #include - #include - #include #include "color.h" -extern double stadj(), sdec(), sazi(), salt(), tz2mer(); +extern int jdate(int month, int day); +extern double stadj(int jd); +extern double sdec(int jd); +extern double salt(double sd, double st); +extern double sazi(double sd, double st); #ifndef PI #define PI 3.14159265358979323846 @@ -35,7 +35,7 @@ extern double stadj(), sdec(), sazi(), salt(), tz2mer #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 */ @@ -51,22 +51,22 @@ 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 + {"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 */ @@ -90,11 +90,21 @@ int u_solar = 0; /* -1=irradiance, 1=radiance */ char *progname; char errmsg[128]; +void computesky(void); +void printsky(void); +void printdefaults(void); +void userror(char *msg); +double normsc(void); +int cvthour(char *hs); +void printhead(register int ac, register char **av); + +int main(argc, argv) int argc; char *argv[]; { + int got_meridian = 0; int i; progname = argv[0]; @@ -115,7 +125,7 @@ char *argv[]; day = atoi(argv[2]); if (day < 1 || day > 31) userror("bad day"); - cvthour(argv[3]); + got_meridian = cvthour(argv[3]); } for (i = 4; i < argc; i++) if (argv[i][0] == '-' || argv[i][0] == '+') @@ -157,6 +167,10 @@ char *argv[]; s_longitude = atof(argv[++i]) * (PI/180); break; case 'm': + if (got_meridian) { + ++i; + break; /* time overrides */ + } s_meridian = atof(argv[++i]) * (PI/180); break; default: @@ -180,7 +194,8 @@ char *argv[]; } -computesky() /* compute sky parameters */ +void +computesky(void) /* compute sky parameters */ { double normfactor; /* compute solar direction */ @@ -265,7 +280,8 @@ computesky() /* compute sky parameters */ } -printsky() /* print out sky */ +void +printsky(void) /* print out sky */ { if (dosun) { printf("\nvoid light solar\n"); @@ -288,7 +304,8 @@ printsky() /* print out sky */ } -printdefaults() /* print default values */ +void +printdefaults(void) /* print default values */ { switch (skytype) { case S_OVER: @@ -321,8 +338,10 @@ printdefaults() /* print default values */ } -userror(msg) /* print usage error and quit */ -char *msg; +void +userror( /* print usage error and quit */ + char *msg +) { if (msg != NULL) fprintf(stderr, "%s: Use error - %s\n", progname, msg); @@ -334,7 +353,7 @@ char *msg; double -normsc() /* compute normalization factor (E0*F2/L0) */ +normsc(void) /* compute normalization factor (E0*F2/L0) */ { static double nfc[2][5] = { /* clear sky approx. */ @@ -356,13 +375,15 @@ normsc() /* compute normalization factor (E0*F2/L0) } -cvthour(hs) /* convert hour string */ -char *hs; +int +cvthour( /* convert hour string */ + char *hs +) { register char *cp = hs; register int i, j; - if (tsolar = *cp == '+') cp++; /* solar time? */ + if ( (tsolar = *cp == '+') ) cp++; /* solar time? */ while (isdigit(*cp)) cp++; if (*cp == ':') hour = atoi(hs) + atoi(++cp)/60.0; @@ -372,7 +393,7 @@ char *hs; } while (isdigit(*cp)) cp++; if (!*cp) - return; + return(0); if (tsolar || !isalpha(*cp)) { fprintf(stderr, "%s: bad time format: %s\n", progname, hs); exit(1); @@ -384,7 +405,7 @@ char *hs; break; if (!cp[j] && !tzone[i].zname[j]) { s_meridian = tzone[i].zmer * (PI/180); - return; + return(1); } } while (tzone[i++].zname[0]); @@ -397,9 +418,11 @@ char *hs; } -printhead(ac, av) /* print command header */ -register int ac; -register char **av; +void +printhead( /* print command header */ + register int ac, + register char **av +) { putchar('#'); while (ac--) {