86 |
|
#include <string.h> |
87 |
|
#include <ctype.h> |
88 |
|
#include "rtmath.h" |
89 |
+ |
#include "resolu.h" |
90 |
+ |
#include "platform.h" |
91 |
|
#include "color.h" |
92 |
+ |
#include "resolu.h" |
93 |
|
|
94 |
|
char *progname; /* Program name */ |
95 |
|
char errmsg[128]; /* Error message buffer */ |
212 |
|
{ 1.950, 2.800 }, |
213 |
|
{ 2.800, 4.500 }, |
214 |
|
{ 4.500, 6.200 }, |
215 |
< |
{ 6.200, 12.00 } /* Clear */ |
215 |
> |
{ 6.200, 12.01 } /* Clear */ |
216 |
|
}; |
217 |
|
|
218 |
|
/* Luminous efficacy model coefficients */ |
295 |
|
extern float * resize_dmatrix(float *mtx_data, int nsteps, int npatch); |
296 |
|
extern void AddDirect(float *parr); |
297 |
|
|
298 |
+ |
|
299 |
+ |
static const char * |
300 |
+ |
getfmtname(int fmt) |
301 |
+ |
{ |
302 |
+ |
switch (fmt) { |
303 |
+ |
case 'a': |
304 |
+ |
return("ascii"); |
305 |
+ |
case 'f': |
306 |
+ |
return("float"); |
307 |
+ |
case 'd': |
308 |
+ |
return("double"); |
309 |
+ |
} |
310 |
+ |
return("unknown"); |
311 |
+ |
} |
312 |
+ |
|
313 |
+ |
|
314 |
|
int |
315 |
|
main(int argc, char *argv[]) |
316 |
|
{ |
317 |
|
char buf[256]; |
318 |
+ |
int doheader = 1; /* output header? */ |
319 |
|
double rotation = 0; /* site rotation (degrees) */ |
320 |
|
double elevation; /* site elevation (meters) */ |
321 |
|
int dir_is_horiz; /* direct is meas. on horizontal? */ |
322 |
|
float *mtx_data = NULL; /* our matrix data */ |
323 |
|
int ntsteps = 0; /* number of rows in matrix */ |
324 |
+ |
int step_alloc = 0; |
325 |
|
int last_monthly = 0; /* month of last report */ |
326 |
+ |
int inconsistent = 0; /* inconsistent options set? */ |
327 |
|
int mo, da; /* month (1-12) and day (1-31) */ |
328 |
|
double hr; /* hour (local standard time) */ |
329 |
|
double dir, dif; /* direct and diffuse values */ |
342 |
|
case 'v': /* verbose progress reports */ |
343 |
|
verbose++; |
344 |
|
break; |
345 |
+ |
case 'h': /* turn off header */ |
346 |
+ |
doheader = 0; |
347 |
+ |
break; |
348 |
|
case 'o': /* output format */ |
349 |
|
switch (argv[i][2]) { |
350 |
|
case 'f': |
374 |
|
rhsubdiv = atoi(argv[++i]); |
375 |
|
break; |
376 |
|
case 'c': /* sky color */ |
377 |
+ |
inconsistent |= (skycolor[1] <= 1e-4); |
378 |
|
skycolor[0] = atof(argv[++i]); |
379 |
|
skycolor[1] = atof(argv[++i]); |
380 |
|
skycolor[2] = atof(argv[++i]); |
381 |
|
break; |
382 |
|
case 'd': /* solar (direct) only */ |
383 |
|
skycolor[0] = skycolor[1] = skycolor[2] = 0; |
384 |
< |
if (suncolor[1] <= 1e-4) |
384 |
> |
if (suncolor[1] <= 1e-4) { |
385 |
> |
inconsistent = 1; |
386 |
|
suncolor[0] = suncolor[1] = suncolor[2] = 1; |
387 |
+ |
} |
388 |
|
break; |
389 |
|
case 's': /* sky only (no direct) */ |
390 |
|
suncolor[0] = suncolor[1] = suncolor[2] = 0; |
391 |
< |
if (skycolor[1] <= 1e-4) |
391 |
> |
if (skycolor[1] <= 1e-4) { |
392 |
> |
inconsistent = 1; |
393 |
|
skycolor[0] = skycolor[1] = skycolor[2] = 1; |
394 |
+ |
} |
395 |
|
break; |
396 |
|
case 'r': /* rotate distribution */ |
397 |
|
if (argv[i][2] && argv[i][2] != 'z') |
400 |
|
break; |
401 |
|
case '5': /* 5-phase calculation */ |
402 |
|
nsuns = 1; |
403 |
< |
fixed_sun_sa = 6.797e-05; |
403 |
> |
fixed_sun_sa = PI/360.*atof(argv[++i]); |
404 |
> |
if (fixed_sun_sa <= 0) { |
405 |
> |
fprintf(stderr, "%s: missing solar disk size argument for '-5' option\n", |
406 |
> |
argv[0]); |
407 |
> |
exit(1); |
408 |
> |
} |
409 |
> |
fixed_sun_sa *= fixed_sun_sa*PI; |
410 |
|
break; |
411 |
|
default: |
412 |
|
goto userr; |
413 |
|
} |
414 |
|
if (i < argc-1) |
415 |
|
goto userr; |
416 |
+ |
if (inconsistent) |
417 |
+ |
fprintf(stderr, "%s: WARNING: inconsistent -s, -d, -c options!\n", |
418 |
+ |
progname); |
419 |
|
if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
420 |
|
fprintf(stderr, "%s: cannot open '%s' for input\n", |
421 |
|
progname, argv[i]); |
478 |
|
double sda, sta; |
479 |
|
/* make space for next time step */ |
480 |
|
mtx_offset = 3*nskypatch*ntsteps++; |
481 |
< |
mtx_data = resize_dmatrix(mtx_data, ntsteps, nskypatch); |
481 |
> |
if (ntsteps > step_alloc) { |
482 |
> |
step_alloc += (step_alloc>>1) + ntsteps + 7; |
483 |
> |
mtx_data = resize_dmatrix(mtx_data, step_alloc, nskypatch); |
484 |
> |
} |
485 |
|
if (dif <= 1e-4) { |
486 |
|
memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch); |
487 |
|
continue; |
520 |
|
break; |
521 |
|
} |
522 |
|
/* write out matrix */ |
523 |
+ |
if (outfmt != 'a') |
524 |
+ |
SET_FILE_BINARY(stdout); |
525 |
|
#ifdef getc_unlocked |
526 |
|
flockfile(stdout); |
527 |
|
#endif |
528 |
|
if (verbose) |
529 |
|
fprintf(stderr, "%s: writing %smatrix with %d time steps...\n", |
530 |
|
progname, outfmt=='a' ? "" : "binary ", ntsteps); |
531 |
+ |
if (doheader) { |
532 |
+ |
newheader("RADIANCE", stdout); |
533 |
+ |
printargs(argc, argv, stdout); |
534 |
+ |
printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude), |
535 |
+ |
-RadToDeg(s_longitude)); |
536 |
+ |
printf("NROWS=%d\n", nskypatch); |
537 |
+ |
printf("NCOLS=%d\n", ntsteps); |
538 |
+ |
printf("NCOMP=3\n"); |
539 |
+ |
fputformat((char *)getfmtname(outfmt), stdout); |
540 |
+ |
putchar('\n'); |
541 |
+ |
} |
542 |
|
/* patches are rows (outer sort) */ |
543 |
|
for (i = 0; i < nskypatch; i++) { |
544 |
|
mtx_offset = 3*i; |
580 |
|
fprintf(stderr, "%s: done.\n", progname); |
581 |
|
exit(0); |
582 |
|
userr: |
583 |
< |
fprintf(stderr, "Usage: %s [-v][-d|-s][-r deg][-m N][-g r g b][-c r g b][-o{f|d}][-O{0|1}] [tape.wea]\n", |
583 |
> |
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", |
584 |
|
progname); |
585 |
|
exit(1); |
586 |
|
fmterr: |
677 |
|
/* Calculate relative horizontal illuminance */ |
678 |
|
norm_diff_illum = CalcRelHorzIllum(parr); |
679 |
|
|
680 |
+ |
/* Check for zero sky -- make uniform in that case */ |
681 |
+ |
if (norm_diff_illum <= FTINY) { |
682 |
+ |
for (i = 1; i < nskypatch; i++) |
683 |
+ |
setcolor(parr+3*i, 1., 1., 1.); |
684 |
+ |
norm_diff_illum = PI; |
685 |
+ |
} |
686 |
|
/* Normalization coefficient */ |
687 |
|
norm_diff_illum = diff_illum / norm_diff_illum; |
688 |
|
|