#!/usr/bin/perl -w # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # This program, predict-format, is written by Jeffrey Hundstad Copyright (c) 2010 use warnings; use strict; use Time::Local; if (!defined($ARGV[0])) { die "Usage: $0 \n"; } my $tsat = $ARGV[0]; my $begtime = time(); my ($mon,$year,$isdst) = (localtime($begtime))[4,5,8]; $begtime = timelocal(0, 0, 0, 1, $mon, $year); my $endmon = $mon+1; my $endyear = $year; if ($endmon > 12) { $endmon = 1; $endyear++; } my $endtime = timelocal(0, 0, 0, 1, $endmon, $endyear); ($mon,$year,$isdst) = (localtime($begtime))[4,5,8]; my $tz = ($isdst) ? 'CST' : 'DST'; print "Date ($tz) Time ($tz) of Duration Azimuth at Peak Vis Orbit\n"; print " AOS MEL LOS of Pass AOS MEL LOS Elev\n"; my @days=('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); my @months=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); my $lastdate = ''; while ($begtime <= $endtime) { open (PREDICT, "predict -p $tsat $begtime |") or die "\nPlease install Predict, http://www.qsl.net/kd2bd/predict.html\n\n"; last if (eof(PREDICT)); ($begtime,$lastdate) = nextpass($lastdate); $begtime += 60; } exit; sub nextpass { my $lastdate = shift; my ($taos,$tmel,$tlos); my ($aaos,$amel,$alos); my ($vaos,$vmel,$vlos); my ($oaos,$omel,$olos); my $pe; my $first = 1; my ($sepoc,$sday,$sdate,$stime,$selev,$sazim,$sphas,$slat,$slon,$srange,$sorbit,$sv); while () { chomp; ($sepoc,$sday,$sdate,$stime,$selev,$sazim,$sphas,$slat,$slon,$srange,$sorbit,$sv) = split(/ +/,$_); if ($first) { $taos = $sepoc; $aaos = $sazim; $vaos = $sv; $oaos = $sorbit; $tmel = 0; $amel = 0; $vmel = 0; $pe = $selev; $first = 0; } elsif ($selev > $pe) { $tmel = $sepoc; $amel = $sazim; $vmel = $sv; $omel = $sorbit; $pe = $selev } } $tlos = $sepoc; $alos = $sazim; $olos = $sorbit; $vlos = $sv; my $newdate = ftime($taos,'d'); if ($newdate ne $lastdate) { $lastdate = $newdate; print "\n" . $newdate . ' '; } else { print ' '; } print ftime($taos) . ' ' . ftime($tmel) . ' ' . ftime($tlos) . ' '; print timeform($tlos - $taos) . ' '; printf "%3d %3d %3d ", $aaos,$amel,$alos; printf "%2d", $pe; print (($pe < 40) ? ' ' : '* '); print dn($vaos) . dn($vmel) . dn($vlos) . ' '; print "$oaos\n"; return ($tlos,$lastdate); } sub timeform { my $insec = shift; my $hours = int($insec / 3600); $insec -= $hours * 3600; my $min = int($insec / 60); $insec -= $min * 60; return sprintf "%02d:%02d:%02d", $hours,$min,$insec; } sub dn { my $sv = shift; my $daynight; if ($sv eq '*') { $daynight = 'D'; } elsif ($sv eq '+') { $daynight = 'V'; } else { $daynight = 'N'; } return $daynight; } sub ftime { my $sepoc = shift; my $type = shift; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($sepoc); $year -= 100; my $localtime = sprintf("%02d:%02d:%02d",$hour,$min,$sec); my $localdate = sprintf("%3s %02d%3s%02d",$days[$wday],$mday,$months[$mon],$year); if (!defined($type)) { return $localtime; } elsif ($type eq 'b') { return ($localdate,$localtime); } else { return $localdate; } }