]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/fixlist.cxx
Patch from Norman Vine:
[flightgear.git] / src / Navaids / fixlist.cxx
1 // fixlist.cxx -- fix list 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 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <simgear/debug/logstream.hxx>
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/math/sg_geodesy.hxx>
31
32 #include "fixlist.hxx"
33
34
35 FGFixList *current_fixlist;
36
37
38 // Constructor
39 FGFixList::FGFixList( void ) {
40 }
41
42
43 // Destructor
44 FGFixList::~FGFixList( void ) {
45 }
46
47
48 // load the navaids and build the map
49 bool FGFixList::init( SGPath path ) {
50
51     fixlist.erase( fixlist.begin(), fixlist.end() );
52
53     sg_gzifstream in( path.str() );
54     if ( !in.is_open() ) {
55         SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
56         exit(-1);
57     }
58
59     // read in each line of the file
60
61     in >> skipeol;
62     in >> skipcomment;
63
64 #ifdef __MWERKS__
65     char c = 0;
66     while ( in.get(c) && c != '\0' ) {
67         in.putback(c);
68 #else   
69     while ( ! in.eof() ) {
70 #endif
71
72         FGFix fix;
73         in >> fix;
74         if ( fix.get_ident() == "[End]" ) {
75             break;
76         }
77
78         /* cout << "ident=" << fix.get_ident()
79              << ", lat=" << fix.get_lat()
80              << ", lon=" << fix.get_lon() << endl; */
81
82         fixlist[fix.get_ident()] = fix;
83         in >> skipcomment;
84     }
85     
86     return true;
87 }
88
89
90 // query the database for the specified frequency, lon and lat are in
91 // degrees, elev is in meters
92 bool FGFixList::query( const string& ident, double lon, double lat, double elev,
93                        FGFix *fix, double *heading, double *dist )
94 {
95     *fix = fixlist[ident];
96     if ( fix->get_ident().empty() ) {
97         return false;
98     }
99
100     double az1, az2, s;
101     geo_inverse_wgs_84( elev, lat, lon, 
102                         fix->get_lat(), fix->get_lon(),
103                         &az1, &az2, &s );
104     // cout << "  dist = " << s << endl;
105     *heading = az2;
106     *dist = s;
107     return true;
108 }