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.34 by greg, Tue Jan 7 01:42:30 2020 UTC vs.
Revision 2.36 by greg, Mon Apr 13 17:12:19 2020 UTC

# Line 252 | Line 252 | static const ModelCoeff DirectLumEff[8] =
252   #define NSUNPATCH       4               /* max. # patches to spread sun into */
253   #endif
254  
255 + #define SUN_ANG_DEG     0.533           /* sun full-angle in degrees */
256 +
257   int             nsuns = NSUNPATCH;      /* number of sun patches to use */
258   double          fixed_sun_sa = -1;      /* fixed solid angle per sun? */
259  
# Line 270 | Line 272 | float          *rh_palt;               /* sky patch altitudes (radians) */
272   float           *rh_pazi;               /* sky patch azimuths (radians) */
273   float           *rh_dom;                /* sky patch solid angle (sr) */
274  
275 < #define         vector(v,alt,azi)       (       (v)[1] = tcos(alt), \
276 <                                                (v)[0] = (v)[1]*tsin(azi), \
277 <                                                (v)[1] *= tcos(azi), \
278 <                                                (v)[2] = tsin(alt) )
275 > #define         vector(v,alt,azi)       (       (v)[1] = cos(alt), \
276 >                                                (v)[0] = (v)[1]*sin(azi), \
277 >                                                (v)[1] *= cos(azi), \
278 >                                                (v)[2] = sin(alt) )
279  
280   #define         rh_vector(v,i)          vector(v,rh_palt[i],rh_pazi[i])
281  
282   #define         rh_cos(i)               tsin(rh_palt[i])
283  
284 + #define         solar_minute(jd,hr)     ((24*60)*((jd)-1)+(int)((hr)*60.+.5))
285 +
286   extern int      rh_init(void);
287   extern float *  resize_dmatrix(float *mtx_data, int nsteps, int npatch);
288 + extern void     OutputSun(int id, int goodsun, FILE *fp, FILE *mfp);
289   extern void     AddDirect(float *parr);
290  
291  
# Line 306 | Line 311 | main(int argc, char *argv[])
311          int     doheader = 1;           /* output header? */
312          double  rotation = 0;           /* site rotation (degrees) */
313          double  elevation;              /* site elevation (meters) */
314 +        int     leap_day = 0;           /* add leap day? */
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 368 | 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 376 | 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");
381 <                        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 <                                                argv[0], argv[i]);
402 >                                                progname, argv[i]);
403                                  exit(1);
404                          }
386                        fixed_sun_sa = PI/360.*0.533;
387                        fixed_sun_sa *= PI*fixed_sun_sa;
405                          break;
406                  case 's':                       /* sky only (no direct) */
407                          suncolor[0] = suncolor[1] = suncolor[2] = 0;
# Line 399 | Line 416 | main(int argc, char *argv[])
416                          fixed_sun_sa = PI/360.*atof(argv[++i]);
417                          if (fixed_sun_sa <= 0) {
418                                  fprintf(stderr, "%s: missing solar disk size argument for '-5' option\n",
419 <                                                argv[0]);
419 >                                                progname);
420                                  exit(1);
421                          }
422                          fixed_sun_sa *= fixed_sun_sa*PI;
# Line 417 | Line 434 | main(int argc, char *argv[])
434                                  progname, argv[i]);
435                  exit(1);
436          }
437 +        if ((modsfp != NULL) & (sunsfp == NULL))
438 +                fprintf(stderr, "%s: warning -M output will be empty without -D\n",
439 +                                progname);
440          if (verbose) {
441                  if (i == argc-1)
442                          fprintf(stderr, "%s: reading weather tape '%s'\n",
# Line 459 | Line 479 | main(int argc, char *argv[])
479                  fprintf(stderr, "%s: location '%s'\n", progname, buf);
480                  fprintf(stderr, "%s: (lat,long)=(%.1f,%.1f) degrees north, west\n",
481                                  progname, s_latitude, s_longitude);
482 <                fprintf(stderr, "%s: %d sky patches per time step\n",
483 <                                progname, nskypatch);
482 >                if (avgSky >= 0)
483 >                        fprintf(stderr, "%s: %d sky patches\n",
484 >                                        progname, nskypatch);
485 >                if (sunsfp)
486 >                        fprintf(stderr, "%s: outputting suns to file\n",
487 >                                        progname);
488                  if (rotation != 0)
489                          fprintf(stderr, "%s: rotating output %.0f degrees\n",
490                                          progname, rotation);
# Line 483 | Line 507 | main(int argc, char *argv[])
507                          mtx_data = resize_dmatrix(mtx_data, tstorage, nskypatch);
508                  }
509                  ntsteps++;              /* keep count of time steps */
486                if (dif <= 1e-4) {
487                        if (!avgSky | !mtx_offset)
488                                memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
489                        continue;
490                }
510                                          /* compute solar position */
511 <                julian_date = jdate(mo, da);
511 >                if ((mo == 2) & (da == 29)) {
512 >                        julian_date = 60;
513 >                        leap_day = 1;
514 >                } else
515 >                        julian_date = jdate(mo, da) + leap_day;
516                  sda = sdec(julian_date);
517                  sta = stadj(julian_date);
518                  altitude = salt(sda, hr+sta);
519                  azimuth = sazi(sda, hr+sta) + PI - DegToRad(rotation);
520 +
521 +                if (dir+dif <= 1e-4) {  /* effectively nighttime? */
522 +                        if (!avgSky | !mtx_offset)
523 +                                memset(mtx_data+mtx_offset, 0,
524 +                                                sizeof(float)*3*nskypatch);
525 +                        if (sunsfp)     /* output black sun */
526 +                                OutputSun(solar_minute(julian_date,hr), 0,
527 +                                                        sunsfp, modsfp);
528 +                        continue;
529 +                }
530                                          /* convert measured values */
531                  if (dir_is_horiz && altitude > 0.)
532                          dir /= sin(altitude);
# Line 506 | Line 539 | main(int argc, char *argv[])
539                  }
540                                          /* compute sky patch values */
541                  ComputeSky(mtx_data+mtx_offset);
542 <                                        /* output sun if indicated */
543 <                if (sunsfp && (altitude > 0) & (dir_illum > 1e-4)) {
544 <                        double  srad = dir_illum/(WHTEFFICACY * fixed_sun_sa);
545 <                        FVECT   sv;
546 <                        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 <                }
542 >
543 >                if (sunsfp)             /* output sun if requested */
544 >                        OutputSun(solar_minute(julian_date,hr), 1,
545 >                                                sunsfp, modsfp);
546 >
547                  if (avgSky < 0)         /* no matrix? */
548                          continue;
549  
# Line 528 | Line 555 | main(int argc, char *argv[])
555                  if (verbose && mo != last_monthly)
556                          fprintf(stderr, "%s: stepping through month %d...\n",
557                                                  progname, last_monthly=mo);
558 +                                        /* note whether leap-day was given */
559          }
560          if (!ntsteps) {
561                  fprintf(stderr, "%s: no valid time steps on input\n", progname);
# Line 776 | Line 804 | AddDirect(float *parr)
804                  *pdest++ += val_add*suncolor[1];
805                  *pdest++ += val_add*suncolor[2];
806          }
807 + }
808 +
809 + /* Output a sun to indicated file if appropriate for this time step */
810 + void
811 + OutputSun(int id, int goodsun, FILE *fp, FILE *mfp)
812 + {
813 +        double  srad;
814 +        FVECT   sv;
815 +
816 +        srad = DegToRad(SUN_ANG_DEG/2.);
817 +
818 +        if (altitude < -srad)           /* well below horizon? */
819 +                return;
820 +
821 +        srad = goodsun ? dir_illum/(WHTEFFICACY * PI*srad*srad) : 0;
822 +        vector(sv, altitude, azimuth);
823 +        fprintf(fp, "\nvoid light solar%d\n0\n0\n", id);
824 +        fprintf(fp, "3 %.3e %.3e %.3e\n", srad*suncolor[0],
825 +                        srad*suncolor[1], srad*suncolor[2]);
826 +        fprintf(fp, "\nsolar%d source sun%d\n0\n0\n", id, id);
827 +        fprintf(fp, "4 %.6f %.6f %.6f %.4f\n", sv[0], sv[1], sv[2], SUN_ANG_DEG);
828 +        
829 +        if (mfp != NULL)                /* saving modifier IDs? */
830 +                fprintf(mfp, "solar%d\n", id);
831   }
832  
833   /* Initialize Reinhart sky patch positions (GW) */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines