]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/navdb.cxx
5ca43646e73af8039657b438c6f043aa73043f74
[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 - curt@flightgear.org
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #include <simgear/debug/logstream.hxx>
25
26 #include <Main/globals.hxx>
27
28 #include "navrecord.hxx"
29
30 #include "navdb.hxx"
31
32
33 // load and initialize the navigational databases
34 bool fgNavDBInit( FGNavList *navlist, FGNavList *loclist, FGNavList *gslist,
35                   FGNavList *dmelist, FGNavList *mkrlist )
36 {
37     SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaid Databases");
38     // SG_LOG(SG_GENERAL, SG_INFO, "  VOR/NDB");
39     // SGPath p_nav( globals->get_fg_root() );
40     // p_nav.append( "Navaids/default.nav" );
41     // navlist->init( p_nav );
42
43     // SG_LOG(SG_GENERAL, SG_INFO, "  ILS and Marker Beacons");
44     // beacons->init();
45     // SGPath p_ils( globals->get_fg_root() );
46     // p_ils.append( "Navaids/default.ils" );
47     // ilslist->init( p_ils );
48
49
50     SGPath path( globals->get_fg_root() );
51     path.append( "Navaids/nav.dat" );
52
53     sg_gzifstream in( path.str() );
54     if ( !in.is_open() ) {
55         SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
56         exit(-1);
57     }
58
59     // skip first two lines
60     in >> skipeol;
61     in >> skipeol;
62
63
64 #ifdef __MWERKS__
65     char c = 0;
66     while ( in.get(c) && c != '\0'  ) {
67         in.putback(c);
68 #else
69     while ( ! in.eof() ) {
70 #endif
71
72         FGNavRecord *r = new FGNavRecord;
73         in >> (*r);
74         if ( r->get_type() > 95 ) {
75             break;
76         }
77
78         /* cout << "id = " << n.get_ident() << endl;
79         cout << " type = " << n.get_type() << endl;
80         cout << " lon = " << n.get_lon() << endl;
81         cout << " lat = " << n.get_lat() << endl;
82         cout << " elev = " << n.get_elev() << endl;
83         cout << " freq = " << n.get_freq() << endl;
84         cout << " range = " << n.get_range() << endl << endl; */
85
86         if ( r->get_type() == 2 || r->get_type() == 3 ) {
87             // NDB=2, VOR=3
88             navlist->add( r );
89         } else if ( r->get_type() == 4 || r->get_type() == 5 ) {
90             // ILS=4, LOC(only)=5
91             loclist->add( r );
92         } else if ( r->get_type() == 6 ) {
93             // GS=6
94             gslist->add( r );
95         } else if ( r->get_type() == 7 || r->get_type() == 8
96                     || r->get_type() == 9 )
97         {
98             // Marker Beacon = 7,8,9
99             mkrlist->add( r );
100         } else if ( r->get_type() == 12 ) {
101             // DME=12
102             dmelist->add( r );
103         }
104                 
105         in >> skipcomment;
106     }
107
108     // cout << "min freq = " << min << endl;
109     // cout << "max freq = " << max << endl;
110
111     return true;
112 }