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/sg_geodesy.hxx>
28 #include "mkrbeacons.hxx"
29 #include "ilslist.hxx"
32 FGILSList *current_ilslist;
36 FGILSList::FGILSList( void ) {
41 FGILSList::~FGILSList( void ) {
45 // load the navaids and build the map
46 bool FGILSList::init( FGPath path ) {
49 ilslist.erase( ilslist.begin(), ilslist.end() );
51 fg_gzifstream in( path.str() );
52 if ( !in.is_open() ) {
53 FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path.str() );
57 // read in each line of the file
65 while ( in.get(c) && c != '\0' && ils.get_ilstype() != '[' ) {
68 if ( ils.get_ilstype() != '[' ) {
69 ilslist[ils.get_locfreq()].push_back(ils);
76 double min = 1000000.0;
79 while ( ! in.eof() && ils.get_ilstype() != '[' ) {
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; */
88 if ( ils.get_ilstype() != '[' ) {
89 ilslist[ils.get_locfreq()].push_back(ils);
93 if ( ils.get_locfreq() < min ) {
94 min = ils.get_locfreq();
96 if ( ils.get_locfreq() > max ) {
97 max = ils.get_locfreq();
100 // update the marker beacon list
101 if ( fabs(ils.get_omlon()) > FG_EPSILON ||
102 fabs(ils.get_omlat()) > FG_EPSILON ) {
103 current_beacons->add( ils.get_omlon(), ils.get_omlat(),
104 ils.get_gselev(), FGBeacon::OUTER );
106 if ( fabs(ils.get_mmlon()) > FG_EPSILON ||
107 fabs(ils.get_mmlat()) > FG_EPSILON ) {
108 current_beacons->add( ils.get_mmlon(), ils.get_mmlat(),
109 ils.get_gselev(), FGBeacon::MIDDLE );
111 if ( fabs(ils.get_imlon()) > FG_EPSILON ||
112 fabs(ils.get_imlat()) > FG_EPSILON ) {
113 current_beacons->add( ils.get_imlon(), ils.get_imlat(),
114 ils.get_gselev(), FGBeacon::INNER );
118 // cout << "min freq = " << min << endl;
119 // cout << "max freq = " << max << endl;
127 // query the database for the specified frequency, lon and lat are in
128 // degrees, elev is in meters
129 bool FGILSList::query( double lon, double lat, double elev, double freq,
132 ils_list_type stations = ilslist[(int)(freq*100.0 + 0.5)];
134 ils_list_iterator current = stations.begin();
135 ils_list_iterator last = stations.end();
137 // double az1, az2, s;
138 Point3D aircraft = sgGeodToCart( Point3D(lon, lat, elev) );
141 for ( ; current != last ; ++current ) {
142 // cout << " testing " << current->get_locident() << endl;
143 station = Point3D(current->get_x(),
146 // cout << " aircraft = " << aircraft << " station = " << station
149 d = aircraft.distance3Dsquared( station );
150 // cout << " distance = " << d << " ("
151 // << FG_ILS_DEFAULT_RANGE * NM_TO_METER
152 // * FG_ILS_DEFAULT_RANGE * NM_TO_METER
155 // cout << " dist = " << s << endl;
157 // match up to twice the published range so we can model
158 // reduced signal strength
159 if ( d < (2* FG_ILS_DEFAULT_RANGE * NM_TO_METER
160 * 2 * FG_ILS_DEFAULT_RANGE * NM_TO_METER) ) {