#! /usr/bin/perl # base36test.pl - Test of looking-up Amateur Radio DXCC entities via callsign prefixes # lu6.pl requires a complete callsign to query QRZ.com, # but also returns more details. This script was developed # to be used when only a partial callsign was heard # Callsigns are composed of the characters [0..9] [A..Z] # Prefixes can be 1,2, or 3 characters # Each country or entity has been assigned a unique prefix # It was noticed that combinations of these ranges may be # interpreted as Base36 numbers. This provided for a # simplified numerical search # A table of DXCC entities(dxcc.txt) was downloaded from ARRL.COM # and was cleaned up a little and arranged in alphabetical order. # builddxcctable() creates a Base36 encoded version of this table # where beginning and ending prefix strings are converted # to Base36 numbers for comparison against a Base36 encoded prefix # finddxcc() searches the Base36 table and returns the entity name # linear search through the table ranges(300 +/- rows) # # James M. Lynes Jr. - KE4MIQ # Created: February 22, 2023 # Last Modified: 02/22/2023 - First version created # - command line version # # Environment: Ubuntu 22.04LTS # Notes: Install Perl Tk and Non-Core Modules # sudo apt update # sudo apt install perl-tk # cpanm Math::Base36 # # DXCC - DX(long distance) Century Club # A certificate earned by contacting 100 countries/entities # Outside of your home country # use Math::Base36 ':all'; use Text::Tabs; my @dxcc; # DXCC table builddxcctable(); # Build table of DXCC entities while(1) { # Loop for entity entry print "\nEnter a DXCC Prefix(ke): "; my $prefix = ; chomp($prefix); if(length($prefix) == 1) { # Entries may be 1,2, or 3 characters $prefix = uc($prefix) . 'AA'; # Pad with A's TO 3 characters } elsif(length($prefix) == 2) { $prefix = uc($prefix) . 'A'; } my $base36num = decode_base36($prefix); # Encode entry into Base36 my $entity = finddxcc($base36num); # Search for entry print "$entity\n"; } # # Read dxcc.txt file and build the DXCC lookup table in Base36 # sub builddxcctable { open(my $fh, '<', 'dxcc.txt'); while(defined(my $line = <$fh>)) { chomp($line); $line = expand($line); my $len = length($line) -1; my $bcall = substr($line, 0, 3); my $ecall = substr($line, 4, 3); my $desc = substr($line ,16, $len); # Entity name my $dbcall = decode_base36($bcall); # Base36 prefix range beginning my $decall = decode_base36($ecall); # Base36 prefix range end push(@dxcc, [$dbcall, $decall, $desc]); } close($fh); } # # Linear search the DXCC table for a match with entered Base36 encoded prefix # sub finddxcc { my($base) = @_; my $dx; for my $i(0 .. $#dxcc) { next if($dxcc[$i][1] < $base); $dx = $dxcc[$i][2]; last; } return $dx; }