1#!perl 2# Testing CFITSIO read/write of fits headers 3 4use strict; 5 6use Test::More; 7 8BEGIN { 9 eval "use Astro::FITS::CFITSIO qw / :longnames /; use Astro::FITS::CFITSIO qw/ :constants /;"; 10 if ($@) { 11 plan skip_all => "Astro::FITS::CFITSIO module not available"; 12 exit; 13 } else { 14 plan tests => 41; 15 } 16} 17 18use File::Spec; 19use File::Copy; 20 21# ---------------------------------------------------------------------------- 22 23# Copy the test data to a temporary location 24BEGIN{ copy( File::Spec->catfile("t", "cfitsio.fit"), 25 File::Spec->catfile("t", "test.fit" ) ) 26 or croak("Unable to copy test data file to temporary location"); }; 27 28# Delete the temporary copy of the test data 29END{ unlink File::Spec->catfile("t", "test.fit" ) 30 or croak("Unable to delete test data"); }; 31 32# ---------------------------------------------------------------------------- 33 34require_ok( "Astro::FITS::Header::CFITSIO" ); 35 36# Read from the __DATA__ block 37my @cards = <DATA>; 38chomp(@cards); 39 40# Version test, need cfitsio library version > 2.1 41ok( fits_get_version(my $version) > 2.1, "Check Astro::FITS::CFITSIO version number"); 42 43# get the path to the test data file 44my $file = File::Spec->catfile("t", "test.fit"); 45 46# create a header 47my $header = new Astro::FITS::Header::CFITSIO( File => $file ); 48 49# overwrite the header in memory with cards stored in __DATA__ 50# its a cheap and cheerful kludge and not the OO way to do it 51$header->configure( Cards => \@cards ); 52 53# write our modified header out again 54$header->writehdr( File => $file ); 55 56# open the header back up again reading directly from the file 57my $compare = new Astro::FITS::Header::CFITSIO( File => $file ); 58 59# test the header against the raw data 60for my $i (0 .. $#cards) { 61 my @items = $compare->item($i); 62 is( "$items[0]", $cards[$i], "Compare item $i"); 63} 64 65exit; 66 67__DATA__ 68SIMPLE = T / file does conform to FITS standard 69BITPIX = -32 / number of bits per data pixel 70NAXIS = 2 / number of data axes 71NAXIS1 = 59 / length of data axis 1 72NAXIS2 = 110 / length of data axis 2 73EXTEND = T / FITS dataset may contain extensions 74COMMENT FITS (Flexible Image Transport System) format defined in Astronomy and 75COMMENT Astrophysics Supplement Series v44/p363, v44/p371, v73/p359, v73/p365. 76COMMENT Contact the NASA Science Office of Standards and Technology for the 77COMMENT FITS Definition document #100 and other FITS information. 78CLOCK0 = -6.20000000000000018 / ALICE CLOCK0 voltage 79CLOCK1 = -3 / ALICE CLOCK1 voltage 80CLOCK2 = -7.5 / ALICE CLOCK2 voltage 81CLOCK3 = -2.79999999999999982 / ALICE CLOCK3 voltage 82CLOCK4 = -6 / ALICE CLOCK4 voltage 83CLOCK5 = -2 / ALICE CLOCK5 voltage 84CLOCK6 = -7.5 / ALICE CLOCK6 voltage 85CRVAL1 = -0.03125 / Axis 1 reference value 86CRPIX1 = 29.5 / Axis 1 pixel value 87CTYPE1 = 'LINEAR ' / Quantity represented by axis 1 88CRVAL2 = -0.03125 / Axis 2 reference value 89CRPIX2 = 55.0 / Axis 2 pixel value 90CTYPE2 = 'LINEAR ' / Quantity represented by axis 2 91CD1_1 = 0.0625 / Axis rotation and scaling matrix 92CD1_2 = 0.0 / Axis rotation and scaling matrix 93CD2_1 = 0.0 / Axis rotation and scaling matrix 94CD2_2 = 0.0625 / Axis rotation and scaling matrix 95OBJECT = ' ' / Title of the dataset 96DATE = '2000-12-12T20:28:35'/ file creation date (YYYY-MM-DDThh:mm:ss UTC) 97ORIGIN = 'Starlink Project, U.K.'/ Origin of this FITS file 98BSCALE = 1.0 / True_value = BSCALE * FITS_value + BZERO 99BZERO = 0.0 / True_value = BSCALE * FITS_value + BZERO 100HDUCLAS1= 'NDF ' / Starlink NDF (hierarchical n-dim format) 101HDUCLAS2= 'DATA ' / Array component subclass 102LINEAR = F / Linearisation disabled 103FILTER = 'B1 ' / Combined filter name 104FILTERS = 'B1 ' / Combined filter name 105LAMP = 'off ' / Name of calibration lamp 106END 107