1 /*****************************************************************************
3 Module: FGWeatherParse.cpp
4 Author: Christian Mayer
6 Called by: FGMicroWeather
8 -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place - Suite 330, Boston, MA 02111-1307, USA.
24 Further information about the GNU General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 ------------------------------------------------------------------------------
29 Parse the weather that can be downloaded from
31 http://129.13.102.67/out/flight/yymmddhhdata.txt.gz
33 where yy stands for the year, mm for the month, dd for the day and hh for the
35 The columns are explained at
37 http://129.13.102.67/out/flight/kopf.txt
39 and a list of the stations can be found at
41 http://129.13.102.67/out/flight/wmoconv.txt.gz
43 Many thanks to Georg Mueller (Georg.Mueller@imk.fzk.de) of the
45 Institut fuer Meteorologie und Klimaforschung, Universitaet Karlsruhe
47 for makeking such a service aviable.
48 You can also visit his homepage at http://www.wetterzentrale.de
51 ------------------------------------------------------------------------------
52 18.10.1999 Christian Mayer Created
53 14.12.1999 Christian Mayer minor internal changes
54 *****************************************************************************/
56 /****************************************************************************/
58 /****************************************************************************/
59 #include <simgear/constants.h>
61 #include "FGWeatherParse.h"
62 #include "FGWeatherUtils.h"
64 /****************************************************************************/
65 /********************************** CODE ************************************/
66 /****************************************************************************/
68 FGWeatherParse::FGWeatherParse()
72 FGWeatherParse::~FGWeatherParse()
76 void FGWeatherParse::input(const char *file)
82 cerr << "Parsing \"" << file << "\" for weather datas:\n";
88 cerr << "Couldn't find that file!\nExiting...\n";
102 in >> temp.station_number;
107 in >> temp.temperature;
109 in >> temp.airpressure;
110 in >> temp.airpressure_history[0];
111 in >> temp.airpressure_history[1];
112 in >> temp.airpressure_history[2];
113 in >> temp.airpressure_history[3];
115 for (unsigned int i = 0; i < weather_station.size(); i++)
117 if ((weather_station[i].lat == temp.lat) && (weather_station[i].lon == temp.lon))
119 // Two weatherstations are at the same positon
120 // => averageing both
122 // just taking care of the stuff that metters for us
123 weather_station[i].x_wind += temp.x_wind; weather_station[i].x_wind *= 0.5;
124 weather_station[i].y_wind += temp.y_wind; weather_station[i].y_wind *= 0.5;
125 weather_station[i].temperature += temp.temperature; weather_station[i].temperature *= 0.5;
126 weather_station[i].dewpoint += temp.dewpoint; weather_station[i].dewpoint *= 0.5;
127 weather_station[i].airpressure += temp.airpressure; weather_station[i].airpressure *= 0.5;
134 weather_station.push_back( temp );
138 // output a point to ease the waiting
139 if ( ((nr++)%100) == 0 )
143 cerr << "\n" << nr << " stations read\n";
147 FGPhysicalProperties FGWeatherParse::getFGPhysicalProperties(const unsigned int nr) const
149 FGPhysicalProperties ret_val;
152 entry this_entry = weather_station[nr];
154 ret_val.Wind[-1000.0] = FGWindItem(this_entry.x_wind, this_entry.y_wind, 0.0);
155 ret_val.Wind[10000.0] = FGWindItem(this_entry.x_wind, this_entry.y_wind, 0.0);
156 ret_val.Temperature[0.0] = Celsius( this_entry.temperature );
157 ret_val.AirPressure = FGAirPressureItem( this_entry.airpressure * 10.0 ); //*10 to go from 10 hPa to Pa
159 //I have the dewpoint and the temperature, so I can get the vapor pressure
160 ret_val.VaporPressure[-1000.0] = sat_vp( this_entry.dewpoint );
161 ret_val.VaporPressure[10000.0] = sat_vp( this_entry.dewpoint );
163 //I've got no ideas about clouds...
164 //ret_val.Clouds[0] = 0.0;
169 void FGWeatherParse::getPosition(const unsigned int nr, sgVec2 pos) const
171 //set the position of the station
172 sgSetVec2( pos, weather_station[nr].lat * SGD_DEGREES_TO_RADIANS, weather_station[nr].lon * SGD_DEGREES_TO_RADIANS );