| 321 |
|
double elevation; /* site elevation (meters) */ |
| 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; |
| 324 |
> |
int ntsteps = 0; /* number of time steps */ |
| 325 |
> |
int avgSky = 0; /* compute average sky r.t. matrix? */ |
| 326 |
> |
int nrows = 0; /* number of rows in matrix */ |
| 327 |
> |
int rows_alloc = 0; /* number of allocated rows */ |
| 328 |
|
int last_monthly = 0; /* month of last report */ |
| 329 |
|
int inconsistent = 0; /* inconsistent options set? */ |
| 330 |
|
int mo, da; /* month (1-12) and day (1-31) */ |
| 411 |
|
} |
| 412 |
|
fixed_sun_sa *= fixed_sun_sa*PI; |
| 413 |
|
break; |
| 414 |
+ |
case 'A': /* compute average sky */ |
| 415 |
+ |
avgSky = 1; |
| 416 |
+ |
break; |
| 417 |
|
default: |
| 418 |
|
goto userr; |
| 419 |
|
} |
| 479 |
|
s_latitude = DegToRad(s_latitude); |
| 480 |
|
s_longitude = DegToRad(s_longitude); |
| 481 |
|
s_meridian = DegToRad(s_meridian); |
| 482 |
+ |
/* initial allocation */ |
| 483 |
+ |
mtx_data = resize_dmatrix(mtx_data, rows_alloc=2, nskypatch); |
| 484 |
|
/* process each time step in tape */ |
| 485 |
|
while (scanf("%d %d %lf %lf %lf\n", &mo, &da, &hr, &dir, &dif) == 5) { |
| 486 |
|
double sda, sta; |
| 487 |
< |
/* make space for next time step */ |
| 488 |
< |
mtx_offset = 3*nskypatch*ntsteps++; |
| 489 |
< |
if (ntsteps > step_alloc) { |
| 490 |
< |
step_alloc += (step_alloc>>1) + ntsteps + 7; |
| 491 |
< |
mtx_data = resize_dmatrix(mtx_data, step_alloc, nskypatch); |
| 487 |
> |
|
| 488 |
> |
mtx_offset = 3*nskypatch*nrows; |
| 489 |
> |
nrows += !avgSky | !nrows; |
| 490 |
> |
/* make space for next row */ |
| 491 |
> |
if (nrows > rows_alloc) { |
| 492 |
> |
rows_alloc += (rows_alloc>>1) + nrows + 7; |
| 493 |
> |
mtx_data = resize_dmatrix(mtx_data, rows_alloc, nskypatch); |
| 494 |
|
} |
| 495 |
+ |
ntsteps++; /* keep count of time steps */ |
| 496 |
|
if (dif <= 1e-4) { |
| 497 |
< |
memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch); |
| 497 |
> |
if (!avgSky | !nrows) |
| 498 |
> |
memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch); |
| 499 |
|
continue; |
| 500 |
|
} |
| 501 |
|
if (verbose && mo != last_monthly) |
| 520 |
|
/* compute sky patch values */ |
| 521 |
|
ComputeSky(mtx_data+mtx_offset); |
| 522 |
|
AddDirect(mtx_data+mtx_offset); |
| 523 |
+ |
/* update cumulative sky? */ |
| 524 |
+ |
for (i = 3*nskypatch*(avgSky&(ntsteps>1)); i--; ) |
| 525 |
+ |
mtx_data[i] += mtx_data[mtx_offset+i]; |
| 526 |
|
} |
| 527 |
|
/* check for junk at end */ |
| 528 |
|
while ((i = fgetc(stdin)) != EOF) |
| 534 |
|
fputs(buf, stderr); fputc('\n', stderr); |
| 535 |
|
break; |
| 536 |
|
} |
| 537 |
+ |
if (!ntsteps) { |
| 538 |
+ |
fprintf(stderr, "%s: no valid time steps on input\n", progname); |
| 539 |
+ |
exit(1); |
| 540 |
+ |
} |
| 541 |
+ |
dif = 1./(double)ntsteps; /* average sky? */ |
| 542 |
+ |
for (i = 3*nskypatch*(avgSky&(ntsteps>1)); i--; ) |
| 543 |
+ |
mtx_data[i] *= dif; |
| 544 |
|
/* write out matrix */ |
| 545 |
|
if (outfmt != 'a') |
| 546 |
|
SET_FILE_BINARY(stdout); |
| 549 |
|
#endif |
| 550 |
|
if (verbose) |
| 551 |
|
fprintf(stderr, "%s: writing %smatrix with %d time steps...\n", |
| 552 |
< |
progname, outfmt=='a' ? "" : "binary ", ntsteps); |
| 552 |
> |
progname, outfmt=='a' ? "" : "binary ", nrows); |
| 553 |
|
if (doheader) { |
| 554 |
|
newheader("RADIANCE", stdout); |
| 555 |
|
printargs(argc, argv, stdout); |
| 556 |
|
printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude), |
| 557 |
|
-RadToDeg(s_longitude)); |
| 558 |
|
printf("NROWS=%d\n", nskypatch); |
| 559 |
< |
printf("NCOLS=%d\n", ntsteps); |
| 559 |
> |
printf("NCOLS=%d\n", nrows); |
| 560 |
|
printf("NCOMP=3\n"); |
| 561 |
|
fputformat((char *)getfmtname(outfmt), stdout); |
| 562 |
|
putchar('\n'); |
| 566 |
|
mtx_offset = 3*i; |
| 567 |
|
switch (outfmt) { |
| 568 |
|
case 'a': |
| 569 |
< |
for (j = 0; j < ntsteps; j++) { |
| 569 |
> |
for (j = 0; j < nrows; j++) { |
| 570 |
|
printf("%.3g %.3g %.3g\n", mtx_data[mtx_offset], |
| 571 |
|
mtx_data[mtx_offset+1], |
| 572 |
|
mtx_data[mtx_offset+2]); |
| 573 |
|
mtx_offset += 3*nskypatch; |
| 574 |
|
} |
| 575 |
< |
if (ntsteps > 1) |
| 575 |
> |
if (nrows > 1) |
| 576 |
|
fputc('\n', stdout); |
| 577 |
|
break; |
| 578 |
|
case 'f': |
| 579 |
< |
for (j = 0; j < ntsteps; j++) { |
| 579 |
> |
for (j = 0; j < nrows; j++) { |
| 580 |
|
putbinary(mtx_data+mtx_offset, sizeof(float), 3, |
| 581 |
|
stdout); |
| 582 |
|
mtx_offset += 3*nskypatch; |
| 583 |
|
} |
| 584 |
|
break; |
| 585 |
|
case 'd': |
| 586 |
< |
for (j = 0; j < ntsteps; j++) { |
| 586 |
> |
for (j = 0; j < nrows; j++) { |
| 587 |
|
double ment[3]; |
| 588 |
|
ment[0] = mtx_data[mtx_offset]; |
| 589 |
|
ment[1] = mtx_data[mtx_offset+1]; |
| 602 |
|
fprintf(stderr, "%s: done.\n", progname); |
| 603 |
|
exit(0); |
| 604 |
|
userr: |
| 605 |
< |
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", |
| 605 |
> |
fprintf(stderr, "Usage: %s [-v][-h][-A][-d|-s][-r deg][-m N][-g r g b][-c r g b][-o{f|d}][-O{0|1}] [tape.wea]\n", |
| 606 |
|
progname); |
| 607 |
|
exit(1); |
| 608 |
|
fmterr: |