86 |
|
#include <string.h> |
87 |
|
#include <ctype.h> |
88 |
|
#include "rtmath.h" |
89 |
+ |
#include "rtio.h" |
90 |
+ |
#include "resolu.h" |
91 |
|
#include "platform.h" |
92 |
|
#include "color.h" |
93 |
+ |
#include "resolu.h" |
94 |
|
|
95 |
|
char *progname; /* Program name */ |
96 |
|
char errmsg[128]; /* Error message buffer */ |
322 |
|
int dir_is_horiz; /* direct is meas. on horizontal? */ |
323 |
|
float *mtx_data = NULL; /* our matrix data */ |
324 |
|
int ntsteps = 0; /* number of rows in matrix */ |
325 |
+ |
int step_alloc = 0; |
326 |
|
int last_monthly = 0; /* month of last report */ |
327 |
+ |
int inconsistent = 0; /* inconsistent options set? */ |
328 |
|
int mo, da; /* month (1-12) and day (1-31) */ |
329 |
|
double hr; /* hour (local standard time) */ |
330 |
|
double dir, dif; /* direct and diffuse values */ |
375 |
|
rhsubdiv = atoi(argv[++i]); |
376 |
|
break; |
377 |
|
case 'c': /* sky color */ |
378 |
+ |
inconsistent |= (skycolor[1] <= 1e-4); |
379 |
|
skycolor[0] = atof(argv[++i]); |
380 |
|
skycolor[1] = atof(argv[++i]); |
381 |
|
skycolor[2] = atof(argv[++i]); |
382 |
|
break; |
383 |
|
case 'd': /* solar (direct) only */ |
384 |
|
skycolor[0] = skycolor[1] = skycolor[2] = 0; |
385 |
< |
if (suncolor[1] <= 1e-4) |
385 |
> |
if (suncolor[1] <= 1e-4) { |
386 |
> |
inconsistent = 1; |
387 |
|
suncolor[0] = suncolor[1] = suncolor[2] = 1; |
388 |
+ |
} |
389 |
|
break; |
390 |
|
case 's': /* sky only (no direct) */ |
391 |
|
suncolor[0] = suncolor[1] = suncolor[2] = 0; |
392 |
< |
if (skycolor[1] <= 1e-4) |
392 |
> |
if (skycolor[1] <= 1e-4) { |
393 |
> |
inconsistent = 1; |
394 |
|
skycolor[0] = skycolor[1] = skycolor[2] = 1; |
395 |
+ |
} |
396 |
|
break; |
397 |
|
case 'r': /* rotate distribution */ |
398 |
|
if (argv[i][2] && argv[i][2] != 'z') |
401 |
|
break; |
402 |
|
case '5': /* 5-phase calculation */ |
403 |
|
nsuns = 1; |
404 |
< |
fixed_sun_sa = 6.797e-05; |
404 |
> |
fixed_sun_sa = PI/360.*atof(argv[++i]); |
405 |
> |
if (fixed_sun_sa <= 0) { |
406 |
> |
fprintf(stderr, "%s: missing solar disk size argument for '-5' option\n", |
407 |
> |
argv[0]); |
408 |
> |
exit(1); |
409 |
> |
} |
410 |
> |
fixed_sun_sa *= fixed_sun_sa*PI; |
411 |
|
break; |
412 |
|
default: |
413 |
|
goto userr; |
414 |
|
} |
415 |
|
if (i < argc-1) |
416 |
|
goto userr; |
417 |
+ |
if (inconsistent) |
418 |
+ |
fprintf(stderr, "%s: WARNING: inconsistent -s, -d, -c options!\n", |
419 |
+ |
progname); |
420 |
|
if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
421 |
|
fprintf(stderr, "%s: cannot open '%s' for input\n", |
422 |
|
progname, argv[i]); |
476 |
|
s_meridian = DegToRad(s_meridian); |
477 |
|
/* process each time step in tape */ |
478 |
|
while (scanf("%d %d %lf %lf %lf\n", &mo, &da, &hr, &dir, &dif) == 5) { |
460 |
– |
static int step_alloc = 0; |
479 |
|
double sda, sta; |
480 |
|
/* make space for next time step */ |
481 |
|
mtx_offset = 3*nskypatch*ntsteps++; |
482 |
|
if (ntsteps > step_alloc) { |
483 |
< |
step_alloc += step_alloc>>1 + 8; |
483 |
> |
step_alloc += (step_alloc>>1) + ntsteps + 7; |
484 |
|
mtx_data = resize_dmatrix(mtx_data, step_alloc, nskypatch); |
485 |
|
} |
486 |
|
if (dif <= 1e-4) { |
537 |
|
printf("NROWS=%d\n", nskypatch); |
538 |
|
printf("NCOLS=%d\n", ntsteps); |
539 |
|
printf("NCOMP=3\n"); |
540 |
< |
fputformat(getfmtname(outfmt), stdout); |
540 |
> |
fputformat((char *)getfmtname(outfmt), stdout); |
541 |
|
putchar('\n'); |
542 |
|
} |
543 |
|
/* patches are rows (outer sort) */ |
556 |
|
break; |
557 |
|
case 'f': |
558 |
|
for (j = 0; j < ntsteps; j++) { |
559 |
< |
fwrite(mtx_data+mtx_offset, sizeof(float), 3, |
559 |
> |
putbinary(mtx_data+mtx_offset, sizeof(float), 3, |
560 |
|
stdout); |
561 |
|
mtx_offset += 3*nskypatch; |
562 |
|
} |
567 |
|
ment[0] = mtx_data[mtx_offset]; |
568 |
|
ment[1] = mtx_data[mtx_offset+1]; |
569 |
|
ment[2] = mtx_data[mtx_offset+2]; |
570 |
< |
fwrite(ment, sizeof(double), 3, stdout); |
570 |
> |
putbinary(ment, sizeof(double), 3, stdout); |
571 |
|
mtx_offset += 3*nskypatch; |
572 |
|
} |
573 |
|
break; |
1129 |
|
double sspa; /* Sun-sky point angle */ |
1130 |
|
double zsa; /* Zenithal sun angle */ |
1131 |
|
|
1132 |
+ |
fprintf(stderr, "Alt, azi: %f %f\n", altitude, azimuth); |
1133 |
+ |
fprintf(stderr, "Perez parameters: %f %f %f %f %f\n", |
1134 |
+ |
perez_param[0], perez_param[1], perez_param[2], perez_param[3], perez_param[4]); |
1135 |
+ |
|
1136 |
|
for (i = 1; i < nskypatch; i++) |
1137 |
|
{ |
1138 |
|
/* Calculate sun-sky point azimuthal angle */ |
1147 |
|
|
1148 |
|
/* Calculate patch luminance */ |
1149 |
|
parr[3*i] = CalcRelLuminance(sspa, zsa); |
1150 |
+ |
fprintf(stderr, "CalcRelLuminance(%f, %f) = %f\n", sspa, zsa, parr[3*i]); |
1151 |
|
if (parr[3*i] < 0) parr[3*i] = 0; |
1152 |
|
parr[3*i+2] = parr[3*i+1] = parr[3*i]; |
1153 |
|
} |