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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <simgear/debug/logstream.hxx>
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/math/sg_geodesy.hxx>
32 #include "fixlist.hxx"
35 FGFixList *current_fixlist;
39 FGFixList::FGFixList( void ) {
44 FGFixList::~FGFixList( void ) {
48 // load the navaids and build the map
49 bool FGFixList::init( SGPath path ) {
51 fixlist.erase( fixlist.begin(), fixlist.end() );
53 sg_gzifstream in( path.str() );
54 if ( !in.is_open() ) {
55 SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
59 // toss the first two lines of the file
63 // read in each remaining line of the file
67 while ( in.get(c) && c != '\0' ) {
70 while ( ! in.eof() ) {
75 if ( fix.get_lat() > 95.0 ) {
79 /* cout << "ident=" << fix.get_ident()
80 << ", lat=" << fix.get_lat()
81 << ", lon=" << fix.get_lon() << endl; */
83 fixlist[fix.get_ident()] = fix;
91 // query the database for the specified fix, lon and lat are in
92 // degrees, elev is in meters
93 bool FGFixList::query( const string& ident, FGFix *fix ) {
94 *fix = fixlist[ident];
95 if ( ! fix->get_ident().empty() ) {
103 // query the database for the specified fix, lon and lat are in
104 // degrees, elev is in meters
105 bool FGFixList::query_and_offset( const string& ident, double lon, double lat,
106 double elev, FGFix *fix, double *heading,
109 *fix = fixlist[ident];
110 if ( fix->get_ident().empty() ) {
115 geo_inverse_wgs_84( elev, lat, lon,
116 fix->get_lat(), fix->get_lon(),
118 // cout << " dist = " << s << endl;
124 const FGFix* FGFixList::findFirstByIdent( const string& ident, bool exact)
126 fix_map_iterator itr;
128 itr = fixlist.find(ident);
130 itr = fixlist.lower_bound(ident);
132 if(itr == fixlist.end()) {
135 return(&(itr->second));