#!/usr/bin/perl
# Routine to extract the PDS label from the stardust raw data, change
# the LINE_SAMPLES keyword, and the LINE_PREFIX_BYTES and LINE_SUFFIX_BYTES
# keywords, and create a new detatched label. THis can be used by
# PDSREAD to read in the overscan regions, which can then be written out to
#the FITS file.
#$SRCDIR = "../TEST";
$SRCDIR = "../IMGFILES";
$TMPLBL = "TMP.LBL";
opendir(SRC,$SRCDIR);
foreach $file (readdir(SRC))
{ next if ($file !~ /\.img$/);
run_label($file);
}
closedir(SRC);
#===========================================================================
sub run_label
# Open image file, read it to create new detatched label for
# the IMG File that can be read by PDSREAD.
{ local ($file) = $_[0];
my ($img,$label,$not_done,$window);
my ($fitsfile,$junk);
$img = "$SRCDIR/$file";
$label = "$SRCDIR/$file";
$label =~ s/\.img/.lbl/;
# Open the various files:
open(IMG,$img) || die "Could not open source image pipe ($!)";
open(LBL,"| fixlen -c > $label") || die "Could not open label pipe ($!)";
# Digging through the label file:
$window = 0;
# check to see if windows exist
$not_done = 1;
while (($line=) && $not_done)
{ if ($line =~ /OBJECT\s*=\s*WINDOW/)
{$window=$window+1;}
elsif ($line =~ /^\s*END\s*$/)
{ $not_done = 0; }}
close(IMG);
# $nwin = $window/2;
open(IMG,$img) || die "Could not open source image pipe ($!)";
$not_done = 1;
while (($line=) && $not_done)
{
if ($line =~ /RECORD_BYTES\s*=\s*(.*)\s/)
{if ($1 == 2092) {$pbytes = 2;}
else {$pbytes = 4;}
if ($window > 0) {$pbytes = 4;}}
elsif ($line =~ /FILE_RECORDS\s*=\s*(.*)\s/)
{if ($1 == 1034) {$lsamp=1045;} else {$lsamp=1044;}}
# elsif ($line =~ /MISSION_NAME/)
# {printf LBL "NUM_WIN = $nwin\n";}
elsif ($line =~ /\^IMAGE.*\s*=\s*(.*)\s/)
{$rec=$1;
$line =~ s/= .*/= ("$file",$rec)/;}
elsif ($line =~ /LINE_SAMPLES/)
{{$line =~ s/=.*1024/= $lsamp/;}}
elsif ($line =~ /LINE_PREFIX_BYTES/)
{{$line =~ s/=.*/= $pbytes/;}}
elsif ($line =~ /LINE_SUFFIX_BYTES/)
{{$line =~ s/=.*/= 0/;}}
elsif ($line =~ /^\s*END\s*$/)
{ $not_done = 0; }
printf LBL $line;
}
close(IMG);
close(LBL);
# That's it for the label.
return;
}
#=============================================================================