libNavAids_a_SOURCES = navaid.hxx navaids.hxx navaids.cxx
testnavs_SOURCES = testnavs.cxx
-testnavs_LDADD = libNavAids.a -lsgdebug -lsgmisc -lz
+testnavs_LDADD = libNavAids.a -lsgdebug -lsgmath -lsgmisc -lz
INCLUDES += -I$(top_builddir) -I$(top_builddir)/src
#endif
-class FGNavAid {
+class FGNavaid {
char type;
double lon, lat;
public:
- inline FGNavAid(void) {}
- inline ~FGNavAid(void) {}
+ inline FGNavaid(void) {}
+ inline ~FGNavaid(void) {}
inline char get_type() const { return type; }
inline double get_lon() const { return lon; }
inline void set_dme( bool b ) { dme = b; }
inline void set_ident( char *i ) { strncpy( ident, i, 5 ); }
- friend istream& operator>> ( istream&, FGNavAid& );
+ friend istream& operator>> ( istream&, FGNavaid& );
};
inline istream&
-operator >> ( istream& in, FGNavAid& n )
+operator >> ( istream& in, FGNavaid& n )
{
double f;
char c;
- in >> n.type >> n.lon >> n.lat >> n.elev >> f >> n.range
+ in >> n.type >> n.lat >> n.lon >> n.elev >> f >> n.range
>> c >> n.ident;
n.freq = (int)(f * 100.0);
// $Id$
-#include <simgear/misc/fgstream.hxx>
#include <simgear/debug/logstream.hxx>
+#include <simgear/misc/fgstream.hxx>
+#include <simgear/math/fg_geodesy.hxx>
#include "navaids.hxx"
// Constructor
-FGNavAids::FGNavAids( void ) {
+FGNavaids::FGNavaids( void ) {
}
// Destructor
-FGNavAids::~FGNavAids( void ) {
+FGNavaids::~FGNavaids( void ) {
}
// load the navaids and build the map
-bool FGNavAids::init( FGPath path ) {
- FGNavAid n;
+bool FGNavaids::init( FGPath path ) {
+ FGNavaid n;
navaids.erase( navaids.begin(), navaids.end() );
return true;
}
+
+
+// query the database for the specified frequency, lon and lat are in
+// degrees, elev is in meters
+bool FGNavaids::query( double lon, double lat, double elev, double freq,
+ FGNavaid *n, double *heading, double *dist )
+{
+ nav_list_type stations = navaids[(int)(freq*100.0)];
+
+ nav_list_iterator current = stations.begin();
+ nav_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_lat(), current->get_lon(),
+ &az1, &az2, &s );
+ // cout << " dist = " << s << endl;
+ if ( s < ( current->get_range() * NM_TO_METER ) ) {
+ *n = *current;
+ *heading = az2;
+ *dist = s;
+ return true;
+ }
+ }
+
+ return false;
+}
FG_USING_STD(vector);
-// convenience types
-typedef vector < FGNavAid > nav_list_type;
-typedef nav_list_type::iterator nav_list_iterator;
-typedef nav_list_type::const_iterator nav_list_const_iterator;
+class FGNavaids {
-typedef map < int, nav_list_type, less<int> > nav_map_type;
-typedef nav_map_type::iterator nav_map_iterator;
-typedef nav_map_type::const_iterator nav_map_const_iterator;
+ // convenience types
+ typedef vector < FGNavaid > nav_list_type;
+ typedef nav_list_type::iterator nav_list_iterator;
+ typedef nav_list_type::const_iterator nav_list_const_iterator;
-class FGNavAids {
+ typedef map < int, nav_list_type, less<int> > nav_map_type;
+ typedef nav_map_type::iterator nav_map_iterator;
+ typedef nav_map_type::const_iterator nav_map_const_iterator;
nav_map_type navaids;
public:
- FGNavAids();
- ~FGNavAids();
+ FGNavaids();
+ ~FGNavaids();
// load the navaids and build the map
bool init( FGPath path );
- // query the database for the specified frequency
- FGNavAid query( double lon, double lat, int freq );
+ // 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,
+ FGNavaid *n, double *heading, double *dist);
};
#include "navaids.hxx"
int main() {
- FGNavAids navs;
+ FGNavaids navs;
- FGPath p( "/home/curt/FlightGear/Navaids/default.nav.gz" );
+ FGPath p( "/export/data2/curt/FlightGear/Navaids/default.nav" );
navs.init( p );
+
+ FGNavaid n;
+ double heading, dist;
+ if ( navs.query( -93.2, 45.14, 3000, 117.30,
+ &n, &heading, &dist) ) {
+ cout << "Found a station in range" << endl;
+ cout << " id = " << n.get_ident() << endl;
+ cout << " heading = " << heading << " dist = " << dist << endl;
+ } else {
+ cout << "not picking anything up. :-(" << endl;
+ }
}