1 |
greg |
2.1 |
/* Copyright (c) 2003 |
2 |
|
|
* National Research Council Canada |
3 |
|
|
* written by Christoph Reinhart |
4 |
|
|
*/ |
5 |
|
|
|
6 |
greg |
2.2 |
/* epw2wea: daylight analysis subprogram of DAYSIM */ |
7 |
|
|
/* Program converts EnergyPlus weather format (*.ppw) into DAYSIM format (*.wea) */ |
8 |
greg |
2.1 |
|
9 |
greg |
2.2 |
#include <stdio.h> |
10 |
greg |
2.1 |
#include <stdlib.h> |
11 |
|
|
#include <string.h> |
12 |
|
|
|
13 |
greg |
2.2 |
int main( int argc, char *argv[]) |
14 |
greg |
2.1 |
{ |
15 |
|
|
FILE *EPW_FILE; |
16 |
|
|
FILE* WEA_FILE; |
17 |
greg |
2.2 |
int year, month,day, hour_in,minute=60,i; |
18 |
|
|
int minute_message=1; |
19 |
greg |
2.4 |
int get_ac = 0; |
20 |
greg |
2.1 |
float dir_norm_rad, dif_or_rad,dummy_float; |
21 |
greg |
2.4 |
float aod; |
22 |
|
|
int cc; |
23 |
greg |
2.2 |
char keyword[2000]=""; |
24 |
|
|
char minute_string[2000]=""; |
25 |
greg |
2.1 |
char epw_file[200]=""; |
26 |
|
|
char wea_file[200] =""; |
27 |
|
|
char city[200] =""; |
28 |
|
|
char country[200] =""; |
29 |
|
|
char latitude[200] ="",longitude[200] ="",time_zone[200] ="",elevation[200] =""; |
30 |
|
|
|
31 |
|
|
if (argc < 3) |
32 |
|
|
{ |
33 |
|
|
fprintf(stderr,"epw2wea: FATAL ERROR - wrong number of arguments\n"); |
34 |
greg |
2.2 |
fprintf(stderr,"start program with: epw2wea <file-name.epw> <file-name.wea>\n"); |
35 |
|
|
exit(1); |
36 |
greg |
2.1 |
} |
37 |
|
|
if (argc >= 3) |
38 |
|
|
{ |
39 |
|
|
strcpy(epw_file, argv[1]); |
40 |
|
|
strcpy(wea_file, argv[2]); |
41 |
greg |
2.4 |
if (argc ==4 && argv[3][0] == '-' && argv[3][1] == 'a') /* option -a */ |
42 |
|
|
get_ac = 1; |
43 |
greg |
2.1 |
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 |
greg |
2.2 |
} |
50 |
greg |
2.1 |
else |
51 |
|
|
{ |
52 |
|
|
fprintf(stdout,"epw2wea: fatal error - %s bad option for input arguments\n", argv[i]); |
53 |
greg |
2.2 |
exit(0); |
54 |
|
|
} |
55 |
greg |
2.1 |
} |
56 |
|
|
|
57 |
greg |
2.2 |
EPW_FILE=fopen(epw_file, "r"); |
58 |
|
|
WEA_FILE=fopen(wea_file, "w"); |
59 |
greg |
2.1 |
fscanf(EPW_FILE,"%[^,]s",keyword); |
60 |
greg |
2.2 |
if( !strcmp(keyword,"LOCATION") ){ |
61 |
greg |
2.1 |
fscanf(EPW_FILE,",%[^,]s",city); |
62 |
|
|
fscanf(EPW_FILE,",%[^,]s",country); |
63 |
|
|
fscanf(EPW_FILE,",%[^,]s",country); |
64 |
|
|
sprintf(keyword,"place %s_%s\n",city,country); |
65 |
|
|
printf("%s",keyword); |
66 |
|
|
fprintf(WEA_FILE,"%s",keyword); |
67 |
|
|
|
68 |
|
|
fscanf(EPW_FILE,",%[^,]s",country); |
69 |
greg |
2.2 |
fscanf(EPW_FILE,",%[^,]s",country); |
70 |
greg |
2.1 |
fscanf(EPW_FILE,",%[^,]s",latitude); |
71 |
|
|
printf("latitude %s\n",latitude); |
72 |
|
|
fprintf(WEA_FILE,"latitude %s\n",latitude); |
73 |
|
|
fscanf(EPW_FILE,",%[^,]s",longitude); |
74 |
|
|
|
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 |
greg |
2.3 |
printf("time_zone %.2f\n",-15.0*atof(time_zone)); |
79 |
greg |
2.1 |
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); |
82 |
|
|
fprintf(WEA_FILE,"site_elevation %s\nweather_data_file_units 1\n",elevation); |
83 |
|
|
|
84 |
|
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
85 |
|
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
86 |
|
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
87 |
|
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
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 |
greg |
2.2 |
|
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 |
|
|
while( EOF != fscanf(EPW_FILE,"%d,%d,%d,%d",&year,&month,&day, &hour_in)){ |
102 |
|
|
|
103 |
greg |
2.1 |
fprintf(WEA_FILE,"%d %d %.3f ",month,day,hour_in*1.0-minute*(0.5/60)); |
104 |
greg |
2.2 |
|
105 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
106 |
greg |
2.1 |
fscanf(EPW_FILE,",%[^,]s",city); |
107 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
108 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
109 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
110 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
111 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
112 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
113 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
114 |
|
|
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 |
greg |
2.4 |
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 |
greg |
2.1 |
|
138 |
|
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
139 |
|
|
fprintf(WEA_FILE,"\n"); |
140 |
|
|
} |
141 |
|
|
|
142 |
greg |
2.2 |
}else{ |
143 |
|
|
fprintf(stderr,"epw2wea: FATAL ERROR - this does not seem to be an epw file \n");exit(1); |
144 |
|
|
} |
145 |
greg |
2.1 |
|
146 |
greg |
2.2 |
fclose(EPW_FILE); |
147 |
|
|
fclose(WEA_FILE); |
148 |
|
|
return 0; |
149 |
greg |
2.1 |
} |
150 |
|
|
|
151 |
|
|
|