| 1 |
#! /usr/bin/perl -w |
| 2 |
|
| 3 |
sub usage { |
| 4 |
print <<EoF; |
| 5 |
Read the apt.dat (or apt.dat.gz) file. |
| 6 |
Remap airport names to remove ugly abbreviations. |
| 7 |
Print airport names, one per line. |
| 8 |
|
| 9 |
Remapping is done by reference to the atis_remap.hxx file. |
| 10 |
|
| 11 |
Typical usage: |
| 12 |
FG_ROOT=whatever FG_SRC=whatever ATIS_ONLY=yes ./list-airports.pl | ./words_per_line.sh > airports.vlist |
| 13 |
EoF |
| 14 |
} |
| 15 |
|
| 16 |
use strict; |
| 17 |
use Symbol; |
| 18 |
|
| 19 |
my $noparen = 1; |
| 20 |
my $verbose = 0; |
| 21 |
my $apt_name = ''; |
| 22 |
my $lat; |
| 23 |
my $lon; |
| 24 |
my $atis; |
| 25 |
my $country = ''; |
| 26 |
my $elev; |
| 27 |
my $tower; |
| 28 |
my $bldgs; |
| 29 |
my $apt_id; |
| 30 |
my $shapefile; |
| 31 |
my $namer = 'NAME'; |
| 32 |
my $skipping = 0; |
| 33 |
my $tot_apts = 0; |
| 34 |
|
| 35 |
my %states = (); |
| 36 |
my %short_country = (); |
| 37 |
|
| 38 |
|
| 39 |
my $fgroot = $ENV{'FG_ROOT'} || '.'; |
| 40 |
my $atis_only = $ENV{'ATIS_ONLY'} || 0; |
| 41 |
my $mapfn = "$ENV{'FG_SRC'}/src/ATCDCL/atis_remap.hxx"; |
| 42 |
|
| 43 |
sub process_apt { |
| 44 |
if ($atis_only && ! $atis) { |
| 45 |
return; |
| 46 |
} |
| 47 |
my $str .= $apt_name; |
| 48 |
|
| 49 |
$str =~ s' *$''; ## remove trailing spaces |
| 50 |
if ($noparen) { |
| 51 |
$str =~ s/[(][^)]*[)]?//g; |
| 52 |
} |
| 53 |
print "$str\n"; |
| 54 |
$tot_apts++; |
| 55 |
} |
| 56 |
|
| 57 |
my %remap = (); |
| 58 |
|
| 59 |
sub get_remap { |
| 60 |
|
| 61 |
# Note: in this context, GKI probably stands for Gereja Kristen Indonesia |
| 62 |
# I guess the church builds lots of airports. |
| 63 |
|
| 64 |
my $mapch = Symbol::gensym; |
| 65 |
if (!open($mapch, '<', $mapfn)) { |
| 66 |
print STDERR "Could not open abbreviation file '$mapfn'\n"; |
| 67 |
print STDERR "Maybe you need to set FG_ROOT\n"; |
| 68 |
exit(1); |
| 69 |
} |
| 70 |
while (my $line = <$mapch>) { |
| 71 |
chomp $line; |
| 72 |
if ($line =~ s/[ \t]*REMAP[(]//) { |
| 73 |
$line =~ s/[)][ \t]*$//; |
| 74 |
my @stuff = split(',', $line, 2); |
| 75 |
my $from = $stuff[0]; |
| 76 |
my $to = $stuff[1]; |
| 77 |
$to =~ s/^[ \t]*//; |
| 78 |
if ($to eq 'NIL') { |
| 79 |
$to = ''; |
| 80 |
} |
| 81 |
$remap{$from} = $to; |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
main: { |
| 87 |
if (@ARGV) { |
| 88 |
usage; |
| 89 |
exit; |
| 90 |
} |
| 91 |
|
| 92 |
get_remap; |
| 93 |
|
| 94 |
my $delim = '-'; |
| 95 |
my $fgroot = $ENV{'FG_ROOT'} || 0; |
| 96 |
my $incmd = "zcat $fgroot/Airports/apt.dat.gz"; |
| 97 |
my $inch = Symbol::gensym; |
| 98 |
open ($inch, '-|', $incmd) |
| 99 |
|| die "Couldn't open pipe from '$incmd'\n"; |
| 100 |
|
| 101 |
|
| 102 |
my $junk = <$inch>; |
| 103 |
$junk = <$inch>; |
| 104 |
liner: while (my $line = <$inch>) { |
| 105 |
chomp $line; |
| 106 |
my @stuff = split(' ', $line); |
| 107 |
my $type = shift @stuff || 0; |
| 108 |
### print "..$type ... $line ...\n"; |
| 109 |
|
| 110 |
if ($type == 1) { |
| 111 |
## Here if new airport. |
| 112 |
## |
| 113 |
## First, print results of previous work, i.e. airport |
| 114 |
## stanzas already seen ... since the apt.dat file |
| 115 |
## doesn't have a clear way of signaling the end of a stanza. |
| 116 |
if ($apt_name) { |
| 117 |
process_apt(); |
| 118 |
} |
| 119 |
$apt_name = ''; |
| 120 |
$atis = ''; |
| 121 |
$lat = 0; |
| 122 |
$lon = 0; |
| 123 |
$country = ''; |
| 124 |
|
| 125 |
$elev = shift @stuff; |
| 126 |
$tower = shift @stuff; |
| 127 |
$bldgs = shift @stuff; |
| 128 |
$apt_id = shift @stuff; |
| 129 |
my $name = join $delim, @stuff; |
| 130 |
|
| 131 |
for my $from (keys %remap) { |
| 132 |
my $to = $remap{$from}; |
| 133 |
$name =~ s/\b$from\b/$to/gi; |
| 134 |
} |
| 135 |
|
| 136 |
## option for plain words, not hyphenated phrases |
| 137 |
if (1) { |
| 138 |
$name =~ s/$delim/ /g; |
| 139 |
} |
| 140 |
|
| 141 |
$apt_name = "$name"; |
| 142 |
} |
| 143 |
|
| 144 |
if ($type == 10) { |
| 145 |
$lat = $stuff[0]; |
| 146 |
$lon = $stuff[1]; |
| 147 |
} |
| 148 |
|
| 149 |
if ($type == 50) { |
| 150 |
$atis = join(' ', @stuff); |
| 151 |
} |
| 152 |
} |
| 153 |
process_apt(); ## flush out the very last one |
| 154 |
print STDERR "Total airports: $tot_apts\n"; |
| 155 |
} |