]> git.mxchange.org Git - flightgear.git/blob - GenAirports/main.cxx
fa5464c5654bbaca04b5566cfe7432104ba15135
[flightgear.git] / GenAirports / main.cxx
1 // main.cxx -- main loop
2 //
3 // Written by Curtis Olson, started March 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU 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 // (Log is kept at end of this file)
23 //
24
25
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
29
30 #ifdef HAVE_STDLIB_H
31 #include <stdlib.h>
32 #endif
33
34 #include <list>
35 #include <stdio.h>
36 #include <string.h>
37 #include <string>
38
39 #include <Bucket/bucketutils.h>
40 #include <Include/fg_constants.h>
41 #include <Include/fg_zlib.h>
42
43 #include "area.hxx"
44
45
46 // process and airport + runway list
47 void process_airport( string last_airport, list < string > & runway_list ) {
48     list < point2d > rwy_list, apt_list;
49     list < point2d > :: iterator current;                          
50     list < point2d > :: iterator last;                    
51
52     string line_str;
53     double lon, lat;
54     int len, width, hdg, label_hdg, elev;
55     char codes[10];
56     char side;
57
58     printf( "(apt) %s", last_airport.c_str() );
59
60     while ( runway_list.size() ) {
61         line_str = runway_list.front();
62         runway_list.pop_front();
63         printf( "%s", line_str.c_str() );
64
65         sscanf( line_str.c_str(), "%lf %lf %d %d %d %s %d %c %d\n",
66                 &lon, &lat, &len, &width, &hdg, codes, &label_hdg, 
67                 &side, &elev );
68
69         rwy_list = gen_runway_area( lon, lat, (double)hdg * DEG_TO_RAD, 
70                                     (double)len * FEET_TO_METER,
71                                     (double)width * FEET_TO_METER );
72
73         // add rwy_list to apt_list
74         current = rwy_list.begin();
75         last = rwy_list.end();
76         while ( current != last ) {
77             apt_list.push_back(*current);
78             current++;
79         }
80     }
81
82     printf("Final results in degrees\n");
83     current = apt_list.begin();
84     last = apt_list.end();
85     while ( current != last ) {
86         // printf( "(%.4f, %.4f)\n", 
87         printf( "%.5f %.5f\n", 
88                 current->lon * RAD_TO_DEG,
89                 current->lat * RAD_TO_DEG );
90         current++;
91     }
92     printf("\n");
93 }
94
95
96 // reads the apt_full file and extracts and processes the individual
97 // airport records
98 int main( int argc, char **argv ) {
99     list < string > runway_list;
100     string apt_path, gz_apt_path;
101     string airport, last_airport;
102     fgFile f;
103     char line[256];
104     /*
105     fgBUCKET b;
106     point2d nodes[4];
107     char base[256], path[256], command[256], file[256], exfile[256];
108     double lon, lat, elevation, heading;
109     double length, width;
110     long int index;
111     */
112
113     if ( argc != 3 ) {
114         printf("Usage %s <apt_file> <work dir>\n", argv[0]);
115         exit(0);
116     }
117
118     apt_path = argv[1];
119     gz_apt_path = apt_path + ".gz";
120
121     // first try "path.gz"
122     if ( (f = fgopen(gz_apt_path.c_str(), "rb")) == NULL ) {
123         // next try "path"
124         if ( (f = fgopen(apt_path.c_str(), "rb")) == NULL ) {
125             printf( "Cannot open file: %s\n", apt_path.c_str());
126         }
127     }
128
129     while ( fggets(f, line, 250) != NULL ) {
130         // printf("%s", line);
131         if ( strlen(line) == 0 ) {
132             // empty, skip
133         } else if ( line[0] == '#' ) {
134             // comment, skip
135         } else if ( line[0] == '\t' ) {
136             // runway entry
137             runway_list.push_back(line);
138         } else {
139             // start of airport record
140             airport = line;
141
142             if ( last_airport.length() ) {
143                 // process previous record
144                 process_airport(last_airport, runway_list);
145             }
146
147             last_airport = airport;
148         }
149     }
150
151     if ( last_airport.length() ) {
152         // process previous record
153         process_airport(last_airport, runway_list);
154     }
155
156     fgclose(f);
157
158     return(1);
159 }
160
161
162 #if 0
163     // P13 (Globe, AZ)
164     // lon = -110.6642442;
165     // lat = 33.3528903;
166     // heading = 102.0 * DEG_TO_RAD;
167     // length = 1769;
168     // width = 23;
169
170     // KANE
171     lon = -93.2113889;
172     lat = 45.145;
173     elevation = 912 * FEET_TO_METER;
174     heading = 270.0 * DEG_TO_RAD;
175     length = 1220;
176     width = 23;
177
178     gen_runway_area( lon * DEG_TO_RAD, lat * DEG_TO_RAD, 
179                      heading, length, width, nodes, &count );
180
181     fgBucketFind(lon, lat, &b);
182     printf( "Bucket = lon,lat = %d,%d  x,y index = %d,%d\n", 
183             b.lon, b.lat, b.x, b.y);
184
185     index = fgBucketGenIndex(&b);
186     fgBucketGenBasePath(&b, base);
187     sprintf(path, "%s/Scenery/%s", argv[1], base);
188     sprintf(command, "mkdir -p %s\n", path);
189     system(command);
190     
191     sprintf(exfile, "%s/%ld.node.ex", path, index);
192     sprintf(file, "%s/%ld.poly", path, index);
193     printf( "extra node file = %s\n", exfile);
194     printf( "poly file = %s\n", file);
195
196     // output extra nodes
197     if ( (fd = fopen(exfile, "w")) == NULL ) {
198         printf("Cannot open file: %s\n", exfile);
199         exit(-1);
200     }
201
202     fprintf(fd, "%d 2 0 0\n", count);
203     for ( i = 0; i < count; i++ ) {
204         fprintf( fd, "%d %.2f %.2f %.2f\n", i + 1, 
205                  nodes[i].lon * RAD_TO_ARCSEC, nodes[i].lat * RAD_TO_ARCSEC, 
206                  elevation);
207     }
208     fclose(fd);
209
210     // output poly
211     if ( (fd = fopen(file, "w")) == NULL ) {
212         printf("Cannot open file: %s\n", file);
213         exit(-1);
214     }
215
216     // output empty node list
217     fprintf(fd, "0 2 0 0\n");
218
219     // output segments
220     fprintf(fd, "%d 0\n", count);
221     for ( i = 0; i < count - 1; i++ ) {
222         fprintf( fd, "%d %d %d\n", i + 1, i + 1, i + 2 );
223     }
224     fprintf( fd, "%d %d %d\n", count, count, 1 );
225
226     // output hole center
227     fprintf( fd, "1\n");
228     fprintf( fd, "1 %.2f %.2f\n", lon * 3600.0, lat * 3600);
229
230     fclose(fd);
231
232 #endif
233
234
235 // $Log: main.c,v
236 //