Astro-Coords
view release on metacpan or search on metacpan
lib/Astro/Coords.pm view on Meta::CPAN
croak "Event must be either +1 or -1";
}
# do we have DateTime objects
my $dtime = $self->_isdt();
# Somewhere to store the previous time so we can make sure things
# are iterating nicely
my $prevtime;
# The current best guess of the meridian time
my $mtime;
# Number of times we want to loop before aborting
my $max = 10;
# Tolerance for good convergence
my $tol = 1;
# Increment (in hours) to jump forward each loop
# Need to make sure we lock onto the correct transit so I'm
lib/Astro/Coords/Angle.pm view on Meta::CPAN
Internal class method to convert an input string to the equivalent value in
radians. The following units are supported:
sexagesimal - A string of format "dd:mm:ss.ss", "dd mm ss.ss"
or even "-ddxmmyss.ss" (ie -5x53y28.5z)
degrees - decimal degrees
radians - radians
arcsec - arc seconds (abbreviated form is 'as')
arcmin - arc minutes (abbreviated form is 'am')
If units are not supplied, default is to call the C<_guess_units>
method.
$radians = $angle->_cvt_torad( $angle, $units );
Warnings are issued if the string can not be parsed or the values are
out of range.
If the supplied angle is an Angle object itself, units are ignored and
the value is extracted directly from the object.
lib/Astro/Coords/Angle.pm view on Meta::CPAN
# do we have an object?
# and can it implement the radians() method?
if (UNIVERSAL::can( $input, 'radians')) {
return $input->radians;
}
# Clean up the string
$input =~ s/^\s+//g;
$input =~ s/\s+$//g;
# guess the units
unless (defined $units) {
$units = $self->_guess_units( $input );
croak "No units supplied, and unable to guess any units either"
unless defined $units;
}
# Now process the input - starting with strings
my $output = 0;
if ($units =~ /^s/) {
# Since we can support aritrary delimiters on write,
# we should be flexible on read. Slalib is very flexible
# once the numbers are space separated, so remove all
lib/Astro/Coords/Angle.pm view on Meta::CPAN
$output = $input * Astro::PAL::DAS2R * 60 ;
} else {
# Already in radians
$output = $input;
}
return $output;
}
=item B<_guess_units>
Given a string or number, tries to guess the units. Default is to
assume "sexagesimal" if the supplied string does not look like a
number to perl, "degrees" if the supplied number is greater than 2*PI
(6.28), and "radians" for all other values.
$units = $class->_guess_units( $input );
Returns undef if the input does not look at all plausible or is undef
itself.
Arcsec or arcmin can not be determined with this routine.
=cut
sub _guess_units {
my $self = shift;
my $input = shift;
return undef if !defined $input;
# Now if we have a space, colon or alphabetic character
# then we have a real string and assume sexagesimal.
# Use pre-defined character classes
my $units;
# if it does not look like a number choose sexagesimal
if (!looks_like_number($input)) {
lib/Astro/Coords/Angle/Hour.pm view on Meta::CPAN
$ha = new Astro::Coords::Angle::Hour( 12.53 );
=head1 DESCRIPTION
Class similar to C<Astro::Coords::Angle> but representing the angle
as a time. Suitable for use as hour angle or Right Ascension.
Inherits from C<Astro::Coords::Angle>.
For hour angle a range of "PI" is suitable, for Right Ascension use "2PI".
Default range is none at all. If no units are provided, the units will be
guessed using the same scheme as for C<Astro::Coords::Angle> except that
values greater than 2PI will be assumed to be decimal hours.
=cut
use 5.006;
use strict;
use warnings;
use warnings::register;
use Carp;
lib/Astro/Coords/Angle/Hour.pm view on Meta::CPAN
or sexagesimal, the resulting number is multiplied by 15 before being
passed up to the constructor (since 24 hours is equivalent to 360 degrees).
=cut
sub _cvt_torad {
my $self = shift;
my $input = shift;
my $units = shift;
# If we haven't got any units attempt to guess some
$units = $self->_guess_units( $input ) unless defined $units;
# if units are hours, tell the base class we have degrees
# $unt is the unit that will be reported to the base class
# $units is the unit known to the subclass
my $unt = $units;
if (defined $units && $units =~ /^h/) {
$unt = 'deg';
}
# Do the conversion
my $rad = $self->SUPER::_cvt_torad( $input, $unt );
# scale if we had sexagesimal or hour as units
if (defined $rad && $units =~ /^[sh]/) {
$rad *= 15;
}
return $rad;
}
=item B<_guess_units>
Guess the units. Same as base class except that values greater than 2PI
radians are assumed to be hours rather than degrees.
$guess = $hr->_guess_units( $input );
=cut
sub _guess_units {
my $self = shift;
my $input = shift;
my $guess = $self->SUPER::_guess_units( $input );
$guess = 'h' if $guess =~ /^d/;
return $guess;
}
=item B<_r2f>
Routine to convert angle in radians to a formatted array
of numbers in order of sign, hour, min, sec, frac.
@retval = $ang->_r2f( $ndp );
Note that the number of decimal places is an argument.
lib/Astro/Coords/Equatorial.pm view on Meta::CPAN
$mtime->add(seconds => $event * $self->_sidereal_period());
} else {
$mtime = $mtime + ($event * $self->_sidereal_period());
}
}
return $mtime;
}
=item B<_iterative_el>
For the simplest case, the initial guess should have been good enough,
so iterating would not be necessary. Therefore if there is no
proper motion or parallax, this subroutine does nothing.
See L<Astro::Coords/_iterative_el>.
=cut
sub _iterative_el {
my $self = shift;
my $ra = new Astro::Coords::Angle::Hour( '12h13m45.6s', units => 'sex',
range => 'PI'
);
$ra->str_ndp(1);
is("$ra", '-11:46:14.4', "hour angle -12 to +12");
isa_ok( $ra, "Astro::Coords::Angle::Hour");
# guess units
my $ang3 = new Astro::Coords::Angle( 45 );
delta_ok($ang3->degrees, 45, "Check 45 deg without units");
my $ang4 = new Astro::Coords::Angle( '45:00:00' );
delta_ok($ang4->degrees, 45, "Check 45:00:00 deg without units");
my $rad = 0.5;
my $ang5 = new Astro::Coords::Angle( $rad );
delta_ok($ang5->radians, 0.5, "Check 0.5 rad is still 0.5 rad");
# check that defaulting is correct for Hours
my $hour = 12;
my $ang6 = new Astro::Coords::Angle::Hour( $hour );
delta_ok( $ang6->hours, 12, "Default guess of units");
( run in 1.455 second using v1.01-cache-2.11-cpan-702932259ff )