2 // simple.cxx -- a really simplistic class to manage airport ID,
3 // lat, lon of the center of one of it's runways, and
6 // Written by Curtis Olson, started April 1998.
8 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #include <simgear/compiler.h>
34 #include <simgear/debug/logstream.hxx>
40 SG_USING_NAMESPACE(std);
43 // add an entry to the list
44 void FGAirportList::add( const string id, const double longitude,
45 const double latitude, const double elevation,
46 const string name, const bool has_metar )
50 a._longitude = longitude;
51 a._latitude = latitude;
52 a._elevation = elevation;
54 a._has_metar = has_metar;
55 airports_by_id[a._id] = a;
56 airports_array.push_back( &airports_by_id[a._id] );
57 SG_LOG( SG_GENERAL, SG_DEBUG, "Adding " << id << " pos = " << longitude
58 << ", " << latitude << " elev = " << elevation );
62 // search for the specified id
63 FGAirport FGAirportList::search( const string& id) {
64 return airports_by_id[id];
68 // search for the airport nearest the specified position
69 FGAirport FGAirportList::search( double lon_deg, double lat_deg,
72 double min_dist = 360.0;
74 for ( i = 0; i < airports_array.size(); ++i ) {
75 // crude manhatten distance based on lat/lon difference
76 double d = fabs(lon_deg - airports_array[i]->_longitude)
77 + fabs(lat_deg - airports_array[i]->_latitude);
79 if ( !with_metar || (with_metar&&airports_array[i]->_has_metar) ) {
86 return *airports_array[closest];
91 FGAirportList::~FGAirportList( void ) {
95 FGAirportList::size () const
97 return airports_array.size();
100 const FGAirport *FGAirportList::getAirport( int index ) const
102 return airports_array[index];
107 * Mark the specified airport record as not having metar
109 void FGAirportList::no_metar( const string &id ) {
110 airports_by_id[id]._has_metar = false;
115 * Mark the specified airport record as (yes) having metar
117 void FGAirportList::has_metar( const string &id ) {
118 airports_by_id[id]._has_metar = true;