1 // fixlist.cxx -- fix list management class
3 // Written by Curtis Olson, started April 2000.
5 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <simgear/debug/logstream.hxx>
31 #include <simgear/misc/sgstream.hxx>
32 #include <simgear/math/sg_geodesy.hxx>
34 #include "fixlist.hxx"
35 #include "Airports/simple.hxx"
41 FGFixList::FGFixList( void ) {
46 FGFixList::~FGFixList( void ) {
50 // load the navaids and build the map
51 bool FGFixList::init( SGPath path ) {
52 fixlist.erase( fixlist.begin(), fixlist.end() );
54 sg_gzifstream in( path.str() );
55 if ( !in.is_open() ) {
56 SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
60 // toss the first two lines of the file
64 // read in each remaining line of the file
65 while ( ! in.eof() ) {
69 if ( fix.get_lat() > 95.0 ) {
73 /* cout << "ident=" << fix.get_ident()
74 << ", lat=" << fix.get_lat()
75 << ", lon=" << fix.get_lon() << endl; */
77 fixlist.insert(pair<string, FGFix>(fix.get_ident(), fix));
84 // query the database for the specified fix, lon and lat are in
85 // degrees, elev is in meters
86 bool FGFixList::query( const string& ident, FGFix *fix ) {
87 fix_map_const_iterator it = fixlist.find(ident);
88 if ( it != fixlist.end() ) {
97 // query the database for the specified fix, lon and lat are in
98 // degrees, elev is in meters
99 bool FGFixList::query_and_offset( const string& ident, double lon, double lat,
100 double elev, FGFix *fix, double *heading,
103 pair<fix_map_const_iterator, fix_map_const_iterator> range = fixlist.equal_range(ident);
105 if (range.first == range.second) {
110 for (fix_map_const_iterator current = range.first; current != range.second; ++current) {
112 geo_inverse_wgs_84( elev, lat, lon,
113 current->second.get_lat(), current->second.get_lon(),
115 // cout << " dist = " << s << endl;
116 if (min_s < 0 || s < min_s) {
120 *fix = current->second;
127 const FGFix* FGFixList::search(const string& ident)
129 fix_map_iterator itr = fixlist.find(ident);
130 if (itr == fixlist.end()) {
137 class orderingFunctor
140 orderingFunctor(FGIdentOrdering* aOrder) :
144 bool operator()(const fix_map_type::value_type& aA, const std::string& aB) const
146 return mOrdering->compare(aA.first,aB);
150 FGIdentOrdering* mOrdering;
153 const FGFix* FGFixList::findFirstByIdent( const string& ident, FGIdentOrdering* aOrder)
155 fix_map_iterator itr;
157 orderingFunctor func(aOrder);
158 itr = std::lower_bound(fixlist.begin(),fixlist.end(), ident, func);
160 itr = fixlist.lower_bound(ident);
163 if (itr == fixlist.end()) {