1 // navaids.cxx -- navaids 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.
28 #include <simgear/debug/logstream.hxx>
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/math/sg_geodesy.hxx>
32 #include "navlist.hxx"
35 FGNavList *current_navlist;
39 FGNavList::FGNavList( void ) {
44 FGNavList::~FGNavList( void ) {
48 // load the navaids and build the map
49 bool FGNavList::init( SGPath path ) {
51 navaids.erase( navaids.begin(), navaids.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 // read in each line of the file
64 // double min = 100000;
69 while ( in.get(c) && c != '\0' ) {
72 while ( ! in.eof() ) {
77 if ( n.get_type() == '[' ) {
81 /* cout << "id = " << n.get_ident() << endl;
82 cout << " type = " << n.get_type() << endl;
83 cout << " lon = " << n.get_lon() << endl;
84 cout << " lat = " << n.get_lat() << endl;
85 cout << " elev = " << n.get_elev() << endl;
86 cout << " freq = " << n.get_freq() << endl;
87 cout << " range = " << n.get_range() << endl << endl; */
89 navaids[n.get_freq()].push_back(n);
92 /* if ( n.get_type() != 'N' ) {
93 if ( n.get_freq() < min ) {
96 if ( n.get_freq() > max ) {
102 // cout << "min freq = " << min << endl;
103 // cout << "max freq = " << max << endl;
109 // query the database for the specified frequency, lon and lat are in
110 // degrees, elev is in meters
111 bool FGNavList::query( double lon, double lat, double elev, double freq,
114 nav_list_type stations = navaids[(int)(freq*100.0 + 0.5)];
116 nav_list_iterator current = stations.begin();
117 nav_list_iterator last = stations.end();
119 // double az1, az2, s;
120 Point3D aircraft = sgGeodToCart( Point3D(lon, lat, elev) );
123 for ( ; current != last ; ++current ) {
124 // cout << "testing " << current->get_ident() << endl;
125 station = Point3D(current->get_x(), current->get_y(), current->get_z());
127 d = aircraft.distance3Dsquared( station );
129 // cout << " dist = " << sqrt(d)
130 // << " range = " << current->get_range() * SG_NM_TO_METER << endl;
132 // match up to twice the published range so we can model
133 // reduced signal strength
134 if ( d < (2 * current->get_range() * SG_NM_TO_METER
135 * 2 * current->get_range() * SG_NM_TO_METER ) ) {
136 // cout << "matched = " << current->get_ident() << endl;