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.21 by schorsch, Sun Jul 27 22:12:02 2003 UTC vs.
Revision 2.26 by greg, Wed Jul 30 17:30:27 2014 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11   */
12  
13   #include  <stdio.h>
14
14   #include  <stdlib.h>
16
15   #include  <string.h>
18
16   #include  <math.h>
20
17   #include  <ctype.h>
18 <
18 > #include  "sun.h"
19   #include  "color.h"
20  
25 extern double  stadj(), sdec(), sazi(), salt(), tz2mer();
26
21   #ifndef  PI
22   #define  PI             3.14159265358979323846
23   #endif
# Line 38 | Line 32 | extern double  stadj(), sdec(), sazi(), salt(), tz2mer
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 <        "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
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  month, day;                                /* date */
# 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 + void printhead(int  ac, char  **av);
90  
91 < main(argc, argv)
92 < int  argc;
93 < char  *argv[];
91 >
92 > int
93 > main(
94 >        int  argc,
95 >        char  *argv[]
96 > )
97   {
98 +        int  got_meridian = 0;
99          int  i;
100  
101          progname = argv[0];
# Line 115 | Line 116 | char  *argv[];
116                  day = atoi(argv[2]);
117                  if (day < 1 || day > 31)
118                          userror("bad day");
119 <                cvthour(argv[3]);
119 >                got_meridian = cvthour(argv[3]);
120          }
121          for (i = 4; i < argc; i++)
122                  if (argv[i][0] == '-' || argv[i][0] == '+')
# Line 157 | Line 158 | char  *argv[];
158                                  s_longitude = atof(argv[++i]) * (PI/180);
159                                  break;
160                          case 'm':
161 +                                if (got_meridian) {
162 +                                        ++i;
163 +                                        break;          /* time overrides */
164 +                                }
165                                  s_meridian = atof(argv[++i]) * (PI/180);
166                                  break;
167                          default:
# Line 166 | Line 171 | char  *argv[];
171                  else
172                          userror("bad option");
173  
174 <        if (fabs(s_meridian-s_longitude) > 45*PI/180)
174 >        if (month && !tsolar && fabs(s_meridian-s_longitude) > 45*PI/180)
175                  fprintf(stderr,
176 <        "%s: warning: %.1f hours btwn. standard meridian and longitude\n",
176 >        "%s: warning - %.1f hours btwn. standard meridian and longitude\n",
177                          progname, (s_longitude-s_meridian)*12/PI);
178  
179          printhead(argc, argv);
# Line 180 | Line 185 | char  *argv[];
185   }
186  
187  
188 < computesky()                    /* compute sky parameters */
188 > void
189 > computesky(void)                        /* compute sky parameters */
190   {
191          double  normfactor;
192                                          /* compute solar direction */
# Line 265 | Line 271 | computesky()                   /* compute sky parameters */
271   }
272  
273  
274 < printsky()                      /* print out sky */
274 > void
275 > printsky(void)                  /* print out sky */
276   {
277          if (dosun) {
278                  printf("\nvoid light solar\n");
# Line 288 | Line 295 | printsky()                     /* print out sky */
295   }
296  
297  
298 < printdefaults()                 /* print default values */
298 > void
299 > printdefaults(void)                     /* print default values */
300   {
301          switch (skytype) {
302          case S_OVER:
# Line 321 | Line 329 | printdefaults()                        /* print default values */
329   }
330  
331  
332 < userror(msg)                    /* print usage error and quit */
333 < char  *msg;
332 > void
333 > userror(                        /* print usage error and quit */
334 >        char  *msg
335 > )
336   {
337          if (msg != NULL)
338                  fprintf(stderr, "%s: Use error - %s\n", progname, msg);
# Line 334 | Line 344 | char  *msg;
344  
345  
346   double
347 < normsc()                        /* compute normalization factor (E0*F2/L0) */
347 > normsc(void)                    /* compute normalization factor (E0*F2/L0) */
348   {
349          static double  nfc[2][5] = {
350                                  /* clear sky approx. */
# Line 342 | Line 352 | normsc()                       /* compute normalization factor (E0*F2/L0)
352                                  /* intermediate sky approx. */
353                  {3.5556, -2.7152, -1.3081, 1.0660, 0.60227},
354          };
355 <        register double  *nf;
355 >        double  *nf;
356          double  x, nsc;
357 <        register int  i;
357 >        int  i;
358                                          /* polynomial approximation */
359          nf = nfc[skytype==S_INTER];
360          x = (altitude - PI/4.0)/(PI/4.0);
# Line 356 | Line 366 | normsc()                       /* compute normalization factor (E0*F2/L0)
366   }
367  
368  
369 < cvthour(hs)                     /* convert hour string */
370 < char  *hs;
369 > int
370 > cvthour(                        /* convert hour string */
371 >        char  *hs
372 > )
373   {
374 <        register char  *cp = hs;
375 <        register int    i, j;
374 >        char  *cp = hs;
375 >        int     i, j;
376  
377          if ( (tsolar = *cp == '+') ) cp++;              /* solar time? */
378          while (isdigit(*cp)) cp++;
# Line 372 | Line 384 | char  *hs;
384          }
385          while (isdigit(*cp)) cp++;
386          if (!*cp)
387 <                return;
387 >                return(0);
388          if (tsolar || !isalpha(*cp)) {
389                  fprintf(stderr, "%s: bad time format: %s\n", progname, hs);
390                  exit(1);
# Line 384 | Line 396 | char  *hs;
396                                  break;
397                  if (!cp[j] && !tzone[i].zname[j]) {
398                          s_meridian = tzone[i].zmer * (PI/180);
399 <                        return;
399 >                        return(1);
400                  }
401          } while (tzone[i++].zname[0]);
402  
# Line 397 | Line 409 | char  *hs;
409   }
410  
411  
412 < printhead(ac, av)               /* print command header */
413 < register int  ac;
414 < register char  **av;
412 > void
413 > printhead(              /* print command header */
414 >        int  ac,
415 >        char  **av
416 > )
417   {
418          putchar('#');
419          while (ac--) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines