X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2Fcreate_prefix.pl;h=d87cf14412ec357701757943e0ae7ce318006617;hb=7d4b15681464d77945e7ea78ef60ed3305d57d95;hp=edfc3a0c1c548c17dcdbd8d5ac08dee4e4e8b6b6;hpb=43aae2e09b38a7a275516be724a718b894b7c492;p=spider.git diff --git a/perl/create_prefix.pl b/perl/create_prefix.pl index edfc3a0c..d87cf144 100755 --- a/perl/create_prefix.pl +++ b/perl/create_prefix.pl @@ -1,25 +1,32 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # a program to create a prefix file from a wpxloc.raw file # # Copyright (c) - Dirk Koopman G1TLH # -# $Id$ +# # -require 5.004; +use 5.10.1; # search local then perl directories BEGIN { # root of directory tree for this system $root = "/spider"; $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'}; - + + mkdir "$root/local_data", 02777 unless -d "$root/local_data"; + unshift @INC, "$root/perl"; # this IS the right way round! unshift @INC, "$root/local"; } use DXVars; +use SysVar; + use Data::Dumper; +use DXUtil; +use DXBearing; + use strict; my %loc = (); # the location unique hash @@ -28,10 +35,26 @@ my %locn = (); # the inverse of the above my %pre = (); # the prefix hash my %pren = (); # the inverse -# open the input file -my $ifn = $ARGV[0] if $ARGV[0]; -$ifn = "$main::data/wpxloc.raw" if !$ifn; -open (IN, $ifn) or die "can't open $ifn ($!)"; +my $prefix; +my $system; + +if (@ARGV && $ARGV[0] =~ /^-?-?syst?e?m?$/) { + $prefix = $main::data; + ++$system; + shift; + say "create_prefix.pl: creating SYSTEM prefix files"; +} else { + $prefix = $main::local_data; + say "create_prefix.pl: creating LOCAL prefix files"; +} + +my $ifn; + +$ifn = $system ? "$main::data/wpxloc.raw" : "$prefix/wpxloc.raw"; +unless (open (IN, $ifn)) { + $ifn = "$main::data/wpxloc.raw"; + open(IN, $ifn) or die "can't open $ifn ($!)"; +} # first pass, find all the 'master' location records while () { @@ -90,38 +113,18 @@ close(IN); #print Data::Dumper->Dump([\%pre, \%locn], [qw(pre locn)]); -# now open the rsgb.cty file and process that again the prefix file we have -open(IN, "$main::data/rsgb.cty") or die "Can't open $main::data/rsgb.cty ($!)"; -$line = 0; -while () { - $line++; - next if /^\s*#/; - next if /^\s*$/; - my $l = $_; - chomp; - my @f = split /:\s+|;/; - my $p = uc $f[4]; - my $ref = $pre{$p}; - if ($ref) { - # split up the alias string - my @alias = split /=/, $f[5]; - my $a; - foreach $a (@alias) { - next if $a eq $p; # ignore if we have it already - my $nref = $pre{$a}; - $pre{$a} = $ref if !$nref; # copy the original ref if new - } - } else { - print "line $line: unknown prefix '$p' on $l in rsgb.cty\n"; - } +# now open the cty.dat file if it is there +my $r; +$ifn = $system ? "$main::data/cty.dat" : "$prefix/cty.dat"; +unless ($r = open (IN, $ifn)) { + $ifn = "$main::data/cty.dat"; + $r = open(IN, $ifn); } -close IN; -# now open the cty.dat file if it is there my @f; my @a; $line = 0; -if (open(IN, "$main::data/cty.dat")) { +if ($r) { my $state = 0; while () { $line++; @@ -140,7 +143,7 @@ if (open(IN, "$main::data/cty.dat")) { $state = 0; s/[,;]$//; push @a, split /\s*,/; - next if $f[7] =~ /^\*/; # ignore callsigns starting '*' + $f[7] =~ s/^\*\s*//; # remove any preceeding '*' before a callsign ct($_, uc $f[7], @a) if @a; } else { s/,$//; @@ -152,7 +155,7 @@ if (open(IN, "$main::data/cty.dat")) { close IN; -open(OUT, ">$main::data/prefix_data.pl") or die "Can't open $main::data/prefix_data.pl ($!)"; +open(OUT, ">$prefix/prefix_data.pl") or die "Can't open $prefix/prefix_data.pl ($!)"; print OUT "\%pre = (\n"; foreach my $k (sort keys %pre) { @@ -170,6 +173,7 @@ foreach my $l (sort {$a <=> $b} keys %locn) { $longd = 0-$longd if (uc $longl) eq 'W'; $latd += ($latm/60); $latd = 0-$latd if (uc $latl) eq 'S'; + my $qra = DXBearing::lltoqra($latd, $longd); print OUT " name => '$name',"; print OUT " dxcc => $dxcc,"; print OUT " itu => $itu,"; @@ -177,6 +181,7 @@ foreach my $l (sort {$a <=> $b} keys %locn) { print OUT " utcoff => $utcoff,"; print OUT " lat => $latd,"; print OUT " long => $longd"; + print OUT " qra => $qra"; print OUT " }, 'Prefix'),\n"; } print OUT ");\n\n"; @@ -215,7 +220,11 @@ sub ct my $a; foreach $a (@a) { # for now remove (nn) [nn] - $a =~ s/(?:\(\d+\)|\[\d+\])//g; + my ($itu) = $a =~ /(\(\d+\))/; $a =~ s/(\(\d+\))//g; + my ($cq) = $a =~ /(\[\d+\])/; $a =~ s/(\[\d+\])//g; + my ($lat, $long) = $a =~ m{(<[-+\d.]+/[-+\d.]+>)}; $a =~ s{(<[-+\d.]+/[-+\d.]+>)}{}g; + my ($cont) = $a =~ /(\{[A-Z]{2}\})/; $a =~ s/(\{[A-Z]{2}\})//g; + unless ($a) { print "line $line: blank prefix on $l in cty.dat\n"; next;