]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/FGWeatherParse.cpp
The code to find the highest hit below you didn't work quite right when
[flightgear.git] / src / WeatherCM / FGWeatherParse.cpp
1 /*****************************************************************************
2
3  Module:       FGWeatherParse.cpp
4  Author:       Christian Mayer
5  Date started: 28.05.99
6  Called by:    FGMicroWeather
7
8  -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
9
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
13  version.
14
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
18  details.
19
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.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 ------------------------------------------------------------------------------
29 Parse the weather that can be downloaded from 
30
31     http://129.13.102.67/out/flight/yymmddhhdata.txt.gz
32
33 where yy stands for the year, mm for the month, dd for the day and hh for the
34 hour.
35 The columns are explained at
36
37     http://129.13.102.67/out/flight/kopf.txt
38
39 and a list of the stations can be found at
40
41     http://129.13.102.67/out/flight/wmoconv.txt.gz
42
43 Many thanks to Georg Mueller (Georg.Mueller@imk.fzk.de) of the 
44
45     Institut fuer Meteorologie und Klimaforschung, Universitaet Karlsruhe
46
47 for makeking such a service aviable. 
48 You can also visit his homepage at http://www.wetterzentrale.de
49
50 HISTORY
51 ------------------------------------------------------------------------------
52 18.10.1999 Christian Mayer      Created
53 14.12.1999 Christian Mayer      minor internal changes
54 *****************************************************************************/
55
56 /****************************************************************************/
57 /* INCLUDES                                                                 */
58 /****************************************************************************/
59 #include <simgear/constants.h>
60
61 #include "FGWeatherParse.h"
62 #include "FGWeatherUtils.h"
63
64 /****************************************************************************/
65 /********************************** CODE ************************************/
66 /****************************************************************************/
67
68 FGWeatherParse::FGWeatherParse()
69 {
70 }
71
72 FGWeatherParse::~FGWeatherParse()
73 {
74 }
75
76 void FGWeatherParse::input(const char *file)
77 {
78     unsigned int nr = 0;
79
80     sg_gzifstream in;
81
82     cerr << "Parsing \"" << file << "\" for weather datas:\n";
83     
84     in.open( file );
85     
86     if (! in.is_open() )
87     {
88         cerr << "Couldn't find that file!\nExiting...\n";
89         exit(-1);
90     }
91     else
92     {
93         bool skip = false;
94         while ( in )
95         {
96             entry temp;
97             
98             in >> temp.year; 
99             in >> temp.month; 
100             in >> temp.day; 
101             in >> temp.hour; 
102             in >> temp.station_number; 
103             in >> temp.lat; 
104             in >> temp.lon; 
105             in >> temp.x_wind; 
106             in >> temp.y_wind; 
107             in >> temp.temperature; 
108             in >> temp.dewpoint; 
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]; 
114             
115             for (unsigned int i = 0; i < weather_station.size(); i++)
116             {
117                 if ((weather_station[i].lat == temp.lat) && (weather_station[i].lon == temp.lon))
118                 {
119                         // Two weatherstations are at the same positon 
120                         //   => averageing both
121
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;
128
129                         skip = true;
130                 }
131             }
132             
133             if (skip == false)
134                 weather_station.push_back( temp );
135             
136             skip = false;
137             
138             // output a point to ease the waiting
139             if ( ((nr++)%100) == 0 )
140                 cerr << ".";
141         }
142         
143         cerr << "\n" << nr << " stations read\n";
144     }
145 }
146
147 FGPhysicalProperties FGWeatherParse::getFGPhysicalProperties(const unsigned int nr) const
148 {
149     FGPhysicalProperties ret_val;
150
151     //chache this entry
152     entry this_entry = weather_station[nr];
153     
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
158
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 );
162
163     //I've got no ideas about clouds...
164     //ret_val.Clouds[0]              = 0.0;
165     
166     return ret_val;
167 }
168
169 void FGWeatherParse::getPosition(const unsigned int nr, sgVec2 pos) const
170 {
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 ); 
173 }
174