bit more tidying up
[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 $numhours = 3 if $numhours < 0;
21 $numhours = 24 if $numhours > 24;
22 $step = 5 unless $step && $step =~ /^\d+$/;
23 $step = 5 if $step < 0;
24 $step = 30 if $step > 30;
25
26 # get nearest lat and long (I can see we will need the altitude here soon as well :-)
27 my $lat = $self->user->lat;
28 my $lon = $self->user->long;
29 my $alt = 0;
30 my $call = $self->call;
31 unless ($lon || $lat) {
32         $lat = $main::mylatitude;
33         $lon = $main::mylongitude;
34         $call = $main::mycall;
35 }
36
37 if ($satname && $Sun::keps{$satname}) {
38         my $jtime; # lats and longs in radians
39         my ($sec, $min, $hr, $day, $mon, $yr) = (gmtime($main::systime))[0,1,2,3,4,5];
40         #printf("%2.2d %2.2d %2.2d %2.2d %2.2d\n",$min,$hr,$day,$mon,$yr);
41
42         $mon++;
43         $yr += 1900;
44         $alt=0.0;
45
46         $jtime=Sun::Julian_Day($yr,$mon,$day)+$hr/24+$min/60/24;
47         ($yr,$mon,$day,$hr,$min)=Sun::Calendar_date_and_time_from_JD($jtime);
48         #printf("%2.2d %2.2d %2.2d %2.2d %2.2d\n",$min,$hr,$day,$mon,$yr);
49         push @out, $self->msg("pos", $call, slat($lat), slong($lon));
50         push @out, $self->msg("sat1", $satname, $numhours, $step);
51         push @out, $self->msg("sat2");
52         
53         my ($slat,$slon,$salt,$az,$el,$distance)=Sun::get_satellite_pos($jtime,$lat*$d2r,$lon*$d2r,$alt,$satname);
54         # print the current satellite position
55         push @out,sprintf("Now   %2.2d:%2.2d %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f", 
56                                           $hr,$min,$slat*$r2d,$slon*$r2d,$salt,
57                                           $az*$r2d,$el*$r2d,$distance);
58
59         my $numsteps=0;
60         $jtime=$jtime+$step/24/60;
61         my $disc = 0;             # discontinuity flag
62         while ( $numsteps < $numhours*60/$step ) # look $numhours  ahead for tracking table
63         {
64                 my ($yr,$mon,$day,$hr,$min)=Sun::Calendar_date_and_time_from_JD($jtime);
65                 my ($slat,$slon,$salt,$az,$el,$distance)=Sun::get_satellite_pos($jtime,$lat*$d2r,$lon*$d2r,$alt,$satname);
66                 if ( $el*$r2d > -5 ) {
67                         if ($disc) {
68                                 $disc = 0;
69                                 push @out, $self->msg("satdisc");
70                         }
71                         push @out,sprintf("%2.2d/%2.2d %2.2d:%2.2d %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f", 
72                                                           $day,$mon,$hr,$min,$slat*$r2d,$slon*$r2d,$salt,
73                                                           $az*$r2d,$el*$r2d,$distance);
74                 } else {
75                         $disc++;
76                 }
77                 $numsteps++;
78                 $jtime=$jtime+$step/60/24;
79         }
80 } else {
81         push @out, $self->msg("satnf", $satname) if $satname;
82         push @out, $self->msg("sat3");
83         push @out, $self->msg("sat4");
84         my @l;
85         my $i = 0;
86         my $sat;
87         foreach $sat (sort keys %Sun::keps) {
88                 if ($i >= 6) {
89                         push @out, join ' + ', @l;
90                         @l = ();
91                         $i = 0;
92                 }
93                 push @l, $sat;
94                 $i++;
95         }
96         push @out, join ' + ', @l;
97 }
98
99 return (1,@out);
100
101
102
103
104
105
106
107
108
109
110