2 # a program to create a prefix file from a wpxloc.raw file
4 # Copyright (c) - Dirk Koopman G1TLH
12 %loc = (); # the location unique hash
13 $nextloc = 1; # the next location number
14 %locn = (); # the inverse of the above
15 %pre = (); # the prefix hash
16 %pren = (); # the inverse
19 $ifn = $ARGV[0] if $ARGV[0];
20 $ifn = "$data/wpxloc.raw" if !$fn;
21 open (IN, $ifn) or die "can't open $ifn ($!)";
23 # first pass, find all the 'master' location records
25 next if /^\!/; # ignore comment lines
27 @f = split; # get each 'word'
28 next if @f == 0; # ignore blank lines
30 if ($f[14] eq '@' || $f[15] eq '@') {
31 $locstr = join ' ', @f[1..13];
33 $loc = addloc($locstr) if !$loc;
37 #foreach $loc (sort {$a <=> $b;} keys %locn) {
38 # print "loc: $loc data: $locn{$loc}\n";
41 # go back to the beginning and this time add prefixes (adding new location entries, if required)
46 next if /^\!/; # ignore comment lines
48 @f = split; # get each 'word'
49 next if @f == 0; # ignore blank lines
52 $locstr = join ' ', @f[1..13];
54 $loc = addloc($locstr) if !$loc;
56 @prefixes = split /,/, $f[0];
57 foreach $p (@prefixes) {
62 for ($i = 0; $i < 9; ++$i) {
75 #print Data::Dumper->Dump([\%pre, \%locn], [qw(pre locn)]);
77 # now open the rsgb.cty file and process that again the prefix file we have
78 open(IN, "$data/rsgb.cty") or die "Can't open $data/rsgb.cty ($!)";
85 # split up the alias string
86 my @alias = split /=/, $f[5];
89 next if $a eq $p; # ignore if we have it already
91 $pre{$a} = $ref if !$nref; # copy the original ref if new
94 print "unknown prefix $p\n";
98 open(OUT, ">$data/prefix_data.pl") or die "Can't open $data/prefix_data.pl ($!)";
100 print OUT "\%pre = (\n";
101 foreach $k (sort keys %pre) {
102 my $ans = printpre($k);
103 print OUT " '$k' => '$ans',\n";
107 print OUT "\n\%prefix_loc = (\n";
108 foreach $l (sort {$a <=> $b} keys %locn) {
109 print OUT " $l => bless( {";
110 my ($name, $dxcc, $itu, $cq, $utcoff, $latd, $latm, $lats, $latl, $longd, $longm, $longs, $longl) = split /\s+/, $locn{$l};
112 $longd += ($longm/60);
113 $longd = 0-$longd if (uc $longl) eq 'W';
115 $latd = 0-$latd if (uc $latl) eq 'S';
116 print OUT " name => '$name',";
117 print OUT " dxcc => $dxcc,";
118 print OUT " itu => $itu,";
119 print OUT " cq => $cq,";
120 print OUT " utcoff => $utcoff,";
121 print OUT " lat => $latd,";
122 print OUT " long => $longd";
123 print OUT " }, 'Prefix'),\n";
133 $ref = $pre{$p} = [] if !$ref;
144 foreach $r (@{$ref}) {
154 $locstr =~ s/\'/\\'/g;
155 my $loc = $loc{$locstr} = $nextloc++;
156 $locn{$loc} = $locstr;