fixed sh/qra so that it shows the correct lat/long
[spider.git] / cmd / show / satellite.pl
1 #!/usr/bin/perl
2 #
3 # show satellite az/el 
4 #
5 # copyright (c) 1999 Steve Franke K9AN
6 #
7 # $Id$
8
9
10 my ($self, $line) = @_;
11 my @out;
12
13 my @f = split /\s+/, $line;
14 my $satname = uc shift @f;
15 my $numhours = shift @f;               # the number of hours ahead to print
16 my $step = shift @f;                            # tracking table resolution in minutes
17
18 # default hours and step size
19 $numhours = 3 unless $numhours && $numhours =~ /^\d+$/;
20 $step = 5 unless $step && $step =~ /^\d+$/;
21
22 # get nearest lat and long (I can see we will need the altitude here soon as well :-)
23 my $lat = $self->user->lat;
24 my $lon = $self->user->long;
25 my $alt = 0;
26 my $call = $self->call;
27 unless ($lon || $lat) {
28         $lat = $main::mylatitude;
29         $lon = $main::mylongitude;
30         $call = $main::mycall;
31 }
32
33 if ($satname && $Sun::keps{$satname}) {
34         my $jtime; # lats and longs in radians
35         my ($sec, $min, $hr, $day, $mon, $yr) = (gmtime($main::systime))[0,1,2,3,4,5];
36         #printf("%2.2d %2.2d %2.2d %2.2d %2.2d\n",$min,$hr,$day,$mon,$yr);
37
38         $mon++;
39         $yr += 1900;
40         $alt=0.0;
41
42         $jtime=Sun::Julian_Day($yr,$mon,$day)+$hr/24+$min/60/24;
43         ($yr,$mon,$day,$hr,$min)=Sun::Calendar_date_and_time_from_JD($jtime);
44         #printf("%2.2d %2.2d %2.2d %2.2d %2.2d\n",$min,$hr,$day,$mon,$yr);
45         push @out, $self->msg("pos", $call, slat($lat), slong($lon));
46         push @out, $self->msg("sat1", $satname, $numhours, $step);
47         push @out, $self->msg("sat2");
48         
49         my ($slat,$slon,$salt,$az,$el,$distance)=Sun::get_satellite_pos($jtime,$lat*$d2r,$lon*$d2r,$alt,$satname);
50         # print the current satellite position
51         push @out,sprintf("Now   %2.2d:%2.2d %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f", 
52                                           $hr,$min,$slat*$r2d,$slon*$r2d,$salt,
53                                           $az*$r2d,$el*$r2d,$distance);
54
55         my $numsteps=0;
56         $jtime=$jtime+$step/24/60;
57         my $disc = 0;             # discontinuity flag
58         while ( $numsteps < $numhours*60/$step ) # look $numhours  ahead for tracking table
59         {
60                 my ($yr,$mon,$day,$hr,$min)=Sun::Calendar_date_and_time_from_JD($jtime);
61                 my ($slat,$slon,$salt,$az,$el,$distance)=Sun::get_satellite_pos($jtime,$lat*$d2r,$lon*$d2r,$alt,$satname);
62                 if ( $el*$r2d > -5 ) {
63                         if ($disc) {
64                                 $disc = 0;
65                                 push @out, $self->msg("satdisc");
66                         }
67                         push @out,sprintf("%2.2d/%2.2d %2.2d:%2.2d %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f", 
68                                                           $day,$mon,$hr,$min,$slat*$r2d,$slon*$r2d,$salt,
69                                                           $az*$r2d,$el*$r2d,$distance);
70                 } else {
71                         $disc++;
72                 }
73                 $numsteps++;
74                 $jtime=$jtime+$step/60/24;
75         }
76 } else {
77         push @out, $self->msg("satnf", $satname) if $satname;
78         push @out, $self->msg("sat3");
79         push @out, $self->msg("sat4");
80         my @l;
81         my $i = 0;
82         my $sat;
83         foreach $sat (sort keys %Sun::keps) {
84                 if ($i >= 6) {
85                         push @out, join ' + ', @l;
86                         @l = ();
87                         $i = 0;
88                 }
89                 push @l, $sat;
90                 $i++;
91         }
92         push @out, join ' + ', @l;
93 }
94
95 return (1,@out);
96
97
98
99
100
101
102
103
104
105
106