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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines