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/structure/exception.hxx>
35 #include <simgear/misc/sgstream.hxx>
37 #include "navrecord.hxx"
39 #include "Main/globals.hxx"
44 // load and initialize the navigational databases
45 bool fgNavDBInit( FGNavList *navlist, FGNavList *loclist, FGNavList *gslist,
46 FGNavList *dmelist, FGNavList *mkrlist,
47 FGNavList *tacanlist, FGNavList *carrierlist,
48 FGTACANList *channellist)
50 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaid Databases");
51 // SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
52 // SGPath p_nav( globals->get_fg_root() );
53 // p_nav.append( "Navaids/default.nav" );
54 // navlist->init( p_nav );
56 // SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
58 // SGPath p_ils( globals->get_fg_root() );
59 // p_ils.append( "Navaids/default.ils" );
60 // ilslist->init( p_ils );
63 SGPath path( globals->get_fg_root() );
64 path.append( "Navaids/nav.dat" );
66 sg_gzifstream in( path.str() );
67 if ( !in.is_open() ) {
68 SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
72 // skip first two lines
77 FGNavRecord *r = FGNavRecord::createFromStream(in);
83 case FGPositioned::NDB:
84 case FGPositioned::VOR:
88 case FGPositioned::ILS:
89 case FGPositioned::LOC:
93 case FGPositioned::GS:
97 case FGPositioned::OM:
98 case FGPositioned::MM:
99 case FGPositioned::IM:
103 case FGPositioned::DME:
106 string::size_type loc1= r->get_name().find( "TACAN", 0 );
107 string::size_type loc2 = r->get_name().find( "VORTAC", 0 );
109 if( loc1 != string::npos || loc2 != string::npos) {
117 throw sg_range_exception("got unsupported NavRecord type", "fgNavDBInit");
121 } // of stream data loop
123 // load the carrier navaids file
126 path = globals->get_fg_root() ;
127 path.append( "Navaids/carrier_nav.dat" );
130 SG_LOG( SG_GENERAL, SG_INFO, "opening file: " << path.str() );
132 sg_gzifstream incarrier( path.str() );
134 if ( !incarrier.is_open() ) {
135 SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
139 // skip first two lines
140 //incarrier >> skipeol;
141 //incarrier >> skipeol;
143 while ( ! incarrier.eof() ) {
144 FGNavRecord *r = FGNavRecord::createFromStream(incarrier);
149 carrierlist->add (r);
152 // end loading the carrier navaids file
154 // load the channel/freqency file
155 string channel, freq;
157 path = globals->get_fg_root();
158 path.append( "Navaids/TACAN_freq.dat" );
160 SG_LOG( SG_GENERAL, SG_INFO, "opening file: " << path.str() );
162 sg_gzifstream inchannel( path.str() );
164 if ( !inchannel.is_open() ) {
165 SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
170 inchannel >> skipeol;
171 while ( ! inchannel.eof() ) {
172 FGTACANRecord *r = new FGTACANRecord;
174 channellist->add ( r );
175 //cout << "channel = " << r->get_channel() ;
176 //cout << " freq = " << r->get_freq() << endl;