HISTORY
------------------------------------------------------------------------------
18.10.1999 Christian Mayer Created
+14.12.1999 Christian Mayer minor internal changes
*****************************************************************************/
/****************************************************************************/
/* INCLUDES */
/****************************************************************************/
-#include "Include/fg_constants.h"
+#include <simgear/constants.h>
#include "FGWeatherParse.h"
#include "FGWeatherUtils.h"
{
unsigned int nr = 0;
- fg_gzifstream in;
+ sg_gzifstream in;
cerr << "Parsing \"" << file << "\" for weather datas:\n";
in.open( file );
-
- while ( in )
+
+ if (! in.is_open() )
{
- entry temp;
-
- in >> temp.year;
- in >> temp.month;
- in >> temp.day;
- in >> temp.hour;
- in >> temp.station_number;
- in >> temp.lat;
- in >> temp.lon;
- in >> temp.x_wind;
- in >> temp.y_wind;
- in >> temp.temperature;
- in >> temp.dewpoint;
- in >> temp.airpressure;
- in >> temp.airpressure_history[0];
- in >> temp.airpressure_history[1];
- in >> temp.airpressure_history[2];
- in >> temp.airpressure_history[3];
-
- weather_station.push_back( temp );
-
- // output a point to ease the waiting
- if ( ((nr++)%100) == 0 )
- cerr << ".";
+ cerr << "Couldn't find that file!\nExiting...\n";
+ exit(-1);
+ }
+ else
+ {
+ bool skip = false;
+ while ( in )
+ {
+ entry temp;
+
+ in >> temp.year;
+ in >> temp.month;
+ in >> temp.day;
+ in >> temp.hour;
+ in >> temp.station_number;
+ in >> temp.lat;
+ in >> temp.lon;
+ in >> temp.x_wind;
+ in >> temp.y_wind;
+ in >> temp.temperature;
+ in >> temp.dewpoint;
+ in >> temp.airpressure;
+ in >> temp.airpressure_history[0];
+ in >> temp.airpressure_history[1];
+ in >> temp.airpressure_history[2];
+ in >> temp.airpressure_history[3];
+
+ for (unsigned int i = 0; i < weather_station.size(); i++)
+ {
+ if ((weather_station[i].lat == temp.lat) && (weather_station[i].lon == temp.lon))
+ {
+ // Two weatherstations are at the same positon
+ // => averageing both
+
+ // just taking care of the stuff that metters for us
+ weather_station[i].x_wind += temp.x_wind; weather_station[i].x_wind *= 0.5;
+ weather_station[i].y_wind += temp.y_wind; weather_station[i].y_wind *= 0.5;
+ weather_station[i].temperature += temp.temperature; weather_station[i].temperature *= 0.5;
+ weather_station[i].dewpoint += temp.dewpoint; weather_station[i].dewpoint *= 0.5;
+ weather_station[i].airpressure += temp.airpressure; weather_station[i].airpressure *= 0.5;
+
+ skip = true;
+ }
+ }
+
+ if (skip == false)
+ weather_station.push_back( temp );
+
+ skip = false;
+
+ // output a point to ease the waiting
+ if ( ((nr++)%100) == 0 )
+ cerr << ".";
+ }
+
+ cerr << "\n" << nr << " stations read\n";
}
-
- cerr << "\n" << nr << " stations read\n";
}
-FGPhysicalProperties2D FGWeatherParse::getFGPhysicalProperties2D(const unsigned int nr) const
+FGPhysicalProperties FGWeatherParse::getFGPhysicalProperties(const unsigned int nr) const
{
- FGPhysicalProperties2D ret_val;
+ FGPhysicalProperties ret_val;
//chache this entry
entry this_entry = weather_station[nr];
- //set the position of the station
- sgSetVec2( ret_val.p, this_entry.lat * DEG_TO_RAD, this_entry.lon * DEG_TO_RAD );
-
ret_val.Wind[-1000.0] = FGWindItem(this_entry.x_wind, this_entry.y_wind, 0.0);
ret_val.Wind[10000.0] = FGWindItem(this_entry.x_wind, this_entry.y_wind, 0.0);
ret_val.Temperature[0.0] = Celsius( this_entry.temperature );
return ret_val;
}
-
-
+void FGWeatherParse::getPosition(const unsigned int nr, sgVec2 pos) const
+{
+ //set the position of the station
+ sgSetVec2( pos, weather_station[nr].lat * SGD_DEGREES_TO_RADIANS, weather_station[nr].lon * SGD_DEGREES_TO_RADIANS );
+}