| 1 | 
/*  Copyright (c) 2003 | 
| 2 | 
 *  National Research Council Canada | 
| 3 | 
 *  written by Christoph Reinhart | 
| 4 | 
 */ | 
| 5 | 
 | 
| 6 | 
/* epw2wea: daylight analysis subprogram of DAYSIM */ | 
| 7 | 
/* Program converts EnergyPlus weather format (*.ppw) into DAYSIM format (*.wea) */ | 
| 8 | 
 | 
| 9 | 
#include <stdio.h> | 
| 10 | 
#include <stdlib.h> | 
| 11 | 
#include <string.h> | 
| 12 | 
 | 
| 13 | 
int main( int argc, char  *argv[]) | 
| 14 | 
{ | 
| 15 | 
        FILE *EPW_FILE; | 
| 16 | 
        FILE* WEA_FILE; | 
| 17 | 
        int year, month,day, hour_in,minute=60,i; | 
| 18 | 
        int minute_message=1; | 
| 19 | 
        float dir_norm_rad, dif_or_rad,dummy_float; | 
| 20 | 
    char keyword[2000]=""; | 
| 21 | 
        char minute_string[2000]=""; | 
| 22 | 
        char epw_file[200]=""; | 
| 23 | 
        char wea_file[200] =""; | 
| 24 | 
        char city[200] =""; | 
| 25 | 
        char country[200] =""; | 
| 26 | 
        char latitude[200] ="",longitude[200] ="",time_zone[200] ="",elevation[200] =""; | 
| 27 | 
 | 
| 28 | 
        if (argc < 3) | 
| 29 | 
        { | 
| 30 | 
                fprintf(stderr,"epw2wea: FATAL ERROR - wrong number of arguments\n"); | 
| 31 | 
                fprintf(stderr,"start program with: epw2wea <file-name.epw> <file-name.wea>\n"); | 
| 32 | 
                exit(1); | 
| 33 | 
        } | 
| 34 | 
        if (argc >= 3) | 
| 35 | 
        { | 
| 36 | 
                strcpy(epw_file, argv[1]); | 
| 37 | 
                strcpy(wea_file, argv[2]); | 
| 38 | 
                for (i = 3; i < argc; i++) | 
| 39 | 
                if (argv[i][0] == '-' ) | 
| 40 | 
                        switch (argv[i][1]) | 
| 41 | 
                        { | 
| 42 | 
                                case 'h':       /* scaling factor */ | 
| 43 | 
                                        break; | 
| 44 | 
                        } | 
| 45 | 
                else | 
| 46 | 
                { | 
| 47 | 
                        fprintf(stdout,"epw2wea: fatal error - %s bad option for input arguments\n", argv[i]); | 
| 48 | 
                        exit(0); | 
| 49 | 
                } | 
| 50 | 
        } | 
| 51 | 
 | 
| 52 | 
        EPW_FILE=fopen(epw_file, "r"); | 
| 53 | 
        WEA_FILE=fopen(wea_file, "w"); | 
| 54 | 
        fscanf(EPW_FILE,"%[^,]s",keyword); | 
| 55 | 
        if( !strcmp(keyword,"LOCATION") ){ | 
| 56 | 
        fscanf(EPW_FILE,",%[^,]s",city); | 
| 57 | 
        fscanf(EPW_FILE,",%[^,]s",country); | 
| 58 | 
        fscanf(EPW_FILE,",%[^,]s",country); | 
| 59 | 
        sprintf(keyword,"place %s_%s\n",city,country); | 
| 60 | 
        printf("%s",keyword); | 
| 61 | 
        fprintf(WEA_FILE,"%s",keyword); | 
| 62 | 
 | 
| 63 | 
        fscanf(EPW_FILE,",%[^,]s",country); | 
| 64 | 
        fscanf(EPW_FILE,",%[^,]s",country); | 
| 65 | 
        fscanf(EPW_FILE,",%[^,]s",latitude); | 
| 66 | 
        printf("latitude %s\n",latitude); | 
| 67 | 
        fprintf(WEA_FILE,"latitude %s\n",latitude); | 
| 68 | 
        fscanf(EPW_FILE,",%[^,]s",longitude); | 
| 69 | 
 | 
| 70 | 
        printf("longitude %.2f\n",-1.0*atof(longitude)); | 
| 71 | 
        fprintf(WEA_FILE,"longitude %.2f\n",-1.0*atof(longitude)); | 
| 72 | 
        fscanf(EPW_FILE,",%[^,]s",time_zone); | 
| 73 | 
        printf("time_zone %.2f\n",-15.0*atof(time_zone)); | 
| 74 | 
        fprintf(WEA_FILE,"time_zone %.0f\n",-15.0*atoi(time_zone)); | 
| 75 | 
        fscanf(EPW_FILE,",%s[^\n]",elevation); | 
| 76 | 
        printf("site_elevation %s\nweather_data_file_units 1\n",elevation); | 
| 77 | 
        fprintf(WEA_FILE,"site_elevation %s\nweather_data_file_units 1\n",elevation); | 
| 78 | 
 | 
| 79 | 
        fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); | 
| 80 | 
        fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); | 
| 81 | 
        fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); | 
| 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 | 
                 | 
| 87 | 
        /* read in time step interval */ | 
| 88 | 
        fscanf(EPW_FILE,"%[^,]s",keyword); | 
| 89 | 
        fscanf(EPW_FILE,",%[^,]s",keyword); | 
| 90 | 
        fscanf(EPW_FILE,",%[^,]s",minute_string); | 
| 91 | 
        minute=atoi(minute_string); | 
| 92 | 
        if(minute==1)   /* one measurement per hour equals a 60 minute time step */ | 
| 93 | 
                minute=60; | 
| 94 | 
        fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); | 
| 95 | 
     | 
| 96 | 
        while( EOF != fscanf(EPW_FILE,"%d,%d,%d,%d",&year,&month,&day, &hour_in)){ | 
| 97 | 
                 | 
| 98 | 
                fprintf(WEA_FILE,"%d %d %.3f ",month,day,hour_in*1.0-minute*(0.5/60)); | 
| 99 | 
                 | 
| 100 | 
                fscanf(EPW_FILE,",%f",&dummy_float); | 
| 101 | 
                fscanf(EPW_FILE,",%[^,]s",city); | 
| 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 | 
                fscanf(EPW_FILE,",%f",&dummy_float); | 
| 109 | 
                fscanf(EPW_FILE,",%f",&dummy_float); | 
| 110 | 
 | 
| 111 | 
                fscanf(EPW_FILE,",%f,%f",&dir_norm_rad, &dif_or_rad); | 
| 112 | 
                fprintf(WEA_FILE,"%.0f %.0f",dir_norm_rad, dif_or_rad); | 
| 113 | 
 | 
| 114 | 
                fscanf(EPW_FILE,"%*[^\n]");fscanf(EPW_FILE,"%*[\n\r]"); | 
| 115 | 
                fprintf(WEA_FILE,"\n"); | 
| 116 | 
        } | 
| 117 | 
 | 
| 118 | 
}else{ | 
| 119 | 
                fprintf(stderr,"epw2wea: FATAL ERROR - this does not seem to be an epw file \n");exit(1); | 
| 120 | 
} | 
| 121 | 
 | 
| 122 | 
fclose(EPW_FILE); | 
| 123 | 
fclose(WEA_FILE); | 
| 124 | 
return 0; | 
| 125 | 
} | 
| 126 | 
 | 
| 127 | 
 |