Skip to content

Commit

Permalink
make wfits handle multi HISTORY
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Aug 22, 2024
1 parent ed911ba commit 4c525ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
4 changes: 3 additions & 1 deletion IO/FITS/FITS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,9 @@ sub PDL::wfits {
}
# Make sure that the HISTORY lines all come at the end
my @hindex = $afhdr->index('HISTORY');
$afhdr->insert(-1-$_, $afhdr->remove($hindex[-1-$_])) for 0..$#hindex;
my @hitems = map $afhdr->item($_), @hindex;
$afhdr->remove($_) for reverse @hindex; # remove from back as from front disrupts numbering
$afhdr->insert(-1, $_) for @hitems;
# Make sure the last card is an END
$afhdr->insert(scalar($afhdr->cards),
Astro::FITS::Header::Item->new(Keyword=>'END'));
Expand Down
11 changes: 3 additions & 8 deletions IO/FITS/t/fits.t
Original file line number Diff line number Diff line change
Expand Up @@ -348,25 +348,20 @@ ok all(approx $m51, $m51_2), 'read back written-out compressed FITS file' or dia
}
}

#multi-line HISTORY header writing
{ my $f_out;
my $hstr = join("\n",'A'..'G');

$f_out = 'long_history.fits';
{
my $hstr = join("\n",'A'..'G',''); # must end in newline
(undef, my $f_out) = File::Temp::tempfile( 'delmeXXXXX', SUFFIX => '.fits', %tmp_opts );
my $x = xvals(10);
$x->hdr->{'HISTORY'} = $hstr;
$x->wfits($f_out);
my $xr = rfits($f_out);
is($xr->hdr->{'HISTORY'}, $hstr, 'multi-line HISTORY correct with fresh header');
unlink($f_out) or die "couldn't delete $f_out";

$f_out = 'm51_longhist.fits';
my $m51 = rfits('t/m51.fits.fz');
$m51->hdr->{HISTORY} = $hstr;
$m51->wfits($f_out);
my $m51r = rfits($f_out);
is($m51r->hdr->{'HISTORY'}, $hstr, 'multi-line HISTORY correct with pre-existing header');
unlink($f_out) or die "couldn't delete $f_out";
}

done_testing();

0 comments on commit 4c525ed

Please sign in to comment.