00001
00025 #include "WindSpd.h"
00026
00027 int GetWindSpeedMpsFIXEDFromProps(ChHashTable * proptbl, double fbedhgtm, int month, int day, int hour,
00028 unsigned int row, unsigned int col, double * wspmps) {
00029
00030 static int smonth = 0;
00031 static int sday = 0;
00032 static int shour = 0;
00033 static double swsp = 0.0;
00034 static DblTwoDArray * swsp_tbl = NULL;
00035
00036 KeyVal * entry = NULL;
00037 FILE * fstream = NULL;
00038 char * units = NULL;
00039 int rec;
00040
00041 if ( (smonth != month) || (sday != day) || (shour != hour) ) {
00042
00043 if (swsp_tbl == NULL ) {
00044 *wspmps = swsp;
00045
00046 if ( ChHashTableRetrieve(proptbl, GetFireProp(PROP_WSPDFFILE), (void *)&entry) ) {
00047 ERR_ERROR("Unable to retrieve WIND_SPEED_FIXED_FILE property. \n", ERR_EINVAL);
00048 }
00049
00050 if ( (fstream = fopen((char *) entry->val, "r")) == NULL ) {
00051 ERR_ERROR("Unable to open file containing fixed Wind Speeds. \n", ERR_EIOFAIL);
00052 }
00053
00054 units = GetValFromKeyStringFStreamIO(fstream, WIND_SPD_WSP_KEYWORD_UNITS,
00055 WIND_SPD_SEP_CHARS, WIND_SPD_WSP_COMMENT_CHAR);
00056
00057 if ( (swsp_tbl = GetDblTwoDArrayTableFStreamIO(fstream,
00058 WIND_SPD_SEP_CHARS, WIND_SPD_WSP_COMMENT_CHAR)) == NULL ) {
00059 free(units);
00060 fclose(fstream);
00061 ERR_ERROR("Unable to initialize fixed Wind Speed table. \n", ERR_EFAILED);
00062 }
00063
00064 if ( ConvertWindSpeedUnitsToMps(swsp_tbl, units) ) {
00065 fclose(fstream);
00066 ERR_ERROR("Unable to convert values in fixed Wind Speed table to mps. \n", ERR_EFAILED);
00067 }
00068
00069 free(units);
00070 fclose(fstream);
00071 }
00072
00073 row = DBLTWODARRAY_SIZE_ROW(swsp_tbl);
00074 for(rec = 0; rec < row; rec++) {
00075
00076 if ( DBLTWODARRAY_GET_DATA(swsp_tbl, rec, WIND_SPD_MO_WSP_TBL_INDEX) == month
00077 && DBLTWODARRAY_GET_DATA(swsp_tbl, rec, WIND_SPD_DY_WSP_TBL_INDEX) == day ) {
00078
00079 col = WIND_SPD_HR_TO_WSP_TBL_INDEX(hour);
00080 swsp = DBLTWODARRAY_GET_DATA(swsp_tbl, rec, col);
00081 break;
00082 }
00083 }
00084
00085 smonth = month;
00086 sday = day;
00087 shour = hour;
00088 }
00089
00090 *wspmps = WIND_SPD_REF_HGT_TO_MIDFLAME(swsp, WIND_SPD_RAWS_REF_HGT_METERS, fbedhgtm);
00091
00092 return ERR_SUCCESS;
00093 }
00094
00095 int GetWindSpeedMpsRANDUFromProps(ChHashTable * proptbl, double fbedhgtm, int month, int day, int hour,
00096 unsigned int row, unsigned int col, double * wspmps) {
00097
00098 static int smonth = 0;
00099 static int sday = 0;
00100 static int shour = 0;
00101 static double swsp = 0.0;
00102
00103
00104 row = col = 0;
00105 if ( proptbl == NULL ) {
00106 ERR_ERROR("Simulation properties table not initialized. \n", ERR_EINVAL);
00107 }
00108
00109 if ( (smonth != month) || (sday != day) || (shour != hour) ) {
00110
00111 swsp = randu(WIND_SPD_RANDU_MIN_MPS, WIND_SPD_RANDU_MAX_MPS);
00112
00113 smonth = month;
00114 sday = day;
00115 shour = hour;
00116 }
00117
00118 *wspmps = WIND_SPD_REF_HGT_TO_MIDFLAME(swsp, WIND_SPD_RAWS_REF_HGT_METERS, fbedhgtm);
00119
00120 return ERR_SUCCESS;
00121 }
00122
00123 int GetWindSpeedMpsRANDHFromProps(ChHashTable * proptbl, double fbedhgtm, int month, int day, int hour,
00124 unsigned int row, unsigned int col, double * wspmps) {
00125
00126 static int smonth = 0;
00127 static int sday = 0;
00128 static int shour = 0;
00129 static double swsp = 0.0;
00130 static DblTwoDArray * swsp_tbl = NULL;
00131
00132 KeyVal * entry = NULL;
00133 FILE * fstream = NULL;
00134 char * units = NULL;
00135
00136 if ( (smonth != month) || (sday != day) || (shour != hour) ) {
00137
00138 if (swsp_tbl == NULL ) {
00139 *wspmps = swsp;
00140
00141 if ( ChHashTableRetrieve(proptbl, GetFireProp(PROP_WSPDHFILE), (void *)&entry) ) {
00142 ERR_ERROR("Unable to retrieve WIND_SPEED_HISTORICAL_FILE property. \n", ERR_EINVAL);
00143 }
00144
00145 if ( (fstream = fopen((char *) entry->val, "r")) == NULL ) {
00146 ERR_ERROR("Unable to open file containing historical Wind Speeds. \n", ERR_EIOFAIL);
00147 }
00148
00149 units = GetValFromKeyStringFStreamIO(fstream, WIND_SPD_WSP_KEYWORD_UNITS,
00150 WIND_SPD_SEP_CHARS, WIND_SPD_WSP_COMMENT_CHAR);
00151
00152 if ( (swsp_tbl = GetDblTwoDArrayTableFStreamIO(fstream,
00153 WIND_SPD_SEP_CHARS, WIND_SPD_WSP_COMMENT_CHAR)) == NULL ) {
00154 free(units);
00155 fclose(fstream);
00156 ERR_ERROR("Unable to initialize historical Wind Speed table. \n", ERR_EFAILED);
00157 }
00158
00159 if ( ConvertWindSpeedUnitsToMps(swsp_tbl, units) ) {
00160 fclose(fstream);
00161 ERR_ERROR("Unable to convert values in historical Wind Speed table to mps. \n", ERR_EFAILED);
00162 }
00163
00164 free(units);
00165 fclose(fstream);
00166 }
00167
00168 do {
00169
00170
00171
00172
00173 row = randi(0) % DBLTWODARRAY_SIZE_ROW(swsp_tbl);
00174 col = WIND_SPD_HR_TO_WSP_TBL_INDEX(hour);
00175
00176 swsp = DBLTWODARRAY_GET_DATA(swsp_tbl, row, col);
00177 } while( swsp == WIND_SPD_WSP_NO_DATA_VALUE );
00178
00179 smonth = month;
00180 sday = day;
00181 shour = hour;
00182 }
00183
00184 *wspmps = WIND_SPD_REF_HGT_TO_MIDFLAME(swsp, WIND_SPD_RAWS_REF_HGT_METERS, fbedhgtm);
00185
00186 return ERR_SUCCESS;
00187 }
00188
00189 int GetWindSpeedMpsSPATIALFromProps(ChHashTable * proptbl, double fbedhgtm, int month, int day, int hour,
00190 unsigned int row, unsigned int col, double * wspmps) {
00191
00192 month = day = hour = row = col = fbedhgtm = *wspmps = 0;
00193 if ( proptbl == NULL ) {
00194 ERR_ERROR("Simulation properties table not initialized. \n", ERR_EINVAL);
00195 }
00196
00197 ERR_ERROR("SPATIAL option for WIND_SPEED_TYPE not yet implemented. \n", ERR_EUNIMPL);
00198 }
00199
00200 double ConvertWindSpeedAtRefHgtToArbitraryHgt(double wsmps, double refhgtm, double hgtm) {
00201 return wsmps / log(((refhgtm + (0.36*hgtm)) / (0.13*hgtm)));
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 int ConvertWindSpeedUnitsToMps(DblTwoDArray * wsp_tbl, const char * units) {
00225 int rec, hr;
00226 double wsp2cvrt;
00227
00228
00229 if ( wsp_tbl == NULL || units == NULL ) {
00230 ERR_ERROR("Arguments to convert values in WindSpeed table are invalid. \n", ERR_EINVAL);
00231 }
00232
00233 if ( strcmp(units, WIND_SPD_WSP_KEYWORD_MILEPHR) == 0 ) {
00234
00235 for(rec = 0; rec < DBLTWODARRAY_SIZE_ROW(wsp_tbl); rec++) {
00236 for(hr = 0; hr < 24; hr++) {
00237 if ( (wsp2cvrt = DBLTWODARRAY_GET_DATA(wsp_tbl, rec, WIND_SPD_HR_TO_WSP_TBL_INDEX(hr))) !=
00238 WIND_SPD_WSP_NO_DATA_VALUE ) {
00239 DBLTWODARRAY_SET_DATA(wsp_tbl, rec, WIND_SPD_HR_TO_WSP_TBL_INDEX(hr),
00240 UNITS_MILEPHR_TO_MPSEC(wsp2cvrt));
00241 }
00242 }
00243 }
00244 }
00245 else if ( strcmp(units, WIND_SPD_WSP_KEYWORD_KMPHR) == 0 ) {
00246
00247 for(rec = 0; rec < DBLTWODARRAY_SIZE_ROW(wsp_tbl); rec++) {
00248 for(hr = 0; hr < 24; hr++) {
00249 if ( (wsp2cvrt = DBLTWODARRAY_GET_DATA(wsp_tbl, rec, WIND_SPD_HR_TO_WSP_TBL_INDEX(hr))) !=
00250 WIND_SPD_WSP_NO_DATA_VALUE ) {
00251 DBLTWODARRAY_SET_DATA(wsp_tbl, rec, WIND_SPD_HR_TO_WSP_TBL_INDEX(hr),
00252 UNITS_KMPHR_TO_MPSEC(wsp2cvrt));
00253 }
00254 }
00255 }
00256 }
00257 else {
00258 ERR_ERROR("Unable to determine units in Wind Speed table, values not converted. \n", ERR_EDOM);
00259 }
00260
00261 return ERR_SUCCESS;
00262 }
00263
00264