From ce86c8322288976bd7bddead6ac2f99665590485 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 21 Apr 2000 05:26:24 +0000 Subject: [PATCH] Basic query routine now working. --- src/Navaids/Makefile.am | 2 +- src/Navaids/navaid.hxx | 12 ++++++------ src/Navaids/navaids.cxx | 40 +++++++++++++++++++++++++++++++++++----- src/Navaids/navaids.hxx | 26 ++++++++++++++------------ src/Navaids/testnavs.cxx | 15 +++++++++++++-- 5 files changed, 69 insertions(+), 26 deletions(-) diff --git a/src/Navaids/Makefile.am b/src/Navaids/Makefile.am index 11d7f38ba..58b602bac 100644 --- a/src/Navaids/Makefile.am +++ b/src/Navaids/Makefile.am @@ -5,6 +5,6 @@ noinst_PROGRAMS = testnavs libNavAids_a_SOURCES = navaid.hxx navaids.hxx navaids.cxx testnavs_SOURCES = testnavs.cxx -testnavs_LDADD = libNavAids.a -lsgdebug -lsgmisc -lz +testnavs_LDADD = libNavAids.a -lsgdebug -lsgmath -lsgmisc -lz INCLUDES += -I$(top_builddir) -I$(top_builddir)/src diff --git a/src/Navaids/navaid.hxx b/src/Navaids/navaid.hxx index 66adeaf9b..b6a110ab7 100644 --- a/src/Navaids/navaid.hxx +++ b/src/Navaids/navaid.hxx @@ -43,7 +43,7 @@ FG_USING_STD(istream); #endif -class FGNavAid { +class FGNavaid { char type; double lon, lat; @@ -55,8 +55,8 @@ class FGNavAid { public: - inline FGNavAid(void) {} - inline ~FGNavAid(void) {} + inline FGNavaid(void) {} + inline ~FGNavaid(void) {} inline char get_type() const { return type; } inline double get_lon() const { return lon; } @@ -76,16 +76,16 @@ public: inline void set_dme( bool b ) { dme = b; } inline void set_ident( char *i ) { strncpy( ident, i, 5 ); } - friend istream& operator>> ( istream&, FGNavAid& ); + friend istream& operator>> ( istream&, FGNavaid& ); }; inline istream& -operator >> ( istream& in, FGNavAid& n ) +operator >> ( istream& in, FGNavaid& n ) { double f; char c; - in >> n.type >> n.lon >> n.lat >> n.elev >> f >> n.range + in >> n.type >> n.lat >> n.lon >> n.elev >> f >> n.range >> c >> n.ident; n.freq = (int)(f * 100.0); diff --git a/src/Navaids/navaids.cxx b/src/Navaids/navaids.cxx index 7bb679b5b..e67b52c69 100644 --- a/src/Navaids/navaids.cxx +++ b/src/Navaids/navaids.cxx @@ -21,25 +21,26 @@ // $Id$ -#include #include +#include +#include #include "navaids.hxx" // Constructor -FGNavAids::FGNavAids( void ) { +FGNavaids::FGNavaids( void ) { } // Destructor -FGNavAids::~FGNavAids( void ) { +FGNavaids::~FGNavaids( void ) { } // load the navaids and build the map -bool FGNavAids::init( FGPath path ) { - FGNavAid n; +bool FGNavaids::init( FGPath path ) { + FGNavaid n; navaids.erase( navaids.begin(), navaids.end() ); @@ -87,3 +88,32 @@ bool FGNavAids::init( FGPath path ) { return true; } + + +// query the database for the specified frequency, lon and lat are in +// degrees, elev is in meters +bool FGNavaids::query( double lon, double lat, double elev, double freq, + FGNavaid *n, double *heading, double *dist ) +{ + nav_list_type stations = navaids[(int)(freq*100.0)]; + + nav_list_iterator current = stations.begin(); + nav_list_iterator last = stations.end(); + + double az1, az2, s; + for ( ; current != last ; ++current ) { + // cout << "testing " << current->get_ident() << endl; + geo_inverse_wgs_84( elev, lat, lon, + current->get_lat(), current->get_lon(), + &az1, &az2, &s ); + // cout << " dist = " << s << endl; + if ( s < ( current->get_range() * NM_TO_METER ) ) { + *n = *current; + *heading = az2; + *dist = s; + return true; + } + } + + return false; +} diff --git a/src/Navaids/navaids.hxx b/src/Navaids/navaids.hxx index 17596d4db..f537ce66d 100644 --- a/src/Navaids/navaids.hxx +++ b/src/Navaids/navaids.hxx @@ -37,29 +37,31 @@ FG_USING_STD(map); FG_USING_STD(vector); -// convenience types -typedef vector < FGNavAid > nav_list_type; -typedef nav_list_type::iterator nav_list_iterator; -typedef nav_list_type::const_iterator nav_list_const_iterator; +class FGNavaids { -typedef map < int, nav_list_type, less > nav_map_type; -typedef nav_map_type::iterator nav_map_iterator; -typedef nav_map_type::const_iterator nav_map_const_iterator; + // convenience types + typedef vector < FGNavaid > nav_list_type; + typedef nav_list_type::iterator nav_list_iterator; + typedef nav_list_type::const_iterator nav_list_const_iterator; -class FGNavAids { + typedef map < int, nav_list_type, less > nav_map_type; + typedef nav_map_type::iterator nav_map_iterator; + typedef nav_map_type::const_iterator nav_map_const_iterator; nav_map_type navaids; public: - FGNavAids(); - ~FGNavAids(); + FGNavaids(); + ~FGNavaids(); // load the navaids and build the map bool init( FGPath path ); - // query the database for the specified frequency - FGNavAid query( double lon, double lat, int freq ); + // query the database for the specified frequency, lon and lat are + // in degrees, elev is in meters + bool query( double lon, double lat, double elev, double freq, + FGNavaid *n, double *heading, double *dist); }; diff --git a/src/Navaids/testnavs.cxx b/src/Navaids/testnavs.cxx index a54da99d0..f988f5312 100644 --- a/src/Navaids/testnavs.cxx +++ b/src/Navaids/testnavs.cxx @@ -3,9 +3,20 @@ #include "navaids.hxx" int main() { - FGNavAids navs; + FGNavaids navs; - FGPath p( "/home/curt/FlightGear/Navaids/default.nav.gz" ); + FGPath p( "/export/data2/curt/FlightGear/Navaids/default.nav" ); navs.init( p ); + + FGNavaid n; + double heading, dist; + if ( navs.query( -93.2, 45.14, 3000, 117.30, + &n, &heading, &dist) ) { + cout << "Found a station in range" << endl; + cout << " id = " << n.get_ident() << endl; + cout << " heading = " << heading << " dist = " << dist << endl; + } else { + cout << "not picking anything up. :-(" << endl; + } }