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 */ |
110 |
|
double solar_rad; /* Solar radiance */ |
111 |
|
double sun_zenith; /* Sun zenith angle (radians) */ |
112 |
|
int input = 0; /* Input type */ |
113 |
+ |
int output = 0; /* Output type */ |
114 |
|
|
115 |
|
extern double dmax( double, double ); |
116 |
|
extern double CalcAirMass(); |
211 |
|
{ 1.950, 2.800 }, |
212 |
|
{ 2.800, 4.500 }, |
213 |
|
{ 4.500, 6.200 }, |
214 |
< |
{ 6.200, 12.00 } /* Clear */ |
214 |
> |
{ 6.200, 12.01 } /* Clear */ |
215 |
|
}; |
216 |
|
|
217 |
|
/* Luminous efficacy model coefficients */ |
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': |
354 |
|
goto userr; |
355 |
|
} |
356 |
|
break; |
357 |
+ |
case 'O': /* output type */ |
358 |
+ |
switch (argv[i][2]) { |
359 |
+ |
case '0': |
360 |
+ |
output = 0; |
361 |
+ |
break; |
362 |
+ |
case '1': |
363 |
+ |
output = 1; |
364 |
+ |
break; |
365 |
+ |
default: |
366 |
+ |
goto userr; |
367 |
+ |
} |
368 |
+ |
if (argv[i][3]) |
369 |
+ |
goto userr; |
370 |
+ |
break; |
371 |
|
case 'm': /* Reinhart subdivisions */ |
372 |
|
rhsubdiv = atoi(argv[++i]); |
373 |
|
break; |
462 |
|
double sda, sta; |
463 |
|
/* make space for next time step */ |
464 |
|
mtx_offset = 3*nskypatch*ntsteps++; |
465 |
< |
mtx_data = resize_dmatrix(mtx_data, ntsteps, nskypatch); |
465 |
> |
if (ntsteps > step_alloc) { |
466 |
> |
step_alloc += (step_alloc>>1) + ntsteps + 7; |
467 |
> |
mtx_data = resize_dmatrix(mtx_data, step_alloc, nskypatch); |
468 |
> |
} |
469 |
|
if (dif <= 1e-4) { |
470 |
|
memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch); |
471 |
|
continue; |
504 |
|
break; |
505 |
|
} |
506 |
|
/* write out matrix */ |
507 |
+ |
if (outfmt != 'a') |
508 |
+ |
SET_FILE_BINARY(stdout); |
509 |
|
#ifdef getc_unlocked |
510 |
|
flockfile(stdout); |
511 |
|
#endif |
512 |
|
if (verbose) |
513 |
|
fprintf(stderr, "%s: writing %smatrix with %d time steps...\n", |
514 |
|
progname, outfmt=='a' ? "" : "binary ", ntsteps); |
515 |
+ |
if (doheader) { |
516 |
+ |
newheader("RADIANCE", stdout); |
517 |
+ |
printargs(argc, argv, stdout); |
518 |
+ |
printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude), |
519 |
+ |
-RadToDeg(s_longitude)); |
520 |
+ |
printf("NROWS=%d\n", nskypatch); |
521 |
+ |
printf("NCOLS=%d\n", ntsteps); |
522 |
+ |
printf("NCOMP=3\n"); |
523 |
+ |
fputformat(getfmtname(outfmt), stdout); |
524 |
+ |
putchar('\n'); |
525 |
+ |
} |
526 |
|
/* patches are rows (outer sort) */ |
527 |
|
for (i = 0; i < nskypatch; i++) { |
528 |
|
mtx_offset = 3*i; |
564 |
|
fprintf(stderr, "%s: done.\n", progname); |
565 |
|
exit(0); |
566 |
|
userr: |
567 |
< |
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", |
567 |
> |
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", |
568 |
|
progname); |
569 |
|
exit(1); |
570 |
|
fmterr: |
623 |
|
|
624 |
|
/* Limit sky brightness */ |
625 |
|
if (sky_brightness < 0.01) |
626 |
< |
sky_brightness = 0.01; |
626 |
> |
sky_brightness = 0.01; |
627 |
|
|
628 |
|
/* Calculate illuminance */ |
629 |
|
index = GetCategoryIndex(); |
636 |
|
index = CalcSkyParamFromIllum(); |
637 |
|
} |
638 |
|
|
639 |
+ |
if (output == 1) { /* hack for solar radiance */ |
640 |
+ |
diff_illum = diff_irrad * WHTEFFICACY; |
641 |
+ |
dir_illum = dir_irrad * WHTEFFICACY; |
642 |
+ |
} |
643 |
+ |
|
644 |
|
if (bright(skycolor) <= 1e-4) { /* 0 sky component? */ |
645 |
|
memset(parr, 0, sizeof(float)*3*nskypatch); |
646 |
|
return; |
661 |
|
/* Calculate relative horizontal illuminance */ |
662 |
|
norm_diff_illum = CalcRelHorzIllum(parr); |
663 |
|
|
664 |
+ |
/* Check for zero sky -- make uniform in that case */ |
665 |
+ |
if (norm_diff_illum <= FTINY) { |
666 |
+ |
for (i = 1; i < nskypatch; i++) |
667 |
+ |
setcolor(parr+3*i, 1., 1., 1.); |
668 |
+ |
norm_diff_illum = PI; |
669 |
+ |
} |
670 |
|
/* Normalization coefficient */ |
671 |
|
norm_diff_illum = diff_illum / norm_diff_illum; |
672 |
|
|
866 |
|
double sz_cubed; /* Sun zenith angle cubed */ |
867 |
|
|
868 |
|
/* Calculate sun zenith angle cubed */ |
869 |
< |
sz_cubed = pow(sun_zenith, 3.0); |
869 |
> |
sz_cubed = sun_zenith*sun_zenith*sun_zenith; |
870 |
|
|
871 |
|
return ((diff_irrad + dir_irrad) / diff_irrad + 1.041 * |
872 |
|
sz_cubed) / (1.0 + 1.041 * sz_cubed); |
897 |
|
double CalcDirectIrradiance() |
898 |
|
{ |
899 |
|
return CalcDiffuseIrradiance() * ((sky_clearness - 1.0) * (1 + 1.041 |
900 |
< |
* pow(sun_zenith, 3.0))); |
900 |
> |
* sun_zenith*sun_zenith*sun_zenith)); |
901 |
|
} |
902 |
|
|
903 |
|
/* Calculate sky brightness and clearness from illuminance values */ |