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.27 by greg, Tue Jun 25 00:09:45 2019 UTC vs.
Revision 2.32 by greg, Mon Jan 6 21:02:57 2020 UTC

# Line 81 | Line 81 | static const char RCSid[] = "$Id$";
81  
82   /* Include files */
83   #define _USE_MATH_DEFINES
84 #include <stdio.h>
84   #include <stdlib.h>
86 #include <string.h>
85   #include <ctype.h>
86 + #include "platform.h"
87   #include "rtmath.h"
88   #include "rtio.h"
90 #include "resolu.h"
91 #include "platform.h"
89   #include "color.h"
90 < #include "resolu.h"
90 > #include "sun.h"
91  
92   char *progname;                                                         /* Program name */
93   char errmsg[128];                                                       /* Error message buffer */
# Line 255 | Line 252 | static const ModelCoeff DirectLumEff[8] =
252   #define NSUNPATCH       4               /* max. # patches to spread sun into */
253   #endif
254  
258 extern int jdate(int month, int day);
259 extern double stadj(int  jd);
260 extern double sdec(int  jd);
261 extern double salt(double sd, double st);
262 extern double sazi(double sd, double st);
263                                        /* sun calculation constants */
264 extern double  s_latitude;
265 extern double  s_longitude;
266 extern double  s_meridian;
267
255   int             nsuns = NSUNPATCH;      /* number of sun patches to use */
256   double          fixed_sun_sa = -1;      /* fixed solid angle per sun? */
257  
# Line 321 | Line 308 | main(int argc, char *argv[])
308          double  elevation;              /* site elevation (meters) */
309          int     dir_is_horiz;           /* direct is meas. on horizontal? */
310          float   *mtx_data = NULL;       /* our matrix data */
324        int     ntsteps = 0;            /* number of time steps */
311          int     avgSky = 0;             /* compute average sky r.t. matrix? */
312 <        int     nrows = 0;              /* number of rows in matrix */
313 <        int     rows_alloc = 0;         /* number of allocated rows */
312 >        int     ntsteps = 0;            /* number of time steps */
313 >        int     tstorage = 0;           /* number of allocated time steps */
314 >        int     nstored = 0;            /* number of time steps in matrix */
315          int     last_monthly = 0;       /* month of last report */
316          int     inconsistent = 0;       /* inconsistent options set? */
317          int     mo, da;                 /* month (1-12) and day (1-31) */
# Line 480 | Line 467 | main(int argc, char *argv[])
467          s_longitude = DegToRad(s_longitude);
468          s_meridian = DegToRad(s_meridian);
469                                          /* initial allocation */
470 <        mtx_data = resize_dmatrix(mtx_data, rows_alloc=2, nskypatch);
470 >        mtx_data = resize_dmatrix(mtx_data, tstorage=2, nskypatch);
471                                          /* process each time step in tape */
472          while (scanf("%d %d %lf %lf %lf\n", &mo, &da, &hr, &dir, &dif) == 5) {
473                  double          sda, sta;
474  
475 <                mtx_offset = 3*nskypatch*nrows;
476 <                nrows += !avgSky | !nrows;
475 >                mtx_offset = 3*nskypatch*nstored;
476 >                nstored += !avgSky | !nstored;
477                                          /* make space for next row */
478 <                if (nrows > rows_alloc) {
479 <                        rows_alloc += (rows_alloc>>1) + nrows + 7;
480 <                        mtx_data = resize_dmatrix(mtx_data, rows_alloc, nskypatch);
478 >                if (nstored > tstorage) {
479 >                        tstorage += (tstorage>>1) + nstored + 7;
480 >                        mtx_data = resize_dmatrix(mtx_data, tstorage, nskypatch);
481                  }
482                  ntsteps++;              /* keep count of time steps */
483                  if (dif <= 1e-4) {
484 <                        if (!avgSky | !nrows)
484 >                        if (!avgSky | !mtx_offset)
485                                  memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
486                          continue;
487                  }
# Line 549 | Line 536 | main(int argc, char *argv[])
536   #endif
537          if (verbose)
538                  fprintf(stderr, "%s: writing %smatrix with %d time steps...\n",
539 <                                progname, outfmt=='a' ? "" : "binary ", nrows);
539 >                                progname, outfmt=='a' ? "" : "binary ", nstored);
540          if (doheader) {
541                  newheader("RADIANCE", stdout);
542                  printargs(argc, argv, stdout);
543                  printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude),
544                                          -RadToDeg(s_longitude));
545                  printf("NROWS=%d\n", nskypatch);
546 <                printf("NCOLS=%d\n", nrows);
546 >                printf("NCOLS=%d\n", nstored);
547                  printf("NCOMP=3\n");
548 +                if ((outfmt == 'f') | (outfmt == 'd'))
549 +                        fputendian(stdout);
550                  fputformat((char *)getfmtname(outfmt), stdout);
551                  putchar('\n');
552          }
# Line 566 | Line 555 | main(int argc, char *argv[])
555                  mtx_offset = 3*i;
556                  switch (outfmt) {
557                  case 'a':
558 <                        for (j = 0; j < nrows; j++) {
558 >                        for (j = 0; j < nstored; j++) {
559                                  printf("%.3g %.3g %.3g\n", mtx_data[mtx_offset],
560                                                  mtx_data[mtx_offset+1],
561                                                  mtx_data[mtx_offset+2]);
562                                  mtx_offset += 3*nskypatch;
563                          }
564 <                        if (nrows > 1)
564 >                        if (nstored > 1)
565                                  fputc('\n', stdout);
566                          break;
567                  case 'f':
568 <                        for (j = 0; j < nrows; j++) {
568 >                        for (j = 0; j < nstored; j++) {
569                                  putbinary(mtx_data+mtx_offset, sizeof(float), 3,
570                                                  stdout);
571                                  mtx_offset += 3*nskypatch;
572                          }
573                          break;
574                  case 'd':
575 <                        for (j = 0; j < nrows; j++) {
575 >                        for (j = 0; j < nstored; j++) {
576                                  double  ment[3];
577                                  ment[0] = mtx_data[mtx_offset];
578                                  ment[1] = mtx_data[mtx_offset+1];
# Line 678 | Line 667 | ComputeSky(float *parr)
667                  diff_illum = diff_irrad * WHTEFFICACY;
668                  dir_illum = dir_irrad * WHTEFFICACY;
669          }
681
682        if (bright(skycolor) <= 1e-4) {                 /* 0 sky component? */
683                memset(parr, 0, sizeof(float)*3*nskypatch);
684                return;
685        }
670          /* Compute ground radiance (include solar contribution if any) */
671          parr[0] = diff_illum;
672          if (altitude > 0)
# Line 690 | Line 674 | ComputeSky(float *parr)
674          parr[2] = parr[1] = parr[0] *= (1./PI/WHTEFFICACY);
675          multcolor(parr, grefl);
676  
677 +        if (bright(skycolor) <= 1e-4) {                 /* 0 sky component? */
678 +                memset(parr+3, 0, sizeof(float)*3*(nskypatch-1));
679 +                return;
680 +        }
681          /* Calculate Perez sky model parameters */
682          CalcPerezParam(sun_zenith, sky_clearness, sky_brightness, index);
683  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines