From 6dba794faa24b875385819f26cbb0de73bd81141 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 21 Apr 2000 18:30:59 +0000 Subject: [PATCH] Added fix routines. --- src/Navaids/Makefile.am | 1 + src/Navaids/fix.hxx | 79 ++++++++++++++++++++++++++++ src/Navaids/fixlist.cxx | 111 +++++++++++++++++++++++++++++++++++++++ src/Navaids/fixlist.hxx | 65 +++++++++++++++++++++++ src/Navaids/testnavs.cxx | 14 +++++ 5 files changed, 270 insertions(+) create mode 100644 src/Navaids/fix.hxx create mode 100644 src/Navaids/fixlist.cxx create mode 100644 src/Navaids/fixlist.hxx diff --git a/src/Navaids/Makefile.am b/src/Navaids/Makefile.am index ffdc80cd1..c6301cf53 100644 --- a/src/Navaids/Makefile.am +++ b/src/Navaids/Makefile.am @@ -3,6 +3,7 @@ noinst_LIBRARIES = libNavAids.a noinst_PROGRAMS = testnavs libNavAids_a_SOURCES = \ + fix.hxx fixlist.hxx fixlist.cxx \ ils.hxx ilslist.hxx ilslist.cxx \ nav.hxx navlist.hxx navlist.cxx diff --git a/src/Navaids/fix.hxx b/src/Navaids/fix.hxx new file mode 100644 index 000000000..a70e3251f --- /dev/null +++ b/src/Navaids/fix.hxx @@ -0,0 +1,79 @@ +// fix.hxx -- fix 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_FIX_HXX +#define _FG_FIX_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 + +#include STL_STRING +FG_USING_STD(string); + + +class FGFix { + + string ident; + double lon, lat; + +public: + + inline FGFix(void) {} + inline ~FGFix(void) {} + + inline string get_ident() const { return ident; } + inline double get_lon() const { return lon; } + inline double get_lat() const { return lat; } + + friend istream& operator>> ( istream&, FGFix& ); +}; + + +inline istream& +operator >> ( istream& in, FGFix& f ) +{ + in >> f.ident >> f.lat >> f.lon; + + // cout << "id = " << f.ident << endl; + + // return in >> skipeol; + return in; +} + + +#endif // _FG_FIX_HXX diff --git a/src/Navaids/fixlist.cxx b/src/Navaids/fixlist.cxx new file mode 100644 index 000000000..19de9895f --- /dev/null +++ b/src/Navaids/fixlist.cxx @@ -0,0 +1,111 @@ +// fixlist.cxx -- fix list 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 "fixlist.hxx" + + +// Constructor +FGFixList::FGFixList( void ) { +} + + +// Destructor +FGFixList::~FGFixList( void ) { +} + + +// load the navaids and build the map +bool FGFixList::init( FGPath path ) { + FGFix fix; + + fixlist.erase( fixlist.begin(), fixlist.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' && fix.get_ident() != "[End]" ) { + in.putback(c); + in >> fix; + if ( fix.get_ident() != "[End]" ) { + fixlist[fix.get_ident()] = fix; + } + in >> skipcomment; + } + +#else + + while ( ! in.eof() && fix.get_ident() != "[End]" ) { + in >> fix; + /* 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 ( fix.get_ident() != "[End]" ) { + fixlist[fix.get_ident()] = fix; + } + in >> skipcomment; + } + +#endif + + return true; +} + + +// query the database for the specified frequency, lon and lat are in +// degrees, elev is in meters +bool FGFixList::query( const string& ident, double lon, double lat, double elev, + FGFix *fix, double *heading, double *dist ) +{ + *fix = fixlist[ident]; + if ( fix->get_ident() == "" ) { + return false; + } + + double az1, az2, s; + geo_inverse_wgs_84( elev, lat, lon, + fix->get_lat(), fix->get_lon(), + &az1, &az2, &s ); + // cout << " dist = " << s << endl; + *heading = az2; + *dist = s; + return true; +} diff --git a/src/Navaids/fixlist.hxx b/src/Navaids/fixlist.hxx new file mode 100644 index 000000000..f172e323b --- /dev/null +++ b/src/Navaids/fixlist.hxx @@ -0,0 +1,65 @@ +// fixlist.hxx -- fix list 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_FIXLIST_HXX +#define _FG_FIXLIST_HXX + + +#include +#include + +#include +#include +#include STL_STRING + +#include "fix.hxx" + +FG_USING_STD(map); +FG_USING_STD(vector); +FG_USING_STD(string); + + +class FGFixList { + + typedef map < string, FGFix, less > fix_map_type; + typedef fix_map_type::iterator fix_map_iterator; + typedef fix_map_type::const_iterator fix_map_const_iterator; + + fix_map_type fixlist; + +public: + + FGFixList(); + ~FGFixList(); + + // 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( const string& ident, double lon, double lat, double elev, + FGFix *f, double *heading, double *dist); +}; + + +#endif // _FG_FIXLIST_HXX diff --git a/src/Navaids/testnavs.cxx b/src/Navaids/testnavs.cxx index d04baa369..1a2e3dcfd 100644 --- a/src/Navaids/testnavs.cxx +++ b/src/Navaids/testnavs.cxx @@ -1,5 +1,6 @@ #include +#include "fixlist.hxx" #include "ilslist.hxx" #include "navlist.hxx" @@ -32,4 +33,17 @@ int main() { } else { cout << "not picking up ils. :-(" << endl; } + + FGFixList fixlist; + FGPath p_fix( "/home/curt/FlightGear/Navaids/default.fix" ); + fixlist.init( p_fix ); + FGFix fix; + if ( fixlist.query( "GONER", -82, 41, 3000, + &fix, &heading, &dist) ) { + cout << "Found a matching fix" << endl; + cout << " id = " << fix.get_ident() << endl; + cout << " heading = " << heading << " dist = " << dist << endl; + } else { + cout << "did not find fix. :-(" << endl; + } } -- 2.39.5