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.35 by greg, Tue Jan 7 18:26:55 2020 UTC vs.
Revision 2.37 by greg, Sat Aug 15 03:28:56 2020 UTC

# Line 135 | Line 135 | extern void ComputeSky( float *parr );
135   /* Radiuans into degrees */
136   #define RadToDeg(rad)   ((rad)*(180./PI))
137  
138
138   /* Perez sky model coefficients */
139  
140   /* Reference:   Perez, R., R. Seals, and J. Michalsky, 1993. "All- */
# Line 272 | Line 271 | float          *rh_palt;               /* sky patch altitudes (radians) */
271   float           *rh_pazi;               /* sky patch azimuths (radians) */
272   float           *rh_dom;                /* sky patch solid angle (sr) */
273  
274 < #define         vector(v,alt,azi)       (       (v)[1] = tcos(alt), \
275 <                                                (v)[0] = (v)[1]*tsin(azi), \
276 <                                                (v)[1] *= tcos(azi), \
277 <                                                (v)[2] = tsin(alt) )
274 > #define         vector(v,alt,azi)       (       (v)[1] = cos(alt), \
275 >                                                (v)[0] = (v)[1]*sin(azi), \
276 >                                                (v)[1] *= cos(azi), \
277 >                                                (v)[2] = sin(alt) )
278  
279   #define         rh_vector(v,i)          vector(v,rh_palt[i],rh_pazi[i])
280  
281   #define         rh_cos(i)               tsin(rh_palt[i])
282  
283 + #define         solar_minute(jd,hr)     ((24*60)*((jd)-1)+(int)((hr)*60.+.5))
284 +
285   extern int      rh_init(void);
286   extern float *  resize_dmatrix(float *mtx_data, int nsteps, int npatch);
287 < extern void     OutputSun(int id, FILE *fp);
287 > extern void     OutputSun(int id, int goodsun, FILE *fp, FILE *mfp);
288   extern void     AddDirect(float *parr);
289  
290  
# Line 309 | Line 310 | main(int argc, char *argv[])
310          int     doheader = 1;           /* output header? */
311          double  rotation = 0;           /* site rotation (degrees) */
312          double  elevation;              /* site elevation (meters) */
313 +        int     leap_day = 0;           /* add leap day? */
314 +        int     sun_hours_only = 0;     /* only output sun hours? */
315          int     dir_is_horiz;           /* direct is meas. on horizontal? */
316          FILE    *sunsfp = NULL;         /* output file for individual suns */
317 +        FILE    *modsfp = NULL;         /* modifier output file */
318          float   *mtx_data = NULL;       /* our matrix data */
319          int     avgSky = 0;             /* compute average sky r.t. matrix? */
320          int     ntsteps = 0;            /* number of time steps */
# Line 371 | Line 375 | main(int argc, char *argv[])
375                          skycolor[1] = atof(argv[++i]);
376                          skycolor[2] = atof(argv[++i]);
377                          break;
378 +                case 'D':                       /* output suns to file */
379 +                        if (strcmp(argv[++i], "-")) {
380 +                                sunsfp = fopen(argv[i], "w");
381 +                                if (sunsfp == NULL) {
382 +                                        fprintf(stderr,
383 +                                        "%s: cannot open '%s' for output\n",
384 +                                                        progname, argv[i]);
385 +                                        exit(1);
386 +                                }
387 +                                break;          /* still may output matrix */
388 +                        }
389 +                        sunsfp = stdout;        /* sending to stdout, so... */
390 +                        /* fall through */
391                  case 'n':                       /* no matrix output */
392                          avgSky = -1;
393                          rhsubdiv = 1;
# Line 379 | Line 396 | main(int argc, char *argv[])
396                          skycolor[0] = skycolor[1] = skycolor[2] = 0;
397                          grefl[0] = grefl[1] = grefl[2] = 0;
398                          break;
399 <                case 'D':                       /* output suns to file */
400 <                        sunsfp = fopen(argv[++i], "w");
384 <                        if (!sunsfp) {
399 >                case 'M':                       /* send sun modifiers to file */
400 >                        if ((modsfp = fopen(argv[++i], "w")) == NULL) {
401                                  fprintf(stderr, "%s: cannot open '%s' for output\n",
402                                                  progname, argv[i]);
403                                  exit(1);
# Line 390 | Line 406 | main(int argc, char *argv[])
406                  case 's':                       /* sky only (no direct) */
407                          suncolor[0] = suncolor[1] = suncolor[2] = 0;
408                          break;
409 +                case 'u':                       /* solar hours only */
410 +                        sun_hours_only = 1;
411 +                        break;
412                  case 'r':                       /* rotate distribution */
413                          if (argv[i][2] && argv[i][2] != 'z')
414                                  goto userr;
# Line 418 | Line 437 | main(int argc, char *argv[])
437                                  progname, argv[i]);
438                  exit(1);
439          }
440 +        if ((modsfp != NULL) & (sunsfp == NULL))
441 +                fprintf(stderr, "%s: warning -M output will be empty without -D\n",
442 +                                progname);
443          if (verbose) {
444                  if (i == argc-1)
445                          fprintf(stderr, "%s: reading weather tape '%s'\n",
# Line 479 | Line 501 | main(int argc, char *argv[])
501                                          /* process each time step in tape */
502          while (scanf("%d %d %lf %lf %lf\n", &mo, &da, &hr, &dir, &dif) == 5) {
503                  double          sda, sta;
504 +                int             sun_in_sky;
505 +                                        /* compute solar position */
506 +                if ((mo == 2) & (da == 29)) {
507 +                        julian_date = 60;
508 +                        leap_day = 1;
509 +                } else
510 +                        julian_date = jdate(mo, da) + leap_day;
511 +                sda = sdec(julian_date);
512 +                sta = stadj(julian_date);
513 +                altitude = salt(sda, hr+sta);
514 +                sun_in_sky = (altitude > -DegToRad(SUN_ANG_DEG/2.));
515 +                if (sun_hours_only && !sun_in_sky)
516 +                        continue;       /* skipping nighttime points */
517 +                azimuth = sazi(sda, hr+sta) + PI - DegToRad(rotation);
518  
519                  mtx_offset = 3*nskypatch*nstored;
520                  nstored += !avgSky | !nstored;
# Line 488 | Line 524 | main(int argc, char *argv[])
524                          mtx_data = resize_dmatrix(mtx_data, tstorage, nskypatch);
525                  }
526                  ntsteps++;              /* keep count of time steps */
527 <                if (dif <= 1e-4) {
527 >
528 >                if (dir+dif <= 1e-4) {  /* effectively nighttime? */
529                          if (!avgSky | !mtx_offset)
530 <                                memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
530 >                                memset(mtx_data+mtx_offset, 0,
531 >                                                sizeof(float)*3*nskypatch);
532 >                                        /* output black sun? */
533 >                        if (sunsfp && sun_in_sky)
534 >                                OutputSun(solar_minute(julian_date,hr), 0,
535 >                                                        sunsfp, modsfp);
536                          continue;
537                  }
496                                        /* compute solar position */
497                julian_date = jdate(mo, da);
498                sda = sdec(julian_date);
499                sta = stadj(julian_date);
500                altitude = salt(sda, hr+sta);
501                azimuth = sazi(sda, hr+sta) + PI - DegToRad(rotation);
538                                          /* convert measured values */
539                  if (dir_is_horiz && altitude > 0.)
540                          dir /= sin(altitude);
# Line 511 | Line 547 | main(int argc, char *argv[])
547                  }
548                                          /* compute sky patch values */
549                  ComputeSky(mtx_data+mtx_offset);
550 +                                        /* output sun if requested */
551 +                if (sunsfp && sun_in_sky)
552 +                        OutputSun(solar_minute(julian_date,hr), 1,
553 +                                                sunsfp, modsfp);
554  
515                if (sunsfp)             /* output sun if indicated */
516                        OutputSun(ntsteps, sunsfp);
517
555                  if (avgSky < 0)         /* no matrix? */
556                          continue;
557  
# Line 526 | Line 563 | main(int argc, char *argv[])
563                  if (verbose && mo != last_monthly)
564                          fprintf(stderr, "%s: stepping through month %d...\n",
565                                                  progname, last_monthly=mo);
566 +                                        /* note whether leap-day was given */
567          }
568          if (!ntsteps) {
569                  fprintf(stderr, "%s: no valid time steps on input\n", progname);
# Line 612 | Line 650 | alldone:
650                  fprintf(stderr, "%s: done.\n", progname);
651          exit(0);
652   userr:
653 <        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",
653 >        fprintf(stderr, "Usage: %s [-v][-h][-A][-d|-s|-n][-u][-D file [-M modfile]][-r deg][-m N][-g r g b][-c r g b][-o{f|d}][-O{0|1}] [tape.wea]\n",
654                          progname);
655          exit(1);
656   fmterr:
# Line 778 | Line 816 | AddDirect(float *parr)
816  
817   /* Output a sun to indicated file if appropriate for this time step */
818   void
819 < OutputSun(int id, FILE *fp)
819 > OutputSun(int id, int goodsun, FILE *fp, FILE *mfp)
820   {
821          double  srad;
822          FVECT   sv;
823  
786        if ((altitude <= 0) | (dir_illum <= 1e-4))
787                return;
788
824          srad = DegToRad(SUN_ANG_DEG/2.);
825 <        srad = dir_illum/(WHTEFFICACY * PI*srad*srad);
825 >        srad = goodsun ? dir_illum/(WHTEFFICACY * PI*srad*srad) : 0;
826          vector(sv, altitude, azimuth);
827          fprintf(fp, "\nvoid light solar%d\n0\n0\n", id);
828          fprintf(fp, "3 %.3e %.3e %.3e\n", srad*suncolor[0],
829                          srad*suncolor[1], srad*suncolor[2]);
830          fprintf(fp, "\nsolar%d source sun%d\n0\n0\n", id, id);
831          fprintf(fp, "4 %.6f %.6f %.6f %.4f\n", sv[0], sv[1], sv[2], SUN_ANG_DEG);
832 +        
833 +        if (mfp != NULL)                /* saving modifier IDs? */
834 +                fprintf(mfp, "solar%d\n", id);
835   }
836  
837   /* Initialize Reinhart sky patch positions (GW) */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines