88 |
|
#include "rtio.h" |
89 |
|
#include "color.h" |
90 |
|
#include "sun.h" |
91 |
+ |
#include "loadEPW.h" |
92 |
|
|
93 |
|
char *progname; /* Program name */ |
94 |
|
const double DC_SolarConstantE = 1367.0; /* Solar constant W/m^2 */ |
310 |
|
int |
311 |
|
main(int argc, char *argv[]) |
312 |
|
{ |
313 |
< |
char buf[256]; |
313 |
> |
EPWheader *epw = NULL; /* EPW/WEA input file */ |
314 |
> |
EPWrecord erec; /* current EPW/WEA input record */ |
315 |
> |
float dpthist[2]; /* previous dew point temps */ |
316 |
> |
double dir, dif; |
317 |
|
int doheader = 1; /* output header? */ |
318 |
|
double rotation = 0; /* site rotation (degrees) */ |
319 |
|
double elevation; /* site elevation (meters) */ |
328 |
|
int tstorage = 0; /* number of allocated time steps */ |
329 |
|
int nstored = 0; /* number of time steps in matrix */ |
330 |
|
int last_monthly = 0; /* month of last report */ |
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 */ |
331 |
|
int mtx_offset; |
332 |
|
int i, j; |
333 |
|
double timeinterval = 0; |
438 |
|
default: |
439 |
|
goto userr; |
440 |
|
} |
441 |
< |
if (i < argc-1) |
441 |
> |
if ((i < argc-1) | (i > argc)) |
442 |
|
goto userr; |
443 |
< |
if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
444 |
< |
fprintf(stderr, "%s: cannot open '%s' for input\n", |
444 |
< |
progname, argv[i]); |
443 |
> |
epw = EPWopen(argv[i]); |
444 |
> |
if (epw == NULL) |
445 |
|
exit(1); |
446 |
– |
} |
446 |
|
if ((modsfp != NULL) & (sunsfp == NULL)) |
447 |
|
fprintf(stderr, "%s: warning -M output will be empty without -D\n", |
448 |
|
progname); |
455 |
|
progname); |
456 |
|
} |
457 |
|
/* read weather tape header */ |
458 |
< |
if (scanf("place %[^\r\n] ", buf) != 1) |
459 |
< |
goto fmterr; |
460 |
< |
if (scanf("latitude %lf\n", &s_latitude) != 1) |
461 |
< |
goto fmterr; |
462 |
< |
if (scanf("longitude %lf\n", &s_longitude) != 1) |
463 |
< |
goto fmterr; |
464 |
< |
if (scanf("time_zone %lf\n", &s_meridian) != 1) |
466 |
< |
goto fmterr; |
467 |
< |
if (scanf("site_elevation %lf\n", &elevation) != 1) |
468 |
< |
goto fmterr; |
469 |
< |
if (scanf("weather_data_file_units %d\n", &input) != 1) |
470 |
< |
goto fmterr; |
471 |
< |
switch (input) { /* translate units */ |
472 |
< |
case 1: |
458 |
> |
s_latitude = epw->loc.latitude; |
459 |
> |
s_longitude = -epw->loc.longitude; |
460 |
> |
s_meridian = -15.*epw->loc.timezone; |
461 |
> |
elevation = epw->loc.elevation; |
462 |
> |
switch (epw->isWEA) { /* translate units */ |
463 |
> |
case WEAnot: |
464 |
> |
case WEAradnorm: |
465 |
|
input = 1; /* radiometric quantities */ |
466 |
|
dir_is_horiz = 0; /* direct is perpendicular meas. */ |
467 |
|
break; |
468 |
< |
case 2: |
468 |
> |
case WEAradhoriz: |
469 |
|
input = 1; /* radiometric quantities */ |
470 |
|
dir_is_horiz = 1; /* solar measured horizontally */ |
471 |
|
break; |
472 |
< |
case 3: |
472 |
> |
case WEAphotnorm: |
473 |
|
input = 2; /* photometric quantities */ |
474 |
|
dir_is_horiz = 0; /* direct is perpendicular meas. */ |
475 |
|
break; |
478 |
|
} |
479 |
|
rh_init(); /* initialize sky patches */ |
480 |
|
if (verbose) { |
481 |
< |
fprintf(stderr, "%s: location '%s'\n", progname, buf); |
481 |
> |
fprintf(stderr, "%s: location '%s, %s'\n", progname, |
482 |
> |
epw->loc.city, epw->loc.country); |
483 |
|
fprintf(stderr, "%s: (lat,long)=(%.1f,%.1f) degrees north, west\n", |
484 |
|
progname, s_latitude, s_longitude); |
485 |
|
if (avgSky >= 0) |
498 |
|
s_meridian = DegToRad(s_meridian); |
499 |
|
/* initial allocation */ |
500 |
|
mtx_data = resize_dmatrix(mtx_data, tstorage=2, nskypatch); |
501 |
+ |
dpthist[0] = -100; |
502 |
|
/* process each time step in tape */ |
503 |
< |
while (scanf("%d %d %lf %lf %lf\n", &mo, &da, &hr, &dir, &dif) == 5) { |
503 |
> |
while ((j = EPWread(epw, &erec)) > 0) { |
504 |
> |
int mo = erec.date.month+1; |
505 |
> |
int da = erec.date.day; |
506 |
> |
double hr = erec.date.hour; |
507 |
|
double sda, sta, st; |
508 |
|
int sun_in_sky; |
509 |
|
/* compute solar position */ |
528 |
|
continue; /* skipping nighttime points */ |
529 |
|
azimuth = sazi(sda, st) + PI - DegToRad(rotation); |
530 |
|
|
531 |
+ |
switch (epw->isWEA) { /* translate units */ |
532 |
+ |
case WEAnot: |
533 |
+ |
case WEAradnorm: |
534 |
+ |
if (!EPWisset(&erec,dirirrad) | |
535 |
+ |
!EPWisset(&erec,horizdiffirrad)) { |
536 |
+ |
fprintf(stderr, "%s: missing required irradiances at line %d\n", |
537 |
+ |
progname, epw->lino); |
538 |
+ |
exit(1); |
539 |
+ |
} |
540 |
+ |
dir = erec.dirirrad; |
541 |
+ |
dif = erec.horizdiffirrad; |
542 |
+ |
break; |
543 |
+ |
case WEAradhoriz: |
544 |
+ |
dir = erec.globhorizirrad - erec.horizdiffirrad; |
545 |
+ |
dif = erec.horizdiffirrad; |
546 |
+ |
break; |
547 |
+ |
case WEAphotnorm: |
548 |
+ |
dir = erec.dirillum; |
549 |
+ |
dif = erec.diffillum; |
550 |
+ |
break; |
551 |
+ |
} |
552 |
+ |
if (EPWisset(&erec,dptemp)) { /* 3-hour dew point temp */ |
553 |
+ |
if (dpthist[0] < -99) |
554 |
+ |
dpthist[0] = dpthist[1] = erec.dptemp; |
555 |
+ |
dew_point = (1./3.)*(dpthist[0] + dpthist[1] + erec.dptemp); |
556 |
+ |
dpthist[0] = dpthist[1]; dpthist[1] = erec.dptemp; |
557 |
+ |
} |
558 |
|
mtx_offset = 3*nskypatch*nstored; |
559 |
|
nstored += !avgSky | !nstored; |
560 |
|
/* make space for next row */ |
608 |
|
progname, last_monthly=mo); |
609 |
|
/* note whether leap-day was given */ |
610 |
|
} |
611 |
+ |
if (j != EOF) { |
612 |
+ |
fprintf(stderr, "%s: error on input\n", progname); |
613 |
+ |
exit(1); |
614 |
+ |
} |
615 |
+ |
EPWclose(epw); epw = NULL; |
616 |
|
if (!ntsteps) { |
617 |
|
fprintf(stderr, "%s: no valid time steps on input\n", progname); |
618 |
|
exit(1); |
619 |
|
} |
591 |
– |
/* check for junk at end */ |
592 |
– |
while ((i = fgetc(stdin)) != EOF) |
593 |
– |
if (!isspace(i)) { |
594 |
– |
fprintf(stderr, "%s: warning - unexpected data past EOT: ", |
595 |
– |
progname); |
596 |
– |
buf[0] = i; buf[1] = '\0'; |
597 |
– |
fgets(buf+1, sizeof(buf)-1, stdin); |
598 |
– |
fputs(buf, stderr); fputc('\n', stderr); |
599 |
– |
break; |
600 |
– |
} |
601 |
– |
|
620 |
|
if (avgSky < 0) /* no matrix output? */ |
621 |
|
goto alldone; |
622 |
|
|