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.31 by greg, Sat Dec 28 18:05:14 2019 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"
89   #include "color.h"
90 + #include "sun.h"
91  
92   char *progname;                                                         /* Program name */
93   char errmsg[128];                                                       /* Error message buffer */
# Line 108 | Line 109 | double sky_clearness;                  /* Sky clearness */
109   double solar_rad;                       /* Solar radiance */
110   double sun_zenith;                      /* Sun zenith angle (radians) */
111   int     input = 0;                              /* Input type */
112 + int     output = 0;                             /* Output type */
113  
114   extern double dmax( double, double );
115   extern double CalcAirMass();
# Line 208 | Line 210 | static const CategoryBounds SkyClearCat[8] =
210          { 1.950, 2.800 },
211          { 2.800, 4.500 },
212          { 4.500, 6.200 },
213 <        { 6.200, 12.00 }        /* Clear */
213 >        { 6.200, 12.01 }        /* Clear */
214   };
215  
216   /* Luminous efficacy model coefficients */
# Line 246 | Line 248 | static const ModelCoeff DirectLumEff[8] =
248          { 101.18,  1.58, -1.10,  -8.29 }
249   };
250  
251 < extern int jdate(int month, int day);
252 < extern double stadj(int  jd);
253 < extern double sdec(int  jd);
252 < extern double salt(double sd, double st);
253 < extern double sazi(double sd, double st);
254 <                                        /* sun calculation constants */
255 < extern double  s_latitude;
256 < extern double  s_longitude;
257 < extern double  s_meridian;
251 > #ifndef NSUNPATCH
252 > #define NSUNPATCH       4               /* max. # patches to spread sun into */
253 > #endif
254  
255 < double          grefl = 0.2;            /* diffuse ground reflectance */
255 > int             nsuns = NSUNPATCH;      /* number of sun patches to use */
256 > double          fixed_sun_sa = -1;      /* fixed solid angle per sun? */
257  
258   int             verbose = 0;            /* progress reports to stderr? */
259  
# Line 264 | Line 261 | int            outfmt = 'a';           /* output format */
261  
262   int             rhsubdiv = 1;           /* Reinhart sky subdivisions */
263  
264 < float           skycolor[3] = {.96, 1.004, 1.118};      /* sky coloration */
264 > COLOR           skycolor = {.96, 1.004, 1.118}; /* sky coloration */
265 > COLOR           suncolor = {1., 1., 1.};        /* sun color */
266 > COLOR           grefl = {.2, .2, .2};           /* ground reflectance */
267  
269 int             do_sun = 1;             /* output direct solar contribution? */
270
268   int             nskypatch;              /* number of Reinhart patches */
269   float           *rh_palt;               /* sky patch altitudes (radians) */
270   float           *rh_pazi;               /* sky patch azimuths (radians) */
# Line 286 | Line 283 | extern int     rh_init(void);
283   extern float *  resize_dmatrix(float *mtx_data, int nsteps, int npatch);
284   extern void     AddDirect(float *parr);
285  
286 +
287 + static const char *
288 + getfmtname(int fmt)
289 + {
290 +        switch (fmt) {
291 +        case 'a':
292 +                return("ascii");
293 +        case 'f':
294 +                return("float");
295 +        case 'd':
296 +                return("double");
297 +        }
298 +        return("unknown");
299 + }
300 +
301 +
302   int
303   main(int argc, char *argv[])
304   {
305          char    buf[256];
306 +        int     doheader = 1;           /* output header? */
307 +        double  rotation = 0;           /* site rotation (degrees) */
308          double  elevation;              /* site elevation (meters) */
309          int     dir_is_horiz;           /* direct is meas. on horizontal? */
310          float   *mtx_data = NULL;       /* our matrix data */
311 <        int     ntsteps = 0;            /* number of rows in matrix */
311 >        int     avgSky = 0;             /* compute average sky r.t. matrix? */
312 >        int     ntsteps = 0;            /* number of time steps */
313 >        int     tstorage = 0;           /* number of allocated time steps */
314 >        int     nstored = 0;            /* number of time steps in matrix */
315          int     last_monthly = 0;       /* month of last report */
316 +        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 305 | Line 324 | main(int argc, char *argv[])
324                                          /* get options */
325          for (i = 1; i < argc && argv[i][0] == '-'; i++)
326                  switch (argv[i][1]) {
327 <                case 'g':
328 <                        grefl = atof(argv[++i]);
327 >                case 'g':                       /* ground reflectance */
328 >                        grefl[0] = atof(argv[++i]);
329 >                        grefl[1] = atof(argv[++i]);
330 >                        grefl[2] = atof(argv[++i]);
331                          break;
332 <                case 'v':
332 >                case 'v':                       /* verbose progress reports */
333                          verbose++;
334                          break;
335 <                case 'o':
335 >                case 'h':                       /* turn off header */
336 >                        doheader = 0;
337 >                        break;
338 >                case 'o':                       /* output format */
339                          switch (argv[i][2]) {
340                          case 'f':
341                          case 'd':
# Line 322 | Line 346 | main(int argc, char *argv[])
346                                  goto userr;
347                          }
348                          break;
349 <                case 'm':
349 >                case 'O':                       /* output type */
350 >                        switch (argv[i][2]) {
351 >                        case '0':
352 >                                output = 0;
353 >                                break;
354 >                        case '1':
355 >                                output = 1;
356 >                                break;
357 >                        default:
358 >                                goto userr;
359 >                        }
360 >                        if (argv[i][3])
361 >                                goto userr;
362 >                        break;
363 >                case 'm':                       /* Reinhart subdivisions */
364                          rhsubdiv = atoi(argv[++i]);
365                          break;
366 <                case 'c':
366 >                case 'c':                       /* sky color */
367 >                        inconsistent |= (skycolor[1] <= 1e-4);
368                          skycolor[0] = atof(argv[++i]);
369                          skycolor[1] = atof(argv[++i]);
370                          skycolor[2] = atof(argv[++i]);
371                          break;
372 <                case 'd':
334 <                        do_sun = 1;
372 >                case 'd':                       /* solar (direct) only */
373                          skycolor[0] = skycolor[1] = skycolor[2] = 0;
374 +                        if (suncolor[1] <= 1e-4) {
375 +                                inconsistent = 1;
376 +                                suncolor[0] = suncolor[1] = suncolor[2] = 1;
377 +                        }
378                          break;
379 <                case 's':
380 <                        do_sun = 0;
381 <                        if (skycolor[1] <= 1e-4)
379 >                case 's':                       /* sky only (no direct) */
380 >                        suncolor[0] = suncolor[1] = suncolor[2] = 0;
381 >                        if (skycolor[1] <= 1e-4) {
382 >                                inconsistent = 1;
383                                  skycolor[0] = skycolor[1] = skycolor[2] = 1;
384 +                        }
385                          break;
386 +                case 'r':                       /* rotate distribution */
387 +                        if (argv[i][2] && argv[i][2] != 'z')
388 +                                goto userr;
389 +                        rotation = atof(argv[++i]);
390 +                        break;
391 +                case '5':                       /* 5-phase calculation */
392 +                        nsuns = 1;
393 +                        fixed_sun_sa = PI/360.*atof(argv[++i]);
394 +                        if (fixed_sun_sa <= 0) {
395 +                                fprintf(stderr, "%s: missing solar disk size argument for '-5' option\n",
396 +                                                argv[0]);
397 +                                exit(1);
398 +                        }
399 +                        fixed_sun_sa *= fixed_sun_sa*PI;
400 +                        break;
401 +                case 'A':                       /* compute average sky */
402 +                        avgSky = 1;
403 +                        break;
404                  default:
405                          goto userr;
406                  }
407          if (i < argc-1)
408                  goto userr;
409 +        if (inconsistent)
410 +                fprintf(stderr, "%s: WARNING: inconsistent -s, -d, -c options!\n",
411 +                                progname);
412          if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) {
413                  fprintf(stderr, "%s: cannot open '%s' for input\n",
414                                  progname, argv[i]);
# Line 358 | Line 423 | main(int argc, char *argv[])
423                                          progname);
424          }
425                                          /* read weather tape header */
426 <        if (scanf("place %[^\n]\n", buf) != 1)
426 >        if (scanf("place %[^\r\n] ", buf) != 1)
427                  goto fmterr;
428          if (scanf("latitude %lf\n", &s_latitude) != 1)
429                  goto fmterr;
# Line 393 | Line 458 | main(int argc, char *argv[])
458                                  progname, s_latitude, s_longitude);
459                  fprintf(stderr, "%s: %d sky patches per time step\n",
460                                  progname, nskypatch);
461 +                if (rotation != 0)
462 +                        fprintf(stderr, "%s: rotating output %.0f degrees\n",
463 +                                        progname, rotation);
464          }
465 +                                        /* convert quantities to radians */
466 +        s_latitude = DegToRad(s_latitude);
467 +        s_longitude = DegToRad(s_longitude);
468 +        s_meridian = DegToRad(s_meridian);
469 +                                        /* initial allocation */
470 +        mtx_data = resize_dmatrix(mtx_data, tstorage=2, nskypatch);
471                                          /* process each time step in tape */
472          while (scanf("%d %d %lf %lf %lf\n", &mo, &da, &hr, &dir, &dif) == 5) {
473                  double          sda, sta;
474 <                                        /* make space for next time step */
475 <                mtx_offset = 3*nskypatch*ntsteps++;
476 <                mtx_data = resize_dmatrix(mtx_data, ntsteps, nskypatch);
474 >
475 >                mtx_offset = 3*nskypatch*nstored;
476 >                nstored += !avgSky | !nstored;
477 >                                        /* make space for next row */
478 >                if (nstored > tstorage) {
479 >                        tstorage += (tstorage>>1) + nstored + 7;
480 >                        mtx_data = resize_dmatrix(mtx_data, tstorage, nskypatch);
481 >                }
482 >                ntsteps++;              /* keep count of time steps */
483                  if (dif <= 1e-4) {
484 <                        memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
484 >                        if (!avgSky | !mtx_offset)
485 >                                memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
486                          continue;
487                  }
488                  if (verbose && mo != last_monthly)
# Line 412 | Line 493 | main(int argc, char *argv[])
493                  sda = sdec(julian_date);
494                  sta = stadj(julian_date);
495                  altitude = salt(sda, hr+sta);
496 <                azimuth = sazi(sda, hr+sta);
496 >                azimuth = sazi(sda, hr+sta) + PI - DegToRad(rotation);
497                                          /* convert measured values */
498                  if (dir_is_horiz && altitude > 0.)
499                          dir /= sin(altitude);
# Line 425 | Line 506 | main(int argc, char *argv[])
506                  }
507                                          /* compute sky patch values */
508                  ComputeSky(mtx_data+mtx_offset);
509 <                if (do_sun)
510 <                        AddDirect(mtx_data+mtx_offset);
509 >                AddDirect(mtx_data+mtx_offset);
510 >                                        /* update cumulative sky? */
511 >                for (i = 3*nskypatch*(avgSky&(ntsteps>1)); i--; )
512 >                        mtx_data[i] += mtx_data[mtx_offset+i];
513          }
514                                          /* check for junk at end */
515          while ((i = fgetc(stdin)) != EOF)
# Line 438 | Line 521 | main(int argc, char *argv[])
521                          fputs(buf, stderr); fputc('\n', stderr);
522                          break;
523                  }
524 +        if (!ntsteps) {
525 +                fprintf(stderr, "%s: no valid time steps on input\n", progname);
526 +                exit(1);
527 +        }
528 +        dif = 1./(double)ntsteps;       /* average sky? */
529 +        for (i = 3*nskypatch*(avgSky&(ntsteps>1)); i--; )
530 +                mtx_data[i] *= dif;
531                                          /* write out matrix */
532 +        if (outfmt != 'a')
533 +                SET_FILE_BINARY(stdout);
534   #ifdef getc_unlocked
535          flockfile(stdout);
536   #endif
537          if (verbose)
538                  fprintf(stderr, "%s: writing %smatrix with %d time steps...\n",
539 <                                progname, outfmt=='a' ? "" : "binary ", ntsteps);
539 >                                progname, outfmt=='a' ? "" : "binary ", nstored);
540 >        if (doheader) {
541 >                newheader("RADIANCE", stdout);
542 >                printargs(argc, argv, stdout);
543 >                printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude),
544 >                                        -RadToDeg(s_longitude));
545 >                printf("NROWS=%d\n", nskypatch);
546 >                printf("NCOLS=%d\n", nstored);
547 >                printf("NCOMP=3\n");
548 >                if ((outfmt == 'f') | (outfmt == 'd'))
549 >                        fputendian(stdout);
550 >                fputformat((char *)getfmtname(outfmt), stdout);
551 >                putchar('\n');
552 >        }
553                                          /* patches are rows (outer sort) */
554          for (i = 0; i < nskypatch; i++) {
555                  mtx_offset = 3*i;
556                  switch (outfmt) {
557                  case 'a':
558 <                        for (j = 0; j < ntsteps; j++) {
559 <                                printf("%.3e %.3e %.3e\n", mtx_data[mtx_offset],
558 >                        for (j = 0; j < nstored; j++) {
559 >                                printf("%.3g %.3g %.3g\n", mtx_data[mtx_offset],
560                                                  mtx_data[mtx_offset+1],
561                                                  mtx_data[mtx_offset+2]);
562                                  mtx_offset += 3*nskypatch;
563                          }
564 <                        fputc('\n', stdout);
564 >                        if (nstored > 1)
565 >                                fputc('\n', stdout);
566                          break;
567                  case 'f':
568 <                        for (j = 0; j < ntsteps; j++) {
569 <                                fwrite(mtx_data+mtx_offset, sizeof(float), 3,
568 >                        for (j = 0; j < nstored; j++) {
569 >                                putbinary(mtx_data+mtx_offset, sizeof(float), 3,
570                                                  stdout);
571                                  mtx_offset += 3*nskypatch;
572                          }
573                          break;
574                  case 'd':
575 <                        for (j = 0; j < ntsteps; j++) {
575 >                        for (j = 0; j < nstored; j++) {
576                                  double  ment[3];
577                                  ment[0] = mtx_data[mtx_offset];
578                                  ment[1] = mtx_data[mtx_offset+1];
579                                  ment[2] = mtx_data[mtx_offset+2];
580 <                                fwrite(ment, sizeof(double), 3, stdout);
580 >                                putbinary(ment, sizeof(double), 3, stdout);
581                                  mtx_offset += 3*nskypatch;
582                          }
583                          break;
# Line 485 | Line 591 | main(int argc, char *argv[])
591                  fprintf(stderr, "%s: done.\n", progname);
592          exit(0);
593   userr:
594 <        fprintf(stderr, "Usage: %s [-v][-d|-s][-m N][-g refl][-c r g b][-o{f|d}] [tape.wea]\n",
594 >        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",
595                          progname);
596          exit(1);
597   fmterr:
# Line 506 | Line 612 | ComputeSky(float *parr)
612   {
613          int index;                      /* Category index */
614          double norm_diff_illum;         /* Normalized diffuse illuimnance */
509        double zlumin;                  /* Zenith luminance */
615          int i;
511
512        if (bright(skycolor) <= 1e-4) {                 /* 0 sky component? */
513                memset(parr, 0, sizeof(float)*3*nskypatch);
514                return;
515        }
616          
617          /* Calculate atmospheric precipitable water content */
618          apwc = CalcPrecipWater(dew_point);
619  
620 <        /* Limit solar altitude to keep circumsolar off zenith */
621 <        if (altitude > DegToRad(87.0))
622 <                altitude = DegToRad(87.0);
620 >        /* Calculate sun zenith angle (don't let it dip below horizon) */
621 >        /* Also limit minimum angle to keep circumsolar off zenith */
622 >        if (altitude <= 0.0)
623 >                sun_zenith = DegToRad(90.0);
624 >        else if (altitude >= DegToRad(87.0))
625 >                sun_zenith = DegToRad(3.0);
626 >        else
627 >                sun_zenith = DegToRad(90.0) - altitude;
628  
524        /* Calculate sun zenith angle */
525        sun_zenith = DegToRad(90.0) - altitude;
526
629          /* Compute the inputs for the calculation of the sky distribution */
630          
631          if (input == 0)                                 /* XXX never used */
# Line 542 | Line 644 | ComputeSky(float *parr)
644                  sky_brightness = CalcSkyBrightness();
645                  sky_clearness =  CalcSkyClearness();
646  
647 +                /* Limit sky clearness */
648 +                if (sky_clearness > 11.9)
649 +                        sky_clearness = 11.9;
650 +
651 +                /* Limit sky brightness */
652 +                if (sky_brightness < 0.01)
653 +                        sky_brightness = 0.01;
654 +
655                  /* Calculate illuminance */
656                  index = GetCategoryIndex();
657                  diff_illum = diff_irrad * CalcDiffuseIllumRatio(index);
# Line 553 | Line 663 | ComputeSky(float *parr)
663                  index = CalcSkyParamFromIllum();
664          }
665  
666 +        if (output == 1) {                      /* hack for solar radiance */
667 +                diff_illum = diff_irrad * WHTEFFICACY;
668 +                dir_illum = dir_irrad * WHTEFFICACY;
669 +        }
670 +
671 +        if (bright(skycolor) <= 1e-4) {                 /* 0 sky component? */
672 +                memset(parr, 0, sizeof(float)*3*nskypatch);
673 +                return;
674 +        }
675          /* Compute ground radiance (include solar contribution if any) */
676 <        parr[0] = diff_illum * (1./PI/WHTEFFICACY);
676 >        parr[0] = diff_illum;
677          if (altitude > 0)
678 <                parr[0] += dir_illum * sin(altitude) * (1./PI/WHTEFFICACY);
679 <        parr[2] = parr[1] = parr[0];
678 >                parr[0] += dir_illum * sin(altitude);
679 >        parr[2] = parr[1] = parr[0] *= (1./PI/WHTEFFICACY);
680 >        multcolor(parr, grefl);
681  
682          /* Calculate Perez sky model parameters */
683          CalcPerezParam(sun_zenith, sky_clearness, sky_brightness, index);
# Line 568 | Line 688 | ComputeSky(float *parr)
688          /* Calculate relative horizontal illuminance */
689          norm_diff_illum = CalcRelHorzIllum(parr);
690  
691 +        /* Check for zero sky -- make uniform in that case */
692 +        if (norm_diff_illum <= FTINY) {
693 +                for (i = 1; i < nskypatch; i++)
694 +                        setcolor(parr+3*i, 1., 1., 1.);
695 +                norm_diff_illum = PI;
696 +        }
697          /* Normalization coefficient */
698          norm_diff_illum = diff_illum / norm_diff_illum;
699  
574        /* Calculate relative zenith luminance */
575        zlumin = CalcRelLuminance(sun_zenith, 0.0);
576
577        /* Calculate absolute zenith illuminance */
578        zlumin *= norm_diff_illum;
579
700          /* Apply to sky patches to get absolute radiance values */
701          for (i = 1; i < nskypatch; i++) {
702 <                scalecolor(parr+3*i, zlumin*(1./WHTEFFICACY));
702 >                scalecolor(parr+3*i, norm_diff_illum*(1./WHTEFFICACY));
703                  multcolor(parr+3*i, skycolor);
704          }
705   }
# Line 589 | Line 709 | void
709   AddDirect(float *parr)
710   {
711          FVECT   svec;
712 <        double  near_dprod[4];
713 <        int     near_patch[4];
714 <        double  wta[4], wtot;
712 >        double  near_dprod[NSUNPATCH];
713 >        int     near_patch[NSUNPATCH];
714 >        double  wta[NSUNPATCH], wtot;
715          int     i, j, p;
716  
717 <        if (!do_sun || dir_illum < 1e-4)
717 >        if (dir_illum <= 1e-4 || bright(suncolor) <= 1e-4)
718                  return;
719 <                                        /* identify 4 closest patches */
720 <        for (i = 4; i--; )
719 >                                        /* identify nsuns closest patches */
720 >        if (nsuns > NSUNPATCH)
721 >                nsuns = NSUNPATCH;
722 >        else if (nsuns <= 0)
723 >                nsuns = 1;
724 >        for (i = nsuns; i--; )
725                  near_dprod[i] = -1.;
726          vector(svec, altitude, azimuth);
727          for (p = 1; p < nskypatch; p++) {
# Line 605 | Line 729 | AddDirect(float *parr)
729                  double  dprod;
730                  rh_vector(pvec, p);
731                  dprod = DOT(pvec, svec);
732 <                for (i = 0; i < 4; i++)
732 >                for (i = 0; i < nsuns; i++)
733                          if (dprod > near_dprod[i]) {
734 <                                for (j = 4; --j > i; ) {
734 >                                for (j = nsuns; --j > i; ) {
735                                          near_dprod[j] = near_dprod[j-1];
736                                          near_patch[j] = near_patch[j-1];
737                                  }
# Line 617 | Line 741 | AddDirect(float *parr)
741                          }
742          }
743          wtot = 0;                       /* weight by proximity */
744 <        for (i = 4; i--; )
744 >        for (i = nsuns; i--; )
745                  wtot += wta[i] = 1./(1.002 - near_dprod[i]);
746                                          /* add to nearest patch radiances */
747 <        for (i = 4; i--; )
748 <                parr[near_patch[i]] += wta[i] * dir_illum /
749 <                                        (wtot * rh_dom[near_patch[i]]);
747 >        for (i = nsuns; i--; ) {
748 >                float   *pdest = parr + 3*near_patch[i];
749 >                float   val_add = wta[i] * dir_illum / (WHTEFFICACY * wtot);
750 >
751 >                val_add /= (fixed_sun_sa > 0)   ? fixed_sun_sa
752 >                                                : rh_dom[near_patch[i]] ;
753 >                *pdest++ += val_add*suncolor[0];
754 >                *pdest++ += val_add*suncolor[1];
755 >                *pdest++ += val_add*suncolor[2];
756 >        }
757   }
758  
759   /* Initialize Reinhart sky patch positions (GW) */
# Line 656 | Line 787 | rh_init(void)
787          for (i = 0; i < NROW*rhsubdiv; i++) {
788                  const float     ralt = alpha*(i + .5);
789                  const int       ninrow = tnaz[i/rhsubdiv]*rhsubdiv;
790 <                const float     dom = (sin(alpha*(i+1)) - sin(alpha*i))/ninrow;
790 >                const float     dom = 2.*PI*(sin(alpha*(i+1)) - sin(alpha*i)) /
791 >                                                (double)ninrow;
792                  for (j = 0; j < ninrow; j++) {
793                          rh_palt[p] = ralt;
794                          rh_pazi[p] = 2.*PI * j / (double)ninrow;
# Line 761 | Line 893 | double CalcSkyClearness()
893          double sz_cubed;        /* Sun zenith angle cubed */
894  
895          /* Calculate sun zenith angle cubed */
896 <        sz_cubed = pow(sun_zenith, 3.0);
896 >        sz_cubed = sun_zenith*sun_zenith*sun_zenith;
897  
898          return ((diff_irrad + dir_irrad) / diff_irrad + 1.041 *
899                          sz_cubed) / (1.0 + 1.041 * sz_cubed);
# Line 792 | Line 924 | double CalcDiffuseIrradiance()
924   double CalcDirectIrradiance()
925   {
926          return CalcDiffuseIrradiance() * ((sky_clearness - 1.0) * (1 + 1.041
927 <                        * pow(sun_zenith, 3.0)));
927 >                        * sun_zenith*sun_zenith*sun_zenith));
928   }
929  
930   /* Calculate sky brightness and clearness from illuminance values */
# Line 818 | Line 950 | int CalcSkyParamFromIllum()
950                  sky_clearness = 12.0;
951  
952          /* Limit sky brightness */
953 <        if (sky_brightness < 0.05)
953 >        if (sky_brightness < 0.01)
954                          sky_brightness = 0.01;
955  
956          while (((fabs(diff_irrad - test1) > 10.0) ||
# Line 831 | Line 963 | int CalcSkyParamFromIllum()
963                  /* Convert illuminance to irradiance */
964                  index = GetCategoryIndex();
965                  diff_irrad = diff_illum / CalcDiffuseIllumRatio(index);
966 <                dir_irrad = dir_illum / CalcDirectIllumRatio(index);
966 >                dir_irrad = CalcDirectIllumRatio(index);
967 >                if (dir_irrad > 0.1)
968 >                        dir_irrad = dir_illum / dir_irrad;
969          
970                  /* Calculate sky brightness and clearness */
971                  sky_brightness = CalcSkyBrightness();
# Line 842 | Line 976 | int CalcSkyParamFromIllum()
976                          sky_clearness = 12.0;
977          
978                  /* Limit sky brightness */
979 <                if (sky_brightness < 0.05)
979 >                if (sky_brightness < 0.01)
980                          sky_brightness = 0.01;
981          }
982  
# Line 928 | Line 1062 | double CalcRelHorzIllum( float *parr )
1062          double rh_illum = 0.0;  /* Relative horizontal illuminance */
1063  
1064          for (i = 1; i < nskypatch; i++)
1065 <                rh_illum += parr[3*i+1] * rh_cos(i);
1065 >                rh_illum += parr[3*i+1] * rh_cos(i) * rh_dom[i];
1066  
1067 <        return rh_illum * (2.0 * PI / (nskypatch-1));
1067 >        return rh_illum;
1068   }
1069  
1070   /* Calculate earth orbit eccentricity correction factor */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines