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.14 by greg, Fri May 30 00:00:54 2014 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 "rtmath.h"
88   #include "platform.h"
89 + #include "rtmath.h"
90 + #include "rtio.h"
91   #include "color.h"
92 + #include "sun.h"
93  
94   char *progname;                                                         /* Program name */
95   char errmsg[128];                                                       /* Error message buffer */
# Line 252 | Line 254 | static const ModelCoeff DirectLumEff[8] =
254   #define NSUNPATCH       4               /* max. # patches to spread sun into */
255   #endif
256  
255 extern int jdate(int month, int day);
256 extern double stadj(int  jd);
257 extern double sdec(int  jd);
258 extern double salt(double sd, double st);
259 extern double sazi(double sd, double st);
260                                        /* sun calculation constants */
261 extern double  s_latitude;
262 extern double  s_longitude;
263 extern double  s_meridian;
264
257   int             nsuns = NSUNPATCH;      /* number of sun patches to use */
258   double          fixed_sun_sa = -1;      /* fixed solid angle per sun? */
259  
# Line 318 | 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 */
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) */
320          double  hr;                     /* hour (local standard time) */
321          double  dir, dif;               /* direct and diffuse values */
# Line 370 | Line 366 | main(int argc, char *argv[])
366                          rhsubdiv = atoi(argv[++i]);
367                          break;
368                  case 'c':                       /* sky color */
369 +                        inconsistent |= (skycolor[1] <= 1e-4);
370                          skycolor[0] = atof(argv[++i]);
371                          skycolor[1] = atof(argv[++i]);
372                          skycolor[2] = atof(argv[++i]);
373                          break;
374                  case 'd':                       /* solar (direct) only */
375                          skycolor[0] = skycolor[1] = skycolor[2] = 0;
376 <                        if (suncolor[1] <= 1e-4)
376 >                        if (suncolor[1] <= 1e-4) {
377 >                                inconsistent = 1;
378                                  suncolor[0] = suncolor[1] = suncolor[2] = 1;
379 +                        }
380                          break;
381                  case 's':                       /* sky only (no direct) */
382                          suncolor[0] = suncolor[1] = suncolor[2] = 0;
383 <                        if (skycolor[1] <= 1e-4)
383 >                        if (skycolor[1] <= 1e-4) {
384 >                                inconsistent = 1;
385                                  skycolor[0] = skycolor[1] = skycolor[2] = 1;
386 +                        }
387                          break;
388                  case 'r':                       /* rotate distribution */
389                          if (argv[i][2] && argv[i][2] != 'z')
# Line 391 | Line 392 | main(int argc, char *argv[])
392                          break;
393                  case '5':                       /* 5-phase calculation */
394                          nsuns = 1;
395 <                        fixed_sun_sa = 6.797e-05;
395 >                        fixed_sun_sa = PI/360.*atof(argv[++i]);
396 >                        if (fixed_sun_sa <= 0) {
397 >                                fprintf(stderr, "%s: missing solar disk size argument for '-5' option\n",
398 >                                                argv[0]);
399 >                                exit(1);
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                  }
409          if (i < argc-1)
410                  goto userr;
411 +        if (inconsistent)
412 +                fprintf(stderr, "%s: WARNING: inconsistent -s, -d, -c options!\n",
413 +                                progname);
414          if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) {
415                  fprintf(stderr, "%s: cannot open '%s' for input\n",
416                                  progname, argv[i]);
# Line 455 | 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 <                mtx_data = resize_dmatrix(mtx_data, ntsteps, 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 487 | 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 498 | 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 506 | 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 <                fputformat(getfmtname(outfmt), stdout);
550 >                if ((outfmt == 'f') | (outfmt == 'd'))
551 >                        fputendian(stdout);
552 >                fputformat((char *)getfmtname(outfmt), stdout);
553                  putchar('\n');
554          }
555                                          /* patches are rows (outer sort) */
# Line 523 | 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++) {
571 <                                fwrite(mtx_data+mtx_offset, sizeof(float), 3,
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];
581                                  ment[2] = mtx_data[mtx_offset+2];
582 <                                fwrite(ment, sizeof(double), 3, stdout);
582 >                                putbinary(ment, sizeof(double), 3, stdout);
583                                  mtx_offset += 3*nskypatch;
584                          }
585                          break;
# Line 559 | 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 931 | 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();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines