]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/navlist.cxx
Various Irix compiler tweaks.
[flightgear.git] / src / Navaids / navlist.cxx
index a23bef3a552474ca8f31b2cb8d4d9097115df5c0..0bfd42a69189ccc20646444761844814dfd74b2a 100644 (file)
 // $Id$
 
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <simgear/debug/logstream.hxx>
-#include <simgear/misc/fgstream.hxx>
-#include <simgear/math/fg_geodesy.hxx>
+#include <simgear/misc/sgstream.hxx>
+#include <simgear/math/sg_geodesy.hxx>
 
 #include "navlist.hxx"
 
 
+FGNavList *current_navlist;
+
+
 // Constructor
-FGNavaids::FGNavaids( void ) {
+FGNavList::FGNavList( void ) {
 }
 
 
 // Destructor
-FGNavaids::~FGNavaids( void ) {
+FGNavList::~FGNavList( void ) {
 }
 
 
 // load the navaids and build the map
-bool FGNavaids::init( FGPath path ) {
-    FGNavaid n;
+bool FGNavList::init( SGPath path ) {
+    FGNav n;
 
     navaids.erase( navaids.begin(), navaids.end() );
 
-    fg_gzifstream in( path.str() );
+    sg_gzifstream in( path.str() );
     if ( !in.is_open() ) {
-        FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path.str() );
+        SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
         exit(-1);
     }
 
@@ -69,6 +76,9 @@ bool FGNavaids::init( FGPath path ) {
 
 #else
 
+    double min = 100000;
+    double max = 0;
+
     while ( ! in.eof() && n.get_type() != '[' ) {
         in >> n;
        /* cout << "id = " << n.get_ident() << endl;
@@ -82,8 +92,20 @@ bool FGNavaids::init( FGPath path ) {
            navaids[n.get_freq()].push_back(n);
        }
         in >> skipcomment;
+
+       if ( n.get_type() != 'N' ) {
+           if ( n.get_freq() < min ) {
+               min = n.get_freq();
+           }
+           if ( n.get_freq() > max ) {
+               max = n.get_freq();
+           }
+       }
     }
 
+    // cout << "min freq = " << min << endl;
+    // cout << "max freq = " << max << endl;
+
 #endif
 
     return true;
@@ -92,25 +114,33 @@ bool FGNavaids::init( FGPath path ) {
 
 // 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 )
+bool FGNavList::query( double lon, double lat, double elev, double freq,
+                      FGNav *n )
 {
-    nav_list_type stations = navaids[(int)(freq*100.0)];
+    nav_list_type stations = navaids[(int)(freq*100.0 + 0.5)];
 
     nav_list_iterator current = stations.begin();
     nav_list_iterator last = stations.end();
 
-    double az1, az2, s;
+    // double az1, az2, s;
+    Point3D aircraft = sgGeodToCart( Point3D(lon, lat, elev) );
+    Point3D station;
+    double d;
     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 ) ) {
+       station = Point3D(current->get_x(), current->get_y(), current->get_z());
+
+       d = aircraft.distance3Dsquared( station );
+
+       // cout << "  dist = " << sqrt(d)
+       //      << "  range = " << current->get_range() * SG_NM_TO_METER << endl;
+
+       // match up to twice the published range so we can model
+       // reduced signal strength
+       if ( d < (2 * current->get_range() * SG_NM_TO_METER 
+                 * 2 * current->get_range() * SG_NM_TO_METER ) ) {
+           // cout << "matched = " << current->get_ident() << endl;
            *n = *current;
-           *heading = az2;
-           *dist = s;
            return true;
        }
     }