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