1 // groundlist.cxx -- ATC Ground data management class
3 // Written by David Luff, started November 2002.
4 // Based on navlist.cxx by Curtis Olson, started April 2000.
6 // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <simgear/debug/logstream.hxx>
28 #include <simgear/misc/sgstream.hxx>
29 #include <simgear/math/sg_geodesy.hxx>
30 #include <simgear/math/sg_random.h>
32 #include "groundlist.hxx"
34 FGGroundList *current_groundlist;
37 FGGroundList::FGGroundList( void ) {
42 FGGroundList::~FGGroundList( void ) {
46 // load the navaids and build the map
47 bool FGGroundList::init( SGPath path ) {
49 groundlist.erase( groundlist.begin(), groundlist.end() );
51 sg_gzifstream in( path.str() );
52 if ( !in.is_open() ) {
53 SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
57 // read in each line of the file
63 while ( in.get(c) && c != '\0' ) {
71 if ( g.get_type() == '[' ) {
75 //cout << "id = " << t.GetIdent() << endl;
76 //cout << " type = " << t.get_type() << endl;
77 //cout << " lon = " << t.get_lon() << endl;
78 //cout << " lat = " << t.get_lat() << endl;
79 //cout << " elev = " << t.get_elev() << endl;
80 //cout << " freq = " << t.get_freq() << endl;
81 //cout << " range = " << t.get_range() << endl;
83 groundlist[g.get_freq()].push_back(g);
91 // query the database for the specified frequency, lon and lat are in
92 // degrees, elev is in meters
93 bool FGGroundList::query( double lon, double lat, double elev, double freq,
96 lon *= SGD_DEGREES_TO_RADIANS;
97 lat *= SGD_DEGREES_TO_RADIANS;
98 //cout << "lon = " << lon << '\n';
99 //cout << "lat = " << lat << '\n';
100 //cout << "elev = " << elev << '\n';
101 //cout << "freq = " << freq << '\n';
103 ground_list_type stations = groundlist[(int)(freq*100.0 + 0.5)];
105 ground_list_iterator current = stations.begin();
106 ground_list_iterator last = stations.end();
108 // double az1, az2, s;
109 Point3D aircraft = sgGeodToCart( Point3D(lon, lat, elev) );
112 for ( ; current != last ; ++current ) {
113 //cout << "testing " << current->GetIdent() << endl;
114 station = Point3D(current->get_x(), current->get_y(), current->get_z());
115 //cout << "aircraft = " << aircraft << endl;
116 //cout << "station = " << station << endl;
118 d = aircraft.distance3Dsquared( station );
120 //cout << " dist = " << sqrt(d)
121 // << " range = " << current->get_range() * SG_NM_TO_METER << endl;
123 // match up to twice the published range so we can model
124 // reduced signal strength
125 if ( d < (2 * current->get_range() * SG_NM_TO_METER
126 * 2 * current->get_range() * SG_NM_TO_METER ) ) {
127 //cout << "matched = " << current->GetIdent() << endl;