1
0
Fork 0

Added fix routines.

This commit is contained in:
curt 2000-04-21 18:30:59 +00:00
parent abc61895ed
commit 6dba794faa
5 changed files with 270 additions and 0 deletions

View file

@ -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

79
src/Navaids/fix.hxx Normal file
View file

@ -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 <simgear/compiler.h>
#include <simgear/misc/fgstream.hxx>
#ifdef FG_HAVE_STD_INCLUDES
# include <istream>
#elif defined( FG_HAVE_NATIVE_SGI_COMPILERS )
# include <iostream.h>
#elif defined( __BORLANDC__ )
# include <iostream>
#else
# include <istream.h>
#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

111
src/Navaids/fixlist.cxx Normal file
View file

@ -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 <simgear/debug/logstream.hxx>
#include <simgear/misc/fgstream.hxx>
#include <simgear/math/fg_geodesy.hxx>
#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;
}

65
src/Navaids/fixlist.hxx Normal file
View file

@ -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 <simgear/compiler.h>
#include <simgear/misc/fgpath.hxx>
#include <map>
#include <vector>
#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<string> > 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

View file

@ -1,5 +1,6 @@
#include <simgear/misc/fgpath.hxx>
#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;
}
}