]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/ils.hxx
Updated to match changes in radiostack.[ch]xx
[flightgear.git] / src / Navaids / ils.hxx
1 // ils.hxx -- navaid class
2 //
3 // Written by Curtis Olson, started April 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson - curt@flightgear.org
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifndef _FG_ILS_HXX
25 #define _FG_ILS_HXX
26
27
28 #include <simgear/compiler.h>
29 #include <simgear/math/sg_geodesy.hxx>
30 #include <simgear/misc/sgstream.hxx>
31
32 #ifdef SG_HAVE_STD_INCLUDES
33 #  include <istream>
34 #elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )
35 #  include <iostream.h>
36 #elif defined( __BORLANDC__ ) || (__APPLE__)
37 #  include <iostream>
38 #else
39 #  include <istream.h>
40 #endif
41
42 #if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )
43 SG_USING_STD(istream);
44 #endif
45
46
47 #define FG_ILS_DEFAULT_RANGE 18
48
49 class FGILS {
50
51     char ilstype;
52     char ilstypename[6];
53     char aptcode[5];
54     char rwyno[4];
55     int  locfreq;
56     char locident[5];           // official ident
57     double locheading;
58     double loclat;
59     double loclon;
60     double x, y, z;
61     bool has_gs;
62     double gselev;
63     double gsangle;
64     double gslat;
65     double gslon;
66     double gs_x, gs_y, gs_z;
67     bool has_dme;
68     double dmelat;
69     double dmelon;
70     double dme_x, dme_y, dme_z;
71     double omlat;
72     double omlon;
73     double mmlat;
74     double mmlon;
75     double imlat;
76     double imlon;
77
78     // for failure modeling
79     string trans_ident;         // transmitted ident
80     bool loc_failed;            // localizer failed?
81     bool gs_failed;             // glide slope failed?
82     bool dme_failed;            // dme failed?
83
84 public:
85
86     inline FGILS(void);
87     inline ~FGILS(void) {}
88
89     inline char get_ilstype() const { return ilstype; }
90     inline char *get_ilstypename() { return ilstypename; }
91     inline char *get_aptcode() { return aptcode; }
92     inline char *get_rwyno() { return rwyno; }
93     inline int get_locfreq() const { return locfreq; }
94     inline char *get_locident() { return locident; }
95     inline string get_trans_ident() { return trans_ident; }
96     inline double get_locheading() const { return locheading; }
97     inline double get_loclat() const { return loclat; }
98     inline double get_loclon() const { return loclon; }
99     inline double get_x() const { return x; }
100     inline double get_y() const { return y; }
101     inline double get_z() const { return z; }
102     inline bool get_has_gs() const { return has_gs; }
103     inline double get_gselev() const { return gselev; }
104     inline double get_gsangle() const { return gsangle; }
105     inline double get_gslat() const { return gslat; }
106     inline double get_gslon() const { return gslon; }
107     inline double get_gs_x() const { return gs_x; }
108     inline double get_gs_y() const { return gs_y; }
109     inline double get_gs_z() const { return gs_z; }
110     inline bool get_has_dme() const { return has_dme; }
111     inline double get_dmelat() const { return dmelat; }
112     inline double get_dmelon() const { return dmelon; }
113     inline double get_dme_x() const { return dme_x; }
114     inline double get_dme_y() const { return dme_y; }
115     inline double get_dme_z() const { return dme_z; }
116     inline double get_omlat() const { return omlat; }
117     inline double get_omlon() const { return omlon; }
118     inline double get_mmlat() const { return mmlat; }
119     inline double get_mmlon() const { return mmlon; }
120     inline double get_imlat() const { return imlat; }
121     inline double get_imlon() const { return imlon; }
122
123     friend istream& operator>> ( istream&, FGILS& );
124 };
125
126
127 inline
128 FGILS::FGILS(void)
129   : ilstype(0),
130     locfreq(0),
131     locheading(0.0),
132     loclat(0.0),
133     loclon(0.0),
134     x(0.0), y(0.0), z(0.0),
135     has_gs(false),
136     gselev(0.0),
137     gsangle(0.0),
138     gslat(0.0),
139     gslon(0.0),
140     gs_x(0.0), gs_y(0.0), gs_z(0.0),
141     has_dme(false),
142     dmelat(0.0),
143     dmelon(0.0),
144     dme_x(0.0), dme_y(0.0), dme_z(0.0),
145     omlat(0.0),
146     omlon(0.0),
147     mmlat(0.0),
148     mmlon(0.0),
149     imlat(0.0),
150     imlon(0.0),
151     trans_ident(""),
152     loc_failed(false),
153     gs_failed(false),
154     dme_failed(false)
155 {
156     ilstypename[0] = '\0';
157     aptcode[0] = '\0';
158     rwyno[0] = '\0';
159     locident[0] = '\0';
160 }
161
162     
163 inline istream&
164 operator >> ( istream& in, FGILS& i )
165 {
166     double f;
167     in >> i.ilstype;
168     
169     if ( i.ilstype == '[' )
170           return in;
171
172     in >> i.ilstypename >> i.aptcode >> i.rwyno 
173        >> f >> i.locident >> i.locheading >> i.loclat >> i.loclon
174        >> i.gselev >> i.gsangle >> i.gslat >> i.gslon
175        >> i.dmelat >> i.dmelon
176        >> i.omlat >> i.omlon
177        >> i.mmlat >> i.mmlon
178        >> i.imlat >> i.imlon;
179         
180
181     i.locfreq = (int)(f*100.0 + 0.5);
182
183     // generate cartesian coordinates
184     Point3D geod, cart;
185
186     geod = Point3D( i.loclon * SGD_DEGREES_TO_RADIANS, i.loclat * SGD_DEGREES_TO_RADIANS, i.gselev );
187     cart = sgGeodToCart( geod );
188     i.x = cart.x();
189     i.y = cart.y();
190     i.z = cart.z();
191
192     if ( i.gslon < SG_EPSILON && i.gslat < SG_EPSILON ) {
193         i.has_gs = false;
194     } else {
195         i.has_gs = true;
196
197         geod = Point3D( i.gslon * SGD_DEGREES_TO_RADIANS, i.gslat * SGD_DEGREES_TO_RADIANS, i.gselev );
198         cart = sgGeodToCart( geod );
199         i.gs_x = cart.x();
200         i.gs_y = cart.y();
201         i.gs_z = cart.z();
202         // cout << "gs = " << cart << endl;
203     }
204
205     if ( i.dmelon < SG_EPSILON && i.dmelat < SG_EPSILON ) {
206         i.has_dme = false;
207     } else {
208         i.has_dme = true;
209
210         geod = Point3D( i.dmelon * SGD_DEGREES_TO_RADIANS, i.dmelat * SGD_DEGREES_TO_RADIANS, i.gselev);
211         cart = sgGeodToCart( geod );
212         i.dme_x = cart.x();
213         i.dme_y = cart.y();
214         i.dme_z = cart.z();
215         // cout << "dme = " << cart << endl;
216     }
217
218     i.trans_ident = "I";
219     i.trans_ident += i.locident;
220     i.loc_failed = i.gs_failed = i.dme_failed = false;
221    
222     // return in >> skipeol;
223     return in;
224 }
225
226
227 #endif // _FG_ILS_HXX