1 |
greg |
2.1 |
#ifndef lint |
2 |
|
|
static const char RCSid[] = "$Id$"; |
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 |
|
|
|
13 |
|
|
#include <stdlib.h> |
14 |
|
|
#include <stdio.h> |
15 |
|
|
#include <string.h> |
16 |
|
|
#include <errno.h> |
17 |
|
|
|
18 |
|
|
int |
19 |
|
|
main(int argc, char *argv[]) |
20 |
|
|
{ |
21 |
|
|
FILE *EPW_FILE; |
22 |
|
|
FILE* WEA_FILE; |
23 |
|
|
int year, month,day, hour_in,minute,i; |
24 |
|
|
float dir_norm_rad, dif_or_rad,dummy_float; |
25 |
|
|
char keyword[2000]=""; |
26 |
|
|
char epw_file[200]=""; |
27 |
|
|
char wea_file[200] =""; |
28 |
|
|
char city[200] =""; |
29 |
|
|
char country[200] =""; |
30 |
|
|
char latitude[200] ="",longitude[200] ="",time_zone[200] ="",elevation[200] =""; |
31 |
|
|
|
32 |
|
|
if (argc < 3) |
33 |
|
|
{ |
34 |
|
|
fprintf(stderr,"epw2wea: FATAL ERROR - wrong number of arguments\n"); |
35 |
|
|
fprintf(stderr,"start program with: epw2wea file-name.epw file-name.wea\n"); |
36 |
|
|
return(1); |
37 |
|
|
} |
38 |
|
|
if (argc >= 3) |
39 |
|
|
{ |
40 |
|
|
strcpy(epw_file, argv[1]); |
41 |
|
|
strcpy(wea_file, argv[2]); |
42 |
|
|
for (i = 3; i < argc; i++) |
43 |
|
|
if (argv[i][0] == '-' ) |
44 |
|
|
switch (argv[i][1]) |
45 |
|
|
{ |
46 |
|
|
case 'h': /* scaling factor */ |
47 |
|
|
break; |
48 |
|
|
}//end switch (argv[i][1]) |
49 |
|
|
else |
50 |
|
|
{ |
51 |
|
|
fprintf(stdout,"epw2wea: fatal error - %s bad option for input arguments\n", argv[i]); |
52 |
|
|
return(1); |
53 |
|
|
}//end else |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
EPW_FILE=fopen(epw_file, "r");; |
57 |
|
|
WEA_FILE=fopen(wea_file, "w");; |
58 |
|
|
fscanf(EPW_FILE,"%[^,]s",keyword); |
59 |
|
|
if(strcmp(keyword,"LOCATION") ){ |
60 |
|
|
fprintf(stderr,"epw2wea: FATAL ERROR - this does not seem to be an epw file \n"); |
61 |
|
|
return(1); |
62 |
|
|
} |
63 |
|
|
fscanf(EPW_FILE,",%[^,]s",city); |
64 |
|
|
fscanf(EPW_FILE,",%[^,]s",country); |
65 |
|
|
fscanf(EPW_FILE,",%[^,]s",country); |
66 |
|
|
sprintf(keyword,"place %s_%s\n",city,country); |
67 |
|
|
printf("%s",keyword); |
68 |
|
|
fprintf(WEA_FILE,"%s",keyword); |
69 |
|
|
|
70 |
|
|
fscanf(EPW_FILE,",%[^,]s",country); |
71 |
|
|
fscanf(EPW_FILE,",%[^,]s",country);//printf("%s\n",country); |
72 |
|
|
fscanf(EPW_FILE,",%[^,]s",latitude); |
73 |
|
|
printf("latitude %s\n",latitude); |
74 |
|
|
fprintf(WEA_FILE,"latitude %s\n",latitude); |
75 |
|
|
fscanf(EPW_FILE,",%[^,]s",longitude); |
76 |
|
|
|
77 |
|
|
printf("longitude %.2f\n",-1.0*atof(longitude)); |
78 |
|
|
fprintf(WEA_FILE,"longitude %.2f\n",-1.0*atof(longitude)); |
79 |
|
|
fscanf(EPW_FILE,",%[^,]s",time_zone); |
80 |
|
|
printf("time_zone %.0f\n",-15.0*atoi(time_zone)); |
81 |
|
|
fprintf(WEA_FILE,"time_zone %.0f\n",-15.0*atoi(time_zone)); |
82 |
|
|
fscanf(EPW_FILE,",%s[^\n]",elevation); |
83 |
|
|
printf("site_elevation %s\nweather_data_file_units 1\n",elevation); |
84 |
|
|
fprintf(WEA_FILE,"site_elevation %s\nweather_data_file_units 1\n",elevation); |
85 |
|
|
|
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 |
|
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
92 |
|
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
93 |
|
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
94 |
|
|
|
95 |
|
|
|
96 |
|
|
while( EOF != fscanf(EPW_FILE,"%d,%d,%d,%d,%d",&year,&month,&day, &hour_in,&minute)){ |
97 |
|
|
fprintf(WEA_FILE,"%d %d %.3f ",month,day,hour_in*1.0-minute*(0.5/60)); |
98 |
|
|
|
99 |
|
|
fscanf(EPW_FILE,",%[^,]s",city); |
100 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
101 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
102 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
103 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
104 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
105 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
106 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
107 |
|
|
fscanf(EPW_FILE,",%f",&dummy_float); |
108 |
|
|
|
109 |
|
|
fscanf(EPW_FILE,",%f,%f",&dir_norm_rad, &dif_or_rad); |
110 |
|
|
fprintf(WEA_FILE,"%.0f %.0f",dir_norm_rad, dif_or_rad); |
111 |
|
|
|
112 |
|
|
fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); |
113 |
|
|
fprintf(WEA_FILE,"\n"); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
fclose(EPW_FILE); |
117 |
|
|
fclose(WEA_FILE); |
118 |
|
|
|
119 |
|
|
return(0); |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
|