1 // nav.hxx -- vor/dme/ndb class
3 // Written by Curtis Olson, started April 2000.
5 // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <simgear/compiler.h>
30 #include <simgear/math/sg_geodesy.hxx>
31 #include <simgear/misc/sgstream.hxx>
32 #include <simgear/magvar/magvar.hxx>
33 #include <simgear/timing/sg_time.hxx>
35 #ifdef SG_HAVE_STD_INCLUDES
37 #elif defined( __BORLANDC__ ) || (__APPLE__)
43 SG_USING_STD(istream);
55 string ident; // to avoid a core dump with corrupt data
56 double magvar; // magvar from true north (negative = W)
58 // for failure modeling
59 string trans_ident; // transmitted ident
60 bool nav_failed; // nav failed?
61 bool dme_failed; // dme failed?
66 inline ~FGNav(void) {}
68 inline char get_type() const { return type; }
69 inline double get_lon() const { return lon; }
70 inline double get_lat() const { return lat; }
71 inline double get_elev() const { return elev; }
72 inline double get_x() const { return x; }
73 inline double get_y() const { return y; }
74 inline double get_z() const { return z; }
75 inline int get_freq() const { return freq; }
76 inline int get_range() const { return range; }
77 inline bool get_has_dme() const { return has_dme; }
78 inline const char *get_ident() { return ident.c_str(); }
79 inline string get_trans_ident() { return trans_ident; }
80 inline double get_magvar () const { return magvar; }
82 /* inline void set_type( char t ) { type = t; }
83 inline void set_lon( double l ) { lon = l; }
84 inline void set_lat( double l ) { lat = l; }
85 inline void set_elev( double e ) { elev = e; }
86 inline void set_freq( int f ) { freq = f; }
87 inline void set_range( int r ) { range = r; }
88 inline void set_dme( bool b ) { dme = b; }
89 inline void set_ident( char *i ) { strncpy( ident, i, 5 ); } */
91 friend istream& operator>> ( istream&, FGNav& );
100 x(0.0), y(0.0), z(0.0),
114 operator >> ( istream& in, FGNav& n )
117 char c /* , magvar_dir */ ;
120 static bool first_time = true;
121 static double julian_date = 0;
122 static const double MJD0 = 2415020.0;
124 julian_date = sgTimeCurrentMJD(0,0) + MJD0;
131 return in >> skipeol;
133 in >> n.lat >> n.lon >> n.elev >> f >> n.range
134 >> c >> n.ident >> magvar_s;
136 n.freq = (int)(f*100.0 + 0.5);
143 // Calculate the magvar from true north.
144 // cout << "Calculating magvar for navaid " << n.ident << endl;
145 if (magvar_s == "XXX") {
146 // default to mag var as of 1990-01-01 (Julian 2447892.5)
147 // cout << "lat = " << n.lat << " lon = " << n.lon << " elev = "
148 // << n.elev << " JD = "
149 // << julian_date << endl;
150 n.magvar = sgGetMagVar( n.lon * SGD_DEGREES_TO_RADIANS,
151 n.lat * SGD_DEGREES_TO_RADIANS,
152 n.elev * SG_FEET_TO_METER,
154 * SGD_RADIANS_TO_DEGREES;
155 // cout << "Default variation at " << n.lon << ',' << n.lat
156 // << " is " << var << endl;
158 // I don't know what this is for - CLO 1 Feb 2001
159 if (var - int(var) >= 0.5)
160 n.magvar = int(var) + 1;
161 else if (var - int(var) <= -0.5)
162 n.magvar = int(var) - 1;
166 // cout << "Defaulted to magvar of " << n.magvar << endl;
170 sscanf(magvar_s.c_str(), "%d%c", &var, &direction);
172 if (direction == 'W')
173 n.magvar = -n.magvar;
174 // cout << "Explicit magvar of " << n.magvar << endl;
176 // cout << n.ident << " " << n.magvar << endl;
178 // generate cartesian coordinates
179 Point3D geod( n.lon * SGD_DEGREES_TO_RADIANS, n.lat * SGD_DEGREES_TO_RADIANS, n.elev );
180 Point3D cart = sgGeodToCart( geod );
185 n.trans_ident = n.ident;
186 n.nav_failed = n.dme_failed = false;
188 return in >> skipeol;
192 #endif // _FG_NAV_HXX