]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/navdb.cxx
James Turner:
[flightgear.git] / src / Navaids / navdb.cxx
1 // navdb.cxx -- top level navaids management routines
2 //
3 // Written by Curtis Olson, started May 2004.
4 //
5 // Copyright (C) 2004  Curtis L. Olson - http://www.flightgear.org/~curt
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <simgear/compiler.h>
28
29 #include <string>
30
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>
36
37 #include "navrecord.hxx"
38 #include "navdb.hxx"
39 #include "Main/globals.hxx"
40
41 using std::string;
42
43
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)
49 {
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 );
55
56     // SG_LOG(SG_GENERAL, SG_INFO, "  ILS and Marker Beacons");
57     // beacons->init();
58     // SGPath p_ils( globals->get_fg_root() );
59     // p_ils.append( "Navaids/default.ils" );
60     // ilslist->init( p_ils );
61
62
63     SGPath path( globals->get_fg_root() );
64     path.append( "Navaids/nav.dat" );
65
66     sg_gzifstream in( path.str() );
67     if ( !in.is_open() ) {
68         SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
69         exit(-1);
70     }
71
72     // skip first two lines
73     in >> skipeol;
74     in >> skipeol;
75
76     while (!in.eof()) {
77       FGNavRecord *r = FGNavRecord::createFromStream(in);
78       if (!r) {
79         break;
80       }
81       
82       switch (r->type()) {
83       case FGPositioned::NDB:
84       case FGPositioned::VOR:
85         navlist->add(r);
86         break;
87         
88       case FGPositioned::ILS:
89       case FGPositioned::LOC:
90         loclist->add(r);
91         break;
92         
93       case FGPositioned::GS:
94         gslist->add(r);
95         break;
96       
97       case FGPositioned::OM:
98       case FGPositioned::MM:
99       case FGPositioned::IM:
100         mkrlist->add(r);
101         break;
102       
103       case FGPositioned::DME:
104       {
105         dmelist->add(r);
106         string::size_type loc1= r->get_name().find( "TACAN", 0 );
107         string::size_type loc2 = r->get_name().find( "VORTAC", 0 );
108                        
109         if( loc1 != string::npos || loc2 != string::npos) {
110           tacanlist->add(r);
111         }
112
113         break;
114       }
115       
116       default:
117         throw sg_range_exception("got unsupported NavRecord type", "fgNavDBInit");
118       }
119
120       in >> skipcomment;
121     } // of stream data loop
122
123 // load the carrier navaids file
124     
125     string file, name;
126     path = globals->get_fg_root() ;
127     path.append( "Navaids/carrier_nav.dat" );
128     
129     file = path.str();
130     SG_LOG( SG_GENERAL, SG_INFO, "opening file: " << path.str() );
131     
132     sg_gzifstream incarrier( path.str() );
133     
134     if ( !incarrier.is_open() ) {
135         SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
136         exit(-1);
137     }
138     
139     // skip first two lines
140     //incarrier >> skipeol;
141     //incarrier >> skipeol;
142     
143     while ( ! incarrier.eof() ) {
144       FGNavRecord *r = FGNavRecord::createFromStream(incarrier);
145       if (!r) {
146         continue;
147       }
148       
149       carrierlist->add (r);
150     } // end while
151
152 // end loading the carrier navaids file
153
154 // load the channel/freqency file
155     string channel, freq;
156     path="";
157     path = globals->get_fg_root();
158     path.append( "Navaids/TACAN_freq.dat" );
159     
160     SG_LOG( SG_GENERAL, SG_INFO, "opening file: " << path.str() );
161         
162     sg_gzifstream inchannel( path.str() );
163     
164     if ( !inchannel.is_open() ) {
165         SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
166         exit(-1);
167     }
168     
169     // skip first line
170     inchannel >> skipeol;
171     while ( ! inchannel.eof() ) {
172         FGTACANRecord *r = new FGTACANRecord;
173         inchannel >> (*r);
174         channellist->add ( r );
175         //cout << "channel = " << r->get_channel() ;
176         //cout << " freq = " << r->get_freq() << endl;
177         
178     } // end while
179
180  
181  // end ReadChanFile
182
183
184     return true;
185 }