Astro-FITS-Header
view release on metacpan or search on metacpan
- New append() method to append a header or items to an existing
header, overwriting duplicates.
- A header can now be constructed from a simple perl hash
- Item objects now have a copy constructor.
- When importing an AST frameset a specific encoding can be
specified.
- The Item constructor can now guess the header type.
- Fixes in item removal, tied interface for history and subheaders
and NDF opening when a directory has a space.
3.0 2006-08-19
- Can now select items by type using the itembytype() method.
- Add equals() method.
lib/Astro/FITS/Header/Item.pm view on Meta::CPAN
Used to specify the value associated with this FITS item.
=item B<Comment>
Used to specify the comment associated with this FITS item.
=item B<Type>
Used to specify the variable type. See the C<type> method
for more details. A type will be guessed if one is not supplied.
The guess may well be wrong.
=back
Does nothing if these keys are not supplied.
=cut
sub configure {
my $self = shift;
my %hash = @_;
lib/Astro/FITS/Header/Item.pm view on Meta::CPAN
# only set type if we have not been given a type
if (!$self->type) {
if (!$self->keyword && !$self->value) {
# completely blank
$self->type("BLANK");
} elsif (!$self->keyword || $self->keyword =~ /^(COMMENT|HISTORY)$/) {
# COMMENT, HISTORY, and blank cards are special
$self->type('COMMENT')
} else {
my $type = $self->guess_type( $self->value );
$self->type( $type ) if defined $type;
}
}
# End cards are special, need only do a Keyword => 'END' to configure
$self->type('END') if $self->keyword() eq 'END';
}
}
=item B<freeze>
lib/Astro/FITS/Header/Item.pm view on Meta::CPAN
} else {
# A real keyword/value so add the "= "
$card .= "= ";
# Try to sort out the type if we havent got one
# We can not find LOGICAL this way since we can't
# tell the difference between 'F' and F
# an undefined value is typeless
unless (defined $type) {
$type = $self->guess_type( $value );
}
# Numbers behave identically whether they are float or int
# Logical is a number formatted as a "T" or "F"
if ($type eq 'INT' or $type eq 'FLOAT' or $type eq 'LOGICAL' or
$type eq 'UNDEF') {
# Change the value for logical
if ($type eq 'LOGICAL') {
$value = ( ($value && ($value ne 'F')) ? 'T' : 'F' );
lib/Astro/FITS/Header/Item.pm view on Meta::CPAN
$card = substr($card,0,80);
$card .= ' 'x(80-length($card));
}
# Return the result
return $card;
}
=item B<guess_type>
This class method can be used to guess the data type of a supplied value.
It is private but can be used by other classes in the Astro::FITS::Header
hierarchy.
$type = Astro::FITS::Header::Item->guess_type( $value );
Can not distinguish a string F from a LOGICAL F so will always guess
"string". Returns "string" if a type could not be determined.
=cut
sub guess_type {
my $self = shift;
my $value = shift;
my $type;
if (!defined $value) {
$type = "UNDEF";
} elsif ($value =~ /^\d+$/) {
$type = "INT";
} elsif ($value =~ /^(-?)(\d*)(\.?)(\d*)([EeDd][-\+]?\d+)?$/) {
$type = "FLOAT";
} else {
( run in 0.615 second using v1.01-cache-2.11-cpan-702932259ff )