X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNavaids%2Fnav.hxx;h=074670651ba936840e54ab5cd161581317871512;hb=bd3c57beee2c368b8947b35e627a4a82c0d9b637;hp=84bd8132ee28f67cf3c9bf18d44c9c9bdfcf36b7;hpb=cbaf01548180f2dcaafd04676c4832b7297abc27;p=flightgear.git diff --git a/src/Navaids/nav.hxx b/src/Navaids/nav.hxx index 84bd8132e..074670651 100644 --- a/src/Navaids/nav.hxx +++ b/src/Navaids/nav.hxx @@ -28,45 +28,48 @@ #include #include -#include +#include #include +#include -#ifdef FG_HAVE_STD_INCLUDES +#ifdef SG_HAVE_STD_INCLUDES # include -#elif defined( FG_HAVE_NATIVE_SGI_COMPILERS ) -# include -#elif defined( __BORLANDC__ ) +#elif defined( __BORLANDC__ ) || (__APPLE__) # include #else # include #endif -#if ! defined( FG_HAVE_NATIVE_SGI_COMPILERS ) -FG_USING_STD(istream); -#endif +SG_USING_STD(istream); class FGNav { char type; double lon, lat; - double elev; + double elev_ft; double x, y, z; int freq; int range; bool has_dme; string ident; // to avoid a core dump with corrupt data double magvar; // magvar from true north (negative = W) + string name; + + // for failure modeling + string trans_ident; // transmitted ident + bool nav_failed; // nav failed? + bool dme_failed; // dme failed? public: - inline FGNav(void) {} + inline FGNav(void); inline ~FGNav(void) {} inline char get_type() const { return type; } inline double get_lon() const { return lon; } inline double get_lat() const { return lat; } - inline double get_elev() const { return elev; } + inline double get_elev_ft() const { return elev_ft; } inline double get_x() const { return x; } inline double get_y() const { return y; } inline double get_z() const { return z; } @@ -74,31 +77,62 @@ 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 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; } - inline void set_lat( double l ) { lat = l; } - inline void set_elev( double e ) { elev = e; } - inline void set_freq( int f ) { freq = f; } - inline void set_range( int r ) { range = r; } - inline void set_dme( bool b ) { dme = b; } - inline void set_ident( char *i ) { strncpy( ident, i, 5 ); } */ + inline string get_name () { return name; } friend istream& operator>> ( istream&, FGNav& ); }; +inline +FGNav::FGNav(void) : + type(0), + lon(0.0), lat(0.0), + elev_ft(0.0), + x(0.0), y(0.0), z(0.0), + freq(0), + range(0), + has_dme(false), + ident(""), + magvar(0.0), + name(""), + trans_ident(""), + nav_failed(false), + dme_failed(false) +{ +} + + inline istream& operator >> ( istream& in, FGNav& n ) { double f; 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,0) + MJD0; + first_time = false; + } + + in >> n.type; - in >> n.type >> n.lat >> n.lon >> n.elev >> f >> n.range + if ( n.type == '[' ) + return in >> skipeol; + + in >> n.lat >> n.lon >> n.elev_ft >> f >> n.range >> c >> n.ident >> magvar_s; + getline(in,n.name); + // Remove the space before the name + if ( n.name.substr(0,1) == " " ) { + n.name = n.name.erase(0,1); + } + n.freq = (int)(f*100.0 + 0.5); if ( c == 'Y' ) { n.has_dme = true; @@ -110,9 +144,14 @@ operator >> ( istream& in, FGNav& n ) // cout << "Calculating magvar for navaid " << n.ident << endl; if (magvar_s == "XXX") { // default to mag var as of 1990-01-01 (Julian 2447892.5) - n.magvar = -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_ft = " + // << n.elev_ft << " JD = " + // << julian_date << endl; + n.magvar = sgGetMagVar( n.lon * SGD_DEGREES_TO_RADIANS, + n.lat * SGD_DEGREES_TO_RADIANS, + n.elev_ft * SG_FEET_TO_METER, + julian_date ) + * SGD_RADIANS_TO_DEGREES; // cout << "Default variation at " << n.lon << ',' << n.lat // << " is " << var << endl; #if 0 @@ -130,20 +169,23 @@ operator >> ( istream& in, FGNav& n ) int var; sscanf(magvar_s.c_str(), "%d%c", &var, &direction); n.magvar = var; - if (direction == 'E') - n.magvar = 0 - n.magvar; + if (direction == 'W') + n.magvar = -n.magvar; // cout << "Explicit magvar of " << n.magvar << endl; } - cout << n.ident << " " << 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_ft * SG_FEET_TO_METER ); Point3D cart = sgGeodToCart( geod ); n.x = cart.x(); n.y = cart.y(); n.z = cart.z(); - return in >> skipeol; + n.trans_ident = n.ident; + n.nav_failed = n.dme_failed = false; + + return in; }