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.16 by greg, Tue Jun 17 21:01:21 2014 UTC

# Line 86 | Line 86 | static const char RCSid[] = "$Id$";
86   #include <string.h>
87   #include <ctype.h>
88   #include "rtmath.h"
89 + #include "platform.h"
90   #include "color.h"
91  
92   char *progname;                                                         /* Program name */
# Line 108 | Line 109 | double sky_clearness;                  /* Sky clearness */
109   double solar_rad;                       /* Solar radiance */
110   double sun_zenith;                      /* Sun zenith angle (radians) */
111   int     input = 0;                              /* Input type */
112 + int     output = 0;                             /* Output type */
113  
114   extern double dmax( double, double );
115   extern double CalcAirMass();
# Line 208 | Line 210 | static const CategoryBounds SkyClearCat[8] =
210          { 1.950, 2.800 },
211          { 2.800, 4.500 },
212          { 4.500, 6.200 },
213 <        { 6.200, 12.00 }        /* Clear */
213 >        { 6.200, 12.01 }        /* Clear */
214   };
215  
216   /* Luminous efficacy model coefficients */
# Line 291 | Line 293 | extern int     rh_init(void);
293   extern float *  resize_dmatrix(float *mtx_data, int nsteps, int npatch);
294   extern void     AddDirect(float *parr);
295  
296 +
297 + static const char *
298 + getfmtname(int fmt)
299 + {
300 +        switch (fmt) {
301 +        case 'a':
302 +                return("ascii");
303 +        case 'f':
304 +                return("float");
305 +        case 'd':
306 +                return("double");
307 +        }
308 +        return("unknown");
309 + }
310 +
311 +
312   int
313   main(int argc, char *argv[])
314   {
315          char    buf[256];
316 +        int     doheader = 1;           /* output header? */
317          double  rotation = 0;           /* site rotation (degrees) */
318          double  elevation;              /* site elevation (meters) */
319          int     dir_is_horiz;           /* direct is meas. on horizontal? */
320          float   *mtx_data = NULL;       /* our matrix data */
321          int     ntsteps = 0;            /* number of rows in matrix */
322 +        int     step_alloc = 0;
323          int     last_monthly = 0;       /* month of last report */
324          int     mo, da;                 /* month (1-12) and day (1-31) */
325          double  hr;                     /* hour (local standard time) */
# Line 319 | Line 339 | main(int argc, char *argv[])
339                  case 'v':                       /* verbose progress reports */
340                          verbose++;
341                          break;
342 +                case 'h':                       /* turn off header */
343 +                        doheader = 0;
344 +                        break;
345                  case 'o':                       /* output format */
346                          switch (argv[i][2]) {
347                          case 'f':
# Line 330 | Line 353 | main(int argc, char *argv[])
353                                  goto userr;
354                          }
355                          break;
356 +                case 'O':                       /* output type */
357 +                        switch (argv[i][2]) {
358 +                        case '0':
359 +                                output = 0;
360 +                                break;
361 +                        case '1':
362 +                                output = 1;
363 +                                break;
364 +                        default:
365 +                                goto userr;
366 +                        }
367 +                        if (argv[i][3])
368 +                                goto userr;
369 +                        break;
370                  case 'm':                       /* Reinhart subdivisions */
371                          rhsubdiv = atoi(argv[++i]);
372                          break;
# Line 424 | Line 461 | main(int argc, char *argv[])
461                  double          sda, sta;
462                                          /* make space for next time step */
463                  mtx_offset = 3*nskypatch*ntsteps++;
464 <                mtx_data = resize_dmatrix(mtx_data, ntsteps, nskypatch);
464 >                if (ntsteps > step_alloc) {
465 >                        step_alloc += (step_alloc>>1) + ntsteps + 7;
466 >                        mtx_data = resize_dmatrix(mtx_data, step_alloc, nskypatch);
467 >                }
468                  if (dif <= 1e-4) {
469                          memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
470                          continue;
# Line 463 | Line 503 | main(int argc, char *argv[])
503                          break;
504                  }
505                                          /* write out matrix */
506 +        if (outfmt != 'a')
507 +                SET_FILE_BINARY(stdout);
508   #ifdef getc_unlocked
509          flockfile(stdout);
510   #endif
511          if (verbose)
512                  fprintf(stderr, "%s: writing %smatrix with %d time steps...\n",
513                                  progname, outfmt=='a' ? "" : "binary ", ntsteps);
514 +        if (doheader) {
515 +                newheader("RADIANCE", stdout);
516 +                printargs(argc, argv, stdout);
517 +                printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude),
518 +                                        -RadToDeg(s_longitude));
519 +                printf("NROWS=%d\n", nskypatch);
520 +                printf("NCOLS=%d\n", ntsteps);
521 +                printf("NCOMP=3\n");
522 +                fputformat(getfmtname(outfmt), stdout);
523 +                putchar('\n');
524 +        }
525                                          /* patches are rows (outer sort) */
526          for (i = 0; i < nskypatch; i++) {
527                  mtx_offset = 3*i;
# Line 510 | Line 563 | main(int argc, char *argv[])
563                  fprintf(stderr, "%s: done.\n", progname);
564          exit(0);
565   userr:
566 <        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",
566 >        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",
567                          progname);
568          exit(1);
569   fmterr:
# Line 569 | Line 622 | ComputeSky(float *parr)
622  
623                  /* Limit sky brightness */
624                  if (sky_brightness < 0.01)
625 <                        sky_brightness = 0.01;
625 >                        sky_brightness = 0.01;
626  
627                  /* Calculate illuminance */
628                  index = GetCategoryIndex();
# Line 582 | Line 635 | ComputeSky(float *parr)
635                  index = CalcSkyParamFromIllum();
636          }
637  
638 +        if (output == 1) {                      /* hack for solar radiance */
639 +                diff_illum = diff_irrad * WHTEFFICACY;
640 +                dir_illum = dir_irrad * WHTEFFICACY;
641 +        }
642 +
643          if (bright(skycolor) <= 1e-4) {                 /* 0 sky component? */
644                  memset(parr, 0, sizeof(float)*3*nskypatch);
645                  return;
# Line 602 | Line 660 | ComputeSky(float *parr)
660          /* Calculate relative horizontal illuminance */
661          norm_diff_illum = CalcRelHorzIllum(parr);
662  
663 +        /* Check for zero sky -- make uniform in that case */
664 +        if (norm_diff_illum <= FTINY) {
665 +                for (i = 1; i < nskypatch; i++)
666 +                        setcolor(parr+3*i, 1., 1., 1.);
667 +                norm_diff_illum = PI;
668 +        }
669          /* Normalization coefficient */
670          norm_diff_illum = diff_illum / norm_diff_illum;
671  
# Line 801 | Line 865 | double CalcSkyClearness()
865          double sz_cubed;        /* Sun zenith angle cubed */
866  
867          /* Calculate sun zenith angle cubed */
868 <        sz_cubed = pow(sun_zenith, 3.0);
868 >        sz_cubed = sun_zenith*sun_zenith*sun_zenith;
869  
870          return ((diff_irrad + dir_irrad) / diff_irrad + 1.041 *
871                          sz_cubed) / (1.0 + 1.041 * sz_cubed);
# Line 832 | Line 896 | double CalcDiffuseIrradiance()
896   double CalcDirectIrradiance()
897   {
898          return CalcDiffuseIrradiance() * ((sky_clearness - 1.0) * (1 + 1.041
899 <                        * pow(sun_zenith, 3.0)));
899 >                        * sun_zenith*sun_zenith*sun_zenith));
900   }
901  
902   /* Calculate sky brightness and clearness from illuminance values */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines