]> git.mxchange.org Git - flightgear.git/blob - Airports/simple.cxx
Contributions from Bernie Bright <bbright@c031.aone.net.au>
[flightgear.git] / Airports / simple.cxx
1 //
2 // airports.cxx -- a really simplistic class to manage airport ID,
3 //                 lat, lon of the center of one of it's runways, and 
4 //                 elevation in feet.
5 //
6 // Written by Curtis Olson, started April 1998.
7 //
8 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 //
24 // $Id$
25 // (Log is kept at end of this file)
26
27
28 #include <string>
29
30 #include <Debug/fg_debug.h>
31 #include <Include/fg_zlib.h>
32 #include <Main/options.hxx>
33
34 #include "simple.hxx"
35
36
37 // Constructor
38 fgAIRPORTS::fgAIRPORTS( void ) {
39 }
40
41
42 // load the data
43 int fgAIRPORTS::load( const string& file ) {
44     fgAIRPORT a;
45     string path, fgpath, id;
46     char id_raw[256], line[256];
47     fgFile f;
48
49     // build the path name to the airport file
50     path = current_options.get_fg_root() + "/Airports/" + file;
51     fgpath = path + ".gz";
52
53     // first try "path.gz"
54     if ( (f = fgopen(fgpath.c_str(), "rb")) == NULL ) {
55         // next try "path"
56         if ( (f = fgopen(path.c_str(), "rb")) == NULL ) {
57             fgPrintf( FG_GENERAL, FG_EXIT, "Cannot open file: %s\n", 
58                       path.c_str());
59         }
60     }
61
62     while ( fggets(f, line, 250) != NULL ) {
63         // printf("%s", line);
64
65         sscanf( line, "%s %lf %lf %lfl\n", id_raw, &a.longitude, &a.latitude, 
66                 &a.elevation );
67         id = id_raw;
68         airports[id] = a;
69     }
70
71     fgclose(f);
72
73     return(1);
74 }
75
76
77 // search for the specified id
78 fgAIRPORT fgAIRPORTS::search( char *id ) {
79     map < string, fgAIRPORT, less<string> > :: iterator find;
80     fgAIRPORT a;
81
82     find = airports.find(id);
83     if ( find == airports.end() ) {
84         // not found
85         a.longitude = a.latitude = a.elevation = 0;
86     } else {
87         a = (*find).second;
88     }
89
90     return(a);
91 }
92
93
94 // Destructor
95 fgAIRPORTS::~fgAIRPORTS( void ) {
96 }
97
98
99 // $Log$
100 // Revision 1.3  1998/08/27 17:01:55  curt
101 // Contributions from Bernie Bright <bbright@c031.aone.net.au>
102 // - use strings for fg_root and airport_id and added methods to return
103 //   them as strings,
104 // - inlined all access methods,
105 // - made the parsing functions private methods,
106 // - deleted some unused functions.
107 // - propogated some of these changes out a bit further.
108 //
109 // Revision 1.2  1998/08/25 20:53:24  curt
110 // Shuffled $FG_ROOT file layout.
111 //
112 // Revision 1.1  1998/08/25 17:19:13  curt
113 // Moved from ../Main/
114 //
115 // Revision 1.8  1998/07/13 21:01:37  curt
116 // Wrote access functions for current fgOPTIONS.
117 //
118 // Revision 1.7  1998/06/03 22:01:07  curt
119 // Tweaking sound library usage.
120 //
121 // Revision 1.6  1998/06/03 00:47:13  curt
122 // Updated to compile in audio support if OSS available.
123 // Updated for new version of Steve's audio library.
124 // STL includes don't use .h
125 // Small view optimizations.
126 //
127 // Revision 1.5  1998/05/29 20:37:22  curt
128 // Tweaked material properties & lighting a bit in GLUTmain.cxx.
129 // Read airport list into a "map" STL for dynamic list sizing and fast tree
130 // based lookups.
131 //
132 // Revision 1.4  1998/05/13 18:26:25  curt
133 // Root path info moved to fgOPTIONS.
134 //
135 // Revision 1.3  1998/05/06 03:16:24  curt
136 // Added an averaged global frame rate counter.
137 // Added an option to control tile radius.
138 //
139 // Revision 1.2  1998/04/28 21:42:50  curt
140 // Wrapped zlib calls up so we can conditionally comment out zlib support.
141 //
142 // Revision 1.1  1998/04/25 15:11:11  curt
143 // Added an command line option to set starting position based on airport ID.
144 //
145 //