--- ray/src/gen/gendaymtx.c 2013/04/06 00:44:59 2.10 +++ ray/src/gen/gendaymtx.c 2014/05/30 00:00:54 2.14 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: gendaymtx.c,v 2.10 2013/04/06 00:44:59 greg Exp $"; +static const char RCSid[] = "$Id: gendaymtx.c,v 2.14 2014/05/30 00:00:54 greg Exp $"; #endif /* * gendaymtx.c @@ -86,6 +86,7 @@ static const char RCSid[] = "$Id: gendaymtx.c,v 2.10 2 #include #include #include "rtmath.h" +#include "platform.h" #include "color.h" char *progname; /* Program name */ @@ -108,6 +109,7 @@ double sky_clearness; /* Sky clearness */ double solar_rad; /* Solar radiance */ double sun_zenith; /* Sun zenith angle (radians) */ int input = 0; /* Input type */ +int output = 0; /* Output type */ extern double dmax( double, double ); extern double CalcAirMass(); @@ -208,7 +210,7 @@ static const CategoryBounds SkyClearCat[8] = { 1.950, 2.800 }, { 2.800, 4.500 }, { 4.500, 6.200 }, - { 6.200, 12.00 } /* Clear */ + { 6.200, 12.01 } /* Clear */ }; /* Luminous efficacy model coefficients */ @@ -291,10 +293,27 @@ extern int rh_init(void); extern float * resize_dmatrix(float *mtx_data, int nsteps, int npatch); extern void AddDirect(float *parr); + +static const char * +getfmtname(int fmt) +{ + switch (fmt) { + case 'a': + return("ascii"); + case 'f': + return("float"); + case 'd': + return("double"); + } + return("unknown"); +} + + int main(int argc, char *argv[]) { char buf[256]; + int doheader = 1; /* output header? */ double rotation = 0; /* site rotation (degrees) */ double elevation; /* site elevation (meters) */ int dir_is_horiz; /* direct is meas. on horizontal? */ @@ -319,6 +338,9 @@ main(int argc, char *argv[]) case 'v': /* verbose progress reports */ verbose++; break; + case 'h': /* turn off header */ + doheader = 0; + break; case 'o': /* output format */ switch (argv[i][2]) { case 'f': @@ -330,6 +352,20 @@ main(int argc, char *argv[]) goto userr; } break; + case 'O': /* output type */ + switch (argv[i][2]) { + case '0': + output = 0; + break; + case '1': + output = 1; + break; + default: + goto userr; + } + if (argv[i][3]) + goto userr; + break; case 'm': /* Reinhart subdivisions */ rhsubdiv = atoi(argv[++i]); break; @@ -463,12 +499,25 @@ main(int argc, char *argv[]) break; } /* write out matrix */ + if (outfmt != 'a') + SET_FILE_BINARY(stdout); #ifdef getc_unlocked flockfile(stdout); #endif if (verbose) fprintf(stderr, "%s: writing %smatrix with %d time steps...\n", progname, outfmt=='a' ? "" : "binary ", ntsteps); + if (doheader) { + newheader("RADIANCE", stdout); + printargs(argc, argv, stdout); + printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude), + -RadToDeg(s_longitude)); + printf("NROWS=%d\n", nskypatch); + printf("NCOLS=%d\n", ntsteps); + printf("NCOMP=3\n"); + fputformat(getfmtname(outfmt), stdout); + putchar('\n'); + } /* patches are rows (outer sort) */ for (i = 0; i < nskypatch; i++) { mtx_offset = 3*i; @@ -510,7 +559,7 @@ main(int argc, char *argv[]) fprintf(stderr, "%s: done.\n", progname); exit(0); userr: - fprintf(stderr, "Usage: %s [-v][-d|-s][-r deg][-m N][-g r g b][-c r g b][-o{f|d}] [tape.wea]\n", + fprintf(stderr, "Usage: %s [-v][-h][-d|-s][-r deg][-m N][-g r g b][-c r g b][-o{f|d}][-O{0|1}] [tape.wea]\n", progname); exit(1); fmterr: @@ -569,7 +618,7 @@ ComputeSky(float *parr) /* Limit sky brightness */ if (sky_brightness < 0.01) - sky_brightness = 0.01; + sky_brightness = 0.01; /* Calculate illuminance */ index = GetCategoryIndex(); @@ -582,6 +631,11 @@ ComputeSky(float *parr) index = CalcSkyParamFromIllum(); } + if (output == 1) { /* hack for solar radiance */ + diff_illum = diff_irrad * WHTEFFICACY; + dir_illum = dir_irrad * WHTEFFICACY; + } + if (bright(skycolor) <= 1e-4) { /* 0 sky component? */ memset(parr, 0, sizeof(float)*3*nskypatch); return; @@ -602,6 +656,12 @@ ComputeSky(float *parr) /* Calculate relative horizontal illuminance */ norm_diff_illum = CalcRelHorzIllum(parr); + /* Check for zero sky -- make uniform in that case */ + if (norm_diff_illum <= FTINY) { + for (i = 1; i < nskypatch; i++) + setcolor(parr+3*i, 1., 1., 1.); + norm_diff_illum = PI; + } /* Normalization coefficient */ norm_diff_illum = diff_illum / norm_diff_illum; @@ -801,7 +861,7 @@ double CalcSkyClearness() double sz_cubed; /* Sun zenith angle cubed */ /* Calculate sun zenith angle cubed */ - sz_cubed = pow(sun_zenith, 3.0); + sz_cubed = sun_zenith*sun_zenith*sun_zenith; return ((diff_irrad + dir_irrad) / diff_irrad + 1.041 * sz_cubed) / (1.0 + 1.041 * sz_cubed); @@ -832,7 +892,7 @@ double CalcDiffuseIrradiance() double CalcDirectIrradiance() { return CalcDiffuseIrradiance() * ((sky_clearness - 1.0) * (1 + 1.041 - * pow(sun_zenith, 3.0))); + * sun_zenith*sun_zenith*sun_zenith)); } /* Calculate sky brightness and clearness from illuminance values */