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.29 by greg, Wed Aug 14 21:00:14 2019 UTC vs.
Revision 2.34 by greg, Tue Jan 7 01:42:30 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 320 | Line 307 | main(int argc, char *argv[])
307          double  rotation = 0;           /* site rotation (degrees) */
308          double  elevation;              /* site elevation (meters) */
309          int     dir_is_horiz;           /* direct is meas. on horizontal? */
310 +        FILE    *sunsfp = NULL;         /* output file for individual suns */
311          float   *mtx_data = NULL;       /* our matrix data */
312          int     avgSky = 0;             /* compute average sky r.t. matrix? */
313          int     ntsteps = 0;            /* number of time steps */
314          int     tstorage = 0;           /* number of allocated time steps */
315          int     nstored = 0;            /* number of time steps in matrix */
316          int     last_monthly = 0;       /* month of last report */
329        int     inconsistent = 0;       /* inconsistent options set? */
317          int     mo, da;                 /* month (1-12) and day (1-31) */
318          double  hr;                     /* hour (local standard time) */
319          double  dir, dif;               /* direct and diffuse values */
# Line 377 | Line 364 | main(int argc, char *argv[])
364                          rhsubdiv = atoi(argv[++i]);
365                          break;
366                  case 'c':                       /* sky color */
380                        inconsistent |= (skycolor[1] <= 1e-4);
367                          skycolor[0] = atof(argv[++i]);
368                          skycolor[1] = atof(argv[++i]);
369                          skycolor[2] = atof(argv[++i]);
370                          break;
371 +                case 'n':                       /* no matrix output */
372 +                        avgSky = -1;
373 +                        rhsubdiv = 1;
374 +                        /* fall through */
375                  case 'd':                       /* solar (direct) only */
376                          skycolor[0] = skycolor[1] = skycolor[2] = 0;
377 <                        if (suncolor[1] <= 1e-4) {
378 <                                inconsistent = 1;
379 <                                suncolor[0] = suncolor[1] = suncolor[2] = 1;
377 >                        grefl[0] = grefl[1] = grefl[2] = 0;
378 >                        break;
379 >                case 'D':                       /* output suns to file */
380 >                        sunsfp = fopen(argv[++i], "w");
381 >                        if (!sunsfp) {
382 >                                fprintf(stderr, "%s: cannot open '%s' for output\n",
383 >                                                argv[0], argv[i]);
384 >                                exit(1);
385                          }
386 +                        fixed_sun_sa = PI/360.*0.533;
387 +                        fixed_sun_sa *= PI*fixed_sun_sa;
388                          break;
389                  case 's':                       /* sky only (no direct) */
390                          suncolor[0] = suncolor[1] = suncolor[2] = 0;
394                        if (skycolor[1] <= 1e-4) {
395                                inconsistent = 1;
396                                skycolor[0] = skycolor[1] = skycolor[2] = 1;
397                        }
391                          break;
392                  case 'r':                       /* rotate distribution */
393                          if (argv[i][2] && argv[i][2] != 'z')
# Line 419 | Line 412 | main(int argc, char *argv[])
412                  }
413          if (i < argc-1)
414                  goto userr;
422        if (inconsistent)
423                fprintf(stderr, "%s: WARNING: inconsistent -s, -d, -c options!\n",
424                                progname);
415          if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) {
416                  fprintf(stderr, "%s: cannot open '%s' for input\n",
417                                  progname, argv[i]);
# Line 498 | Line 488 | main(int argc, char *argv[])
488                                  memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
489                          continue;
490                  }
501                if (verbose && mo != last_monthly)
502                        fprintf(stderr, "%s: stepping through month %d...\n",
503                                                progname, last_monthly=mo);
491                                          /* compute solar position */
492                  julian_date = jdate(mo, da);
493                  sda = sdec(julian_date);
# Line 519 | Line 506 | main(int argc, char *argv[])
506                  }
507                                          /* compute sky patch values */
508                  ComputeSky(mtx_data+mtx_offset);
509 +                                        /* output sun if indicated */
510 +                if (sunsfp && (altitude > 0) & (dir_illum > 1e-4)) {
511 +                        double  srad = dir_illum/(WHTEFFICACY * fixed_sun_sa);
512 +                        FVECT   sv;
513 +                        vector(sv, altitude, azimuth);
514 +                        fprintf(sunsfp, "\nvoid light solar%d\n0\n0\n", ntsteps);
515 +                        fprintf(sunsfp, "3 %.3e %.3e %.3e\n", srad*suncolor[0],
516 +                                        srad*suncolor[1], srad*suncolor[2]);
517 +                        fprintf(sunsfp, "\nsolar%d source sun%d\n0\n0\n", ntsteps, ntsteps);
518 +                        fprintf(sunsfp, "4 %.6f %.6f %.6f 0.533\n", sv[0], sv[1], sv[2]);
519 +                }
520 +                if (avgSky < 0)         /* no matrix? */
521 +                        continue;
522 +
523                  AddDirect(mtx_data+mtx_offset);
524                                          /* update cumulative sky? */
525                  for (i = 3*nskypatch*(avgSky&(ntsteps>1)); i--; )
526                          mtx_data[i] += mtx_data[mtx_offset+i];
527 +                                        /* monthly reporting */
528 +                if (verbose && mo != last_monthly)
529 +                        fprintf(stderr, "%s: stepping through month %d...\n",
530 +                                                progname, last_monthly=mo);
531          }
532 +        if (!ntsteps) {
533 +                fprintf(stderr, "%s: no valid time steps on input\n", progname);
534 +                exit(1);
535 +        }
536                                          /* check for junk at end */
537          while ((i = fgetc(stdin)) != EOF)
538                  if (!isspace(i)) {
# Line 534 | Line 543 | main(int argc, char *argv[])
543                          fputs(buf, stderr); fputc('\n', stderr);
544                          break;
545                  }
546 <        if (!ntsteps) {
547 <                fprintf(stderr, "%s: no valid time steps on input\n", progname);
548 <                exit(1);
549 <        }
546 >
547 >        if (avgSky < 0)                 /* no matrix output? */
548 >                goto alldone;
549 >
550          dif = 1./(double)ntsteps;       /* average sky? */
551          for (i = 3*nskypatch*(avgSky&(ntsteps>1)); i--; )
552                  mtx_data[i] *= dif;
# Line 598 | Line 607 | main(int argc, char *argv[])
607                  if (ferror(stdout))
608                          goto writerr;
609          }
610 <        if (fflush(stdout) == EOF)
610 > alldone:
611 >        if (fflush(NULL) == EOF)
612                  goto writerr;
613          if (verbose)
614                  fprintf(stderr, "%s: done.\n", progname);
615          exit(0);
616   userr:
617 <        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",
617 >        fprintf(stderr, "Usage: %s [-v][-h][-A][-d|-s|-n][-D file][-r deg][-m N][-g r g b][-c r g b][-o{f|d}][-O{0|1}] [tape.wea]\n",
618                          progname);
619          exit(1);
620   fmterr:
621 <        fprintf(stderr, "%s: input weather tape format error\n", progname);
621 >        fprintf(stderr, "%s: weather tape format error in header\n", progname);
622          exit(1);
623   writerr:
624          fprintf(stderr, "%s: write error on output\n", progname);
# Line 680 | Line 690 | ComputeSky(float *parr)
690                  diff_illum = diff_irrad * WHTEFFICACY;
691                  dir_illum = dir_irrad * WHTEFFICACY;
692          }
683
684        if (bright(skycolor) <= 1e-4) {                 /* 0 sky component? */
685                memset(parr, 0, sizeof(float)*3*nskypatch);
686                return;
687        }
693          /* Compute ground radiance (include solar contribution if any) */
694          parr[0] = diff_illum;
695          if (altitude > 0)
# Line 692 | Line 697 | ComputeSky(float *parr)
697          parr[2] = parr[1] = parr[0] *= (1./PI/WHTEFFICACY);
698          multcolor(parr, grefl);
699  
700 +        if (bright(skycolor) <= 1e-4) {                 /* 0 sky component? */
701 +                memset(parr+3, 0, sizeof(float)*3*(nskypatch-1));
702 +                return;
703 +        }
704          /* Calculate Perez sky model parameters */
705          CalcPerezParam(sun_zenith, sky_clearness, sky_brightness, index);
706  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines