ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/epw2wea.c
Revision: 2.5
Committed: Fri Aug 2 21:18:40 2024 UTC (8 months, 4 weeks ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.4: +29 -26 lines
Log Message:
feat(epw2wea): Moved -a flag to front and made second file argument optional

File Contents

# User Rev Content
1 greg 2.5 #ifndef lint
2     static const char RCSid[] = "$Id$";
3     #endif
4 greg 2.1 /* Copyright (c) 2003
5     * National Research Council Canada
6     * written by Christoph Reinhart
7     */
8    
9 greg 2.2 /* epw2wea: daylight analysis subprogram of DAYSIM */
10     /* Program converts EnergyPlus weather format (*.ppw) into DAYSIM format (*.wea) */
11 greg 2.1
12 greg 2.2 #include <stdio.h>
13 greg 2.1 #include <stdlib.h>
14     #include <string.h>
15    
16 greg 2.2 int main( int argc, char *argv[])
17 greg 2.1 {
18 greg 2.5 FILE *EPW_FILE = NULL;
19     FILE* WEA_FILE = stdout;
20 greg 2.2 int year, month,day, hour_in,minute=60,i;
21     int minute_message=1;
22 greg 2.4 int get_ac = 0;
23 greg 2.1 float dir_norm_rad, dif_or_rad,dummy_float;
24 greg 2.4 float aod;
25     int cc;
26 greg 2.2 char keyword[2000]="";
27     char minute_string[2000]="";
28 greg 2.5 char *epw_file = NULL;
29     char *wea_file = NULL;
30 greg 2.1 char city[200] ="";
31     char country[200] ="";
32     char latitude[200] ="",longitude[200] ="",time_zone[200] ="",elevation[200] ="";
33    
34 greg 2.5 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 greg 2.1 {
44     fprintf(stderr,"epw2wea: FATAL ERROR - wrong number of arguments\n");
45 greg 2.5 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 greg 2.2 exit(1);
53 greg 2.1 }
54 greg 2.5 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 greg 2.2 }
61 greg 2.1 }
62     fscanf(EPW_FILE,"%[^,]s",keyword);
63 greg 2.2 if( !strcmp(keyword,"LOCATION") ){
64 greg 2.1 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     printf("%s",keyword);
69     fprintf(WEA_FILE,"%s",keyword);
70    
71     fscanf(EPW_FILE,",%[^,]s",country);
72 greg 2.2 fscanf(EPW_FILE,",%[^,]s",country);
73 greg 2.1 fscanf(EPW_FILE,",%[^,]s",latitude);
74     printf("latitude %s\n",latitude);
75     fprintf(WEA_FILE,"latitude %s\n",latitude);
76     fscanf(EPW_FILE,",%[^,]s",longitude);
77    
78     printf("longitude %.2f\n",-1.0*atof(longitude));
79     fprintf(WEA_FILE,"longitude %.2f\n",-1.0*atof(longitude));
80     fscanf(EPW_FILE,",%[^,]s",time_zone);
81 greg 2.3 printf("time_zone %.2f\n",-15.0*atof(time_zone));
82 greg 2.1 fprintf(WEA_FILE,"time_zone %.0f\n",-15.0*atoi(time_zone));
83     fscanf(EPW_FILE,",%s[^\n]",elevation);
84     printf("site_elevation %s\nweather_data_file_units 1\n",elevation);
85     fprintf(WEA_FILE,"site_elevation %s\nweather_data_file_units 1\n",elevation);
86    
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 greg 2.2
95     /* read in time step interval */
96     fscanf(EPW_FILE,"%[^,]s",keyword);
97     fscanf(EPW_FILE,",%[^,]s",keyword);
98     fscanf(EPW_FILE,",%[^,]s",minute_string);
99     minute=atoi(minute_string);
100     if(minute==1) /* one measurement per hour equals a 60 minute time step */
101     minute=60;
102     fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]");
103    
104     while( EOF != fscanf(EPW_FILE,"%d,%d,%d,%d",&year,&month,&day, &hour_in)){
105    
106 greg 2.1 fprintf(WEA_FILE,"%d %d %.3f ",month,day,hour_in*1.0-minute*(0.5/60));
107 greg 2.2
108     fscanf(EPW_FILE,",%f",&dummy_float);
109 greg 2.1 fscanf(EPW_FILE,",%[^,]s",city);
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     fscanf(EPW_FILE,",%f",&dummy_float);
116     fscanf(EPW_FILE,",%f",&dummy_float);
117     fscanf(EPW_FILE,",%f",&dummy_float);
118    
119     fscanf(EPW_FILE,",%f,%f",&dir_norm_rad, &dif_or_rad);
120     fprintf(WEA_FILE,"%.0f %.0f",dir_norm_rad, dif_or_rad);
121 greg 2.4 if (get_ac){
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,",%f",&dummy_float);
126     fscanf(EPW_FILE,",%f",&dummy_float);
127     fscanf(EPW_FILE,",%f",&dummy_float);
128     fscanf(EPW_FILE,",%d",&cc);
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",&dummy_float);
133     fscanf(EPW_FILE,",%f",&dummy_float);
134     fscanf(EPW_FILE,",%f",&dummy_float);
135     fscanf(EPW_FILE,",%f",&aod);
136    
137     fprintf(WEA_FILE," %.3f %.1f",aod, cc/10.);
138    
139     }
140 greg 2.1
141     fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]");
142     fprintf(WEA_FILE,"\n");
143     }
144    
145 greg 2.2 }else{
146     fprintf(stderr,"epw2wea: FATAL ERROR - this does not seem to be an epw file \n");exit(1);
147     }
148 greg 2.1
149 greg 2.2 fclose(EPW_FILE);
150     fclose(WEA_FILE);
151     return 0;
152 greg 2.1 }
153    
154