86 |
|
#include <string.h> |
87 |
|
#include <ctype.h> |
88 |
|
#include "rtmath.h" |
89 |
+ |
#include "platform.h" |
90 |
|
#include "color.h" |
91 |
+ |
#include "resolu.h" |
92 |
|
|
93 |
|
char *progname; /* Program name */ |
94 |
|
char errmsg[128]; /* Error message buffer */ |
294 |
|
extern float * resize_dmatrix(float *mtx_data, int nsteps, int npatch); |
295 |
|
extern void AddDirect(float *parr); |
296 |
|
|
297 |
+ |
|
298 |
+ |
static const char * |
299 |
+ |
getfmtname(int fmt) |
300 |
+ |
{ |
301 |
+ |
switch (fmt) { |
302 |
+ |
case 'a': |
303 |
+ |
return("ascii"); |
304 |
+ |
case 'f': |
305 |
+ |
return("float"); |
306 |
+ |
case 'd': |
307 |
+ |
return("double"); |
308 |
+ |
} |
309 |
+ |
return("unknown"); |
310 |
+ |
} |
311 |
+ |
|
312 |
+ |
|
313 |
|
int |
314 |
|
main(int argc, char *argv[]) |
315 |
|
{ |
316 |
|
char buf[256]; |
317 |
+ |
int doheader = 1; /* output header? */ |
318 |
|
double rotation = 0; /* site rotation (degrees) */ |
319 |
|
double elevation; /* site elevation (meters) */ |
320 |
|
int dir_is_horiz; /* direct is meas. on horizontal? */ |
321 |
|
float *mtx_data = NULL; /* our matrix data */ |
322 |
|
int ntsteps = 0; /* number of rows in matrix */ |
323 |
+ |
int step_alloc = 0; |
324 |
|
int last_monthly = 0; /* month of last report */ |
325 |
|
int mo, da; /* month (1-12) and day (1-31) */ |
326 |
|
double hr; /* hour (local standard time) */ |
340 |
|
case 'v': /* verbose progress reports */ |
341 |
|
verbose++; |
342 |
|
break; |
343 |
+ |
case 'h': /* turn off header */ |
344 |
+ |
doheader = 0; |
345 |
+ |
break; |
346 |
|
case 'o': /* output format */ |
347 |
|
switch (argv[i][2]) { |
348 |
|
case 'f': |
393 |
|
break; |
394 |
|
case '5': /* 5-phase calculation */ |
395 |
|
nsuns = 1; |
396 |
< |
fixed_sun_sa = 6.797e-05; |
396 |
> |
fixed_sun_sa = PI/360.*atof(argv[++i]); |
397 |
> |
fixed_sun_sa *= fixed_sun_sa*PI; |
398 |
|
break; |
399 |
|
default: |
400 |
|
goto userr; |
463 |
|
double sda, sta; |
464 |
|
/* make space for next time step */ |
465 |
|
mtx_offset = 3*nskypatch*ntsteps++; |
466 |
< |
mtx_data = resize_dmatrix(mtx_data, ntsteps, nskypatch); |
466 |
> |
if (ntsteps > step_alloc) { |
467 |
> |
step_alloc += (step_alloc>>1) + ntsteps + 7; |
468 |
> |
mtx_data = resize_dmatrix(mtx_data, step_alloc, nskypatch); |
469 |
> |
} |
470 |
|
if (dif <= 1e-4) { |
471 |
|
memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch); |
472 |
|
continue; |
505 |
|
break; |
506 |
|
} |
507 |
|
/* write out matrix */ |
508 |
+ |
if (outfmt != 'a') |
509 |
+ |
SET_FILE_BINARY(stdout); |
510 |
|
#ifdef getc_unlocked |
511 |
|
flockfile(stdout); |
512 |
|
#endif |
513 |
|
if (verbose) |
514 |
|
fprintf(stderr, "%s: writing %smatrix with %d time steps...\n", |
515 |
|
progname, outfmt=='a' ? "" : "binary ", ntsteps); |
516 |
+ |
if (doheader) { |
517 |
+ |
newheader("RADIANCE", stdout); |
518 |
+ |
printargs(argc, argv, stdout); |
519 |
+ |
printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude), |
520 |
+ |
-RadToDeg(s_longitude)); |
521 |
+ |
printf("NROWS=%d\n", nskypatch); |
522 |
+ |
printf("NCOLS=%d\n", ntsteps); |
523 |
+ |
printf("NCOMP=3\n"); |
524 |
+ |
fputformat((char *)getfmtname(outfmt), stdout); |
525 |
+ |
putchar('\n'); |
526 |
+ |
} |
527 |
|
/* patches are rows (outer sort) */ |
528 |
|
for (i = 0; i < nskypatch; i++) { |
529 |
|
mtx_offset = 3*i; |
565 |
|
fprintf(stderr, "%s: done.\n", progname); |
566 |
|
exit(0); |
567 |
|
userr: |
568 |
< |
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", |
568 |
> |
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", |
569 |
|
progname); |
570 |
|
exit(1); |
571 |
|
fmterr: |
662 |
|
/* Calculate relative horizontal illuminance */ |
663 |
|
norm_diff_illum = CalcRelHorzIllum(parr); |
664 |
|
|
665 |
+ |
/* Check for zero sky -- make uniform in that case */ |
666 |
+ |
if (norm_diff_illum <= FTINY) { |
667 |
+ |
for (i = 1; i < nskypatch; i++) |
668 |
+ |
setcolor(parr+3*i, 1., 1., 1.); |
669 |
+ |
norm_diff_illum = PI; |
670 |
+ |
} |
671 |
|
/* Normalization coefficient */ |
672 |
|
norm_diff_illum = diff_illum / norm_diff_illum; |
673 |
|
|