Astro::Coords::Angle::Hour - Representation of an angle in units of hours


Astro-Coords documentation Contained in the Astro-Coords distribution.

Index


Code Index:

NAME

Top

Astro::Coords::Angle::Hour - Representation of an angle in units of hours

SYNOPSIS

Top

  use Astro::Coords::Angle::Hour;

  $ha = new Astro::Coords::Angle::Hour( "12h30m22.4s", units => 'sex');
  $ha = new Astro::Coords::Angle::Hour( 12.53, units => 'hour);

  $ha = new Astro::Coords::Angle::Hour( 12.53 );

DESCRIPTION

Top

Class similar to Astro::Coords::Angle but representing the angle as a time. Suitable for use as hour angle or Right Ascension. Inherits from 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 Astro::Coords::Angle except that values greater than 2PI will be assumed to be decimal hours.

METHODS

Top

Accessor Methods

hours

Return the angle in decimal hours.

 $deg = $ang->hours;

General Methods

in_format

As for base class implementation, except that 'hour' (and abbreviation) is a supported format. 'sexagesimal' format will result in a stringified form of the object in hours, minutes and seconds.

 $hr = $hour->in_format( 'hour' );

Class Methods

The following methods control the default behaviour of the class.

NDP

As for the base class except that the default number of decimal places is 1.

This method has no effect on the base class.

DELIM

As for the base class. The global value in this class does not have any effect on the base class.

AUTHOR

Top

Tim Jenness <t.jenness@cpan.org>

COPYRIGHT

Top


Astro-Coords documentation Contained in the Astro-Coords distribution.
package Astro::Coords::Angle::Hour;


use 5.006;
use strict;
use warnings;
use warnings::register;
use Carp;

use Astro::SLA;

use base qw/ Astro::Coords::Angle /;

# Package Global variables
use vars qw/ $VERSION /;

$VERSION = '0.01';

sub hours {
  my $self = shift;
  my $rad = $self->radians;
  return $rad * Astro::SLA::DR2H;
}

sub in_format {
  my $self = shift;
  my $format = shift;
  $format = lc($format) if $format;
  return $self->hours() if (defined $format && $format =~ /^h/);
  return $self->SUPER::in_format( $format );
}

{
  my $DEFAULT_NDP = 1;
  my $NDP = $DEFAULT_NDP;
  sub NDP {
    my $class = shift;
    if (@_) { 
      my $arg = shift;
      if (defined $arg) {
	$NDP = $arg;
      } else {
	$NDP = $DEFAULT_NDP;
      }
    }
    return $NDP;
  }
}

{
  my $DEFAULT_DELIM = ":";
  my $DELIM = $DEFAULT_DELIM;
  sub DELIM {
    my $class = shift;
    if (@_) { 
      my $arg = shift;
      if (defined $arg) {
	$DELIM = $arg;
      } else {
	$DELIM = $DEFAULT_DELIM;
      }
    }
    return $DELIM;
  }
}


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 ($units =~ /^[sh]/) {
    $rad *= 15;
  }

  return $rad;
}

sub _guess_units {
  my $self = shift;
  my $input = shift;
  my $guess = $self->SUPER::_guess_units( $input );
  $guess = 'h' if $guess =~ /^d/;
  return $guess;
}

sub _r2f {
  my $self = shift;
  my $res = shift;
  my @dmsf;
  Astro::SLA::slaDr2tf($res, $self->radians, my $sign, @dmsf);
  return ($sign, @dmsf);
}

1;