]> dxcluster.org Git - spider.git/blob - cmd/show/satellite.pl
moved $build calculation to main routine to make it available everywhere
[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 #$DB::single=1;
38 if ($satname && $Sun::keps{$satname}) {
39         my $jtime; # lats and longs in radians
40         my ($sec, $min, $hr, $day, $mon, $yr) = (gmtime($main::systime))[0,1,2,3,4,5];
41         #printf("%2.2d %2.2d %2.2d %2.2d %2.2d\n",$min,$hr,$day,$mon,$yr);
42
43         $mon++;
44         $yr += 1900;
45         $alt=0.0;
46
47         $jtime=Sun::Julian_Day($yr,$mon,$day)+$hr/24+$min/60/24;
48         ($yr,$mon,$day,$hr,$min)=Sun::Calendar_date_and_time_from_JD($jtime);
49         #printf("%2.2d %2.2d %2.2d %2.2d %2.2d\n",$min,$hr,$day,$mon,$yr);
50         push @out, $self->msg("pos", $call, slat($lat), slong($lon));
51         push @out, $self->msg("sat1", $satname, $numhours, $step);
52         push @out, $self->msg("sat2");
53         
54         my ($slat,$slon,$salt,$az,$el,$distance)=Sun::get_satellite_pos($jtime,$lat*$d2r,$lon*$d2r,$alt,$satname);
55         # print the current satellite position
56         push @out,sprintf("Now   %2.2d:%2.2d %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f", 
57                                           $hr,$min,$slat*$r2d,$slon*$r2d,$salt,
58                                           $az*$r2d,$el*$r2d,$distance);
59
60         my $numsteps=0;
61         $jtime=$jtime+$step/24/60;
62         my $disc = 0;             # discontinuity flag
63         while ( $numsteps < $numhours*60/$step ) # look $numhours  ahead for tracking table
64         {
65                 my ($yr,$mon,$day,$hr,$min)=Sun::Calendar_date_and_time_from_JD($jtime);
66                 my ($slat,$slon,$salt,$az,$el,$distance)=Sun::get_satellite_pos($jtime,$lat*$d2r,$lon*$d2r,$alt,$satname);
67                 if ( $el*$r2d > -5 ) {
68                         if ($disc) {
69                                 $disc = 0;
70                                 push @out, $self->msg("satdisc");
71                         }
72                         push @out,sprintf("%2.2d/%2.2d %2.2d:%2.2d %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f", 
73                                                           $day,$mon,$hr,$min,$slat*$r2d,$slon*$r2d,$salt,
74                                                           $az*$r2d,$el*$r2d,$distance);
75                 } else {
76                         $disc++;
77                 }
78                 $numsteps++;
79                 $jtime=$jtime+$step/60/24;
80         }
81 } else {
82         push @out, $self->msg("satnf", $satname) if $satname;
83         push @out, $self->msg("sat3");
84         push @out, $self->msg("sat4");
85         my @l;
86         my $i = 0;
87         my $sat;
88         foreach $sat (sort keys %Sun::keps) {
89                 if ($i >= 6) {
90                         push @out, join ' + ', @l;
91                         @l = ();
92                         $i = 0;
93                 }
94                 push @l, $sat;
95                 $i++;
96         }
97         push @out, join ' + ', @l;
98 }
99
100 return (1,@out);
101
102
103
104
105
106
107
108
109
110
111