--- ray/src/gen/gendaymtx.c 2015/08/01 23:27:04 2.20 +++ ray/src/gen/gendaymtx.c 2017/04/28 16:07:34 2.26 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: gendaymtx.c,v 2.20 2015/08/01 23:27:04 greg Exp $"; +static const char RCSid[] = "$Id: gendaymtx.c,v 2.26 2017/04/28 16:07:34 greg Exp $"; #endif /* * gendaymtx.c @@ -86,6 +86,7 @@ static const char RCSid[] = "$Id: gendaymtx.c,v 2.20 2 #include #include #include "rtmath.h" +#include "rtio.h" #include "resolu.h" #include "platform.h" #include "color.h" @@ -323,6 +324,7 @@ main(int argc, char *argv[]) int ntsteps = 0; /* number of rows in matrix */ int step_alloc = 0; int last_monthly = 0; /* month of last report */ + int inconsistent = 0; /* inconsistent options set? */ int mo, da; /* month (1-12) and day (1-31) */ double hr; /* hour (local standard time) */ double dir, dif; /* direct and diffuse values */ @@ -373,19 +375,24 @@ main(int argc, char *argv[]) rhsubdiv = atoi(argv[++i]); break; case 'c': /* sky color */ + inconsistent |= (skycolor[1] <= 1e-4); skycolor[0] = atof(argv[++i]); skycolor[1] = atof(argv[++i]); skycolor[2] = atof(argv[++i]); break; case 'd': /* solar (direct) only */ skycolor[0] = skycolor[1] = skycolor[2] = 0; - if (suncolor[1] <= 1e-4) + if (suncolor[1] <= 1e-4) { + inconsistent = 1; suncolor[0] = suncolor[1] = suncolor[2] = 1; + } break; case 's': /* sky only (no direct) */ suncolor[0] = suncolor[1] = suncolor[2] = 0; - if (skycolor[1] <= 1e-4) + if (skycolor[1] <= 1e-4) { + inconsistent = 1; skycolor[0] = skycolor[1] = skycolor[2] = 1; + } break; case 'r': /* rotate distribution */ if (argv[i][2] && argv[i][2] != 'z') @@ -395,6 +402,11 @@ main(int argc, char *argv[]) case '5': /* 5-phase calculation */ nsuns = 1; fixed_sun_sa = PI/360.*atof(argv[++i]); + if (fixed_sun_sa <= 0) { + fprintf(stderr, "%s: missing solar disk size argument for '-5' option\n", + argv[0]); + exit(1); + } fixed_sun_sa *= fixed_sun_sa*PI; break; default: @@ -402,6 +414,9 @@ main(int argc, char *argv[]) } if (i < argc-1) goto userr; + if (inconsistent) + fprintf(stderr, "%s: WARNING: inconsistent -s, -d, -c options!\n", + progname); if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) { fprintf(stderr, "%s: cannot open '%s' for input\n", progname, argv[i]); @@ -541,7 +556,7 @@ main(int argc, char *argv[]) break; case 'f': for (j = 0; j < ntsteps; j++) { - fwrite(mtx_data+mtx_offset, sizeof(float), 3, + putbinary(mtx_data+mtx_offset, sizeof(float), 3, stdout); mtx_offset += 3*nskypatch; } @@ -552,7 +567,7 @@ main(int argc, char *argv[]) ment[0] = mtx_data[mtx_offset]; ment[1] = mtx_data[mtx_offset+1]; ment[2] = mtx_data[mtx_offset+2]; - fwrite(ment, sizeof(double), 3, stdout); + putbinary(ment, sizeof(double), 3, stdout); mtx_offset += 3*nskypatch; } break; @@ -938,7 +953,9 @@ int CalcSkyParamFromIllum() /* Convert illuminance to irradiance */ index = GetCategoryIndex(); diff_irrad = diff_illum / CalcDiffuseIllumRatio(index); - dir_irrad = dir_illum / CalcDirectIllumRatio(index); + dir_irrad = CalcDirectIllumRatio(index); + if (dir_irrad > 0.1) + dir_irrad = dir_illum / dir_irrad; /* Calculate sky brightness and clearness */ sky_brightness = CalcSkyBrightness();