1 // ilslist.cxx -- ils 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/fg_geodesy.hxx>
28 #include "ilslist.hxx"
31 FGILSList *current_ilslist;
35 FGILSList::FGILSList( void ) {
40 FGILSList::~FGILSList( void ) {
44 // load the navaids and build the map
45 bool FGILSList::init( FGPath path ) {
48 ilslist.erase( ilslist.begin(), ilslist.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' && n.get_ilstype() != '[' ) {
67 if ( ils.get_type() != '[' ) {
68 ilslist[ils.get_locfreq()].push_back(ils);
75 double min = 1000000.0;
78 while ( ! in.eof() && ils.get_ilstype() != '[' ) {
80 /* cout << "id = " << n.get_ident() << endl;
81 cout << " type = " << n.get_type() << endl;
82 cout << " lon = " << n.get_lon() << endl;
83 cout << " lat = " << n.get_lat() << endl;
84 cout << " elev = " << n.get_elev() << endl;
85 cout << " freq = " << n.get_freq() << endl;
86 cout << " range = " << n.get_range() << endl; */
87 if ( ils.get_ilstype() != '[' ) {
88 ilslist[ils.get_locfreq()].push_back(ils);
92 if ( ils.get_locfreq() < min ) {
93 min = ils.get_locfreq();
95 if ( ils.get_locfreq() > max ) {
96 max = ils.get_locfreq();
100 // cout << "min freq = " << min << endl;
101 // 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 FGILSList::query( double lon, double lat, double elev, double freq,
114 ils_list_type stations = ilslist[(int)(freq*100.0 + 0.5)];
116 ils_list_iterator current = stations.begin();
117 ils_list_iterator last = stations.end();
119 // double az1, az2, s;
120 Point3D aircraft = fgGeodToCart( Point3D(lon, lat, elev) );
123 for ( ; current != last ; ++current ) {
124 // cout << " testing " << current->get_locident() << endl;
125 station = Point3D(current->get_x(), current->get_y(), current->get_z());
126 // cout << " aircraft = " << aircraft << " station = " << station
129 d = aircraft.distance3Dsquared( station );
130 // cout << " distance = " << d << " ("
131 // << FG_ILS_DEFAULT_RANGE * NM_TO_METER
132 // * FG_ILS_DEFAULT_RANGE * NM_TO_METER
135 // cout << " dist = " << s << endl;
136 if ( d < (FG_ILS_DEFAULT_RANGE * NM_TO_METER
137 * FG_ILS_DEFAULT_RANGE * NM_TO_METER) ) {