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.22 by schorsch, Sun Nov 16 10:29:38 2003 UTC vs.
Revision 2.27 by greg, Thu Nov 7 23:15:07 2019 UTC

# Line 15 | Line 15 | static const char      RCSid[] = "$Id$";
15   #include  <string.h>
16   #include  <math.h>
17   #include  <ctype.h>
18 <
18 > #include  "sun.h"
19   #include  "color.h"
20  
21 extern int jdate(int month, int day);
22 extern double stadj(int  jd);
23 extern double sdec(int  jd);
24 extern double salt(double sd, double st);
25 extern double sazi(double sd, double st);
26
21   #ifndef  PI
22   #define  PI             3.14159265358979323846
23   #endif
# Line 38 | Line 32 | extern double sazi(double sd, double st);
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 69 | Line 59 | struct {
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 78 | 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 95 | Line 86 | void printsky(void);
86   void printdefaults(void);
87   void userror(char  *msg);
88   double normsc(void);
89 < void cvthour(char  *hs);
90 < void printhead(register int  ac, register char  **av);
89 > int cvthour(char  *hs);
90 > void printhead(int  ac, char  **av);
91  
92  
93   int
94 < main(argc, argv)
95 < int  argc;
96 < char  *argv[];
94 > main(
95 >        int  argc,
96 >        char  *argv[]
97 > )
98   {
99 +        int  got_meridian = 0;
100          int  i;
101  
102          progname = argv[0];
# Line 124 | 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 133 | 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 166 | 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 175 | Line 175 | char  *argv[];
175                  else
176                          userror("bad option");
177  
178 <        if (fabs(s_meridian-s_longitude) > 45*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 195 | Line 199 | computesky(void)                       /* compute sky parameters */
199          double  normfactor;
200                                          /* compute solar direction */
201          if (month) {                    /* from date and time */
202 <                int  jd;
199 <                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 356 | Line 365 | normsc(void)                   /* compute normalization factor (E0*F2/
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 370 | Line 379 | normsc(void)                   /* compute normalization factor (E0*F2/
379   }
380  
381  
382 < void
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? */
391          while (isdigit(*cp)) cp++;
# Line 388 | Line 397 | cvthour(                       /* convert hour string */
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 400 | Line 409 | cvthour(                       /* convert hour string */
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 415 | Line 424 | cvthour(                       /* convert hour string */
424  
425   void
426   printhead(              /* print command header */
427 <        register int  ac,
428 <        register char  **av
427 >        int  ac,
428 >        char  **av
429   )
430   {
431          putchar('#');

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines