remove $Id$ strings from everywhere that I can find
[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 #
8
9 # 2001/12/16 added age of keps in the sh/sat output list.
10 #   Note - there is the potential for problems when satellite name
11 #   is longer than 20 characters. The list shows only the 
12 #   first 20 chars, so user won't know the full name.
13 #   So far, it seems that only the GPS sats even come close... 
14
15 my ($self, $line) = @_;
16 my @out;
17
18 my @f = split /\s+/, $line;
19 my $satname = uc shift @f;
20 my $numhours = shift @f;        # the number of hours ahead to print
21 my $step = shift @f;            # tracking table resolution in minutes
22
23 # default hours and step size
24 $numhours = 3 unless $numhours && $numhours =~ /^\d+$/;
25 $numhours = 3 if $numhours < 0;
26 $numhours = 24 if $numhours > 24;
27 $step = 5 unless $step && $step =~ /^\d+$/;
28 $step = 5 if $step < 0;
29 $step = 30 if $step > 30;
30
31 # get nearest lat and long (I can see we will need the altitude here soon as well :-)
32 my $lat = $self->user->lat;
33 my $lon = $self->user->long;
34 my $alt = 0;
35 my $call = $self->call;
36 unless ($lon || $lat) {
37         $lat = $main::mylatitude;
38         $lon = $main::mylongitude;
39         $call = $main::mycall;
40 }
41
42 my $jtime; # lats and longs in radians
43 my ($sec, $min, $hr, $day, $mon, $yr) = (gmtime($main::systime))[0,1,2,3,4,5];
44 #printf("%2.2d %2.2d %2.2d %2.2d %2.2d\n",$min,$hr,$day,$mon,$yr);
45
46 $mon++;
47 $yr += 1900;
48
49 $jtime=Sun::Julian_Day($yr,$mon,$day)+$hr/24+$min/60/24;
50
51 #$DB::single=1;
52 if ($satname && $Sun::keps{$satname}) {
53
54         ($yr,$mon,$day,$hr,$min)=Sun::Calendar_date_and_time_from_JD($jtime);
55         #printf("%2.2d %2.2d %2.2d %2.2d %2.2d\n",$min,$hr,$day,$mon,$yr);
56         push @out, $self->msg("pos", $call, slat($lat), slong($lon));
57         push @out, $self->msg("sat1", $satname, $numhours, $step);
58         push @out, $self->msg("sat2");
59         
60         my ($slat,$slon,$salt,$az,$el,$distance)=Sun::get_satellite_pos($jtime,$lat*$d2r,$lon*$d2r,$alt,$satname);
61         # print the current satellite position
62         push @out,sprintf("Now   %2.2d:%2.2d %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f", 
63                                           $hr,$min,$slat*$r2d,$slon*$r2d,$salt,
64                                           $az*$r2d,$el*$r2d,$distance);
65
66         my $numsteps=0;
67         $jtime=$jtime+$step/24/60;
68         my $disc = 0;             # discontinuity flag
69         while ( $numsteps < $numhours*60/$step ) # look $numhours  ahead for tracking table
70         {
71                 my ($yr,$mon,$day,$hr,$min)=Sun::Calendar_date_and_time_from_JD($jtime);
72                 my ($slat,$slon,$salt,$az,$el,$distance)=Sun::get_satellite_pos($jtime,$lat*$d2r,$lon*$d2r,$alt,$satname);
73                 if ( $el*$r2d > -5 ) {
74                         if ($disc) {
75                                 $disc = 0;
76                                 push @out, $self->msg("satdisc");
77                         }
78                         push @out,sprintf("%2.2d/%2.2d %2.2d:%2.2d %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f", 
79                                                           $day,$mon,$hr,$min,$slat*$r2d,$slon*$r2d,$salt,
80                                                           $az*$r2d,$el*$r2d,$distance);
81                 } else {
82                         $disc++;
83                 }
84                 $numsteps++;
85                 $jtime=$jtime+$step/60/24;
86         }
87 } else {
88         push @out, $self->msg("satnf", $satname) if $satname;
89         push @out, $self->msg("sat3");
90         push @out, $self->msg("sat4");
91         my @l;
92         my $i = 0;
93         my $sat;
94         foreach $sat (sort keys %Sun::keps) {
95                 if ($i >= 2) {
96                         push @out,join '  ', @l;
97                         @l = ();
98                         $i = 0;
99                 }
100                 my $epoch=$Sun::keps{$sat}->{epoch};
101                 my $jt_epoch=Sun::Julian_Date_of_Epoch($epoch);
102                 my $keps_age=int($jtime-$jt_epoch);
103                 push @l, sprintf("%20s: %4s",$sat,$keps_age);
104                 $i++;
105         }
106         push @out, join '  ', @l;
107 }
108
109 return (1,@out);
110
111
112
113
114
115
116
117
118
119
120