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.1 by greg, Tue Nov 12 17:05:02 1991 UTC vs.
Revision 2.7 by greg, Fri Oct 2 16:11:53 1992 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19  
20   #include  "color.h"
21  
22 + #ifndef atof
23 + extern double  atof();
24 + #endif
25   extern char  *strcpy(), *strcat(), *malloc();
26   extern double  stadj(), sdec(), sazi(), salt();
27  
# Line 32 | Line 35 | extern double  s_latitude;
35   extern double  s_longitude;
36   extern double  s_meridian;
37                                          /* required values */
38 < int  month, day;
39 < double  hour;
38 > int  month, day;                                /* date */
39 > double  hour;                                   /* time */
40 > int  tsolar;                                    /* 0=standard, 1=solar */
41 > double  altitude, azimuth;                      /* or solar angles */
42                                          /* default values */
43 < int  cloudy = 0;
43 > int  cloudy = 0;                                /* 1=standard, 2=uniform */
44   int  dosun = 1;
45   double  zenithbr = -1.0;
46   double  turbidity = 2.75;
# Line 54 | Line 59 | main(argc, argv)
59   int  argc;
60   char  *argv[];
61   {
57        extern double  atof(), fabs();
62          int  i;
63  
64          progname = argv[0];
# Line 64 | Line 68 | char  *argv[];
68          }
69          if (argc < 4)
70                  userror("arg count");
71 <        month = atoi(argv[1]);
72 <        day = atoi(argv[2]);
73 <        hour = atof(argv[3]);
71 >        if (!strcmp(argv[1], "-ang")) {
72 >                altitude = atof(argv[2]) * (PI/180);
73 >                azimuth = atof(argv[3]) * (PI/180);
74 >                month = 0;
75 >        } else {
76 >                month = atoi(argv[1]);
77 >                if (month < 1 || month > 12)
78 >                        userror("bad month");
79 >                day = atoi(argv[2]);
80 >                if (day < 1 || day > 31)
81 >                        userror("bad day");
82 >                hour = atof(argv[3]);
83 >                if (hour < 0 || hour >= 24)
84 >                        userror("bad hour");
85 >                tsolar = argv[3][0] == '+';
86 >        }
87          for (i = 4; i < argc; i++)
88                  if (argv[i][0] == '-' || argv[i][0] == '+')
89                          switch (argv[i][1]) {
# Line 75 | Line 92 | char  *argv[];
92                                  dosun = argv[i][0] == '+';
93                                  break;
94                          case 'c':
95 <                                cloudy = 1;
95 >                                cloudy = argv[i][0] == '+' ? 2 : 1;
96                                  dosun = 0;
97                                  break;
98                          case 't':
# Line 117 | Line 134 | char  *argv[];
134  
135   computesky()                    /* compute sky parameters */
136   {
120        int  jd;
121        double  sd, st;
122        double  altitude, azimuth;
137                                          /* compute solar direction */
138 <        jd = jdate(month, day);                 /* Julian date */
139 <        sd = sdec(jd);                          /* solar declination */
140 <        st = hour + stadj(jd);                  /* solar time */
141 <        altitude = salt(sd, st);
142 <        azimuth = sazi(sd, st);
138 >        if (month) {                    /* from date and time */
139 >                int  jd;
140 >                double  sd, st;
141 >
142 >                jd = jdate(month, day);         /* Julian date */
143 >                sd = sdec(jd);                  /* solar declination */
144 >                if (tsolar)                     /* solar time */
145 >                        st = hour;
146 >                else
147 >                        st = hour + stadj(jd);
148 >                altitude = salt(sd, st);
149 >                azimuth = sazi(sd, st);
150 >        }
151          sundir[0] = -sin(azimuth)*cos(altitude);
152          sundir[1] = -cos(azimuth)*cos(altitude);
153          sundir[2] = sin(altitude);
# Line 134 | Line 156 | computesky()                   /* compute sky parameters */
156          if (zenithbr <= 0.0)
157                  if (cloudy) {
158                          zenithbr = 8.6*sundir[2] + .123;
159 <                        zenithbr *= 1000.0/SKYEFFICACY;
159 >                        zenithbr *= 1000.0/WHTEFFICACY;
160                  } else {
161                          zenithbr = (1.376*turbidity-1.81)*tan(altitude)+0.38;
162                          zenithbr *= 1000.0/SKYEFFICACY;
# Line 143 | Line 165 | computesky()                   /* compute sky parameters */
165                  zenithbr = 0.0;
166                                          /* Compute horizontal radiance */
167          if (cloudy) {
168 <                groundbr = zenithbr*0.777778;
168 >                if (cloudy == 2)
169 >                        groundbr = zenithbr;
170 >                else
171 >                        groundbr = zenithbr*0.777778;
172                  printf("# Ground ambient level: %f\n", groundbr);
173          } else {
174                  F2 = 0.274*(0.91 + 10.0*exp(-3.0*(PI/2.0-altitude)) +
175                                  0.45*sundir[2]*sundir[2]);
176 <                groundbr = zenithbr*normsc(PI/2.0-altitude)/F2/PI;
176 >                groundbr = zenithbr*normsc(altitude)/F2/PI;
177                  printf("# Ground ambient level: %f\n", groundbr);
178                  if (sundir[2] > 0.0) {
179                          if (sundir[2] > .16)
# Line 179 | Line 204 | printsky()                     /* print out sky */
204          printf("2 skybright skybright.cal\n");
205          printf("0\n");
206          if (cloudy)
207 <                printf("3 1 %.2e %.2e\n", zenithbr, groundbr);
207 >                printf("3 %d %.2e %.2e\n", cloudy, zenithbr, groundbr);
208          else
209                  printf("7 -1 %.2e %.2e %.2e %f %f %f\n", zenithbr, groundbr,
210                                  F2, sundir[0], sundir[1], sundir[2]);
# Line 188 | Line 213 | printsky()                     /* print out sky */
213  
214   printdefaults()                 /* print default values */
215   {
216 <        if (cloudy)
216 >        if (cloudy == 1)
217                  printf("-c\t\t\t\t# Cloudy sky\n");
218 +        else if (cloudy == 2)
219 +                printf("+c\t\t\t\t# Uniform cloudy sky\n");
220          else if (dosun)
221                  printf("+s\t\t\t\t# Sunny sky with sun\n");
222          else
# Line 211 | Line 238 | char  *msg;
238          if (msg != NULL)
239                  fprintf(stderr, "%s: Use error - %s\n", progname, msg);
240          fprintf(stderr, "Usage: %s month day hour [options]\n", progname);
241 +        fprintf(stderr, "   Or: %s -ang altitude azimuth [options]\n", progname);
242          fprintf(stderr, "   Or: %s -defaults\n", progname);
243          exit(1);
244   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines