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.24 by greg, Fri Aug 19 15:13:40 2016 UTC vs.
Revision 2.30 by greg, Thu Nov 7 23:15:07 2019 UTC

# Line 85 | Line 85 | static const char RCSid[] = "$Id$";
85   #include <stdlib.h>
86   #include <string.h>
87   #include <ctype.h>
88 + #include "platform.h"
89   #include "rtmath.h"
90   #include "rtio.h"
90 #include "resolu.h"
91 #include "platform.h"
91   #include "color.h"
92 < #include "resolu.h"
92 > #include "sun.h"
93  
94   char *progname;                                                         /* Program name */
95   char errmsg[128];                                                       /* Error message buffer */
# Line 255 | Line 254 | static const ModelCoeff DirectLumEff[8] =
254   #define NSUNPATCH       4               /* max. # patches to spread sun into */
255   #endif
256  
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
257   int             nsuns = NSUNPATCH;      /* number of sun patches to use */
258   double          fixed_sun_sa = -1;      /* fixed solid angle per sun? */
259  
# Line 321 | Line 310 | main(int argc, char *argv[])
310          double  elevation;              /* site elevation (meters) */
311          int     dir_is_horiz;           /* direct is meas. on horizontal? */
312          float   *mtx_data = NULL;       /* our matrix data */
313 <        int     ntsteps = 0;            /* number of rows in matrix */
314 <        int     step_alloc = 0;
313 >        int     avgSky = 0;             /* compute average sky r.t. matrix? */
314 >        int     ntsteps = 0;            /* number of time steps */
315 >        int     tstorage = 0;           /* number of allocated time steps */
316 >        int     nstored = 0;            /* number of time steps in matrix */
317          int     last_monthly = 0;       /* month of last report */
318          int     inconsistent = 0;       /* inconsistent options set? */
319          int     mo, da;                 /* month (1-12) and day (1-31) */
# Line 409 | Line 400 | main(int argc, char *argv[])
400                          }
401                          fixed_sun_sa *= fixed_sun_sa*PI;
402                          break;
403 +                case 'A':                       /* compute average sky */
404 +                        avgSky = 1;
405 +                        break;
406                  default:
407                          goto userr;
408                  }
# Line 474 | Line 468 | main(int argc, char *argv[])
468          s_latitude = DegToRad(s_latitude);
469          s_longitude = DegToRad(s_longitude);
470          s_meridian = DegToRad(s_meridian);
471 +                                        /* initial allocation */
472 +        mtx_data = resize_dmatrix(mtx_data, tstorage=2, nskypatch);
473                                          /* process each time step in tape */
474          while (scanf("%d %d %lf %lf %lf\n", &mo, &da, &hr, &dir, &dif) == 5) {
475                  double          sda, sta;
476 <                                        /* make space for next time step */
477 <                mtx_offset = 3*nskypatch*ntsteps++;
478 <                if (ntsteps > step_alloc) {
479 <                        step_alloc += (step_alloc>>1) + ntsteps + 7;
480 <                        mtx_data = resize_dmatrix(mtx_data, step_alloc, nskypatch);
476 >
477 >                mtx_offset = 3*nskypatch*nstored;
478 >                nstored += !avgSky | !nstored;
479 >                                        /* make space for next row */
480 >                if (nstored > tstorage) {
481 >                        tstorage += (tstorage>>1) + nstored + 7;
482 >                        mtx_data = resize_dmatrix(mtx_data, tstorage, nskypatch);
483                  }
484 +                ntsteps++;              /* keep count of time steps */
485                  if (dif <= 1e-4) {
486 <                        memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
486 >                        if (!avgSky | !mtx_offset)
487 >                                memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
488                          continue;
489                  }
490                  if (verbose && mo != last_monthly)
# Line 509 | Line 509 | main(int argc, char *argv[])
509                                          /* compute sky patch values */
510                  ComputeSky(mtx_data+mtx_offset);
511                  AddDirect(mtx_data+mtx_offset);
512 +                                        /* update cumulative sky? */
513 +                for (i = 3*nskypatch*(avgSky&(ntsteps>1)); i--; )
514 +                        mtx_data[i] += mtx_data[mtx_offset+i];
515          }
516                                          /* check for junk at end */
517          while ((i = fgetc(stdin)) != EOF)
# Line 520 | Line 523 | main(int argc, char *argv[])
523                          fputs(buf, stderr); fputc('\n', stderr);
524                          break;
525                  }
526 +        if (!ntsteps) {
527 +                fprintf(stderr, "%s: no valid time steps on input\n", progname);
528 +                exit(1);
529 +        }
530 +        dif = 1./(double)ntsteps;       /* average sky? */
531 +        for (i = 3*nskypatch*(avgSky&(ntsteps>1)); i--; )
532 +                mtx_data[i] *= dif;
533                                          /* write out matrix */
534          if (outfmt != 'a')
535                  SET_FILE_BINARY(stdout);
# Line 528 | Line 538 | main(int argc, char *argv[])
538   #endif
539          if (verbose)
540                  fprintf(stderr, "%s: writing %smatrix with %d time steps...\n",
541 <                                progname, outfmt=='a' ? "" : "binary ", ntsteps);
541 >                                progname, outfmt=='a' ? "" : "binary ", nstored);
542          if (doheader) {
543                  newheader("RADIANCE", stdout);
544                  printargs(argc, argv, stdout);
545                  printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude),
546                                          -RadToDeg(s_longitude));
547                  printf("NROWS=%d\n", nskypatch);
548 <                printf("NCOLS=%d\n", ntsteps);
548 >                printf("NCOLS=%d\n", nstored);
549                  printf("NCOMP=3\n");
550 +                if ((outfmt == 'f') | (outfmt == 'd'))
551 +                        fputendian(stdout);
552                  fputformat((char *)getfmtname(outfmt), stdout);
553                  putchar('\n');
554          }
# Line 545 | Line 557 | main(int argc, char *argv[])
557                  mtx_offset = 3*i;
558                  switch (outfmt) {
559                  case 'a':
560 <                        for (j = 0; j < ntsteps; j++) {
560 >                        for (j = 0; j < nstored; j++) {
561                                  printf("%.3g %.3g %.3g\n", mtx_data[mtx_offset],
562                                                  mtx_data[mtx_offset+1],
563                                                  mtx_data[mtx_offset+2]);
564                                  mtx_offset += 3*nskypatch;
565                          }
566 <                        if (ntsteps > 1)
566 >                        if (nstored > 1)
567                                  fputc('\n', stdout);
568                          break;
569                  case 'f':
570 <                        for (j = 0; j < ntsteps; j++) {
570 >                        for (j = 0; j < nstored; j++) {
571                                  putbinary(mtx_data+mtx_offset, sizeof(float), 3,
572                                                  stdout);
573                                  mtx_offset += 3*nskypatch;
574                          }
575                          break;
576                  case 'd':
577 <                        for (j = 0; j < ntsteps; j++) {
577 >                        for (j = 0; j < nstored; j++) {
578                                  double  ment[3];
579                                  ment[0] = mtx_data[mtx_offset];
580                                  ment[1] = mtx_data[mtx_offset+1];
# Line 581 | Line 593 | main(int argc, char *argv[])
593                  fprintf(stderr, "%s: done.\n", progname);
594          exit(0);
595   userr:
596 <        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",
596 >        fprintf(stderr, "Usage: %s [-v][-h][-A][-d|-s][-r deg][-m N][-g r g b][-c r g b][-o{f|d}][-O{0|1}] [tape.wea]\n",
597                          progname);
598          exit(1);
599   fmterr:
# Line 953 | Line 965 | int CalcSkyParamFromIllum()
965                  /* Convert illuminance to irradiance */
966                  index = GetCategoryIndex();
967                  diff_irrad = diff_illum / CalcDiffuseIllumRatio(index);
968 <                dir_irrad = dir_illum / CalcDirectIllumRatio(index);
968 >                dir_irrad = CalcDirectIllumRatio(index);
969 >                if (dir_irrad > 0.1)
970 >                        dir_irrad = dir_illum / dir_irrad;
971          
972                  /* Calculate sky brightness and clearness */
973                  sky_brightness = CalcSkyBrightness();
# Line 1128 | Line 1142 | void CalcSkyPatchLumin( float *parr )
1142          double aas;                             /* Sun-sky point azimuthal angle */
1143          double sspa;                    /* Sun-sky point angle */
1144          double zsa;                             /* Zenithal sun angle */
1131
1132        perez_param[0], perez_param[1], perez_param[2], perez_param[3], perez_param[4]);
1145  
1146          for (i = 1; i < nskypatch; i++)
1147          {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines