Index: trunk/ippScripts/scripts/ipp_apply_burntool.pl
===================================================================
--- trunk/ippScripts/scripts/ipp_apply_burntool.pl	(revision 27293)
+++ trunk/ippScripts/scripts/ipp_apply_burntool.pl	(revision 27298)
@@ -1,10 +1,10 @@
 #!/usr/bin/env perl
 # this program is used to run 'burntool' on images for a single chip
-# for all exposures for a given time period.   
-# USAGE: ipp_apply_burntool.pl --dbname gpc1 --class_id XY00 --dateobs_begin YYYY/MM/DD --dateobs_end YYYY/MM/DD 
+# for all exposures for a given time period.
+# USAGE: ipp_apply_burntool.pl --dbname gpc1 --class_id XY00 --dateobs_begin YYYY/MM/DD --dateobs_end YYYY/MM/DD
 
 # XXX todo:
 # - add filters to processedimfile
-# 
+#
 
 use warnings;
@@ -82,5 +82,5 @@
 foreach my $cfg (@$recipeData) {
     if ($cfg->{name} eq 'BURNTOOL.STATE.GOOD') {
-	$burntoolStateGood = $cfg->{value};
+        $burntoolStateGood = $cfg->{value};
     }
 }
@@ -100,5 +100,5 @@
 $command .= " -dbname $dbname" if defined $dbname;
 
-( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 
+( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     run ( command => $command, verbose => $verbose);
 unless ($success) {
@@ -114,11 +114,11 @@
     push @single, $value;
     if ($value =~ /^\s*END\s*$/) {
-	push @single, "\n";
-	
-	my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
-	&my_die("Unable to parse output from regtool", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_PROG_ERROR) unless
-	    defined $list;
-	push @{ $files }, @$list;
-	@single = ();
+        push @single, "\n";
+
+        my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
+        &my_die("Unable to parse output from regtool", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_PROG_ERROR) unless
+            defined $list;
+        push @{ $files }, @$list;
+        @single = ();
     }
 }
@@ -142,93 +142,94 @@
     my $rawImfile = $file->{uri};
     my $rawImfileReal = $ipprc->file_resolve($rawImfile, 0);
-    
+
     my $outTable  = $file->{uri};
     $outTable  =~ s/fits$/burn.tbl/;
     my $outTableReal = $ipprc->file_resolve($outTable, 1);
-    
+
     my $process = 0;
     my $previousTableStyle = 0;
 
     if ($state == 0) {
-	$process = 1;
+        $process = 1;
     }
     elsif ($state == -1) {
-	$process = 1;
+        $process = 1;
     }
     elsif ($state == -3) {
-	$process = 1;
+        $process = 1;
     }
     elsif ($state == -2) {
-	&my_die("Aborting as $rawImfile has modified pixel data!");
+        &my_die("Aborting as $rawImfile has modified pixel data!");
     }
     elsif ($state == $burntoolStateGood) {
-	$process = 0;
-	$previousTableStyle = 1;
+        $process = 0;
+        $previousTableStyle = 1;
     }
     elsif ($state == -1 * $burntoolStateGood) {
-	$process = 0;
-#	$previousTable = "in=$outTableReal";
-	$previousTableStyle = -1;
+        $process = 0;
+#       $previousTable = "in=$outTableReal";
+        $previousTableStyle = -1;
     }
     else {
-	$process = 1;
+        $process = 1;
     }
     if ($REALRUN == 0) {
-	print "##Pretending to process as instructed!\n";
-	$process = 1;
+        print "##Pretending to process as instructed!\n";
+        $process = 1;
     }
     if (($process == 1)||($processNext == 1)) {
-	$processNext = 1;
-	# Set state to processing
-	my $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -1", $REALRUN);
-	if ($status) {
-	    &my_die("failed to update imfile");
-	}
-	$file->{burntool_state} = -1;
-	
-	my $tempfile = new File::Temp ( TEMPLATE => "$file->{exp_name}.XXXX",
-					DIR => '/tmp/',
-					UNLINK => !$save_temps,
-					SUFFIX => '.fits');
-	my $tempPixels = $tempfile->filename;
-	
-	# Run burntool
-	$status = vsystem ("$funpack -S $rawImfileReal > $tempPixels", $REALRUN);
-	if ($status) {
-	    &my_die("failed on funpack",$exp_id,$class_id);
-	}
-	if ($previousTable ne '') {
-	    $status = vsystem ("$burntool $tempPixels $previousTable out=$outTableReal tableonly=t persist=t", $REALRUN);
-	}
-	else {
-	    $status = vsystem ("$burntool $tempPixels out=$outTableReal tableonly=t persist=t", $REALRUN);
-	}
-	if ($status) {
-	    &my_die("failed on burntool",$exp_id,$class_id);
-	}
-	
-	$status = vsystem ("$nebXattr --write $outTable user.copies:2",$REALRUN);
-	$status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state $outState", $REALRUN);
-	if ($status) {
-	    &my_die("failed to update imfile");
-	}
-
-	$previousTableStyle = -1;
-	
-	print "\n";
-    }
-    
+        $processNext = 1;
+        # Set state to processing
+        my $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -1", $REALRUN);
+        if ($status) {
+            &my_die("failed to update imfile");
+        }
+        $file->{burntool_state} = -1;
+
+        my $tempfile = new File::Temp ( TEMPLATE => "$file->{exp_name}.XXXX",
+                                        DIR => '/tmp/',
+                                        UNLINK => !$save_temps,
+                                        SUFFIX => '.fits');
+        my $tempPixels = $tempfile->filename;
+
+        # Run burntool
+        $status = vsystem ("$funpack -S $rawImfileReal > $tempPixels", $REALRUN);
+        if ($status) {
+            &my_die("failed on funpack",$exp_id,$class_id);
+        }
+        if ($previousTable ne '') {
+            $status = vsystem ("$burntool $tempPixels $previousTable out=$outTableReal tableonly=t persist=t", $REALRUN);
+        }
+        else {
+            $status = vsystem ("$burntool $tempPixels out=$outTableReal tableonly=t persist=t", $REALRUN);
+        }
+        if ($status) {
+            &my_die("failed on burntool",$exp_id,$class_id);
+        }
+        &my_die("Unable to find output file: $outTableReal", $exp_id, $class_id) unless $ipprc->file_exists($outTableReal);
+
+        $status = vsystem ("$nebXattr --write $outTable user.copies:2",$REALRUN);
+        $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state $outState", $REALRUN);
+        if ($status) {
+            &my_die("failed to update imfile");
+        }
+
+        $previousTableStyle = -1;
+
+        print "\n";
+    }
+
     if ($previousTableStyle == 1) {
-	$previousTable = "infits=$rawImfileReal";
+        $previousTable = "infits=$rawImfileReal";
     }
     elsif ($previousTableStyle == -1) {
-	$previousTable = "in=$outTableReal";
+        $previousTable = "in=$outTableReal";
     }
     else {
-	die "previousTableStyle undefined!\n";
-    }
-    
-}
-    
+        die "previousTableStyle undefined!\n";
+    }
+
+}
+
 exit 0;
 
@@ -238,8 +239,8 @@
 
     print "$command\n";
-    
+
     my $status = 0;
     if ($realrun) {
-	$status = system ($command);
+        $status = system ($command);
     }
 
@@ -250,7 +251,7 @@
     my $message = shift;
     if ($#_ != -1) {
-	my $exp_id = shift;
-	my $class_id = shift;
-	vsystem("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -3",1);
+        my $exp_id = shift;
+        my $class_id = shift;
+        vsystem("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -3",1);
     }
     printf STDERR "$message\n";
