ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/epw2wea.c
(Generate patch)

Comparing ray/src/cv/epw2wea.c (file contents):
Revision 2.1 by greg, Wed Sep 25 16:52:28 2013 UTC vs.
Revision 2.6 by greg, Mon Aug 5 18:02:07 2024 UTC

# Line 6 | Line 6 | static const char RCSid[] = "$Id$";
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 < */
9 > /* epw2wea: daylight analysis subprogram of DAYSIM */
10 > /* Program converts EnergyPlus weather format (*.ppw) into DAYSIM format (*.wea) */
11  
13 #include <stdlib.h>
12   #include <stdio.h>
13 + #include <stdlib.h>
14   #include <string.h>
16 #include <errno.h>
15  
16 < int
19 < main(int argc, char *argv[])
16 > int main( int argc, char  *argv[])
17   {
18 <        FILE *EPW_FILE;
19 <        FILE* WEA_FILE;
20 <        int year, month,day, hour_in,minute,i;
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 <        char keyword[2000]="";
25 <        char epw_file[200]="";
26 <        char wea_file[200] ="";
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 <        if (argc < 3)
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,"start program with: epw2wea file-name.epw file-name.wea\n");
46 <                return(1);
45 >                fprintf(stderr,"Usage: epw2wea [-a] file-name.epw [file-name.wea]\n");
46 >                exit(1);
47          }
48 <        if (argc >= 3)
49 <        {
50 <                strcpy(epw_file, argv[1]);
51 <                strcpy(wea_file, argv[2]);
52 <                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
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 <
55 <        EPW_FILE=fopen(epw_file, "r");;
56 <        WEA_FILE=fopen(wea_file, "w");;
57 <        fscanf(EPW_FILE,"%[^,]s",keyword);
58 <        if(strcmp(keyword,"LOCATION") ){
59 <                fprintf(stderr,"epw2wea: FATAL ERROR - this does not seem to be an epw file \n");
60 <                return(1);
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);
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);
71 >        fscanf(EPW_FILE,",%[^,]s",country);
72          fscanf(EPW_FILE,",%[^,]s",latitude);
73        printf("latitude %s\n",latitude);
73          fprintf(WEA_FILE,"latitude %s\n",latitude);
74          fscanf(EPW_FILE,",%[^,]s",longitude);
75  
77        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);
80        printf("time_zone %.0f\n",-15.0*atoi(time_zone));
78          fprintf(WEA_FILE,"time_zone %.0f\n",-15.0*atoi(time_zone));
79          fscanf(EPW_FILE,",%s[^\n]",elevation);
83        printf("site_elevation %s\nweather_data_file_units 1\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]");
# Line 90 | Line 86 | main(int argc, char *argv[])
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 <
100 <        while( EOF != fscanf(EPW_FILE,"%d,%d,%d,%d,%d",&year,&month,&day, &hour_in,&minute)){
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 <
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);
# Line 108 | Line 113 | main(int argc, char *argv[])
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 <        fclose(EPW_FILE);
141 <        fclose(WEA_FILE);
140 > }else{
141 >                fprintf(stderr,"epw2wea: FATAL ERROR - this does not seem to be an epw file \n");exit(1);
142 > }
143  
144 <        return(0);
144 > fclose(EPW_FILE);
145 > fclose(WEA_FILE);
146 > return 0;
147   }
148  
149  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines