1. Sort out PC41 handling to include type 5 records for QRA locators and also
[spider.git] / cmd / show / qra.pl
1 #
2 # show the distance and bearing to a  QRA locator
3 #
4 # you can enter two qra locators and it will calc the distance between them
5 #
6 # $Id$
7 #
8
9 my ($self, $line) = @_;
10 my @list = split /\s+/, $line;                # generate a list of callsigns
11 return (1, $self->msg('qrashe1')) unless @list > 0;
12
13 my @out;
14
15 # every thing is dealt with in upper case
16 $line = uc $line;
17
18 # convert a lat/long into a qra locator if we see a pattern looking like a lat/long
19 if (is_latlong($line)) {
20         my ($llat, $llong) = DXBearing::stoll(uc $line);
21         return (1, "QRA $line = " . DXBearing::lltoqra($llat, $llong)); 
22 }
23
24 # get the user's lat/long else the cluster's (and whinge about it)
25 my $lat = $self->user->lat;
26 my $long = $self->user->long;
27 if (!$long && !$lat) {
28         push @out, $self->msg('heade1');
29         $lat = $main::mylatitude;
30         $long = $main::mylongitude;
31 }
32
33 unshift @list, $self->user->qra if @list == 1 && $self->user->qra;
34 unshift @list, DXBearing::lltoqra($lat, $long) unless @list > 1;
35
36 # check from qra
37 my $f = uc $list[0];
38 $f .= 'MM' if $f =~ /^[A-Z][A-Z]\d\d$/;
39 return (1, $self->msg('qrae2', $f)) unless is_qra($f);
40 ($lat, $long) = DXBearing::qratoll($f);
41
42 # check to qra
43 my $l = uc $list[1];
44 $l .= 'MM' if $l =~ /^[A-Z][A-Z]\d\d$/;
45 return (1, $self->msg('qrae2', $l)) unless is_qra($l);
46 my ($qlat, $qlong) = DXBearing::qratoll($l);
47
48 # generate alpha lat/long
49 my $fll = DXBearing::lltos($lat, $long);
50 $fll =~ s/\s+([NSEW])/$1/g;
51 my $tll = DXBearing::lltos($qlat, $qlong);
52 $tll =~ s/\s+([NSEW])/$1/g;
53
54 # calc bearings and distances 
55 my ($b, $dx) = DXBearing::bdist($lat, $long, $qlat, $qlong);
56 my ($r, $rdx) = DXBearing::bdist($qlat, $qlong, $lat, $long);
57 my $to = '';
58
59 $to = "->\U$list[1]($tll)" if $f;
60 my $from = "\U$list[0]($fll)" ;
61
62 push @out, sprintf "$from$to To: %.0f Fr: %.0f Dst: %.0fMi %.0fKm", $b, $r, $dx * 0.62133785, $dx;
63
64 return (1, @out);
65