/usr/share/perl5/Astro/FITS/Header/CFITSIO.pm is in libastro-fits-header-perl 3.07-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | package Astro::FITS::Header::CFITSIO;
# ---------------------------------------------------------------------------
=head1 NAME
Astro::FITS::Header::CFITSIO - Manipulates FITS headers from a FITS file
=head1 SYNOPSIS
use Astro::FITS::Header::CFITSIO;
$header = new Astro::FITS::Header::CFITSIO( Cards => \@array );
$header = new Astro::FITS::Header::CFITSIO( File => $file );
$header = new Astro::FITS::Header::CFITSIO( fitsID => $ifits );
$header->writehdr( File => $file );
$header->writehdr( fitsID => $ifits );
=head1 DESCRIPTION
This module makes use of the L<CFITSIO|CFITSIO> module to read and write
directly to a FITS HDU.
It stores information about a FITS header block in an object. Takes an
hash as an argument, with either an array reference pointing to an
array of FITS header cards, or a filename, or (alternatively) and FITS
identifier.
=cut
# L O A D M O D U L E S --------------------------------------------------
use strict;
use vars qw/ $VERSION /;
use Astro::FITS::Header::Item;
use base qw/ Astro::FITS::Header /;
use Astro::FITS::CFITSIO qw / :longnames :constants /;
use Carp;
$VERSION = 3.02;
# C O N S T R U C T O R ----------------------------------------------------
=head1 REVISION
$Id$
=head1 METHODS
=over 4
=item B<configure>
Reads a FITS header from a FITS HDU
$header->configure( Cards => \@cards );
$header->configure( fitsID => $ifits );
$header->configure( File => $file );
$header->configure( File => $file, ReadOnly => $bool );
Accepts an FITS identifier or a filename. If both fitsID and File keys
exist, fitsID key takes priority.
If C<File> is specified, the file is normally opened in ReadWrite
mode. The C<ReadOnly> argument takes a boolean value which determines
whether the file is opened ReadOnly.
=cut
sub configure {
my $self = shift;
my %args = ( ReadOnly => 0, @_ );
# itialise the inherited status to OK.
my $status = 0;
my $ifits;
return $self->SUPER::configure(%args)
if exists $args{Cards} or exists $args{Items};
# read the args hash
if (exists $args{fitsID}) {
$ifits = $args{fitsID};
} elsif (exists $args{File}) {
$ifits = Astro::FITS::CFITSIO::open_file( $args{File},
$args{ReadOnly} ? Astro::FITS::CFITSIO::READONLY() :
Astro::FITS::CFITSIO::READWRITE(),
$status );
} else {
croak("Arguement hash does not contain fitsID, File or Cards");
}
# file sucessfully opened?
if( $status == 0 ) {
# Get size of FITS header
my ($numkeys, $morekeys);
$ifits->get_hdrspace( $numkeys, $morekeys, $status);
# Set the FITS array to empty
my @fits = ();
# read the cards. Note that CFITSIO doesn't include the END card
# in it's counting
for my $i (1 .. $numkeys) {
$ifits->read_record($i, my $card, $status);
push(@fits, $card);
}
# add an END card. previously this was extracted from CFITSIO
# by reading an extra card. however, the header may not have
# been completed by CFITSIO, so that extra card might not exist.
push @fits, Astro::FITS::Header::Item->new( Keyword => 'END')->card;
if ($status == 0) {
# Parse the FITS array
$self->SUPER::configure( Cards => \@fits );
} else {
# Report bad exit status
croak("Error $status reading FITS array");
}
# Look at the name of the file as it was passed in. If there is a FITS
# extension specified, then this is a single fits image that you want
# read. If there isn't one specified, then we should read each of the
# extensions that exist in the file, if in fact there are any.
if ( exists $args{File} )
{
my $ext;
fits_parse_extnum($args{File},$ext,$status);
my @subfrms = ();
if ($ext == -99) {
my $nhdus;
$ifits->get_num_hdus($nhdus,$status);
foreach my $ihdu (1 .. $nhdus-1) {
my $subfr = sprintf("%s[%d]",$args{File},$ihdu);
my $sself = $self->new(File=>$subfr, ReadOnly => $args{ReadOnly});
push @subfrms,$sself;
}
}
$self->subhdrs(@subfrms);
}
}
# clean up
if ( $status != 0 ) {
croak("Error $status opening FITS file");
}
# close file, but only if we opened it
$ifits->close_file( $status )
unless exists $args{fitsID};
return;
}
# W R I T E H D R -----------------------------------------------------------
=item B<writehdr>
Write a FITS header to a FITS file
$header->writehdr( File => $file );
$header->writehdr( fitsID => $ifits );
Its accepts a FITS identifier or a filename. If both fitsID and File keys
exist, fitsID key takes priority.
Returns undef on error, true if the header was written successfully.
=cut
sub writehdr {
my $self = shift;
my %args = @_;
return $self->SUPER::configure(%args) if exists $args{Cards};
# itialise the inherited status to OK.
my $status = 0;
my $ifits;
# read the args hash
if (exists $args{fitsID}) {
$ifits = $args{fitsID};
} elsif (exists $args{File}) {
$ifits = Astro::FITS::CFITSIO::open_file( $args{File},
Astro::FITS::CFITSIO::READWRITE(), $status );
} else {
croak("Argument hash does not contain fitsID, File or Cards");
}
# file sucessfully opened?
if( $status == 0 ) {
# Get size of FITS header
my ($numkeys, $morekeys);
$ifits->get_hdrspace( $numkeys, $morekeys, $status);
# delete the cards in the current header. as cards are deleted the
# ones below it are shifted up (according to the CFITSIO docs).
# we thus delete from the bottom up to avoid all of that work.
$ifits->delete_record( $numkeys--, $status )
while $numkeys;
# write the new cards, not including END card if it exists
my @cards = $self->cards;
if ( defined (my $end_card = $self->index('END')) )
{ splice( @cards, $end_card, 1 ) }
$ifits->write_record($_, $status ) foreach @cards;
}
# clean up
if ( $status != 0 ) {
croak("Error $status opening FITS file");
}
# close file, but only if we opened it
$ifits->close_file( $status )
unless exists $args{fitsID};
return;
}
# T I M E A T T H E B A R --------------------------------------------
=back
=head1 NOTES
This module requires Pete Ratzlaff's L<Astro::FITS::CFITSIO> module,
and William Pence's C<cfitsio> subroutine library (v2.1 or greater).
=head1 SEE ALSO
L<Astro::FITS::Header>, L<Astro::FITS::Header::Item>, L<Astro::FITS::Header::NDF>, L<Astro::FITS::CFITSIO>
=head1 AUTHORS
Alasdair Allan E<lt>aa@astro.ex.ac.ukE<gt>,
Jim Lewis E<lt>jrl@ast.cam.ac.ukE<gt>,
Diab Jerius.
=head1 COPYRIGHT
Copyright (C) 2007-2009 Science & Technology Facilities Council.
Copyright (C) 2001-2006 Particle Physics and Astronomy Research Council.
All Rights Reserved.
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, write to the Free Software Foundation, Inc., 59 Temple
Place,Suite 330, Boston, MA 02111-1307, USA
=cut
# L A S T O R D E R S ------------------------------------------------------
1;
|