1 // navdb.cxx -- top level navaids management routines
3 // Written by Curtis Olson, started May 2004.
5 // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <simgear/compiler.h>
31 #include <simgear/debug/logstream.hxx>
32 #include <simgear/math/sg_geodesy.hxx>
33 #include <simgear/misc/strutils.hxx>
34 #include <simgear/misc/sg_path.hxx>
35 #include <simgear/structure/exception.hxx>
36 #include <simgear/misc/sgstream.hxx>
38 #include "navrecord.hxx"
39 #include "navlist.hxx"
41 #include "Main/globals.hxx"
46 // load and initialize the navigational databases
47 bool fgNavDBInit( FGNavList *navlist, FGNavList *loclist, FGNavList *gslist,
49 FGNavList *tacanlist, FGNavList *carrierlist,
50 FGTACANList *channellist)
52 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaid Databases");
53 // SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
54 // SGPath p_nav( globals->get_fg_root() );
55 // p_nav.append( "Navaids/default.nav" );
56 // navlist->init( p_nav );
58 // SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
60 // SGPath p_ils( globals->get_fg_root() );
61 // p_ils.append( "Navaids/default.ils" );
62 // ilslist->init( p_ils );
65 SGPath path( globals->get_fg_root() );
66 path.append( "Navaids/nav.dat" );
68 sg_gzifstream in( path.str() );
69 if ( !in.is_open() ) {
70 SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
74 // skip first two lines
79 FGNavRecord *r = FGNavRecord::createFromStream(in);
85 case FGPositioned::NDB:
86 case FGPositioned::VOR:
90 case FGPositioned::ILS:
91 case FGPositioned::LOC:
95 case FGPositioned::GS:
99 case FGPositioned::OM:
100 case FGPositioned::MM:
101 case FGPositioned::IM:
102 // no need to add this to a list, never searched by frequency
105 case FGPositioned::DME:
108 string::size_type loc1= r->name().find( "TACAN", 0 );
109 string::size_type loc2 = r->name().find( "VORTAC", 0 );
111 if( loc1 != string::npos || loc2 != string::npos) {
119 throw sg_range_exception("got unsupported NavRecord type", "fgNavDBInit");
123 } // of stream data loop
125 // load the carrier navaids file
128 path = globals->get_fg_root() ;
129 path.append( "Navaids/carrier_nav.dat" );
132 SG_LOG( SG_GENERAL, SG_INFO, "opening file: " << path.str() );
134 sg_gzifstream incarrier( path.str() );
136 if ( !incarrier.is_open() ) {
137 SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
141 // skip first two lines
142 //incarrier >> skipeol;
143 //incarrier >> skipeol;
145 while ( ! incarrier.eof() ) {
146 FGNavRecord *r = FGNavRecord::createFromStream(incarrier);
151 carrierlist->add (r);
154 // end loading the carrier navaids file
156 // load the channel/freqency file
157 string channel, freq;
159 path = globals->get_fg_root();
160 path.append( "Navaids/TACAN_freq.dat" );
162 SG_LOG( SG_GENERAL, SG_INFO, "opening file: " << path.str() );
164 sg_gzifstream inchannel( path.str() );
166 if ( !inchannel.is_open() ) {
167 SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
172 inchannel >> skipeol;
173 while ( ! inchannel.eof() ) {
174 FGTACANRecord *r = new FGTACANRecord;
176 channellist->add ( r );
177 //cout << "channel = " << r->get_channel() ;
178 //cout << " freq = " << r->get_freq() << endl;