]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/ilslist.cxx
Added ils loader.
[flightgear.git] / src / Navaids / ilslist.cxx
1 // ilslist.cxx -- ils management class
2 //
3 // Written by Curtis Olson, started April 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson - curt@flightgear.org
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #include <simgear/debug/logstream.hxx>
25 #include <simgear/misc/fgstream.hxx>
26 #include <simgear/math/fg_geodesy.hxx>
27
28 #include "ilslist.hxx"
29
30
31 // Constructor
32 FGILSList::FGILSList( void ) {
33 }
34
35
36 // Destructor
37 FGILSList::~FGILSList( void ) {
38 }
39
40
41 // load the navaids and build the map
42 bool FGILSList::init( FGPath path ) {
43     FGILS ils;
44
45     ilslist.erase( ilslist.begin(), ilslist.end() );
46
47     fg_gzifstream in( path.str() );
48     if ( !in.is_open() ) {
49         FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path.str() );
50         exit(-1);
51     }
52
53     // read in each line of the file
54
55     in >> skipeol;
56     in >> skipcomment;
57
58 #ifdef __MWERKS__
59
60     char c = 0;
61     while ( in.get(c) && c != '\0' && n.get_ilstype() != '[' ) {
62         in.putback(c);
63         in >> ils;
64         if ( ils.get_type() != '[' ) {
65             ilslist[ils.get_locfreq()].push_back(ils);
66         }
67         in >> skipcomment;
68     }
69
70 #else
71
72     while ( ! in.eof() && ils.get_ilstype() != '[' ) {
73         in >> ils;
74         /* cout << "id = " << n.get_ident() << endl;
75         cout << " type = " << n.get_type() << endl;
76         cout << " lon = " << n.get_lon() << endl;
77         cout << " lat = " << n.get_lat() << endl;
78         cout << " elev = " << n.get_elev() << endl;
79         cout << " freq = " << n.get_freq() << endl;
80         cout << " range = " << n.get_range() << endl; */
81         if ( ils.get_ilstype() != '[' ) {
82             ilslist[ils.get_locfreq()].push_back(ils);
83         }
84         in >> skipcomment;
85     }
86
87 #endif
88
89     return true;
90 }
91
92
93 // query the database for the specified frequency, lon and lat are in
94 // degrees, elev is in meters
95 bool FGILSList::query( double lon, double lat, double elev, double freq,
96                        FGILS *ils, double *heading, double *dist )
97 {
98     ils_list_type stations = ilslist[(int)(freq*100.0)];
99
100     ils_list_iterator current = stations.begin();
101     ils_list_iterator last = stations.end();
102
103     double az1, az2, s;
104     for ( ; current != last ; ++current ) {
105         // cout << "testing " << current->get_ident() << endl;
106         geo_inverse_wgs_84( elev, lat, lon, 
107                             current->get_loclat(), current->get_loclon(),
108                             &az1, &az2, &s );
109         // cout << "  dist = " << s << endl;
110         if ( s < ( FG_ILS_DEFAULT_RANGE * NM_TO_METER ) ) {
111             *ils = *current;
112             *heading = az2;
113             *dist = s;
114             return true;
115         }
116     }
117
118     return false;
119 }