1 |
– |
#ifndef lint |
2 |
– |
static const char RCSid[] = "$Id$"; |
3 |
– |
#endif |
1 |
|
/* Copyright (c) 2003 |
2 |
|
* National Research Council Canada |
3 |
|
* written by Christoph Reinhart |
4 |
|
*/ |
5 |
|
|
6 |
< |
/* epw2wea: daylight analysis subprogram of DAYSIM |
7 |
< |
Program converts EnergyPlus weather format (*.ppw) into DAYSIM format (*.wea) |
11 |
< |
*/ |
6 |
> |
/* epw2wea: daylight analysis subprogram of DAYSIM */ |
7 |
> |
/* Program converts EnergyPlus weather format (*.ppw) into DAYSIM format (*.wea) */ |
8 |
|
|
13 |
– |
#include <stdlib.h> |
9 |
|
#include <stdio.h> |
10 |
+ |
#include <stdlib.h> |
11 |
|
#include <string.h> |
16 |
– |
#include <errno.h> |
12 |
|
|
13 |
< |
int |
19 |
< |
main(int argc, char *argv[]) |
13 |
> |
int main( int argc, char *argv[]) |
14 |
|
{ |
15 |
|
FILE *EPW_FILE; |
16 |
|
FILE* WEA_FILE; |
17 |
< |
int year, month,day, hour_in,minute,i; |
17 |
> |
int year, month,day, hour_in,minute=60,i; |
18 |
> |
int minute_message=1; |
19 |
> |
int get_ac = 0; |
20 |
|
float dir_norm_rad, dif_or_rad,dummy_float; |
21 |
< |
char keyword[2000]=""; |
21 |
> |
float aod; |
22 |
> |
int cc; |
23 |
> |
char keyword[2000]=""; |
24 |
> |
char minute_string[2000]=""; |
25 |
|
char epw_file[200]=""; |
26 |
|
char wea_file[200] =""; |
27 |
|
char city[200] =""; |
31 |
|
if (argc < 3) |
32 |
|
{ |
33 |
|
fprintf(stderr,"epw2wea: FATAL ERROR - wrong number of arguments\n"); |
34 |
< |
fprintf(stderr,"start program with: epw2wea file-name.epw file-name.wea\n"); |
35 |
< |
return(1); |
34 |
> |
fprintf(stderr,"start program with: epw2wea <file-name.epw> <file-name.wea>\n"); |
35 |
> |
exit(1); |
36 |
|
} |
37 |
|
if (argc >= 3) |
38 |
|
{ |
39 |
|
strcpy(epw_file, argv[1]); |
40 |
|
strcpy(wea_file, argv[2]); |
41 |
+ |
if (argc ==4 && argv[3][0] == '-' && argv[3][1] == 'a') /* option -a */ |
42 |
+ |
get_ac = 1; |
43 |
|
for (i = 3; i < argc; i++) |
44 |
|
if (argv[i][0] == '-' ) |
45 |
|
switch (argv[i][1]) |
46 |
|
{ |
47 |
|
case 'h': /* scaling factor */ |
48 |
|
break; |
49 |
< |
}//end switch (argv[i][1]) |
49 |
> |
} |
50 |
|
else |
51 |
|
{ |
52 |
|
fprintf(stdout,"epw2wea: fatal error - %s bad option for input arguments\n", argv[i]); |
53 |
< |
return(1); |
54 |
< |
}//end else |
53 |
> |
exit(0); |
54 |
> |
} |
55 |
|
} |
56 |
|
|
57 |
< |
EPW_FILE=fopen(epw_file, "r");; |
58 |
< |
WEA_FILE=fopen(wea_file, "w");; |
57 |
> |
EPW_FILE=fopen(epw_file, "r"); |
58 |
> |
WEA_FILE=fopen(wea_file, "w"); |
59 |
|
fscanf(EPW_FILE,"%[^,]s",keyword); |
60 |
< |
if(strcmp(keyword,"LOCATION") ){ |
60 |
< |
fprintf(stderr,"epw2wea: FATAL ERROR - this does not seem to be an epw file \n"); |
61 |
< |
return(1); |
62 |
< |
} |
60 |
> |
if( !strcmp(keyword,"LOCATION") ){ |
61 |
|
fscanf(EPW_FILE,",%[^,]s",city); |
62 |
|
fscanf(EPW_FILE,",%[^,]s",country); |
63 |
|
fscanf(EPW_FILE,",%[^,]s",country); |
66 |
|
fprintf(WEA_FILE,"%s",keyword); |
67 |
|
|
68 |
|
fscanf(EPW_FILE,",%[^,]s",country); |
69 |
< |
fscanf(EPW_FILE,",%[^,]s",country);//printf("%s\n",country); |
69 |
> |
fscanf(EPW_FILE,",%[^,]s",country); |
70 |
|
fscanf(EPW_FILE,",%[^,]s",latitude); |
71 |
|
printf("latitude %s\n",latitude); |
72 |
|
fprintf(WEA_FILE,"latitude %s\n",latitude); |
75 |
|
printf("longitude %.2f\n",-1.0*atof(longitude)); |
76 |
|
fprintf(WEA_FILE,"longitude %.2f\n",-1.0*atof(longitude)); |
77 |
|
fscanf(EPW_FILE,",%[^,]s",time_zone); |
78 |
< |
printf("time_zone %.0f\n",-15.0*atoi(time_zone)); |
78 |
> |
printf("time_zone %.2f\n",-15.0*atof(time_zone)); |
79 |
|
fprintf(WEA_FILE,"time_zone %.0f\n",-15.0*atoi(time_zone)); |
80 |
|
fscanf(EPW_FILE,",%s[^\n]",elevation); |
81 |
|
printf("site_elevation %s\nweather_data_file_units 1\n",elevation); |
88 |
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
89 |
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
90 |
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
91 |
+ |
|
92 |
+ |
/* read in time step interval */ |
93 |
+ |
fscanf(EPW_FILE,"%[^,]s",keyword); |
94 |
+ |
fscanf(EPW_FILE,",%[^,]s",keyword); |
95 |
+ |
fscanf(EPW_FILE,",%[^,]s",minute_string); |
96 |
+ |
minute=atoi(minute_string); |
97 |
+ |
if(minute==1) /* one measurement per hour equals a 60 minute time step */ |
98 |
+ |
minute=60; |
99 |
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
100 |
< |
|
101 |
< |
|
102 |
< |
while( EOF != fscanf(EPW_FILE,"%d,%d,%d,%d,%d",&year,&month,&day, &hour_in,&minute)){ |
100 |
> |
|
101 |
> |
while( EOF != fscanf(EPW_FILE,"%d,%d,%d,%d",&year,&month,&day, &hour_in)){ |
102 |
> |
|
103 |
|
fprintf(WEA_FILE,"%d %d %.3f ",month,day,hour_in*1.0-minute*(0.5/60)); |
104 |
< |
|
104 |
> |
|
105 |
> |
fscanf(EPW_FILE,",%f",&dummy_float); |
106 |
|
fscanf(EPW_FILE,",%[^,]s",city); |
107 |
|
fscanf(EPW_FILE,",%f",&dummy_float); |
108 |
|
fscanf(EPW_FILE,",%f",&dummy_float); |
115 |
|
|
116 |
|
fscanf(EPW_FILE,",%f,%f",&dir_norm_rad, &dif_or_rad); |
117 |
|
fprintf(WEA_FILE,"%.0f %.0f",dir_norm_rad, dif_or_rad); |
118 |
+ |
if (get_ac){ |
119 |
+ |
fscanf(EPW_FILE,",%f",&dummy_float); |
120 |
+ |
fscanf(EPW_FILE,",%f",&dummy_float); |
121 |
+ |
fscanf(EPW_FILE,",%f",&dummy_float); |
122 |
+ |
fscanf(EPW_FILE,",%f",&dummy_float); |
123 |
+ |
fscanf(EPW_FILE,",%f",&dummy_float); |
124 |
+ |
fscanf(EPW_FILE,",%f",&dummy_float); |
125 |
+ |
fscanf(EPW_FILE,",%d",&cc); |
126 |
+ |
fscanf(EPW_FILE,",%f",&dummy_float); |
127 |
+ |
fscanf(EPW_FILE,",%f",&dummy_float); |
128 |
+ |
fscanf(EPW_FILE,",%f",&dummy_float); |
129 |
+ |
fscanf(EPW_FILE,",%f",&dummy_float); |
130 |
+ |
fscanf(EPW_FILE,",%f",&dummy_float); |
131 |
+ |
fscanf(EPW_FILE,",%f",&dummy_float); |
132 |
+ |
fscanf(EPW_FILE,",%f",&aod); |
133 |
|
|
134 |
+ |
fprintf(WEA_FILE," %.3f %.1f",aod, cc/10.); |
135 |
+ |
|
136 |
+ |
} |
137 |
+ |
|
138 |
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
139 |
|
fprintf(WEA_FILE,"\n"); |
140 |
|
} |
141 |
|
|
142 |
< |
fclose(EPW_FILE); |
143 |
< |
fclose(WEA_FILE); |
142 |
> |
}else{ |
143 |
> |
fprintf(stderr,"epw2wea: FATAL ERROR - this does not seem to be an epw file \n");exit(1); |
144 |
> |
} |
145 |
|
|
146 |
< |
return(0); |
146 |
> |
fclose(EPW_FILE); |
147 |
> |
fclose(WEA_FILE); |
148 |
> |
return 0; |
149 |
|
} |
150 |
|
|
151 |
|
|