Main Page   Compound List   File List   Compound Members   File Members  

WindAzimuth.c

Go to the documentation of this file.
00001 
00025 #include "WindAzimuth.h"
00026 
00027 int GetWindAzimuthFIXEDFromProps(ChHashTable * proptbl, int month, int day, int hour,
00028                                                 unsigned int row, unsigned int col, double * waz)   {
00029     /* static variables used to store state across function calls */
00030     static int smonth               = 0;
00031     static int sday                 = 0;
00032     static int shour                = 0;
00033     static double swaz              = 0.0;
00034     static DblTwoDArray * swaz_tbl  = NULL;
00035     /* stack variables */
00036     KeyVal * entry                  = NULL;             /* key/val instances from table */
00037     FILE * fstream                  = NULL;             /* file stream */
00038     int rec;
00039 
00040     if ( (smonth != month) || (sday != day) || (shour != hour) )    {
00041         /* new wind azimuth needed */
00042         if (swaz_tbl == NULL )  {
00043             *waz = swaz;        
00044             /* table of fixed values only needs to be initialized once */
00045             if ( ChHashTableRetrieve(proptbl, GetFireProp(PROP_WAZFFILE), (void *)&entry) ) {
00046                 ERR_ERROR("Unable to retrieve WIND_AZIMUTH_FIXED_FILE property. \n", ERR_EINVAL);
00047                 }
00048             /* open fixed azimuth file */
00049             if ( (fstream = fopen((char *) entry->val, "r")) == NULL )  {
00050                 ERR_ERROR("Unable to open file containing fixed Wind Azimuths. \n", ERR_EIOFAIL);
00051                 }
00052             /* create the table of values */
00053             if ( (swaz_tbl = GetDblTwoDArrayTableFStreamIO(fstream, 
00054                     WIND_AZIMUTH_SEP_CHARS, WIND_AZIMUTH_WAZ_COMMENT_CHAR)) == NULL )   {
00055                 fclose(fstream);
00056                 ERR_ERROR("Unable to initialize fixed Wind Azimuth table. \n", ERR_EFAILED);
00057                 }
00058             fclose(fstream);
00059             }
00060         /* find record in table */
00061         row = DBLTWODARRAY_SIZE_ROW(swaz_tbl);
00062         for(rec = 0; rec < row; rec++)  {
00063             /* find matching month and day */
00064             if ( DBLTWODARRAY_GET_DATA(swaz_tbl, rec, WIND_AZIMUTH_MO_WAZ_TBL_INDEX) == month 
00065                  && DBLTWODARRAY_GET_DATA(swaz_tbl, rec, WIND_AZIMUTH_DY_WAZ_TBL_INDEX) == day )    {
00066                 /* retrieve waz on that month and day */
00067                 col = WIND_AZIMUTH_HR_TO_WAZ_TBL_INDEX(hour);
00068                 swaz = DBLTWODARRAY_GET_DATA(swaz_tbl, rec, col);
00069                 break;
00070                 }
00071             }
00072         /* set {month, day, hour} for future calls */
00073         smonth = month;
00074         sday = day;
00075         shour = hour;
00076         }
00077 
00078     *waz = swaz;
00079 
00080     return ERR_SUCCESS; 
00081     }
00082 
00083 int GetWindAzimuthRANDUFromProps(ChHashTable * proptbl, int month, int day, int hour,
00084                                                 unsigned int row, unsigned int col, double * waz)   {
00085     /* static variables used to store state across function calls */
00086     static int smonth               = 0;
00087     static int sday                 = 0;
00088     static int shour                = 0;
00089     static double swaz              = 0.0;
00090     
00091     /* WA: stop warnings from unused vars */
00092     row = col = 0;
00093     if ( proptbl == NULL )  {
00094         ERR_ERROR("Simulation properties table not initialized. \n", ERR_EINVAL);
00095         }
00096 
00097     if ( (smonth != month) || (sday != day) || (shour != hour) )    {   
00098         /* new wind azimuth needed */
00099         swaz = randu(WIND_AZIMUTH_RANDU_MIN_AZ, WIND_AZIMUTH_RANDU_MAX_AZ);
00100         /* set {month, day, hour} for future calls */
00101         smonth = month;
00102         sday = day;
00103         shour = hour;       
00104         }
00105 
00106     *waz = swaz;
00107 
00108     return ERR_SUCCESS;
00109     }
00110 
00111 int GetWindAzimuthRANDHFromProps(ChHashTable * proptbl, int month, int day, int hour,
00112                                                 unsigned int row, unsigned int col, double * waz)   {
00113     /* static variables used to store state across function calls */
00114     static int smonth               = 0;
00115     static int sday                 = 0;
00116     static int shour                = 0;
00117     static double swaz              = 0.0;
00118     static DblTwoDArray * swaz_tbl  = NULL;
00119     /* stack variables */
00120     KeyVal * entry                  = NULL;             /* key/val instances from table */
00121     FILE * fstream                  = NULL;             /* file stream */
00122 
00123     if ( (smonth != month) || (sday != day) || (shour != hour) )    {
00124         /* new wind azimuth needed */
00125         if (swaz_tbl == NULL )  {
00126             *waz = swaz;        
00127             /* table of fixed values only needs to be initialized once */
00128             if ( ChHashTableRetrieve(proptbl, GetFireProp(PROP_WAZHFILE), (void *)&entry) ) {
00129                 ERR_ERROR("Unable to retrieve WIND_AZIMUTH_HISTORICAL_FILE property. \n", ERR_EINVAL);
00130                 }
00131             /* open fixed azimuth file */
00132             if ( (fstream = fopen((char *) entry->val, "r")) == NULL )  {
00133                 ERR_ERROR("Unable to open file containing historical Wind Azimuths. \n", ERR_EIOFAIL);
00134                 }
00135             /* create the table of values */
00136             if ( (swaz_tbl = GetDblTwoDArrayTableFStreamIO(fstream, 
00137                     WIND_AZIMUTH_SEP_CHARS, WIND_AZIMUTH_WAZ_COMMENT_CHAR)) == NULL )   {
00138                 fclose(fstream);
00139                 ERR_ERROR("Unable to initialize historical Wind Azimuth table. \n", ERR_EFAILED);
00140                 }
00141             fclose(fstream);                    
00142             }
00143         /* find wind azimuth from random record in table that is not NO DATA */
00144         do  {
00145             /* retrieve a record at random from table within range 0 to num_recs */
00146             /* convert u.r.n. range 0-max to range a-b = a + (((b-a)*rand)/randmax) */
00147             /*row = 0 + (((DBLTWODARRAY_SIZE_ROW(swaz_tbl) - 0) * randi(0)) / LONG_MAX);*/
00148             /* appears to be flawed bc always returns 0 */
00149             row = randi(0) % DBLTWODARRAY_SIZE_ROW(swaz_tbl);
00150             col = WIND_AZIMUTH_HR_TO_WAZ_TBL_INDEX(hour);
00151             /* retrieve waz from random recno using current hour */
00152             swaz = DBLTWODARRAY_GET_DATA(swaz_tbl, row, col);       
00153             } while( swaz == WIND_AZIMUTH_WAZ_NO_DATA_VALUE );
00154         /* set {month, day, hour} for future calls */
00155         smonth = month;
00156         sday = day;
00157         shour = hour;
00158         }
00159 
00160     *waz = swaz;
00161 
00162     return ERR_SUCCESS;         
00163     }
00164 
00165 int GetWindAzimuthSPATIALFromProps(ChHashTable * proptbl, int month, int day, int hour, 
00166                                                 unsigned int row, unsigned int col, double * waz)   {
00167     /* WA: stop warnings from unused vars */
00168     month = day = hour = row = col = *waz =0;
00169     if ( proptbl == NULL )  {
00170         ERR_ERROR("Simulation properties table not initialized. \n", ERR_EINVAL);
00171         }
00172     
00173     ERR_ERROR("SPATIAL option for WIND_AZIMUTH_TYPE not yet implemented. \n", ERR_EUNIMPL);
00174     }
00175  
00176 /* end of WindAzimuth.c */

Generated at Fri Jun 22 00:46:51 2001 for HFire by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000