The PHP script for this calulator was written by Dipl.-Phys. Arvin Schnell and Dipl.-Ing. Günter W. Schnell, using the equations discussed below.
Perl Script
#!/usr/bin/perl -w use strict; use Math::Trig; my @loc; $loc[0] = uc "JO43LD"; # Replace with your own Locator! print "\nReference locator is $loc[0]\n\nEnter: "; while (<>) { chomp; s/\s+//g; exit if /^exit$|^quit$/; if (/help/) { &help } elsif (/-r([A-R]{2}\d\d[A-X]{2})/i) { $loc[0] = uc $1; print "\nReference locator is $loc[0]\n\nEnter: "; next } elsif (/([A-R]{2}\d\d[A-X]{2})/i) { $loc[1] = uc $1; &doit } elsif (/(\d\d[A-X]{2})/i) { $loc[1] = uc substr ($loc[0], 0, 2).$1; &doit } else { print "\nNot a valid locator!\n" } print "\nEnter: "; } sub doit { my (@lng, @lat); for (0..1) { my @pos = unpack 'C6', $loc[$_]; $lng[$_] = deg2rad (-1581.375 + $pos[0] * 20 + $pos[2] * 2 + $pos[4]/12); $lat[$_] = deg2rad (-790.6875 + $pos[1] * 10 + $pos[3] + $pos[5]/24); } my $tmp = sin ($lat[0]) * sin ($lat[1]) + cos ($lat[0]) * cos ($lat[1]) * cos ($lng[1] - $lng[0]); my $dist = int (111.2 * rad2deg (acos ($tmp < 1 ? $tmp : 1)) + 0.5); $tmp = atan2 (sin ($lng[1] - $lng[0]), sin ($lat[0]) * cos ($lng[1] - $lng[0]) - cos ($lat[0]) * tan ($lat[1])); my $azim = $dist ? int (180 - rad2deg ($tmp) + 0.5) : 0; printf "\n Distance from %s to %s is %s km\n Azimuth seen from %s is %s deg\n", @loc, $dist, $loc[0], $azim; } sub help { my $help = <<HELP; [target locator] (4 or 6 digits) calculates distance and azimuth of target locator with respect to reference locator (currently $loc[0]). If prefix is omitted, the current reference locator\'s prefix is inserted. [<-r> reference locator] (6 digits) temporarily redefines reference locator. Redefine reference locator permanently by editing line 8. [<help>] shows this text. [<exit> or <quit>] exits this program. HELP for ($help) { s|<|\033[1m|go; s|>|\033[m|go } print $help; } # Author: Wolf, DL6BCT (Jan 2002)
Example: Calculate distance and azimuth from JO43LD to IO87UJ, seen from JO43LD.
Reference locator is JO43LD Enter: io87uj Distance from JO43LD to IO87UJ is 854 km Azimuth seen from JO43LD is 308 deg Enter: