1 // main.cxx -- main loop
3 // Written by Curtis Olson, started March 1998.
5 // Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
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.
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.
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.
22 // (Log is kept at end of this file)
39 #include <Bucket/bucketutils.h>
40 #include <Include/fg_constants.h>
41 #include <Include/fg_zlib.h>
44 #include "convex_hull.hxx"
47 // process and airport + runway list
48 void process_airport( string last_airport, list < string > & runway_list ) {
49 list < point2d > rwy_list, apt_list;
50 list < point2d > :: iterator current;
51 list < point2d > :: iterator last;
55 int len, width, hdg, label_hdg, elev;
59 printf( "(apt) %s", last_airport.c_str() );
61 while ( runway_list.size() ) {
62 line_str = runway_list.front();
63 runway_list.pop_front();
64 printf( "%s", line_str.c_str() );
66 sscanf( line_str.c_str(), "%lf %lf %d %d %d %s %d %c %d\n",
67 &lon, &lat, &len, &width, &hdg, codes, &label_hdg,
70 rwy_list = gen_runway_area( lon, lat, (double)hdg * DEG_TO_RAD,
71 (double)len * FEET_TO_METER,
72 (double)width * FEET_TO_METER );
74 // add rwy_list to apt_list
75 current = rwy_list.begin();
76 last = rwy_list.end();
77 while ( current != last ) {
78 apt_list.push_back(*current);
83 printf("Final results in degrees\n");
84 current = apt_list.begin();
85 last = apt_list.end();
86 while ( current != last ) {
87 // printf( "(%.4f, %.4f)\n",
88 printf( "%.5f %.5f\n", current->lon, current->lat );
93 convex_hull(apt_list);
97 // reads the apt_full file and extracts and processes the individual
99 int main( int argc, char **argv ) {
100 list < string > runway_list;
101 string apt_path, gz_apt_path;
102 string airport, last_airport;
108 char base[256], path[256], command[256], file[256], exfile[256];
109 double lon, lat, elevation, heading;
110 double length, width;
115 printf("Usage %s <apt_file> <work dir>\n", argv[0]);
120 gz_apt_path = apt_path + ".gz";
122 // first try "path.gz"
123 if ( (f = fgopen(gz_apt_path.c_str(), "rb")) == NULL ) {
125 if ( (f = fgopen(apt_path.c_str(), "rb")) == NULL ) {
126 printf( "Cannot open file: %s\n", apt_path.c_str());
130 while ( fggets(f, line, 250) != NULL ) {
131 // printf("%s", line);
132 if ( strlen(line) == 0 ) {
134 } else if ( line[0] == '#' ) {
136 } else if ( line[0] == '\t' ) {
138 runway_list.push_back(line);
140 // start of airport record
143 if ( last_airport.length() ) {
144 // process previous record
145 process_airport(last_airport, runway_list);
148 last_airport = airport;
152 if ( last_airport.length() ) {
153 // process previous record
154 process_airport(last_airport, runway_list);
165 // lon = -110.6642442;
167 // heading = 102.0 * DEG_TO_RAD;
174 elevation = 912 * FEET_TO_METER;
175 heading = 270.0 * DEG_TO_RAD;
179 gen_runway_area( lon * DEG_TO_RAD, lat * DEG_TO_RAD,
180 heading, length, width, nodes, &count );
182 fgBucketFind(lon, lat, &b);
183 printf( "Bucket = lon,lat = %d,%d x,y index = %d,%d\n",
184 b.lon, b.lat, b.x, b.y);
186 index = fgBucketGenIndex(&b);
187 fgBucketGenBasePath(&b, base);
188 sprintf(path, "%s/Scenery/%s", argv[1], base);
189 sprintf(command, "mkdir -p %s\n", path);
192 sprintf(exfile, "%s/%ld.node.ex", path, index);
193 sprintf(file, "%s/%ld.poly", path, index);
194 printf( "extra node file = %s\n", exfile);
195 printf( "poly file = %s\n", file);
197 // output extra nodes
198 if ( (fd = fopen(exfile, "w")) == NULL ) {
199 printf("Cannot open file: %s\n", exfile);
203 fprintf(fd, "%d 2 0 0\n", count);
204 for ( i = 0; i < count; i++ ) {
205 fprintf( fd, "%d %.2f %.2f %.2f\n", i + 1,
206 nodes[i].lon * RAD_TO_ARCSEC, nodes[i].lat * RAD_TO_ARCSEC,
212 if ( (fd = fopen(file, "w")) == NULL ) {
213 printf("Cannot open file: %s\n", file);
217 // output empty node list
218 fprintf(fd, "0 2 0 0\n");
221 fprintf(fd, "%d 0\n", count);
222 for ( i = 0; i < count - 1; i++ ) {
223 fprintf( fd, "%d %d %d\n", i + 1, i + 1, i + 2 );
225 fprintf( fd, "%d %d %d\n", count, count, 1 );
227 // output hole center
229 fprintf( fd, "1 %.2f %.2f\n", lon * 3600.0, lat * 3600);