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";
24 %loc = (); # the location unique hash
25 $nextloc = 1; # the next location number
26 %locn = (); # the inverse of the above
27 %pre = (); # the prefix hash
28 %pren = (); # the inverse
31 $ifn = $ARGV[0] if $ARGV[0];
32 $ifn = "$data/wpxloc.raw" if !$fn;
33 open (IN, $ifn) or die "can't open $ifn ($!)";
35 # first pass, find all the 'master' location records
37 next if /^\!/; # ignore comment lines
39 @f = split; # get each 'word'
40 next if @f == 0; # ignore blank lines
42 if ($f[14] eq '@' || $f[15] eq '@') {
43 $locstr = join ' ', @f[1..13];
45 $loc = addloc($locstr) if !$loc;
49 #foreach $loc (sort {$a <=> $b;} keys %locn) {
50 # print "loc: $loc data: $locn{$loc}\n";
53 # go back to the beginning and this time add prefixes (adding new location entries, if required)
58 next if /^\!/; # ignore comment lines
60 @f = split; # get each 'word'
61 next if @f == 0; # ignore blank lines
64 $locstr = join ' ', @f[1..13];
66 $loc = addloc($locstr) if !$loc;
68 @prefixes = split /,/, $f[0];
69 foreach $p (@prefixes) {
74 for ($i = 0; $i < 9; ++$i) {
87 #print Data::Dumper->Dump([\%pre, \%locn], [qw(pre locn)]);
89 # now open the rsgb.cty file and process that again the prefix file we have
90 open(IN, "$data/rsgb.cty") or die "Can't open $data/rsgb.cty ($!)";
97 # split up the alias string
98 my @alias = split /=/, $f[5];
100 foreach $a (@alias) {
101 next if $a eq $p; # ignore if we have it already
103 $pre{$a} = $ref if !$nref; # copy the original ref if new
106 print "unknown prefix $p\n";
110 open(OUT, ">$data/prefix_data.pl") or die "Can't open $data/prefix_data.pl ($!)";
112 print OUT "\%pre = (\n";
113 foreach $k (sort keys %pre) {
114 my $ans = printpre($k);
115 print OUT " '$k' => '$ans',\n";
119 print OUT "\n\%prefix_loc = (\n";
120 foreach $l (sort {$a <=> $b} keys %locn) {
121 print OUT " $l => bless( {";
122 my ($name, $dxcc, $itu, $cq, $utcoff, $latd, $latm, $lats, $latl, $longd, $longm, $longs, $longl) = split /\s+/, $locn{$l};
124 $longd += ($longm/60);
125 $longd = 0-$longd if (uc $longl) eq 'W';
127 $latd = 0-$latd if (uc $latl) eq 'S';
128 print OUT " name => '$name',";
129 print OUT " dxcc => $dxcc,";
130 print OUT " itu => $itu,";
131 print OUT " cq => $cq,";
132 print OUT " utcoff => $utcoff,";
133 print OUT " lat => $latd,";
134 print OUT " long => $longd";
135 print OUT " }, 'Prefix'),\n";
145 $ref = $pre{$p} = [] if !$ref;
156 foreach $r (@{$ref}) {
166 $locstr =~ s/\'/\\'/g;
167 my $loc = $loc{$locstr} = $nextloc++;
168 $locn{$loc} = $locstr;