2 # a program to create a prefix file from a wpxloc.raw file
4 # Copyright (c) - Dirk Koopman G1TLH
11 # search local then perl directories
13 # root of directory tree for this system
15 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
17 unshift @INC, "$root/perl"; # this IS the right way round!
18 unshift @INC, "$root/local";
26 my %loc = (); # the location unique hash
27 my $nextloc = 1; # the next location number
28 my %locn = (); # the inverse of the above
29 my %pre = (); # the prefix hash
30 my %pren = (); # the inverse
33 my $ifn = $ARGV[0] if $ARGV[0];
34 $ifn = "$main::data/wpxloc.raw" if !$ifn;
35 open (IN, $ifn) or die "can't open $ifn ($!)";
37 # first pass, find all the 'master' location records
39 next if /^\!/; # ignore comment lines
41 my @f = split; # get each 'word'
42 next if @f == 0; # ignore blank lines
44 if (($f[14] && $f[14] eq '@') || ($f[15] && $f[15] eq '@')) {
45 my $locstr = join ' ', @f[1..13];
46 my $loc = $loc{$locstr};
47 $loc = addloc($locstr) if !$loc;
51 #foreach $loc (sort {$a <=> $b;} keys %locn) {
52 # print "loc: $loc data: $locn{$loc}\n";
55 # go back to the beginning and this time add prefixes (adding new location entries, if required)
62 next if /^\s*\!/; # ignore comment lines
65 my @f = split; # get each 'word'
66 next if @f == 0; # ignore blank lines
69 my $locstr = join ' ', @f[1..13];
70 my $loc = $loc{$locstr};
71 $loc = addloc($locstr) if !$loc;
73 my @prefixes = split /,/, $f[0];
74 foreach my $p (@prefixes) {
79 for ($i = 0; $i < 9; ++$i) {
92 #print Data::Dumper->Dump([\%pre, \%locn], [qw(pre locn)]);
94 # now open the cty.dat file if it is there
98 if (open(IN, "$main::data/cty.dat")) {
111 } elsif ($state == 1) {
116 push @a, split /\s*,/;
117 $f[7] =~ s/^\*\s*//; # remove any preceeding '*' before a callsign
118 ct($_, uc $f[7], @a) if @a;
121 push @a, split /\s*,/;
129 open(OUT, ">$main::data/prefix_data.pl") or die "Can't open $main::data/prefix_data.pl ($!)";
131 print OUT "\%pre = (\n";
132 foreach my $k (sort keys %pre) {
133 my $ans = printpre($k);
134 print OUT " '$k' => '$ans',\n";
138 print OUT "\n\%prefix_loc = (\n";
139 foreach my $l (sort {$a <=> $b} keys %locn) {
140 print OUT " $l => bless( {";
141 my ($name, $dxcc, $itu, $cq, $utcoff, $latd, $latm, $lats, $latl, $longd, $longm, $longs, $longl) = split /\s+/, $locn{$l};
143 $longd += ($longm/60);
144 $longd = 0-$longd if (uc $longl) eq 'W';
146 $latd = 0-$latd if (uc $latl) eq 'S';
147 print OUT " name => '$name',";
148 print OUT " dxcc => $dxcc,";
149 print OUT " itu => $itu,";
150 print OUT " cq => $cq,";
151 print OUT " utcoff => $utcoff,";
152 print OUT " lat => $latd,";
153 print OUT " long => $longd";
154 print OUT " }, 'Prefix'),\n";
164 $ref = $pre{$p} = [] if !$ref;
175 foreach $r (@{$ref}) {
191 # for now remove (nn) [nn]
192 my ($itu) = $a =~ /(\(\d+\))/; $a =~ s/(\(\d+\))//g;
193 my ($cq) = $a =~ /(\[\d+\])/; $a =~ s/(\[\d+\])//g;
194 my ($lat, $long) = $a =~ m{(<[-+\d.]+/[-+\d.]+>)}; $a =~ s{(<[-+\d.]+/[-+\d.]+>)}{}g;
195 my ($cont) = $a =~ /(\{[A-Z]{2}\})/; $a =~ s/(\{[A-Z]{2}\})//g;
198 print "line $line: blank prefix on $l in cty.dat\n";
201 next if $a eq $p; # ignore if we have it already
203 $pre{$a} = $ref if !$nref; # copy the original ref if new
206 print "line $line: unknown prefix '$p' on $l in cty.dat\n";
213 $locstr =~ s/\'/\\'/g;
214 my $loc = $loc{$locstr} = $nextloc++;
215 $locn{$loc} = $locstr;