Astro-satpass
view release on metacpan or search on metacpan
my @events_found; # Rise and set data.
# Iterate through TLE objects
foreach my $tle ( @of_interest ) {
# Override the common name retrieved from Space Track, if desired.
if ( defined ( my $name = $want_oid{ $tle->get( 'id' ) } ) ) {
$tle->set( name => $name );
}
$tle->validate( $start, $finish ) # Sanity-check the data, and
or next; # punt if we can not use it.
# Iterate through each pass over the station.
foreach my $pass ( $tle->pass( $start, $finish ) ) {
# Record the appropriate data.
if ( $opt{split} ) {
# If -split is asserted, we pull out and record the
# individual events.
push @events_found, grep { $want_event{$_->{event}} } @{
$pass->{events} };
} else {
# If -split is not asserted, we just record the whole pass.
push @events_found, $pass;
}
}
}
# Sort the data by time, run it through the templating system, and
# print.
my $join = template( $opt{join} );
foreach my $data ( sort { $a->{time} <=> $b->{time} } @events_found ) {
defined $data->{event}
and $up += ( $delta_number_up{ $data->{event} } || 0 );
print template( $opt{body_template}, $data ), join( $join,
map { template( $opt{event_template}, $_ ) }
$opt{split} ? $data : grep { $want_event{$_->{event}} } @{
$data->{events} }
), "\n";
}
# ------------------------ Subroutines ---------------------
# $string = format_time( $time );
# Format the time appropriately.
sub format_time {
my ( $time ) = @_;
return $opt{gmt} ? gm_strftime( $opt{time_format}, $time ) :
local_strftime( $opt{time_format}, $time );
}
# load_file( $file_name );
# Load the contents of a file.
sub load_file {
my ( $fn ) = @_;
my $fh;
open $fh, '<', $fn ## no critic (RequireBriefOpen)
or die "Unable to open $fn: $!\n";
local @ARGV;
local $_ = undef;
while ( <$fh> ) {
s/ \s+ \z //smx;
'' eq $_ and next;
s/ \A \s+ //smx;
'#' eq substr $_, 0, 1 and next;
push @ARGV, $_;
}
close $fh;
GetOptions( \%opt, @lgl_opt )
or die "Bad options. Use -help for help.\n";
load_want( @ARGV );
return;
}
# Load arguments into the %want_oid hash. Arguments are expected to be
# of the form 'oid' or 'oid=name'.
sub load_want {
my @args = @_;
foreach ( @args ) {
my ( $oid, $name ) = split qr{ \s*=\s* }smx, $_, 2;
defined $oid or next;
$want_oid{$oid} = $name;
}
return;
}
{
my $errstr;
my %offset;
my $rel_re;
BEGIN {
$errstr = "Invalid ISO time '%s'\n"; # sprintf format
%offset = ( # Seconds relative to today midnight.
yesterday => -86400,
today => 0,
tomorrow => 86400,
);
$rel_re = qr/ @{[ join( '|', keys %offset ) ]} /smx;
}
# $time = parse_iso_time( $string );
# Parse an iso-8601-ish time. See the -start documentation for the
# format.
sub parse_iso_time {
my ( $string ) = @_;
my $time;
local $@;
# Numeric time
if ( $string =~ m/ \A
( \d{4} ) \D* # Year
(?: ( \d{2} ) \D* # Month
(?: ( \d{2} ) \D* # Day
(?: ( \d{2} ) \D* # Hour
(?: ( \d{2} ) \D* # Minute
(?: ( \d{2} ) \D* )? # Second
)?
)?
( run in 2.144 seconds using v1.01-cache-2.11-cpan-5c0b1e786e0 )