#!/usr/bin/perl # Routine to correct the syntax error in the NNSN FITS headers that list # "A'HEARN" in the observer field, as identified in the "ahearn.lst" file. # We'll need to fix both the FITS headers and PDS labels for these files. # Fortunately, it looks like we can assume the OBSERVER line in the headers # always occurs as the 15th line in the first FITS block and the 22nd line # in the corresponding PDS label. # # Format: % fixmaobs $TMPFILE = "__bob.tmp"; # First, we'll read the corrected lines from a file into a hash for easy # reference and substitution later: open (LST,"ahearn.new") || die "Could not open 'ahearn.new' ($!)"; while ($line=) { chop $line; $filename = substr($line,0,8); $obsname = substr($line,13); $newfits{$filename} = sprintf "%-80.80s", $obsname; $obsname =~ s/^[^']+'//; $obsname =~ s/' \/.*$//; $obsname =~ s/''/'/; $newpds{$filename} = sprintf "%-78.78s\r\n", "OBSERVER_FULL_NAME = \"$obsname\""; } close(LST); # Now we'll loop through the list of files to be corrected (this list has the # path information): open (LST,"ahearn.lst") || die "Could not open 'ahearn.lst' ($!)"; while ($file=) { chop $file; $filename = substr($file,12,8); # We'll start with the FITS file. We know the OBSERVER line is the 15th # in the first FITS block. open (TMP,">$TMPFILE") || die "Could not open $TMPFILE ($!)"; open (FIT,$file) || die "Could not open $file ($!)"; read FIT,$block,2880; substr($block,1120,80) = $newfits{$filename}; syswrite TMP,$block,2880; # Now just copy the rest of the file: while (!eof(FIT)) { read FIT, $block, 2880; syswrite TMP, $block, 2880; } close(FIT); close(TMP); rename $TMPFILE, $file; # Now we'll do the PDS label. We expect to find the OBSERVER line at line # 22 of the PDS label: $pdsname = $file; $pdsname =~ s/\.fit/.lbl/; open (TMP,">$TMPFILE") || die "Could not open $TMPFILE ($!)"; open (PDS,$pdsname) || die "Could not open $pdsname ($!)"; # Find the OBSERVER_FULL_NAME line and replace it with the new one: $line = ; while ($line !~ /^ *OBSERVER_FULL_NAME/) { print TMP $line; $line=; } print TMP $newpds{$filename}; # Transfer the rest of the label file: while ($line=) { print TMP $line; } close(TMP); close(PDS); rename $TMPFILE, $pdsname; }