]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/nav.hxx
Various Irix compiler tweaks.
[flightgear.git] / src / Navaids / nav.hxx
index df7c63a4c9138a3f5f0fa7ef2486cebac694cb85..5a521130472641e933b7536ee05bf0c051612625 100644 (file)
 
 #include <simgear/compiler.h>
 #include <simgear/math/sg_geodesy.hxx>
-#include <simgear/misc/fgstream.hxx>
+#include <simgear/misc/sgstream.hxx>
 #include <simgear/magvar/magvar.hxx>
+#include <simgear/timing/sg_time.hxx>
 
-#ifdef FG_HAVE_STD_INCLUDES
+#ifdef SG_HAVE_STD_INCLUDES
 #  include <istream>
-#elif defined( FG_HAVE_NATIVE_SGI_COMPILERS )
+#elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )
 #  include <iostream.h>
 #elif defined( __BORLANDC__ )
 #  include <iostream>
@@ -41,8 +42,8 @@
 #  include <istream.h>
 #endif
 
-#if ! defined( FG_HAVE_NATIVE_SGI_COMPILERS )
-FG_USING_STD(istream);
+#if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )
+SG_USING_STD(istream);
 #endif
 
 
@@ -56,7 +57,12 @@ class FGNav {
     int range;
     bool has_dme;
     string ident;              // to avoid a core dump with corrupt data
-    int offset;                        // offset from true north (negative = W)
+    double magvar;             // magvar from true north (negative = W)
+
+    // for failure modeling
+    string trans_ident;                // transmitted ident
+    bool nav_failed;           // nav failed?
+    bool dme_failed;           // dme failed?
 
 public:
 
@@ -74,7 +80,8 @@ public:
     inline int get_range() const { return range; }
     inline bool get_has_dme() const { return has_dme; }
     inline const char *get_ident() { return ident.c_str(); }
-    inline int get_offset () const { return offset; }
+    inline string get_trans_ident() { return trans_ident; }
+    inline double get_magvar () const { return magvar; }
 
     /* inline void set_type( char t ) { type = t; }
     inline void set_lon( double l ) { lon = l; }
@@ -93,11 +100,24 @@ inline istream&
 operator >> ( istream& in, FGNav& n )
 {
     double f;
-    char c /* , offset_dir */ ;
-    string offset_s;
+    char c /* , magvar_dir */ ;
+    string magvar_s;
+
+    static bool first_time = true;
+    static double julian_date = 0;
+    static const double MJD0    = 2415020.0;
+    if ( first_time ) {
+       julian_date = sgTimeCurrentMJD( 0 ) + MJD0;
+       first_time = false;
+    }
+
+    in >> n.type;
     
-    in >> n.type >> n.lat >> n.lon >> n.elev >> f >> n.range 
-       >> c >> n.ident >> offset_s;
+    if ( n.type == '[' )
+      return in >> skipeol;
+
+    in >> n.lat >> n.lon >> n.elev >> f >> n.range 
+       >> c >> n.ident >> magvar_s;
 
     n.freq = (int)(f*100.0 + 0.5);
     if ( c == 'Y' ) {
@@ -106,37 +126,51 @@ operator >> ( istream& in, FGNav& n )
        n.has_dme = false;
     }
 
-    // Calculate the offset from true north.
-    // cout << "Calculating offset for navaid " << n.ident << endl;
-    if (offset_s == "XXX") {
+    // Calculate the magvar from true north.
+    // cout << "Calculating magvar for navaid " << n.ident << endl;
+    if (magvar_s == "XXX") {
        // default to mag var as of 1990-01-01 (Julian 2447892.5)
-       double var = sgGetMagVar(n.lon * DEG_TO_RAD, n.lat * DEG_TO_RAD,
-                                n.elev * FEET_TO_METER,
-                                2447892.5) * RAD_TO_DEG;
+       // cout << "lat = " << n.lat << " lon = " << n.lon << " elev = " 
+       //      << n.elev << " JD = " 
+       //      << julian_date << endl;
+       n.magvar = sgGetMagVar( n.lon * SGD_DEGREES_TO_RADIANS,
+                                n.lat * SGD_DEGREES_TO_RADIANS,
+                                n.elev * SG_FEET_TO_METER,
+                                julian_date )
+            * SGD_RADIANS_TO_DEGREES;
        // cout << "Default variation at " << n.lon << ',' << n.lat
        //      << " is " << var << endl;
+#if 0
+       // I don't know what this is for - CLO 1 Feb 2001
        if (var - int(var) >= 0.5)
-           n.offset = int(var) + 1;
+           n.magvar = int(var) + 1;
        else if (var - int(var) <= -0.5)
-           n.offset = int(var) - 1;
+           n.magvar = int(var) - 1;
        else
-           n.offset = int(var);
-       // cout << "Defaulted to offset of " << n.offset << endl;
+           n.magvar = int(var);
+#endif
+       // cout << "Defaulted to magvar of " << n.magvar << endl;
     } else {
        char direction;
-       sscanf(offset_s.c_str(), "%d%c", &(n.offset), &direction);
+       int var;
+       sscanf(magvar_s.c_str(), "%d%c", &var, &direction);
+       n.magvar = var;
        if (direction == 'W')
-           n.offset = 0 - n.offset;
-       // cout << "Explicit offset of " << n.offset << endl;
+           n.magvar = -n.magvar;
+       // cout << "Explicit magvar of " << n.magvar << endl;
     }
+    // cout << n.ident << " " << n.magvar << endl;
 
     // generate cartesian coordinates
-    Point3D geod( n.lon * DEG_TO_RAD, n.lat * DEG_TO_RAD, n.elev );
+    Point3D geod( n.lon * SGD_DEGREES_TO_RADIANS, n.lat * SGD_DEGREES_TO_RADIANS, n.elev );
     Point3D cart = sgGeodToCart( geod );
     n.x = cart.x();
     n.y = cart.y();
     n.z = cart.z();
 
+    n.trans_ident = n.ident;
+    n.nav_failed = n.dme_failed = false;
+
     return in >> skipeol;
 }