Index: trunk/ippScripts/scripts/detrend_resid.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid.pl	(revision 13732)
+++ trunk/ippScripts/scripts/detrend_resid.pl	(revision 13748)
@@ -125,12 +125,13 @@
 my $bin2Name =  $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id);
 my $outputStats = $outputRoot . '.' . $class_id . '.stats';
-my $outputBinnedStats = $outputRoot . '.' . $class_id . '.bin.stats';
-
-# Run ppImage
+
+# Run ppImage & ppStats
 my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
 my $binnedStats = PS::IPP::Metadata::Stats->new(); # Stats parser
 unless ($no_op) {
-    my $command = "$ppImage -file $input_uri $outputRoot -recipe PPIMAGE $recipe" .
-	" -stat $outputStats "; # Command to run ppImage
+    my $command = "$ppImage -file $input_uri $outputRoot";
+    $command .= " -recipe PPIMAGE $recipe";
+    $command .= " -recipe PPSTATS RESIDUAL";
+    $command .= " -stats $outputStats";
 
     # Detrend to use in processing
@@ -152,19 +153,19 @@
     &my_die("Couldn't find expected output file: $bin2Name", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin2Name);
 
-    # Get the statistics on the residual image
+    # Load the raw output stats file
     my $statsFile;		# File handle
     open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR);
     my @contents = <$statsFile>; # Contents of file
     close $statsFile;
+
+    # Parse the statistics on the residual image
     my $mdcParser = PS::IPP::Metadata::Config->new;	# Parser for metadata config files
     my $metadata = $mdcParser->parse(join "", @contents) or &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
-    # $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
     $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
 
     # run ppStats on the binned image
-    $command = "$ppStats $bin2Name $outputBinnedStats";
+    $command = "$ppStats -recipe PPSTATS RESIDUAL $bin2Name";
     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
-
     unless ($success) {
 	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
@@ -172,11 +173,6 @@
     }
 
-    &my_die("Couldn't find expected output file: $outputBinnedStats", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputBinnedStats);
-
-    open $statsFile, $ipprc->file_resolve($outputBinnedStats) or &my_die("Can't open statistics file $outputBinnedStats: $!", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR);
-    @contents = <$statsFile>; # Contents of file
-    close $statsFile;
-    my $binnedMetadata = $mdcParser->parse(join "", @contents) or &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
-    # $binnedStats = PS::IPP::Metadata::Stats->new(); # Stats parser
+    # parse the binned image statistics
+    my $binnedMetadata = $mdcParser->parse(join "", @$stdout_buf) or &my_die("Unable to parse metadata output", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     $binnedStats->parse($binnedMetadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
 }
