]> git.mxchange.org Git - flightgear.git/blob - Main/airports.cxx
Renamed runfg.bat.in runfgfs.bat.in
[flightgear.git] / Main / airports.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 "airports.hxx"
35
36
37 // Constructor
38 fgAIRPORTS::fgAIRPORTS( void ) {
39 }
40
41
42 // load the data
43 int fgAIRPORTS::load( char *file ) {
44     fgAIRPORT a;
45     char path[256], fgpath[256], line[256];
46     char id[5];
47     string id_str;
48     fgFile f;
49
50     // build the path name to the airport file
51     current_options.get_fg_root(path);
52     strcat(path, "/Scenery/");
53     strcat(path, "Airports");
54     strcpy(fgpath, path);
55     strcat(fgpath, ".gz");
56
57     // first try "path.gz"
58     if ( (f = fgopen(fgpath, "rb")) == NULL ) {
59         // next try "path"
60         if ( (f = fgopen(path, "rb")) == NULL ) {
61             fgPrintf(FG_GENERAL, FG_EXIT, "Cannot open file: %s\n", path);
62         }
63     }
64
65     while ( fggets(f, line, 250) != NULL ) {
66         // printf("%s", line);
67
68         sscanf( line, "%s %lf %lf %lfl\n", id, &a.longitude, &a.latitude, 
69                 &a.elevation );
70         id_str = id;
71         airports[id_str] = a;
72     }
73
74     fgclose(f);
75
76     return(1);
77 }
78
79
80 // search for the specified id
81 fgAIRPORT fgAIRPORTS::search( char *id ) {
82     map < string, fgAIRPORT, less<string> > :: iterator find;
83     fgAIRPORT a;
84
85     find = airports.find(id);
86     if ( find == airports.end() ) {
87         // not found
88         a.longitude = a.latitude = a.elevation = 0;
89     } else {
90         a = (*find).second;
91     }
92
93     return(a);
94 }
95
96
97 // Destructor
98 fgAIRPORTS::~fgAIRPORTS( void ) {
99 }
100
101
102 // $Log$
103 // Revision 1.8  1998/07/13 21:01:37  curt
104 // Wrote access functions for current fgOPTIONS.
105 //
106 // Revision 1.7  1998/06/03 22:01:07  curt
107 // Tweaking sound library usage.
108 //
109 // Revision 1.6  1998/06/03 00:47:13  curt
110 // Updated to compile in audio support if OSS available.
111 // Updated for new version of Steve's audio library.
112 // STL includes don't use .h
113 // Small view optimizations.
114 //
115 // Revision 1.5  1998/05/29 20:37:22  curt
116 // Tweaked material properties & lighting a bit in GLUTmain.cxx.
117 // Read airport list into a "map" STL for dynamic list sizing and fast tree
118 // based lookups.
119 //
120 // Revision 1.4  1998/05/13 18:26:25  curt
121 // Root path info moved to fgOPTIONS.
122 //
123 // Revision 1.3  1998/05/06 03:16:24  curt
124 // Added an averaged global frame rate counter.
125 // Added an option to control tile radius.
126 //
127 // Revision 1.2  1998/04/28 21:42:50  curt
128 // Wrapped zlib calls up so we can conditionally comment out zlib support.
129 //
130 // Revision 1.1  1998/04/25 15:11:11  curt
131 // Added an command line option to set starting position based on airport ID.
132 //
133 //