diff --git a/src/Navaids/Makefile.am b/src/Navaids/Makefile.am index f5229c05c..ffdc80cd1 100644 --- a/src/Navaids/Makefile.am +++ b/src/Navaids/Makefile.am @@ -2,7 +2,9 @@ noinst_LIBRARIES = libNavAids.a noinst_PROGRAMS = testnavs -libNavAids_a_SOURCES = nav.hxx navlist.hxx navlist.cxx +libNavAids_a_SOURCES = \ + ils.hxx ilslist.hxx ilslist.cxx \ + nav.hxx navlist.hxx navlist.cxx testnavs_SOURCES = testnavs.cxx testnavs_LDADD = libNavAids.a -lsgdebug -lsgmath -lsgmisc -lz diff --git a/src/Navaids/ils.hxx b/src/Navaids/ils.hxx new file mode 100644 index 000000000..a8bd094e1 --- /dev/null +++ b/src/Navaids/ils.hxx @@ -0,0 +1,122 @@ +// ils.hxx -- navaid class +// +// Written by Curtis Olson, started April 2000. +// +// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + + +#ifndef _FG_ILS_HXX +#define _FG_ILS_HXX + + +#include +#include + +#ifdef FG_HAVE_STD_INCLUDES +# include +#elif defined( FG_HAVE_NATIVE_SGI_COMPILERS ) +# include +#elif defined( __BORLANDC__ ) +# include +#else +# include +#endif + +#if ! defined( FG_HAVE_NATIVE_SGI_COMPILERS ) +FG_USING_STD(istream); +#endif + + +#define FG_ILS_DEFAULT_RANGE 30 + +class FGILS { + + char ilstype; + char ilstypename[6]; + char aptcode[5]; + char rwyno[4]; + int locfreq; + char locident[5]; + double locheading; + double loclat; + double loclon; + double gselev; + double gsangle; + double gslat; + double gslon; + double dmelat; + double dmelon; + double omlat; + double omlon; + double mmlat; + double mmlon; + double imlat; + double imlon; + +public: + + inline FGILS(void) {} + inline ~FGILS(void) {} + + inline char get_ilstype() const { return ilstype; } + inline char *get_ilstypename() { return ilstypename; } + inline char *get_aptcode() { return aptcode; } + inline char *get_rwyno() { return rwyno; } + inline int get_locfreq() const { return locfreq; } + inline char *get_locident() { return locident; } + inline double get_locheading() const { return locheading; } + inline double get_loclat() const { return loclat; } + inline double get_loclon() const { return loclon; } + inline double get_gsangle() const { return gsangle; } + inline double get_gslat() const { return gslat; } + inline double get_gslon() const { return gslon; } + inline double get_dmelat() const { return dmelat; } + inline double get_dmelon() const { return dmelon; } + inline double get_omlat() const { return omlat; } + inline double get_omlon() const { return omlon; } + inline double get_mmlat() const { return mmlat; } + inline double get_mmlon() const { return mmlon; } + inline double get_imlat() const { return imlat; } + inline double get_imlon() const { return imlon; } + + friend istream& operator>> ( istream&, FGILS& ); +}; + + +inline istream& +operator >> ( istream& in, FGILS& i ) +{ + double f; + in >> i.ilstype >> i.ilstypename >> i.aptcode >> i.rwyno + >> f >> i.locident >> i.locheading >> i.loclat >> i.loclon + >> i.gselev >> i.gsangle >> i.gslat >> i.gslon + >> i.dmelat >> i.dmelon + >> i.omlat >> i.omlon + >> i.mmlat >> i.mmlon + >> i.imlat >> i.imlon; + + + i.locfreq = (int)(f * 100.0); + + // return in >> skipeol; + return in; +} + + +#endif // _FG_NAVAID_HXX diff --git a/src/Navaids/ilslist.cxx b/src/Navaids/ilslist.cxx new file mode 100644 index 000000000..164b06d2c --- /dev/null +++ b/src/Navaids/ilslist.cxx @@ -0,0 +1,119 @@ +// ilslist.cxx -- ils management class +// +// Written by Curtis Olson, started April 2000. +// +// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + + +#include +#include +#include + +#include "ilslist.hxx" + + +// Constructor +FGILSList::FGILSList( void ) { +} + + +// Destructor +FGILSList::~FGILSList( void ) { +} + + +// load the navaids and build the map +bool FGILSList::init( FGPath path ) { + FGILS ils; + + ilslist.erase( ilslist.begin(), ilslist.end() ); + + fg_gzifstream in( path.str() ); + if ( !in.is_open() ) { + FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path.str() ); + exit(-1); + } + + // read in each line of the file + + in >> skipeol; + in >> skipcomment; + +#ifdef __MWERKS__ + + char c = 0; + while ( in.get(c) && c != '\0' && n.get_ilstype() != '[' ) { + in.putback(c); + in >> ils; + if ( ils.get_type() != '[' ) { + ilslist[ils.get_locfreq()].push_back(ils); + } + in >> skipcomment; + } + +#else + + while ( ! in.eof() && ils.get_ilstype() != '[' ) { + in >> ils; + /* cout << "id = " << n.get_ident() << endl; + cout << " type = " << n.get_type() << endl; + cout << " lon = " << n.get_lon() << endl; + cout << " lat = " << n.get_lat() << endl; + cout << " elev = " << n.get_elev() << endl; + cout << " freq = " << n.get_freq() << endl; + cout << " range = " << n.get_range() << endl; */ + if ( ils.get_ilstype() != '[' ) { + ilslist[ils.get_locfreq()].push_back(ils); + } + in >> skipcomment; + } + +#endif + + return true; +} + + +// query the database for the specified frequency, lon and lat are in +// degrees, elev is in meters +bool FGILSList::query( double lon, double lat, double elev, double freq, + FGILS *ils, double *heading, double *dist ) +{ + ils_list_type stations = ilslist[(int)(freq*100.0)]; + + ils_list_iterator current = stations.begin(); + ils_list_iterator last = stations.end(); + + double az1, az2, s; + for ( ; current != last ; ++current ) { + // cout << "testing " << current->get_ident() << endl; + geo_inverse_wgs_84( elev, lat, lon, + current->get_loclat(), current->get_loclon(), + &az1, &az2, &s ); + // cout << " dist = " << s << endl; + if ( s < ( FG_ILS_DEFAULT_RANGE * NM_TO_METER ) ) { + *ils = *current; + *heading = az2; + *dist = s; + return true; + } + } + + return false; +} diff --git a/src/Navaids/ilslist.hxx b/src/Navaids/ilslist.hxx new file mode 100644 index 000000000..577a23124 --- /dev/null +++ b/src/Navaids/ilslist.hxx @@ -0,0 +1,68 @@ +// ilslist.hxx -- ils management class +// +// Written by Curtis Olson, started April 2000. +// +// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + + +#ifndef _FG_ILSLIST_HXX +#define _FG_ILSLIST_HXX + + +#include +#include + +#include +#include + +#include "ils.hxx" + +FG_USING_STD(map); +FG_USING_STD(vector); + + +class FGILSList { + + // convenience types + typedef vector < FGILS > ils_list_type; + typedef ils_list_type::iterator ils_list_iterator; + typedef ils_list_type::const_iterator ils_list_const_iterator; + + typedef map < int, ils_list_type, less > ils_map_type; + typedef ils_map_type::iterator ils_map_iterator; + typedef ils_map_type::const_iterator ils_map_const_iterator; + + ils_map_type ilslist; + +public: + + FGILSList(); + ~FGILSList(); + + // load the navaids and build the map + bool init( FGPath path ); + + // query the database for the specified frequency, lon and lat are + // in degrees, elev is in meters + bool query( double lon, double lat, double elev, double freq, + FGILS *i, double *heading, double *dist); +}; + + +#endif // _FG_ILSLIST_HXX diff --git a/src/Navaids/nav.hxx b/src/Navaids/nav.hxx index 265bc5911..beb0bab83 100644 --- a/src/Navaids/nav.hxx +++ b/src/Navaids/nav.hxx @@ -67,14 +67,14 @@ public: inline bool get_dme() const { return dme; } inline char *get_ident() { return ident; } - inline void set_type( char t ) { type = t; } + /* 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 void set_ident( char *i ) { strncpy( ident, i, 5 ); } */ friend istream& operator>> ( istream&, FGNav& ); }; diff --git a/src/Navaids/testnavs.cxx b/src/Navaids/testnavs.cxx index 81990f55c..d04baa369 100644 --- a/src/Navaids/testnavs.cxx +++ b/src/Navaids/testnavs.cxx @@ -1,22 +1,35 @@ #include +#include "ilslist.hxx" #include "navlist.hxx" int main() { - FGNavList navs; - - FGPath p( "/export/data2/curt/FlightGear/Navaids/default.nav" ); - - navs.init( p ); - - FGNav n; double heading, dist; + + FGNavList navs; + FGPath p_nav( "/home/curt/FlightGear/Navaids/default.nav" ); + navs.init( p_nav ); + FGNav n; if ( navs.query( -93.2, 45.14, 3000, 117.30, &n, &heading, &dist) ) { - cout << "Found a station in range" << endl; + cout << "Found a vor station in range" << endl; cout << " id = " << n.get_ident() << endl; cout << " heading = " << heading << " dist = " << dist << endl; } else { - cout << "not picking anything up. :-(" << endl; + cout << "not picking up vor. :-(" << endl; + } + + FGILSList ilslist; + FGPath p_ils( "/home/curt/FlightGear/Navaids/default.ils" ); + ilslist.init( p_ils ); + FGILS i; + if ( ilslist.query( -93.1, 45.24, 3000, 110.30, + &i, &heading, &dist) ) { + cout << "Found an ils station in range" << endl; + cout << " apt = " << i.get_aptcode() << endl; + cout << " rwy = " << i.get_rwyno() << endl; + cout << " heading = " << heading << " dist = " << dist << endl; + } else { + cout << "not picking up ils. :-(" << endl; } }