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>
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;
54 int len, width, hdg, label_hdg, elev;
58 printf( "(apt) %s", last_airport.c_str() );
60 while ( runway_list.size() ) {
61 line_str = runway_list.front();
62 runway_list.pop_front();
63 printf( "%s", line_str.c_str() );
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,
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 );
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);
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 );
96 // reads the apt_full file and extracts and processes the individual
98 int main( int argc, char **argv ) {
99 list < string > runway_list;
100 string apt_path, gz_apt_path;
101 string airport, last_airport;
107 char base[256], path[256], command[256], file[256], exfile[256];
108 double lon, lat, elevation, heading;
109 double length, width;
114 printf("Usage %s <apt_file> <work dir>\n", argv[0]);
119 gz_apt_path = apt_path + ".gz";
121 // first try "path.gz"
122 if ( (f = fgopen(gz_apt_path.c_str(), "rb")) == NULL ) {
124 if ( (f = fgopen(apt_path.c_str(), "rb")) == NULL ) {
125 printf( "Cannot open file: %s\n", apt_path.c_str());
129 while ( fggets(f, line, 250) != NULL ) {
130 // printf("%s", line);
131 if ( strlen(line) == 0 ) {
133 } else if ( line[0] == '#' ) {
135 } else if ( line[0] == '\t' ) {
137 runway_list.push_back(line);
139 // start of airport record
142 if ( last_airport.length() ) {
143 // process previous record
144 process_airport(last_airport, runway_list);
147 last_airport = airport;
151 if ( last_airport.length() ) {
152 // process previous record
153 process_airport(last_airport, runway_list);
164 // lon = -110.6642442;
166 // heading = 102.0 * DEG_TO_RAD;
173 elevation = 912 * FEET_TO_METER;
174 heading = 270.0 * DEG_TO_RAD;
178 gen_runway_area( lon * DEG_TO_RAD, lat * DEG_TO_RAD,
179 heading, length, width, nodes, &count );
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);
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);
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);
196 // output extra nodes
197 if ( (fd = fopen(exfile, "w")) == NULL ) {
198 printf("Cannot open file: %s\n", exfile);
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,
211 if ( (fd = fopen(file, "w")) == NULL ) {
212 printf("Cannot open file: %s\n", file);
216 // output empty node list
217 fprintf(fd, "0 2 0 0\n");
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 );
224 fprintf( fd, "%d %d %d\n", count, count, 1 );
226 // output hole center
228 fprintf( fd, "1 %.2f %.2f\n", lon * 3600.0, lat * 3600);