ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/epw2wea.c
Revision: 2.6
Committed: Mon Aug 5 18:02:07 2024 UTC (8 months, 3 weeks ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.5: +1 -6 lines
Log Message:
fix(epw2wea): Eliminated redundant lines when writing to stdout

File Contents

# User Rev Content
1 greg 2.5 #ifndef lint
2 greg 2.6 static const char RCSid[] = "$Id: epw2wea.c,v 2.5 2024/08/02 21:18:40 greg Exp $";
3 greg 2.5 #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     fprintf(WEA_FILE,"%s",keyword);
69    
70     fscanf(EPW_FILE,",%[^,]s",country);
71 greg 2.2 fscanf(EPW_FILE,",%[^,]s",country);
72 greg 2.1 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 greg 2.2
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 greg 2.1 fprintf(WEA_FILE,"%d %d %.3f ",month,day,hour_in*1.0-minute*(0.5/60));
102 greg 2.2
103     fscanf(EPW_FILE,",%f",&dummy_float);
104 greg 2.1 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 greg 2.4 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 greg 2.1
136     fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]");
137     fprintf(WEA_FILE,"\n");
138     }
139    
140 greg 2.2 }else{
141     fprintf(stderr,"epw2wea: FATAL ERROR - this does not seem to be an epw file \n");exit(1);
142     }
143 greg 2.1
144 greg 2.2 fclose(EPW_FILE);
145     fclose(WEA_FILE);
146     return 0;
147 greg 2.1 }
148    
149