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.36 by greg, Mon Apr 13 17:12:19 2020 UTC vs.
Revision 2.40 by greg, Fri Apr 26 23:10:59 2024 UTC

# Line 89 | Line 89 | static const char RCSid[] = "$Id$";
89   #include "color.h"
90   #include "sun.h"
91  
92 < char *progname;                                                         /* Program name */
93 < char errmsg[128];                                                       /* Error message buffer */
92 > char *progname;                                 /* Program name */
93   const double DC_SolarConstantE = 1367.0;        /* Solar constant W/m^2 */
94   const double DC_SolarConstantL = 127.5;         /* Solar constant klux */
95  
# Line 129 | Line 128 | extern void CalcPerezParam( double, double, double, in
128   extern void CalcSkyPatchLumin( float *parr );
129   extern void ComputeSky( float *parr );
130  
131 +
132 + extern double  solar_sunset(int month, int day);
133 + extern double  solar_sunrise(int month, int day);
134 +
135   /* Degrees into radians */
136   #define DegToRad(deg)   ((deg)*(PI/180.))
137  
138   /* Radiuans into degrees */
139   #define RadToDeg(rad)   ((rad)*(180./PI))
140  
138
141   /* Perez sky model coefficients */
142  
143   /* Reference:   Perez, R., R. Seals, and J. Michalsky, 1993. "All- */
# Line 312 | Line 314 | main(int argc, char *argv[])
314          double  rotation = 0;           /* site rotation (degrees) */
315          double  elevation;              /* site elevation (meters) */
316          int     leap_day = 0;           /* add leap day? */
317 +        int     sun_hours_only = 0;     /* only output sun hours? */
318          int     dir_is_horiz;           /* direct is meas. on horizontal? */
319          FILE    *sunsfp = NULL;         /* output file for individual suns */
320          FILE    *modsfp = NULL;         /* modifier output file */
# Line 326 | Line 329 | main(int argc, char *argv[])
329          double  dir, dif;               /* direct and diffuse values */
330          int     mtx_offset;
331          int     i, j;
332 +        double  timeinterval = 0;
333  
334          progname = argv[0];
335                                          /* get options */
# Line 406 | Line 410 | main(int argc, char *argv[])
410                  case 's':                       /* sky only (no direct) */
411                          suncolor[0] = suncolor[1] = suncolor[2] = 0;
412                          break;
413 +                case 'u':                       /* solar hours only */
414 +                        sun_hours_only = 1;
415 +                        break;
416                  case 'r':                       /* rotate distribution */
417                          if (argv[i][2] && argv[i][2] != 'z')
418                                  goto userr;
# Line 424 | Line 431 | main(int argc, char *argv[])
431                  case 'A':                       /* compute average sky */
432                          avgSky = 1;
433                          break;
434 +                case 'i':
435 +                        timeinterval = atof(argv[++i]);
436 +                        break;
437                  default:
438                          goto userr;
439                  }
# Line 483 | Line 493 | main(int argc, char *argv[])
493                          fprintf(stderr, "%s: %d sky patches\n",
494                                          progname, nskypatch);
495                  if (sunsfp)
496 <                        fprintf(stderr, "%s: outputting suns to file\n",
497 <                                        progname);
496 >                        fprintf(stderr, "%s: outputting suns to %s\n",
497 >                                        progname, sunsfp==stdout ? "stdout" : "file");
498                  if (rotation != 0)
499                          fprintf(stderr, "%s: rotating output %.0f degrees\n",
500                                          progname, rotation);
# Line 497 | Line 507 | main(int argc, char *argv[])
507          mtx_data = resize_dmatrix(mtx_data, tstorage=2, nskypatch);
508                                          /* process each time step in tape */
509          while (scanf("%d %d %lf %lf %lf\n", &mo, &da, &hr, &dir, &dif) == 5) {
510 <                double          sda, sta;
510 >                double          sda, sta, st;
511 >                int             sun_in_sky;
512 >                                        /* compute solar position */
513 >                if ((mo == 2) & (da == 29)) {
514 >                        julian_date = 60;
515 >                        leap_day = 1;
516 >                } else
517 >                        julian_date = jdate(mo, da) + leap_day;
518 >                sda = sdec(julian_date);
519 >                sta = stadj(julian_date);
520 >                st = hr + sta;
521 >                
522 >                if (timeinterval > 0) {
523 >                        if (fabs(solar_sunrise(mo, da) - st) <= timeinterval/120)
524 >                                st = (st + timeinterval/120 + solar_sunrise(mo, da))/2;
525 >                        else if (fabs(solar_sunset(mo, da) - st) < timeinterval/120)
526 >                                st = (st - timeinterval/120 + solar_sunset(mo, da))/2;
527 >                }
528 >                altitude = salt(sda, st);
529 >                sun_in_sky = (altitude > -DegToRad(SUN_ANG_DEG/2.));
530 >                if (sun_hours_only && !sun_in_sky)
531 >                        continue;       /* skipping nighttime points */
532 >                azimuth = sazi(sda, st) + PI - DegToRad(rotation);
533  
534                  mtx_offset = 3*nskypatch*nstored;
535                  nstored += !avgSky | !nstored;
# Line 507 | Line 539 | main(int argc, char *argv[])
539                          mtx_data = resize_dmatrix(mtx_data, tstorage, nskypatch);
540                  }
541                  ntsteps++;              /* keep count of time steps */
510                                        /* compute solar position */
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);
542  
543                  if (dir+dif <= 1e-4) {  /* effectively nighttime? */
544                          if (!avgSky | !mtx_offset)
545                                  memset(mtx_data+mtx_offset, 0,
546                                                  sizeof(float)*3*nskypatch);
547 <                        if (sunsfp)     /* output black sun */
547 >                                        /* output black sun? */
548 >                        if (sunsfp && sun_in_sky)
549                                  OutputSun(solar_minute(julian_date,hr), 0,
550                                                          sunsfp, modsfp);
551                          continue;
552                  }
553 +                if (!sun_in_sky && dir > (input==1 ? 20. : 20.*WHTEFFICACY))
554 +                        fprintf(stderr,
555 +                                "%s: warning - unusually bright at %.1f on %d-%d\n",
556 +                                        progname, hr, mo, da);
557                                          /* convert measured values */
558 <                if (dir_is_horiz && altitude > 0.)
558 >                if (dir_is_horiz && altitude > FTINY)
559                          dir /= sin(altitude);
560                  if (input == 1) {
561                          dir_irrad = dir;
# Line 539 | Line 566 | main(int argc, char *argv[])
566                  }
567                                          /* compute sky patch values */
568                  ComputeSky(mtx_data+mtx_offset);
569 <
570 <                if (sunsfp)             /* output sun if requested */
569 >                                        /* output sun if requested */
570 >                if (sunsfp && sun_in_sky)
571                          OutputSun(solar_minute(julian_date,hr), 1,
572                                                  sunsfp, modsfp);
573  
# Line 642 | Line 669 | alldone:
669                  fprintf(stderr, "%s: done.\n", progname);
670          exit(0);
671   userr:
672 <        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",
672 >        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",
673                          progname);
674          exit(1);
675   fmterr:
# Line 653 | Line 680 | writerr:
680          exit(1);
681   }
682  
683 +
684   /* Return maximum of two doubles */
685   double dmax( double a, double b )
686   { return (a > b) ? a : b; }
# Line 698 | Line 726 | ComputeSky(float *parr)
726                  /* Limit sky clearness */
727                  if (sky_clearness > 11.9)
728                          sky_clearness = 11.9;
729 +                else if (sky_clearness < 1.0)
730 +                        sky_clearness = 1.0;
731  
732                  /* Limit sky brightness */
733                  if (sky_brightness < 0.01)
734                          sky_brightness = 0.01;
735 +                else if (sky_brightness > 0.6)
736 +                        sky_brightness = 0.6;
737  
738                  /* Calculate illuminance */
739                  index = GetCategoryIndex();
# Line 754 | Line 786 | ComputeSky(float *parr)
786          }
787   }
788  
789 +
790 + double
791 + solar_sunset(int month, int day)
792 + {
793 +        float W;
794 +        W = -1 * (tan(s_latitude) * tan(sdec(jdate(month, day))));
795 +        return(12 + (M_PI / 2 - atan2(W, sqrt(1 - W * W))) * 180 / (M_PI * 15));
796 + }
797 +
798 +
799 + double
800 + solar_sunrise(int month, int day)
801 + {
802 +        float W;
803 +        W = -1 * (tan(s_latitude) * tan(sdec(jdate(month, day))));
804 +        return(12 - (M_PI / 2 - atan2(W, sqrt(1 - W * W))) * 180 / (M_PI * 15));
805 + }
806 +
807 +
808   /* Add in solar direct to nearest sky patches (GW) */
809   void
810   AddDirect(float *parr)
# Line 814 | Line 865 | OutputSun(int id, int goodsun, FILE *fp, FILE *mfp)
865          FVECT   sv;
866  
867          srad = DegToRad(SUN_ANG_DEG/2.);
817
818        if (altitude < -srad)           /* well below horizon? */
819                return;
820
868          srad = goodsun ? dir_illum/(WHTEFFICACY * PI*srad*srad) : 0;
869          vector(sv, altitude, azimuth);
870          fprintf(fp, "\nvoid light solar%d\n0\n0\n", id);
# Line 1027 | Line 1074 | int CalcSkyParamFromIllum()
1074          if (sky_brightness < 0.01)
1075                          sky_brightness = 0.01;
1076  
1077 +        if (sky_clearness < 1.0000)
1078 +        {
1079 +                sky_clearness = 1.0000;
1080 +        }
1081 +
1082 +        if (sky_brightness > 0.6)
1083 +        {
1084 +                sky_brightness = 0.6;
1085 +        }
1086 +
1087          while (((fabs(diff_irrad - test1) > 10.0) ||
1088                          (fabs(dir_irrad - test2) > 10.0)) && !(counter == 5))
1089          {
# Line 1052 | Line 1109 | int CalcSkyParamFromIllum()
1109                  /* Limit sky brightness */
1110                  if (sky_brightness < 0.01)
1111                          sky_brightness = 0.01;
1112 +
1113 +                if (sky_clearness < 1.0000)
1114 +                {
1115 +                        sky_clearness = 1.0000;
1116 +                }
1117 +
1118 +                if (sky_brightness > 0.6)
1119 +                {
1120 +                        sky_brightness = 0.6;
1121 +                }
1122          }
1123  
1124          return GetCategoryIndex();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines