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.14 by greg, Mon Jan 31 12:53:49 1994 UTC vs.
Revision 2.26 by greg, Wed Jul 30 17:30:27 2014 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>
17 <
17 > #include  <ctype.h>
18 > #include  "sun.h"
19   #include  "color.h"
20  
21 < extern char  *strcpy(), *strcat(), *malloc();
22 < extern double  stadj(), sdec(), sazi(), salt();
21 > #ifndef  PI
22 > #define  PI             3.14159265358979323846
23 > #endif
24  
25 #define  PI             3.141592654
26
25   #define  DOT(v1,v2)     (v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2])
26  
27   #define  S_CLEAR        1
# Line 31 | Line 29 | extern double  stadj(), sdec(), sazi(), salt();
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();
35 <                                        /* sun calculation constants */
36 < extern double  s_latitude;
37 < extern double  s_longitude;
38 < extern double  s_meridian;
35 >
36 > #undef  toupper
37 > #define  toupper(c)     ((c) & ~0x20)   /* ASCII trick to convert case */
38 >
39 >                                        /* European and North American zones */
40 > 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}
60 > };
61                                          /* required values */
62   int  month, day;                                /* date */
63   double  hour;                                   /* time */
# Line 48 | 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 60 | 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 85 | Line 116 | char  *argv[];
116                  day = atoi(argv[2]);
117                  if (day < 1 || day > 31)
118                          userror("bad day");
119 <                hour = atof(argv[3]);
89 <                if (hour < 0 || hour >= 24)
90 <                        userror("bad hour");
91 <                tsolar = argv[3][0] == '+';
119 >                got_meridian = cvthour(argv[3]);
120          }
121          for (i = 4; i < argc; i++)
122                  if (argv[i][0] == '-' || argv[i][0] == '+')
# Line 130 | 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 139 | Line 171 | char  *argv[];
171                  else
172                          userror("bad option");
173  
174 <        if (fabs(s_meridian-s_longitude) > 30*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);
180  
181          computesky();
182          printsky();
183 +
184 +        exit(0);
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 167 | Line 202 | computesky()                   /* compute sky parameters */
202                          st = hour + stadj(jd);
203                  altitude = salt(sd, st);
204                  azimuth = sazi(sd, st);
205 +                printf("# Local solar time: %.2f\n", st);
206                  printf("# Solar altitude and azimuth: %.1f %.1f\n",
207                                  180./PI*altitude, 180./PI*azimuth);
208          }
# Line 235 | 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 258 | 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 291 | 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 304 | 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 312 | 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 326 | Line 366 | normsc()                       /* compute normalization factor (E0*F2/L0)
366   }
367  
368  
369 < printhead(ac, av)               /* print command header */
370 < register int  ac;
371 < register char  **av;
369 > int
370 > cvthour(                        /* convert hour string */
371 >        char  *hs
372 > )
373 > {
374 >        char  *cp = hs;
375 >        int     i, j;
376 >
377 >        if ( (tsolar = *cp == '+') ) cp++;              /* solar time? */
378 >        while (isdigit(*cp)) cp++;
379 >        if (*cp == ':')
380 >                hour = atoi(hs) + atoi(++cp)/60.0;
381 >        else {
382 >                hour = atof(hs);
383 >                if (*cp == '.') cp++;
384 >        }
385 >        while (isdigit(*cp)) cp++;
386 >        if (!*cp)
387 >                return(0);
388 >        if (tsolar || !isalpha(*cp)) {
389 >                fprintf(stderr, "%s: bad time format: %s\n", progname, hs);
390 >                exit(1);
391 >        }
392 >        i = 0;
393 >        do {
394 >                for (j = 0; cp[j]; j++)
395 >                        if (toupper(cp[j]) != tzone[i].zname[j])
396 >                                break;
397 >                if (!cp[j] && !tzone[i].zname[j]) {
398 >                        s_meridian = tzone[i].zmer * (PI/180);
399 >                        return(1);
400 >                }
401 >        } while (tzone[i++].zname[0]);
402 >
403 >        fprintf(stderr, "%s: unknown time zone: %s\n", progname, cp);
404 >        fprintf(stderr, "Known time zones:\n\t%s", tzone[0].zname);
405 >        for (i = 1; tzone[i].zname[0]; i++)
406 >                fprintf(stderr, " %s", tzone[i].zname);
407 >        putc('\n', stderr);
408 >        exit(1);
409 > }
410 >
411 >
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