ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/gendaymtx.c
(Generate patch)

Comparing ray/src/gen/gendaymtx.c (file contents):
Revision 2.10 by greg, Sat Apr 6 00:44:59 2013 UTC vs.
Revision 2.20 by greg, Sat Aug 1 23:27:04 2015 UTC

# Line 86 | Line 86 | static const char RCSid[] = "$Id$";
86   #include <string.h>
87   #include <ctype.h>
88   #include "rtmath.h"
89 + #include "resolu.h"
90 + #include "platform.h"
91   #include "color.h"
92 + #include "resolu.h"
93  
94   char *progname;                                                         /* Program name */
95   char errmsg[128];                                                       /* Error message buffer */
# Line 108 | Line 111 | double sky_clearness;                  /* Sky clearness */
111   double solar_rad;                       /* Solar radiance */
112   double sun_zenith;                      /* Sun zenith angle (radians) */
113   int     input = 0;                              /* Input type */
114 + int     output = 0;                             /* Output type */
115  
116   extern double dmax( double, double );
117   extern double CalcAirMass();
# Line 208 | Line 212 | static const CategoryBounds SkyClearCat[8] =
212          { 1.950, 2.800 },
213          { 2.800, 4.500 },
214          { 4.500, 6.200 },
215 <        { 6.200, 12.00 }        /* Clear */
215 >        { 6.200, 12.01 }        /* Clear */
216   };
217  
218   /* Luminous efficacy model coefficients */
# Line 291 | Line 295 | extern int     rh_init(void);
295   extern float *  resize_dmatrix(float *mtx_data, int nsteps, int npatch);
296   extern void     AddDirect(float *parr);
297  
298 +
299 + static const char *
300 + getfmtname(int fmt)
301 + {
302 +        switch (fmt) {
303 +        case 'a':
304 +                return("ascii");
305 +        case 'f':
306 +                return("float");
307 +        case 'd':
308 +                return("double");
309 +        }
310 +        return("unknown");
311 + }
312 +
313 +
314   int
315   main(int argc, char *argv[])
316   {
317          char    buf[256];
318 +        int     doheader = 1;           /* output header? */
319          double  rotation = 0;           /* site rotation (degrees) */
320          double  elevation;              /* site elevation (meters) */
321          int     dir_is_horiz;           /* direct is meas. on horizontal? */
322          float   *mtx_data = NULL;       /* our matrix data */
323          int     ntsteps = 0;            /* number of rows in matrix */
324 +        int     step_alloc = 0;
325          int     last_monthly = 0;       /* month of last report */
326          int     mo, da;                 /* month (1-12) and day (1-31) */
327          double  hr;                     /* hour (local standard time) */
# Line 319 | Line 341 | main(int argc, char *argv[])
341                  case 'v':                       /* verbose progress reports */
342                          verbose++;
343                          break;
344 +                case 'h':                       /* turn off header */
345 +                        doheader = 0;
346 +                        break;
347                  case 'o':                       /* output format */
348                          switch (argv[i][2]) {
349                          case 'f':
# Line 330 | Line 355 | main(int argc, char *argv[])
355                                  goto userr;
356                          }
357                          break;
358 +                case 'O':                       /* output type */
359 +                        switch (argv[i][2]) {
360 +                        case '0':
361 +                                output = 0;
362 +                                break;
363 +                        case '1':
364 +                                output = 1;
365 +                                break;
366 +                        default:
367 +                                goto userr;
368 +                        }
369 +                        if (argv[i][3])
370 +                                goto userr;
371 +                        break;
372                  case 'm':                       /* Reinhart subdivisions */
373                          rhsubdiv = atoi(argv[++i]);
374                          break;
# Line 355 | Line 394 | main(int argc, char *argv[])
394                          break;
395                  case '5':                       /* 5-phase calculation */
396                          nsuns = 1;
397 <                        fixed_sun_sa = 6.797e-05;
397 >                        fixed_sun_sa = PI/360.*atof(argv[++i]);
398 >                        fixed_sun_sa *= fixed_sun_sa*PI;
399                          break;
400                  default:
401                          goto userr;
# Line 424 | Line 464 | main(int argc, char *argv[])
464                  double          sda, sta;
465                                          /* make space for next time step */
466                  mtx_offset = 3*nskypatch*ntsteps++;
467 <                mtx_data = resize_dmatrix(mtx_data, ntsteps, nskypatch);
467 >                if (ntsteps > step_alloc) {
468 >                        step_alloc += (step_alloc>>1) + ntsteps + 7;
469 >                        mtx_data = resize_dmatrix(mtx_data, step_alloc, nskypatch);
470 >                }
471                  if (dif <= 1e-4) {
472                          memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
473                          continue;
# Line 463 | Line 506 | main(int argc, char *argv[])
506                          break;
507                  }
508                                          /* write out matrix */
509 +        if (outfmt != 'a')
510 +                SET_FILE_BINARY(stdout);
511   #ifdef getc_unlocked
512          flockfile(stdout);
513   #endif
514          if (verbose)
515                  fprintf(stderr, "%s: writing %smatrix with %d time steps...\n",
516                                  progname, outfmt=='a' ? "" : "binary ", ntsteps);
517 +        if (doheader) {
518 +                newheader("RADIANCE", stdout);
519 +                printargs(argc, argv, stdout);
520 +                printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude),
521 +                                        -RadToDeg(s_longitude));
522 +                printf("NROWS=%d\n", nskypatch);
523 +                printf("NCOLS=%d\n", ntsteps);
524 +                printf("NCOMP=3\n");
525 +                fputformat((char *)getfmtname(outfmt), stdout);
526 +                putchar('\n');
527 +        }
528                                          /* patches are rows (outer sort) */
529          for (i = 0; i < nskypatch; i++) {
530                  mtx_offset = 3*i;
# Line 510 | Line 566 | main(int argc, char *argv[])
566                  fprintf(stderr, "%s: done.\n", progname);
567          exit(0);
568   userr:
569 <        fprintf(stderr, "Usage: %s [-v][-d|-s][-r deg][-m N][-g r g b][-c r g b][-o{f|d}] [tape.wea]\n",
569 >        fprintf(stderr, "Usage: %s [-v][-h][-d|-s][-r deg][-m N][-g r g b][-c r g b][-o{f|d}][-O{0|1}] [tape.wea]\n",
570                          progname);
571          exit(1);
572   fmterr:
# Line 569 | Line 625 | ComputeSky(float *parr)
625  
626                  /* Limit sky brightness */
627                  if (sky_brightness < 0.01)
628 <                        sky_brightness = 0.01;
628 >                        sky_brightness = 0.01;
629  
630                  /* Calculate illuminance */
631                  index = GetCategoryIndex();
# Line 582 | Line 638 | ComputeSky(float *parr)
638                  index = CalcSkyParamFromIllum();
639          }
640  
641 +        if (output == 1) {                      /* hack for solar radiance */
642 +                diff_illum = diff_irrad * WHTEFFICACY;
643 +                dir_illum = dir_irrad * WHTEFFICACY;
644 +        }
645 +
646          if (bright(skycolor) <= 1e-4) {                 /* 0 sky component? */
647                  memset(parr, 0, sizeof(float)*3*nskypatch);
648                  return;
# Line 602 | Line 663 | ComputeSky(float *parr)
663          /* Calculate relative horizontal illuminance */
664          norm_diff_illum = CalcRelHorzIllum(parr);
665  
666 +        /* Check for zero sky -- make uniform in that case */
667 +        if (norm_diff_illum <= FTINY) {
668 +                for (i = 1; i < nskypatch; i++)
669 +                        setcolor(parr+3*i, 1., 1., 1.);
670 +                norm_diff_illum = PI;
671 +        }
672          /* Normalization coefficient */
673          norm_diff_illum = diff_illum / norm_diff_illum;
674  
# Line 801 | Line 868 | double CalcSkyClearness()
868          double sz_cubed;        /* Sun zenith angle cubed */
869  
870          /* Calculate sun zenith angle cubed */
871 <        sz_cubed = pow(sun_zenith, 3.0);
871 >        sz_cubed = sun_zenith*sun_zenith*sun_zenith;
872  
873          return ((diff_irrad + dir_irrad) / diff_irrad + 1.041 *
874                          sz_cubed) / (1.0 + 1.041 * sz_cubed);
# Line 832 | Line 899 | double CalcDiffuseIrradiance()
899   double CalcDirectIrradiance()
900   {
901          return CalcDiffuseIrradiance() * ((sky_clearness - 1.0) * (1 + 1.041
902 <                        * pow(sun_zenith, 3.0)));
902 >                        * sun_zenith*sun_zenith*sun_zenith));
903   }
904  
905   /* Calculate sky brightness and clearness from illuminance values */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines