]> git.mxchange.org Git - flightgear.git/commitdiff
Basic query routine now working.
authorcurt <curt>
Fri, 21 Apr 2000 05:26:24 +0000 (05:26 +0000)
committercurt <curt>
Fri, 21 Apr 2000 05:26:24 +0000 (05:26 +0000)
src/Navaids/Makefile.am
src/Navaids/navaid.hxx
src/Navaids/navaids.cxx
src/Navaids/navaids.hxx
src/Navaids/testnavs.cxx

index 11d7f38bab047156f5e4f6da7c35fc96ea723cfc..58b602bacfa04d5e709ca253c954dffd7491cadb 100644 (file)
@@ -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
index 66adeaf9b2fe0a22e4b87de6f1d49330bbe6175e..b6a110ab7478df836c62f02b52cb96b21c939dbe 100644 (file)
@@ -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);
index 7bb679b5b1032a17b6a747930e22f39da59d5210..e67b52c69e7f0b98c7c391e807afe15d5c497455 100644 (file)
 // $Id$
 
 
-#include <simgear/misc/fgstream.hxx>
 #include <simgear/debug/logstream.hxx>
+#include <simgear/misc/fgstream.hxx>
+#include <simgear/math/fg_geodesy.hxx>
 
 #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;
+}
index 17596d4db539005da3f15ce6a7c99a31c1617965..f537ce66dd25143769c97d0c7b7c4d55e74fa8f7 100644 (file)
@@ -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<int> > 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<int> > 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);
 };
 
 
index a54da99d020d3da897f7ed898f8885e8dc949ecc..f988f53125e97042ad6520cacfd9507257b3e3bd 100644 (file)
@@ -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;
+    }
 }