]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/navdb.cxx
Merge branch 'maint2' into next
[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/misc/sg_path.hxx>
35 #include <simgear/structure/exception.hxx>
36 #include <simgear/misc/sgstream.hxx>
37
38 #include "navrecord.hxx"
39 #include "navlist.hxx"
40 #include "navdb.hxx"
41 #include "Main/globals.hxx"
42
43 using std::string;
44
45
46 // load and initialize the navigational databases
47 bool fgNavDBInit( FGNavList *navlist, FGNavList *loclist, FGNavList *gslist,
48                   FGNavList *dmelist, 
49                   FGNavList *tacanlist, FGNavList *carrierlist,
50                   FGTACANList *channellist)
51 {
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 );
57
58     // SG_LOG(SG_GENERAL, SG_INFO, "  ILS and Marker Beacons");
59     // beacons->init();
60     // SGPath p_ils( globals->get_fg_root() );
61     // p_ils.append( "Navaids/default.ils" );
62     // ilslist->init( p_ils );
63
64
65     SGPath path( globals->get_fg_root() );
66     path.append( "Navaids/nav.dat" );
67
68     sg_gzifstream in( path.str() );
69     if ( !in.is_open() ) {
70         SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
71         exit(-1);
72     }
73
74     // skip first two lines
75     in >> skipeol;
76     in >> skipeol;
77
78     while (!in.eof()) {
79       FGNavRecord *r = FGNavRecord::createFromStream(in);
80       if (!r) {
81         break;
82       }
83       
84       switch (r->type()) {
85       case FGPositioned::NDB:
86       case FGPositioned::VOR:
87         navlist->add(r);
88         break;
89         
90       case FGPositioned::ILS:
91       case FGPositioned::LOC:
92         loclist->add(r);
93         break;
94         
95       case FGPositioned::GS:
96         gslist->add(r);
97         break;
98       
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
103         break;
104       
105       case FGPositioned::DME:
106       {
107         dmelist->add(r);
108         string::size_type loc1= r->name().find( "TACAN", 0 );
109         string::size_type loc2 = r->name().find( "VORTAC", 0 );
110                        
111         if( loc1 != string::npos || loc2 != string::npos) {
112           tacanlist->add(r);
113         }
114
115         break;
116       }
117       
118       default:
119         throw sg_range_exception("got unsupported NavRecord type", "fgNavDBInit");
120       }
121
122       in >> skipcomment;
123     } // of stream data loop
124
125 // load the carrier navaids file
126     
127     string file, name;
128     path = globals->get_fg_root() ;
129     path.append( "Navaids/carrier_nav.dat" );
130     
131     file = path.str();
132     SG_LOG( SG_GENERAL, SG_INFO, "opening file: " << path.str() );
133     
134     sg_gzifstream incarrier( path.str() );
135     
136     if ( !incarrier.is_open() ) {
137         SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
138         exit(-1);
139     }
140     
141     // skip first two lines
142     //incarrier >> skipeol;
143     //incarrier >> skipeol;
144     
145     while ( ! incarrier.eof() ) {
146       FGNavRecord *r = FGNavRecord::createFromStream(incarrier);
147       if (!r) {
148         continue;
149       }
150       
151       carrierlist->add (r);
152     } // end while
153
154 // end loading the carrier navaids file
155
156 // load the channel/freqency file
157     string channel, freq;
158     path="";
159     path = globals->get_fg_root();
160     path.append( "Navaids/TACAN_freq.dat" );
161     
162     SG_LOG( SG_GENERAL, SG_INFO, "opening file: " << path.str() );
163         
164     sg_gzifstream inchannel( path.str() );
165     
166     if ( !inchannel.is_open() ) {
167         SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
168         exit(-1);
169     }
170     
171     // skip first line
172     inchannel >> skipeol;
173     while ( ! inchannel.eof() ) {
174         FGTACANRecord *r = new FGTACANRecord;
175         inchannel >> (*r);
176         channellist->add ( r );
177         //cout << "channel = " << r->get_channel() ;
178         //cout << " freq = " << r->get_freq() << endl;
179         
180     } // end while
181
182  
183  // end ReadChanFile
184
185
186     return true;
187 }