1 // fixlist.cxx -- fix list management class
3 // Written by Curtis Olson, started April 2000.
5 // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
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.
24 #include <simgear/debug/logstream.hxx>
25 #include <simgear/misc/fgstream.hxx>
26 #include <simgear/math/sg_geodesy.hxx>
28 #include "fixlist.hxx"
31 FGFixList *current_fixlist;
35 FGFixList::FGFixList( void ) {
40 FGFixList::~FGFixList( void ) {
44 // load the navaids and build the map
45 bool FGFixList::init( FGPath path ) {
48 fixlist.erase( fixlist.begin(), fixlist.end() );
50 fg_gzifstream in( path.str() );
51 if ( !in.is_open() ) {
52 FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path.str() );
56 // read in each line of the file
64 while ( in.get(c) && c != '\0' && fix.get_ident() != "[End]" ) {
67 if ( fix.get_ident() != "[End]" ) {
68 fixlist[fix.get_ident()] = fix;
75 while ( ! in.eof() && fix.get_ident() != "[End]" ) {
77 /* cout << "id = " << n.get_ident() << endl;
78 cout << " type = " << n.get_type() << endl;
79 cout << " lon = " << n.get_lon() << endl;
80 cout << " lat = " << n.get_lat() << endl;
81 cout << " elev = " << n.get_elev() << endl;
82 cout << " freq = " << n.get_freq() << endl;
83 cout << " range = " << n.get_range() << endl; */
84 if ( fix.get_ident() != "[End]" ) {
85 fixlist[fix.get_ident()] = fix;
96 // query the database for the specified frequency, lon and lat are in
97 // degrees, elev is in meters
98 bool FGFixList::query( const string& ident, double lon, double lat, double elev,
99 FGFix *fix, double *heading, double *dist )
101 *fix = fixlist[ident];
102 if ( fix->get_ident() == "" ) {
107 geo_inverse_wgs_84( elev, lat, lon,
108 fix->get_lat(), fix->get_lon(),
110 // cout << " dist = " << s << endl;