ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/gensky.c
(Generate patch)

Comparing ray/src/gen/gensky.c (file contents):
Revision 2.17 by greg, Tue Jul 16 14:14:50 1996 UTC vs.
Revision 2.27 by greg, Thu Nov 7 23:15:07 2019 UTC

# Line 1 | Line 1
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
# Line 14 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
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 <
18 > #include  "sun.h"
19   #include  "color.h"
20  
24 extern char  *strcpy(), *strcat(), *malloc();
25 extern double  stadj(), sdec(), sazi(), salt(), tz2mer();
26
21   #ifndef  PI
22   #define  PI             3.14159265358979323846
23   #endif
# Line 35 | Line 29 | extern double  stadj(), sdec(), sazi(), salt(), tz2mer
29   #define  S_UNIF         3
30   #define  S_INTER        4
31  
32 < #define  overcast       (skytype==S_OVER|skytype==S_UNIF)
32 > #define  overcast       ((skytype==S_OVER)|(skytype==S_UNIF))
33  
34   double  normsc();
41                                        /* sun calculation constants */
42 extern double  s_latitude;
43 extern double  s_longitude;
44 extern double  s_meridian;
35  
36   #undef  toupper
37   #define  toupper(c)     ((c) & ~0x20)   /* ASCII trick to convert case */
# Line 51 | Line 41 | struct {
41          char    zname[8];       /* time zone name (all caps) */
42          float   zmer;           /* standard meridian */
43   } tzone[] = {
44 <        "YST", 135, "YDT", 120,
45 <        "PST", 120, "PDT", 105,
46 <        "MST", 105, "MDT", 90,
47 <        "CST", 90, "CDT", 75,
48 <        "EST", 75, "EDT", 60,
49 <        "AST", 60, "ADT", 45,
50 <        "NST", 52.5, "NDT", 37.5,
51 <        "GMT", 0, "BST", -15,
52 <        "WET", -15, "WETDST", -30,
53 <        "MET", -30, "METDST", -45,
54 <        "MEZ", -30, "MESZ", -45,
55 <        "", 0
44 >        {"YST", 135}, {"YDT", 120},
45 >        {"PST", 120}, {"PDT", 105},
46 >        {"MST", 105}, {"MDT", 90},
47 >        {"CST", 90}, {"CDT", 75},
48 >        {"EST", 75}, {"EDT", 60},
49 >        {"AST", 60}, {"ADT", 45},
50 >        {"NST", 52.5}, {"NDT", 37.5},
51 >        {"GMT", 0}, {"BST", -15},
52 >        {"CET", -15}, {"CEST", -30},
53 >        {"EET", -30}, {"EEST", -45},
54 >        {"AST", -45}, {"ADT", -60},
55 >        {"GST", -60}, {"GDT", -75},
56 >        {"IST", -82.5}, {"IDT", -97.5},
57 >        {"JST", -135}, {"NDT", -150},
58 >        {"NZST", -180}, {"NZDT", -195},
59 >        {"", 0}
60   };
61                                          /* required values */
62 + int  year = 0;                                  /* year (optional) */
63   int  month, day;                                /* date */
64   double  hour;                                   /* time */
65   int  tsolar;                                    /* 0=standard, 1=solar */
# Line 74 | Line 69 | int  skytype = S_CLEAR;                                /* sky type */
69   int  dosun = 1;
70   double  zenithbr = 0.0;
71   int     u_zenith = 0;                           /* -1=irradiance, 1=radiance */
72 < double  turbidity = 2.75;
72 > double  turbidity = 2.45;
73   double  gprefl = 0.2;
74                                          /* computed values */
75   double  sundir[3];
# Line 86 | Line 81 | int    u_solar = 0;                            /* -1=irradiance, 1=radiance */
81   char  *progname;
82   char  errmsg[128];
83  
84 + void computesky(void);
85 + void printsky(void);
86 + void printdefaults(void);
87 + void userror(char  *msg);
88 + double normsc(void);
89 + int cvthour(char  *hs);
90 + void printhead(int  ac, char  **av);
91  
92 < main(argc, argv)
93 < int  argc;
94 < char  *argv[];
92 >
93 > int
94 > main(
95 >        int  argc,
96 >        char  *argv[]
97 > )
98   {
99 +        int  got_meridian = 0;
100          int  i;
101  
102          progname = argv[0];
# Line 111 | Line 117 | char  *argv[];
117                  day = atoi(argv[2]);
118                  if (day < 1 || day > 31)
119                          userror("bad day");
120 <                cvthour(argv[3]);
120 >                got_meridian = cvthour(argv[3]);
121          }
122          for (i = 4; i < argc; i++)
123                  if (argv[i][0] == '-' || argv[i][0] == '+')
# Line 120 | Line 126 | char  *argv[];
126                                  skytype = S_CLEAR;
127                                  dosun = argv[i][0] == '+';
128                                  break;
129 +                        case 'y':
130 +                                year = atoi(argv[++i]);
131 +                                break;
132                          case 'r':
133                          case 'R':
134                                  u_solar = argv[i][1]=='R' ? -1 : 1;
# Line 153 | Line 162 | char  *argv[];
162                                  s_longitude = atof(argv[++i]) * (PI/180);
163                                  break;
164                          case 'm':
165 +                                if (got_meridian) {
166 +                                        ++i;
167 +                                        break;          /* time overrides */
168 +                                }
169                                  s_meridian = atof(argv[++i]) * (PI/180);
170                                  break;
171                          default:
# Line 162 | Line 175 | char  *argv[];
175                  else
176                          userror("bad option");
177  
178 <        if (fabs(s_meridian-s_longitude) > 30*PI/180)
178 >        if (year && (year < 1950) | (year > 2050))
179                  fprintf(stderr,
180 <        "%s: warning: %.1f hours btwn. standard meridian and longitude\n",
180 >                        "%s: warning - year should be in range 1950-2050\n",
181 >                        progname);
182 >        if (month && !tsolar && fabs(s_meridian-s_longitude) > 45*PI/180)
183 >                fprintf(stderr,
184 >        "%s: warning - %.1f hours btwn. standard meridian and longitude\n",
185                          progname, (s_longitude-s_meridian)*12/PI);
186  
187          printhead(argc, argv);
# Line 176 | Line 193 | char  *argv[];
193   }
194  
195  
196 < computesky()                    /* compute sky parameters */
196 > void
197 > computesky(void)                        /* compute sky parameters */
198   {
199          double  normfactor;
200                                          /* compute solar direction */
201          if (month) {                    /* from date and time */
202 <                int  jd;
185 <                double  sd, st;
202 >                double  sd, st = hour;
203  
204 <                jd = jdate(month, day);         /* Julian date */
205 <                sd = sdec(jd);                  /* solar declination */
206 <                if (tsolar)                     /* solar time */
207 <                        st = hour;
208 <                else
209 <                        st = hour + stadj(jd);
204 >                if (year) {                     /* Michalsky algorithm? */
205 >                        double  mjd = mjdate(year, month, day, hour);
206 >                        if (tsolar)
207 >                                sd = msdec(mjd, NULL);
208 >                        else
209 >                                sd = msdec(mjd, &st);
210 >                } else {
211 >                        int  jd = jdate(month, day);    /* Julian date */
212 >                        sd = sdec(jd);                  /* solar declination */
213 >                        if (!tsolar)                    /* get solar time? */
214 >                                st = hour + stadj(jd);
215 >                }
216                  altitude = salt(sd, st);
217                  azimuth = sazi(sd, st);
218                  printf("# Local solar time: %.2f\n", st);
# Line 261 | Line 284 | computesky()                   /* compute sky parameters */
284   }
285  
286  
287 < printsky()                      /* print out sky */
287 > void
288 > printsky(void)                  /* print out sky */
289   {
290          if (dosun) {
291                  printf("\nvoid light solar\n");
# Line 284 | Line 308 | printsky()                     /* print out sky */
308   }
309  
310  
311 < printdefaults()                 /* print default values */
311 > void
312 > printdefaults(void)                     /* print default values */
313   {
314          switch (skytype) {
315          case S_OVER:
# Line 317 | Line 342 | printdefaults()                        /* print default values */
342   }
343  
344  
345 < userror(msg)                    /* print usage error and quit */
346 < char  *msg;
345 > void
346 > userror(                        /* print usage error and quit */
347 >        char  *msg
348 > )
349   {
350          if (msg != NULL)
351                  fprintf(stderr, "%s: Use error - %s\n", progname, msg);
# Line 330 | Line 357 | char  *msg;
357  
358  
359   double
360 < normsc()                        /* compute normalization factor (E0*F2/L0) */
360 > normsc(void)                    /* compute normalization factor (E0*F2/L0) */
361   {
362          static double  nfc[2][5] = {
363                                  /* clear sky approx. */
# Line 338 | Line 365 | normsc()                       /* compute normalization factor (E0*F2/L0)
365                                  /* intermediate sky approx. */
366                  {3.5556, -2.7152, -1.3081, 1.0660, 0.60227},
367          };
368 <        register double  *nf;
368 >        double  *nf;
369          double  x, nsc;
370 <        register int  i;
370 >        int  i;
371                                          /* polynomial approximation */
372          nf = nfc[skytype==S_INTER];
373          x = (altitude - PI/4.0)/(PI/4.0);
# Line 352 | Line 379 | normsc()                       /* compute normalization factor (E0*F2/L0)
379   }
380  
381  
382 < cvthour(hs)                     /* convert hour string */
383 < char  *hs;
382 > int
383 > cvthour(                        /* convert hour string */
384 >        char  *hs
385 > )
386   {
387 <        register char  *cp = hs;
388 <        register int    i, j;
387 >        char  *cp = hs;
388 >        int     i, j;
389  
390 <        if (tsolar = *cp == '+') cp++;          /* solar time? */
390 >        if ( (tsolar = *cp == '+') ) cp++;              /* solar time? */
391          while (isdigit(*cp)) cp++;
392          if (*cp == ':')
393                  hour = atoi(hs) + atoi(++cp)/60.0;
# Line 368 | Line 397 | char  *hs;
397          }
398          while (isdigit(*cp)) cp++;
399          if (!*cp)
400 <                return;
400 >                return(0);
401          if (tsolar || !isalpha(*cp)) {
402                  fprintf(stderr, "%s: bad time format: %s\n", progname, hs);
403                  exit(1);
# Line 380 | Line 409 | char  *hs;
409                                  break;
410                  if (!cp[j] && !tzone[i].zname[j]) {
411                          s_meridian = tzone[i].zmer * (PI/180);
412 <                        return;
412 >                        return(1);
413                  }
414          } while (tzone[i++].zname[0]);
415  
# Line 393 | Line 422 | char  *hs;
422   }
423  
424  
425 < printhead(ac, av)               /* print command header */
426 < register int  ac;
427 < register char  **av;
425 > void
426 > printhead(              /* print command header */
427 >        int  ac,
428 >        char  **av
429 > )
430   {
431          putchar('#');
432          while (ac--) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines