changed pc50 logic
[spider.git] / cmd / show / moon.pl
1 #!/usr/bin/perl
2 #
3 # show sunrise and sunset times for each callsign or prefix entered
4 #
5 # 1999/11/9 Steve Franke K9AN
6 #
7
8 my ($self, $line) = @_;
9 my @list = split /\s+/, $line;
10
11 my $l;
12 my @out;
13 my ($lat, $lon);              # lats and longs in radians
14 my ($sec, $min, $hr, $day, $month, $yr) = (gmtime($main::systime))[0,1,2,3,4,5];
15 $month++;
16 $yr += 1900;
17
18 my @in;
19
20 if (@list) {
21         foreach $l (@list) {
22                 my $user = DXUser->get_current(uc $l);
23                 if ($user && $user->lat && $user->long) {
24                         push @in, [$user->qth, $user->lat * $d2r, $user->long * -$d2r, uc $l ];
25                 } else {
26                         # prefixes --->
27                         my @ans = Prefix::extract($l);
28                         next if !@ans;
29                         my $pre = shift @ans;
30                         my $a;
31                         foreach $a (@ans) {
32                                 $lat = $a->{lat};
33                                 $lon = -$a->{long};
34                                 push @in, [ $a->name, $lat, $lon, $pre ];
35                         }
36                 }
37         }
38 } else {
39         if ($self->user->lat && $self->user->long) {
40                 push @in, [$self->user->qth, $self->user->lat, -$self->user->long, $self->call ];
41         } else {
42                 push @in, [$main::myqth, $main::mylatitude, -$main::mylongitude, $main::mycall ];
43         }
44 }
45
46 push @out, $self->msg('moon');
47
48 foreach $l (@in) {
49         my ($rise, $set, $az, $dec, $loss )=Sun::rise_set($yr,$month,$day,$hr,$min,$l->[1],$l->[2],1);
50         $l->[3] =~ s{(-\d+|/\w+)$}{};
51         push @out,sprintf("%-6.6s %-30.30s %s %s %6.1f %6.1f      %3.1f", $l->[3], $l->[0], $rise, $set, $az, $dec, $loss);
52 }
53
54                         
55
56 return (1, @out);