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.
28 #include <simgear/debug/logstream.hxx>
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/math/sg_geodesy.hxx>
32 #include "fixlist.hxx"
37 FGFixList::FGFixList( void ) {
42 FGFixList::~FGFixList( void ) {
46 // load the navaids and build the map
47 bool FGFixList::init( SGPath path ) {
48 fixlist.erase( fixlist.begin(), fixlist.end() );
50 sg_gzifstream in( path.str() );
51 if ( !in.is_open() ) {
52 SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
56 // toss the first two lines of the file
60 // read in each remaining line of the file
64 while ( in.get(c) && c != '\0' ) {
67 while ( ! in.eof() ) {
72 if ( fix.get_lat() > 95.0 ) {
76 /* cout << "ident=" << fix.get_ident()
77 << ", lat=" << fix.get_lat()
78 << ", lon=" << fix.get_lon() << endl; */
80 fixlist.insert(pair<string, FGFix>(fix.get_ident(), fix));
87 // query the database for the specified fix, lon and lat are in
88 // degrees, elev is in meters
89 bool FGFixList::query( const string& ident, FGFix *fix ) {
90 fix_map_const_iterator it = fixlist.find(ident);
91 if ( it != fixlist.end() ) {
100 // query the database for the specified fix, lon and lat are in
101 // degrees, elev is in meters
102 bool FGFixList::query_and_offset( const string& ident, double lon, double lat,
103 double elev, FGFix *fix, double *heading,
106 pair<fix_map_const_iterator, fix_map_const_iterator> range = fixlist.equal_range(ident);
108 if (range.first == range.second) {
113 for (fix_map_const_iterator current = range.first; current != range.second; ++current) {
115 geo_inverse_wgs_84( elev, lat, lon,
116 current->second.get_lat(), current->second.get_lon(),
118 // cout << " dist = " << s << endl;
119 if (min_s < 0 || s < min_s) {
123 *fix = current->second;
130 const FGFix* FGFixList::findFirstByIdent( const string& ident, bool exact)
132 fix_map_iterator itr;
134 itr = fixlist.find(ident);
136 itr = fixlist.lower_bound(ident);
138 if(itr == fixlist.end()) {
141 return(&(itr->second));