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";
25 my %loc = (); # the location unique hash
26 my $nextloc = 1; # the next location number
27 my %locn = (); # the inverse of the above
28 my %pre = (); # the prefix hash
29 my %pren = (); # the inverse
32 my $ifn = $ARGV[0] if $ARGV[0];
33 $ifn = "$main::data/wpxloc.raw" if !$ifn;
34 open (IN, $ifn) or die "can't open $ifn ($!)";
36 # first pass, find all the 'master' location records
38 next if /^\!/; # ignore comment lines
40 my @f = split; # get each 'word'
41 next if @f == 0; # ignore blank lines
43 if (($f[14] && $f[14] eq '@') || ($f[15] && $f[15] eq '@')) {
44 my $locstr = join ' ', @f[1..13];
45 my $loc = $loc{$locstr};
46 $loc = addloc($locstr) if !$loc;
50 #foreach $loc (sort {$a <=> $b;} keys %locn) {
51 # print "loc: $loc data: $locn{$loc}\n";
54 # go back to the beginning and this time add prefixes (adding new location entries, if required)
61 next if /^\s*\!/; # ignore comment lines
64 my @f = split; # get each 'word'
65 next if @f == 0; # ignore blank lines
68 my $locstr = join ' ', @f[1..13];
69 my $loc = $loc{$locstr};
70 $loc = addloc($locstr) if !$loc;
72 my @prefixes = split /,/, $f[0];
73 foreach my $p (@prefixes) {
78 for ($i = 0; $i < 9; ++$i) {
91 #print Data::Dumper->Dump([\%pre, \%locn], [qw(pre locn)]);
93 # now open the rsgb.cty file and process that again the prefix file we have
94 open(IN, "$main::data/rsgb.cty") or die "Can't open $main::data/rsgb.cty ($!)";
102 my @f = split /:\s+|;/;
106 # split up the alias string
107 my @alias = split /=/, $f[5];
109 foreach $a (@alias) {
110 next if $a eq $p; # ignore if we have it already
112 $pre{$a} = $ref if !$nref; # copy the original ref if new
115 print "line $line: unknown prefix '$p' on $l in rsgb.cty\n";
119 open(OUT, ">$main::data/prefix_data.pl") or die "Can't open $main::data/prefix_data.pl ($!)";
121 print OUT "\%pre = (\n";
122 foreach my $k (sort keys %pre) {
123 my $ans = printpre($k);
124 print OUT " '$k' => '$ans',\n";
128 print OUT "\n\%prefix_loc = (\n";
129 foreach my $l (sort {$a <=> $b} keys %locn) {
130 print OUT " $l => bless( {";
131 my ($name, $dxcc, $itu, $cq, $utcoff, $latd, $latm, $lats, $latl, $longd, $longm, $longs, $longl) = split /\s+/, $locn{$l};
133 $longd += ($longm/60);
134 $longd = 0-$longd if (uc $longl) eq 'W';
136 $latd = 0-$latd if (uc $latl) eq 'S';
137 print OUT " name => '$name',";
138 print OUT " dxcc => $dxcc,";
139 print OUT " itu => $itu,";
140 print OUT " cq => $cq,";
141 print OUT " utcoff => $utcoff,";
142 print OUT " lat => $latd,";
143 print OUT " long => $longd";
144 print OUT " }, 'Prefix'),\n";
154 $ref = $pre{$p} = [] if !$ref;
165 foreach $r (@{$ref}) {
175 $locstr =~ s/\'/\\'/g;
176 my $loc = $loc{$locstr} = $nextloc++;
177 $locn{$loc} = $locstr;