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.1 by greg, Fri Jan 18 01:12:59 2013 UTC vs.
Revision 2.28 by greg, Tue Jun 25 17:06:36 2019 UTC

# Line 86 | Line 86 | static const char RCSid[] = "$Id$";
86   #include <string.h>
87   #include <ctype.h>
88   #include "rtmath.h"
89 + #include "rtio.h"
90 + #include "resolu.h"
91 + #include "platform.h"
92   #include "color.h"
93 + #include "resolu.h"
94  
95   char *progname;                                                         /* Program name */
96   char errmsg[128];                                                       /* Error message buffer */
# Line 108 | Line 112 | double sky_clearness;                  /* Sky clearness */
112   double solar_rad;                       /* Solar radiance */
113   double sun_zenith;                      /* Sun zenith angle (radians) */
114   int     input = 0;                              /* Input type */
115 + int     output = 0;                             /* Output type */
116  
117   extern double dmax( double, double );
118   extern double CalcAirMass();
# Line 208 | Line 213 | static const CategoryBounds SkyClearCat[8] =
213          { 1.950, 2.800 },
214          { 2.800, 4.500 },
215          { 4.500, 6.200 },
216 <        { 6.200, 12.00 }        /* Clear */
216 >        { 6.200, 12.01 }        /* Clear */
217   };
218  
219   /* Luminous efficacy model coefficients */
# Line 246 | Line 251 | static const ModelCoeff DirectLumEff[8] =
251          { 101.18,  1.58, -1.10,  -8.29 }
252   };
253  
254 + #ifndef NSUNPATCH
255 + #define NSUNPATCH       4               /* max. # patches to spread sun into */
256 + #endif
257 +
258   extern int jdate(int month, int day);
259   extern double stadj(int  jd);
260   extern double sdec(int  jd);
# Line 256 | Line 265 | extern double  s_latitude;
265   extern double  s_longitude;
266   extern double  s_meridian;
267  
268 < double          grefl = 0.2;            /* diffuse ground reflectance */
268 > int             nsuns = NSUNPATCH;      /* number of sun patches to use */
269 > double          fixed_sun_sa = -1;      /* fixed solid angle per sun? */
270  
271   int             verbose = 0;            /* progress reports to stderr? */
272  
# Line 264 | Line 274 | int            outfmt = 'a';           /* output format */
274  
275   int             rhsubdiv = 1;           /* Reinhart sky subdivisions */
276  
277 < float           skycolor[3] = {.96, 1.004, 1.118};      /* sky coloration */
277 > COLOR           skycolor = {.96, 1.004, 1.118}; /* sky coloration */
278 > COLOR           suncolor = {1., 1., 1.};        /* sun color */
279 > COLOR           grefl = {.2, .2, .2};           /* ground reflectance */
280  
269 int             do_sun = 1;             /* output direct solar contribution? */
270
281   int             nskypatch;              /* number of Reinhart patches */
282   float           *rh_palt;               /* sky patch altitudes (radians) */
283   float           *rh_pazi;               /* sky patch azimuths (radians) */
# Line 286 | Line 296 | extern int     rh_init(void);
296   extern float *  resize_dmatrix(float *mtx_data, int nsteps, int npatch);
297   extern void     AddDirect(float *parr);
298  
299 +
300 + static const char *
301 + getfmtname(int fmt)
302 + {
303 +        switch (fmt) {
304 +        case 'a':
305 +                return("ascii");
306 +        case 'f':
307 +                return("float");
308 +        case 'd':
309 +                return("double");
310 +        }
311 +        return("unknown");
312 + }
313 +
314 +
315   int
316   main(int argc, char *argv[])
317   {
318          char    buf[256];
319 +        int     doheader = 1;           /* output header? */
320 +        double  rotation = 0;           /* site rotation (degrees) */
321          double  elevation;              /* site elevation (meters) */
322          int     dir_is_horiz;           /* direct is meas. on horizontal? */
323          float   *mtx_data = NULL;       /* our matrix data */
324 <        int     ntsteps = 0;            /* number of rows in matrix */
324 >        int     avgSky = 0;             /* compute average sky r.t. matrix? */
325 >        int     ntsteps = 0;            /* number of time steps */
326 >        int     tstorage = 0;           /* number of allocated time steps */
327 >        int     nstored = 0;            /* number of time steps in matrix */
328          int     last_monthly = 0;       /* month of last report */
329 +        int     inconsistent = 0;       /* inconsistent options set? */
330          int     mo, da;                 /* month (1-12) and day (1-31) */
331          double  hr;                     /* hour (local standard time) */
332          double  dir, dif;               /* direct and diffuse values */
# Line 305 | Line 337 | main(int argc, char *argv[])
337                                          /* get options */
338          for (i = 1; i < argc && argv[i][0] == '-'; i++)
339                  switch (argv[i][1]) {
340 <                case 'g':
341 <                        grefl = atof(argv[++i]);
340 >                case 'g':                       /* ground reflectance */
341 >                        grefl[0] = atof(argv[++i]);
342 >                        grefl[1] = atof(argv[++i]);
343 >                        grefl[2] = atof(argv[++i]);
344                          break;
345 <                case 'v':
345 >                case 'v':                       /* verbose progress reports */
346                          verbose++;
347                          break;
348 <                case 'o':
348 >                case 'h':                       /* turn off header */
349 >                        doheader = 0;
350 >                        break;
351 >                case 'o':                       /* output format */
352                          switch (argv[i][2]) {
353                          case 'f':
354                          case 'd':
# Line 322 | Line 359 | main(int argc, char *argv[])
359                                  goto userr;
360                          }
361                          break;
362 <                case 'm':
362 >                case 'O':                       /* output type */
363 >                        switch (argv[i][2]) {
364 >                        case '0':
365 >                                output = 0;
366 >                                break;
367 >                        case '1':
368 >                                output = 1;
369 >                                break;
370 >                        default:
371 >                                goto userr;
372 >                        }
373 >                        if (argv[i][3])
374 >                                goto userr;
375 >                        break;
376 >                case 'm':                       /* Reinhart subdivisions */
377                          rhsubdiv = atoi(argv[++i]);
378                          break;
379 <                case 'c':
379 >                case 'c':                       /* sky color */
380 >                        inconsistent |= (skycolor[1] <= 1e-4);
381                          skycolor[0] = atof(argv[++i]);
382                          skycolor[1] = atof(argv[++i]);
383                          skycolor[2] = atof(argv[++i]);
384                          break;
385 <                case 'd':
334 <                        do_sun = 1;
385 >                case 'd':                       /* solar (direct) only */
386                          skycolor[0] = skycolor[1] = skycolor[2] = 0;
387 +                        if (suncolor[1] <= 1e-4) {
388 +                                inconsistent = 1;
389 +                                suncolor[0] = suncolor[1] = suncolor[2] = 1;
390 +                        }
391                          break;
392 <                case 's':
393 <                        do_sun = 0;
394 <                        if (skycolor[1] <= 1e-4)
392 >                case 's':                       /* sky only (no direct) */
393 >                        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 +                        }
398                          break;
399 +                case 'r':                       /* rotate distribution */
400 +                        if (argv[i][2] && argv[i][2] != 'z')
401 +                                goto userr;
402 +                        rotation = atof(argv[++i]);
403 +                        break;
404 +                case '5':                       /* 5-phase calculation */
405 +                        nsuns = 1;
406 +                        fixed_sun_sa = PI/360.*atof(argv[++i]);
407 +                        if (fixed_sun_sa <= 0) {
408 +                                fprintf(stderr, "%s: missing solar disk size argument for '-5' option\n",
409 +                                                argv[0]);
410 +                                exit(1);
411 +                        }
412 +                        fixed_sun_sa *= fixed_sun_sa*PI;
413 +                        break;
414 +                case 'A':                       /* compute average sky */
415 +                        avgSky = 1;
416 +                        break;
417                  default:
418                          goto userr;
419                  }
420          if (i < argc-1)
421                  goto userr;
422 +        if (inconsistent)
423 +                fprintf(stderr, "%s: WARNING: inconsistent -s, -d, -c options!\n",
424 +                                progname);
425          if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) {
426                  fprintf(stderr, "%s: cannot open '%s' for input\n",
427                                  progname, argv[i]);
# Line 358 | Line 436 | main(int argc, char *argv[])
436                                          progname);
437          }
438                                          /* read weather tape header */
439 <        if (scanf("place %[^\n]\n", buf) != 1)
439 >        if (scanf("place %[^\r\n] ", buf) != 1)
440                  goto fmterr;
441          if (scanf("latitude %lf\n", &s_latitude) != 1)
442                  goto fmterr;
# Line 393 | Line 471 | main(int argc, char *argv[])
471                                  progname, s_latitude, s_longitude);
472                  fprintf(stderr, "%s: %d sky patches per time step\n",
473                                  progname, nskypatch);
474 +                if (rotation != 0)
475 +                        fprintf(stderr, "%s: rotating output %.0f degrees\n",
476 +                                        progname, rotation);
477          }
478 +                                        /* convert quantities to radians */
479 +        s_latitude = DegToRad(s_latitude);
480 +        s_longitude = DegToRad(s_longitude);
481 +        s_meridian = DegToRad(s_meridian);
482 +                                        /* initial allocation */
483 +        mtx_data = resize_dmatrix(mtx_data, tstorage=2, nskypatch);
484                                          /* process each time step in tape */
485          while (scanf("%d %d %lf %lf %lf\n", &mo, &da, &hr, &dir, &dif) == 5) {
486                  double          sda, sta;
487 <                                        /* make space for next time step */
488 <                mtx_offset = 3*nskypatch*ntsteps++;
489 <                mtx_data = resize_dmatrix(mtx_data, ntsteps, nskypatch);
487 >
488 >                mtx_offset = 3*nskypatch*nstored;
489 >                nstored += !avgSky | !nstored;
490 >                                        /* make space for next row */
491 >                if (nstored > tstorage) {
492 >                        tstorage += (tstorage>>1) + nstored + 7;
493 >                        mtx_data = resize_dmatrix(mtx_data, tstorage, nskypatch);
494 >                }
495 >                ntsteps++;              /* keep count of time steps */
496                  if (dif <= 1e-4) {
497 <                        memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
497 >                        if (!avgSky | !mtx_offset)
498 >                                memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
499                          continue;
500                  }
501                  if (verbose && mo != last_monthly)
# Line 412 | Line 506 | main(int argc, char *argv[])
506                  sda = sdec(julian_date);
507                  sta = stadj(julian_date);
508                  altitude = salt(sda, hr+sta);
509 <                azimuth = sazi(sda, hr+sta);
509 >                azimuth = sazi(sda, hr+sta) + PI - DegToRad(rotation);
510                                          /* convert measured values */
511                  if (dir_is_horiz && altitude > 0.)
512                          dir /= sin(altitude);
# Line 425 | Line 519 | main(int argc, char *argv[])
519                  }
520                                          /* compute sky patch values */
521                  ComputeSky(mtx_data+mtx_offset);
522 <                if (do_sun)
523 <                        AddDirect(mtx_data+mtx_offset);
522 >                AddDirect(mtx_data+mtx_offset);
523 >                                        /* update cumulative sky? */
524 >                for (i = 3*nskypatch*(avgSky&(ntsteps>1)); i--; )
525 >                        mtx_data[i] += mtx_data[mtx_offset+i];
526          }
527                                          /* check for junk at end */
528          while ((i = fgetc(stdin)) != EOF)
# Line 438 | Line 534 | main(int argc, char *argv[])
534                          fputs(buf, stderr); fputc('\n', stderr);
535                          break;
536                  }
537 +        if (!ntsteps) {
538 +                fprintf(stderr, "%s: no valid time steps on input\n", progname);
539 +                exit(1);
540 +        }
541 +        dif = 1./(double)ntsteps;       /* average sky? */
542 +        for (i = 3*nskypatch*(avgSky&(ntsteps>1)); i--; )
543 +                mtx_data[i] *= dif;
544                                          /* write out matrix */
545 +        if (outfmt != 'a')
546 +                SET_FILE_BINARY(stdout);
547   #ifdef getc_unlocked
548          flockfile(stdout);
549   #endif
550          if (verbose)
551                  fprintf(stderr, "%s: writing %smatrix with %d time steps...\n",
552 <                                progname, outfmt=='a' ? "" : "binary ", ntsteps);
552 >                                progname, outfmt=='a' ? "" : "binary ", nstored);
553 >        if (doheader) {
554 >                newheader("RADIANCE", stdout);
555 >                printargs(argc, argv, stdout);
556 >                printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude),
557 >                                        -RadToDeg(s_longitude));
558 >                printf("NROWS=%d\n", nskypatch);
559 >                printf("NCOLS=%d\n", nstored);
560 >                printf("NCOMP=3\n");
561 >                fputformat((char *)getfmtname(outfmt), stdout);
562 >                putchar('\n');
563 >        }
564                                          /* patches are rows (outer sort) */
565          for (i = 0; i < nskypatch; i++) {
566                  mtx_offset = 3*i;
567                  switch (outfmt) {
568                  case 'a':
569 <                        for (j = 0; j < ntsteps; j++) {
570 <                                printf("%.3e %.3e %.3e\n", mtx_data[mtx_offset],
569 >                        for (j = 0; j < nstored; j++) {
570 >                                printf("%.3g %.3g %.3g\n", mtx_data[mtx_offset],
571                                                  mtx_data[mtx_offset+1],
572                                                  mtx_data[mtx_offset+2]);
573                                  mtx_offset += 3*nskypatch;
574                          }
575 <                        fputc('\n', stdout);
575 >                        if (nstored > 1)
576 >                                fputc('\n', stdout);
577                          break;
578                  case 'f':
579 <                        for (j = 0; j < ntsteps; j++) {
580 <                                fwrite(mtx_data+mtx_offset, sizeof(float), 3,
579 >                        for (j = 0; j < nstored; j++) {
580 >                                putbinary(mtx_data+mtx_offset, sizeof(float), 3,
581                                                  stdout);
582                                  mtx_offset += 3*nskypatch;
583                          }
584                          break;
585                  case 'd':
586 <                        for (j = 0; j < ntsteps; j++) {
586 >                        for (j = 0; j < nstored; j++) {
587                                  double  ment[3];
588                                  ment[0] = mtx_data[mtx_offset];
589                                  ment[1] = mtx_data[mtx_offset+1];
590                                  ment[2] = mtx_data[mtx_offset+2];
591 <                                fwrite(ment, sizeof(double), 3, stdout);
591 >                                putbinary(ment, sizeof(double), 3, stdout);
592                                  mtx_offset += 3*nskypatch;
593                          }
594                          break;
# Line 485 | Line 602 | main(int argc, char *argv[])
602                  fprintf(stderr, "%s: done.\n", progname);
603          exit(0);
604   userr:
605 <        fprintf(stderr, "Usage: %s [-v][-d|-s][-m N][-g refl][-c r g b][-o{f|d}] [tape.wea]\n",
605 >        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",
606                          progname);
607          exit(1);
608   fmterr:
# Line 506 | Line 623 | ComputeSky(float *parr)
623   {
624          int index;                      /* Category index */
625          double norm_diff_illum;         /* Normalized diffuse illuimnance */
509        double zlumin;                  /* Zenith luminance */
626          int i;
511
512        if (bright(skycolor) <= 1e-4) {                 /* 0 sky component? */
513                memset(parr, 0, sizeof(float)*3*nskypatch);
514                return;
515        }
627          
628          /* Calculate atmospheric precipitable water content */
629          apwc = CalcPrecipWater(dew_point);
630  
631 <        /* Limit solar altitude to keep circumsolar off zenith */
632 <        if (altitude > DegToRad(87.0))
633 <                altitude = DegToRad(87.0);
631 >        /* Calculate sun zenith angle (don't let it dip below horizon) */
632 >        /* Also limit minimum angle to keep circumsolar off zenith */
633 >        if (altitude <= 0.0)
634 >                sun_zenith = DegToRad(90.0);
635 >        else if (altitude >= DegToRad(87.0))
636 >                sun_zenith = DegToRad(3.0);
637 >        else
638 >                sun_zenith = DegToRad(90.0) - altitude;
639  
524        /* Calculate sun zenith angle */
525        sun_zenith = DegToRad(90.0) - altitude;
526
640          /* Compute the inputs for the calculation of the sky distribution */
641          
642          if (input == 0)                                 /* XXX never used */
# Line 542 | Line 655 | ComputeSky(float *parr)
655                  sky_brightness = CalcSkyBrightness();
656                  sky_clearness =  CalcSkyClearness();
657  
658 +                /* Limit sky clearness */
659 +                if (sky_clearness > 11.9)
660 +                        sky_clearness = 11.9;
661 +
662 +                /* Limit sky brightness */
663 +                if (sky_brightness < 0.01)
664 +                        sky_brightness = 0.01;
665 +
666                  /* Calculate illuminance */
667                  index = GetCategoryIndex();
668                  diff_illum = diff_irrad * CalcDiffuseIllumRatio(index);
# Line 553 | Line 674 | ComputeSky(float *parr)
674                  index = CalcSkyParamFromIllum();
675          }
676  
677 +        if (output == 1) {                      /* hack for solar radiance */
678 +                diff_illum = diff_irrad * WHTEFFICACY;
679 +                dir_illum = dir_irrad * WHTEFFICACY;
680 +        }
681 +
682 +        if (bright(skycolor) <= 1e-4) {                 /* 0 sky component? */
683 +                memset(parr, 0, sizeof(float)*3*nskypatch);
684 +                return;
685 +        }
686          /* Compute ground radiance (include solar contribution if any) */
687 <        parr[0] = diff_illum * (1./PI/WHTEFFICACY);
687 >        parr[0] = diff_illum;
688          if (altitude > 0)
689 <                parr[0] += dir_illum * sin(altitude) * (1./PI/WHTEFFICACY);
690 <        parr[2] = parr[1] = parr[0];
689 >                parr[0] += dir_illum * sin(altitude);
690 >        parr[2] = parr[1] = parr[0] *= (1./PI/WHTEFFICACY);
691 >        multcolor(parr, grefl);
692  
693          /* Calculate Perez sky model parameters */
694          CalcPerezParam(sun_zenith, sky_clearness, sky_brightness, index);
# Line 568 | Line 699 | ComputeSky(float *parr)
699          /* Calculate relative horizontal illuminance */
700          norm_diff_illum = CalcRelHorzIllum(parr);
701  
702 +        /* Check for zero sky -- make uniform in that case */
703 +        if (norm_diff_illum <= FTINY) {
704 +                for (i = 1; i < nskypatch; i++)
705 +                        setcolor(parr+3*i, 1., 1., 1.);
706 +                norm_diff_illum = PI;
707 +        }
708          /* Normalization coefficient */
709          norm_diff_illum = diff_illum / norm_diff_illum;
710  
574        /* Calculate relative zenith luminance */
575        zlumin = CalcRelLuminance(sun_zenith, 0.0);
576
577        /* Calculate absolute zenith illuminance */
578        zlumin *= norm_diff_illum;
579
711          /* Apply to sky patches to get absolute radiance values */
712          for (i = 1; i < nskypatch; i++) {
713 <                scalecolor(parr+3*i, zlumin*(1./WHTEFFICACY));
713 >                scalecolor(parr+3*i, norm_diff_illum*(1./WHTEFFICACY));
714                  multcolor(parr+3*i, skycolor);
715          }
716   }
# Line 589 | Line 720 | void
720   AddDirect(float *parr)
721   {
722          FVECT   svec;
723 <        double  near_dprod[4];
724 <        int     near_patch[4];
725 <        double  wta[4], wtot;
723 >        double  near_dprod[NSUNPATCH];
724 >        int     near_patch[NSUNPATCH];
725 >        double  wta[NSUNPATCH], wtot;
726          int     i, j, p;
727  
728 <        if (!do_sun || dir_illum < 1e-4)
728 >        if (dir_illum <= 1e-4 || bright(suncolor) <= 1e-4)
729                  return;
730 <                                        /* identify 4 closest patches */
731 <        for (i = 4; i--; )
730 >                                        /* identify nsuns closest patches */
731 >        if (nsuns > NSUNPATCH)
732 >                nsuns = NSUNPATCH;
733 >        else if (nsuns <= 0)
734 >                nsuns = 1;
735 >        for (i = nsuns; i--; )
736                  near_dprod[i] = -1.;
737          vector(svec, altitude, azimuth);
738          for (p = 1; p < nskypatch; p++) {
# Line 605 | Line 740 | AddDirect(float *parr)
740                  double  dprod;
741                  rh_vector(pvec, p);
742                  dprod = DOT(pvec, svec);
743 <                for (i = 0; i < 4; i++)
743 >                for (i = 0; i < nsuns; i++)
744                          if (dprod > near_dprod[i]) {
745 <                                for (j = 4; --j > i; ) {
745 >                                for (j = nsuns; --j > i; ) {
746                                          near_dprod[j] = near_dprod[j-1];
747                                          near_patch[j] = near_patch[j-1];
748                                  }
# Line 617 | Line 752 | AddDirect(float *parr)
752                          }
753          }
754          wtot = 0;                       /* weight by proximity */
755 <        for (i = 4; i--; )
755 >        for (i = nsuns; i--; )
756                  wtot += wta[i] = 1./(1.002 - near_dprod[i]);
757                                          /* add to nearest patch radiances */
758 <        for (i = 4; i--; )
759 <                parr[near_patch[i]] += wta[i] * dir_illum /
760 <                                        (wtot * rh_dom[near_patch[i]]);
758 >        for (i = nsuns; i--; ) {
759 >                float   *pdest = parr + 3*near_patch[i];
760 >                float   val_add = wta[i] * dir_illum / (WHTEFFICACY * wtot);
761 >
762 >                val_add /= (fixed_sun_sa > 0)   ? fixed_sun_sa
763 >                                                : rh_dom[near_patch[i]] ;
764 >                *pdest++ += val_add*suncolor[0];
765 >                *pdest++ += val_add*suncolor[1];
766 >                *pdest++ += val_add*suncolor[2];
767 >        }
768   }
769  
770   /* Initialize Reinhart sky patch positions (GW) */
# Line 656 | Line 798 | rh_init(void)
798          for (i = 0; i < NROW*rhsubdiv; i++) {
799                  const float     ralt = alpha*(i + .5);
800                  const int       ninrow = tnaz[i/rhsubdiv]*rhsubdiv;
801 <                const float     dom = (sin(alpha*(i+1)) - sin(alpha*i))/ninrow;
801 >                const float     dom = 2.*PI*(sin(alpha*(i+1)) - sin(alpha*i)) /
802 >                                                (double)ninrow;
803                  for (j = 0; j < ninrow; j++) {
804                          rh_palt[p] = ralt;
805                          rh_pazi[p] = 2.*PI * j / (double)ninrow;
# Line 761 | Line 904 | double CalcSkyClearness()
904          double sz_cubed;        /* Sun zenith angle cubed */
905  
906          /* Calculate sun zenith angle cubed */
907 <        sz_cubed = pow(sun_zenith, 3.0);
907 >        sz_cubed = sun_zenith*sun_zenith*sun_zenith;
908  
909          return ((diff_irrad + dir_irrad) / diff_irrad + 1.041 *
910                          sz_cubed) / (1.0 + 1.041 * sz_cubed);
# Line 792 | Line 935 | double CalcDiffuseIrradiance()
935   double CalcDirectIrradiance()
936   {
937          return CalcDiffuseIrradiance() * ((sky_clearness - 1.0) * (1 + 1.041
938 <                        * pow(sun_zenith, 3.0)));
938 >                        * sun_zenith*sun_zenith*sun_zenith));
939   }
940  
941   /* Calculate sky brightness and clearness from illuminance values */
# Line 818 | Line 961 | int CalcSkyParamFromIllum()
961                  sky_clearness = 12.0;
962  
963          /* Limit sky brightness */
964 <        if (sky_brightness < 0.05)
964 >        if (sky_brightness < 0.01)
965                          sky_brightness = 0.01;
966  
967          while (((fabs(diff_irrad - test1) > 10.0) ||
# Line 831 | Line 974 | int CalcSkyParamFromIllum()
974                  /* Convert illuminance to irradiance */
975                  index = GetCategoryIndex();
976                  diff_irrad = diff_illum / CalcDiffuseIllumRatio(index);
977 <                dir_irrad = dir_illum / CalcDirectIllumRatio(index);
977 >                dir_irrad = CalcDirectIllumRatio(index);
978 >                if (dir_irrad > 0.1)
979 >                        dir_irrad = dir_illum / dir_irrad;
980          
981                  /* Calculate sky brightness and clearness */
982                  sky_brightness = CalcSkyBrightness();
# Line 842 | Line 987 | int CalcSkyParamFromIllum()
987                          sky_clearness = 12.0;
988          
989                  /* Limit sky brightness */
990 <                if (sky_brightness < 0.05)
990 >                if (sky_brightness < 0.01)
991                          sky_brightness = 0.01;
992          }
993  
# Line 928 | Line 1073 | double CalcRelHorzIllum( float *parr )
1073          double rh_illum = 0.0;  /* Relative horizontal illuminance */
1074  
1075          for (i = 1; i < nskypatch; i++)
1076 <                rh_illum += parr[3*i+1] * rh_cos(i);
1076 >                rh_illum += parr[3*i+1] * rh_cos(i) * rh_dom[i];
1077  
1078 <        return rh_illum * (2.0 * PI / (nskypatch-1));
1078 >        return rh_illum;
1079   }
1080  
1081   /* Calculate earth orbit eccentricity correction factor */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines