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.26 by greg, Wed Jul 30 17:30:27 2014 UTC vs.
Revision 2.29 by greg, Thu Mar 30 20:19:05 2023 UTC

# Line 10 | Line 10 | static const char      RCSid[] = "$Id$";
10   *     3/26/86
11   */
12  
13 < #include  <stdio.h>
13 > #include  "rtio.h"
14   #include  <stdlib.h>
15 #include  <string.h>
15   #include  <math.h>
16   #include  <ctype.h>
17   #include  "sun.h"
# Line 59 | Line 58 | struct {
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 86 | Line 86 | void printdefaults(void);
86   void userror(char  *msg);
87   double normsc(void);
88   int cvthour(char  *hs);
89 void printhead(int  ac, char  **av);
89  
90  
91   int
# Line 125 | Line 124 | main(
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 171 | Line 173 | main(
173                  else
174                          userror("bad option");
175  
176 +        if (year && (year < 1950) | (year > 2050))
177 +                fprintf(stderr,
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 191 | Line 198 | computesky(void)                       /* compute sky parameters */
198          double  normfactor;
199                                          /* compute solar direction */
200          if (month) {                    /* from date and time */
201 <                int  jd;
195 <                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 277 | Line 289 | printsky(void)                 /* print out sky */
289          if (dosun) {
290                  printf("\nvoid light solar\n");
291                  printf("0\n0\n");
292 <                printf("3 %.2e %.2e %.2e\n", solarbr, solarbr, solarbr);
292 >                printf("3 %.3e %.3e %.3e\n", solarbr, solarbr, solarbr);
293                  printf("\nsolar source sun\n");
294                  printf("0\n0\n");
295                  printf("4 %f %f %f 0.5\n", sundir[0], sundir[1], sundir[2]);
# Line 287 | Line 299 | printsky(void)                 /* print out sky */
299          printf("2 skybr skybright.cal\n");
300          printf("0\n");
301          if (overcast)
302 <                printf("3 %d %.2e %.2e\n", skytype, zenithbr, groundbr);
302 >                printf("3 %d %.3e %.3e\n", skytype, zenithbr, groundbr);
303          else
304 <                printf("7 %d %.2e %.2e %.2e %f %f %f\n",
304 >                printf("7 %d %.3e %.3e %.3e %f %f %f\n",
305                                  skytype, zenithbr, groundbr, F2,
306                                  sundir[0], sundir[1], sundir[2]);
307   }
# Line 406 | Line 418 | cvthour(                       /* convert hour string */
418                  fprintf(stderr, " %s", tzone[i].zname);
419          putc('\n', stderr);
420          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--) {
420                putchar(' ');
421                fputs(*av++, stdout);
422        }
423        putchar('\n');
421   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines