Index: trunk/ippScripts/scripts/detrend_resid.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid.pl	(revision 14048)
+++ trunk/ippScripts/scripts/detrend_resid.pl	(revision 14115)
@@ -83,18 +83,21 @@
    [   
        #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
-       { name => "ROBUST_MEDIAN",      type => "mean",  flag => "-bg" },
-       { name => "ROBUST_MEDIAN",      type => "stdev", flag => "-bg_mean_stdev" },
-       { name => "ROBUST_STDEV",       type => "rms",   flag => "-bg_stdev" },
-       { name => "FRINGE_0",           type => "mean",  flag => "-fringe_0" },
-       { name => "FRINGE_ERR_0",       type => "rms",   flag => "-fringe_1" },
-       { name => "FRINGE_0",           type => "stdev", flag => "-fringe_2" },
-       { name => "FRINGE_RESID_0",     type => "mean",  flag => "-user_1" },
-       { name => "FRINGE_RESID_ERR_0", type => "rms",   flag => "-user_2" },
-       { name => "FRINGE_RESID_0",     type => "stdev", flag => "-user_3" },
+       { name => "ROBUST_MEDIAN",      type => "mean",  flag => "-bg",            dtype => "float" },
+       { name => "ROBUST_MEDIAN",      type => "stdev", flag => "-bg_mean_stdev", dtype => "float" },
+       { name => "ROBUST_STDEV",       type => "rms",   flag => "-bg_stdev",	  dtype => "float" },
+       { name => "FRINGE_0",           type => "mean",  flag => "-fringe_0",	  dtype => "float" },
+       { name => "FRINGE_ERR_0",       type => "rms",   flag => "-fringe_1",	  dtype => "float" },
+       { name => "FRINGE_0",           type => "stdev", flag => "-fringe_2",	  dtype => "float" },
+       { name => "FRINGE_RESID_0",     type => "mean",  flag => "-user_1",  	  dtype => "float" },
+       { name => "FRINGE_RESID_ERR_0", type => "rms",   flag => "-user_2",  	  dtype => "float" },
+       { name => "FRINGE_RESID_0",     type => "stdev", flag => "-user_3",  	  dtype => "float" },
    ];
+my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
+
 my $BINNED_STATS = 
    [   
        { name => "ROBUST_STDEV",   type => "rms",   flag => "-bin_stdev" },
    ];
+my $binnedStats = PS::IPP::Metadata::Stats->new($BINNED_STATS); # Stats parser
 
 # Flags to specify the particular detrend to use
@@ -167,5 +170,4 @@
 
     # Parse the statistics on the residual image
-    my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
     $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
 
@@ -179,8 +181,8 @@
     }
 
+    # Parse the output contents into a metadata
+    my $binnedMetadata = $mdcParser->parse(join "", @$stdout_buf) or &my_die("Unable to parse metadata output", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
+
     # parse the binned image statistics
-    my $binnedMetadata = $mdcParser->parse(join "", @$stdout_buf) or &my_die("Unable to parse metadata output", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
-
-    my $binnedStats = PS::IPP::Metadata::Stats->new($BINNED_STATS); # Stats parser
     $binnedStats->parse($binnedMetadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
 }
@@ -196,11 +198,6 @@
 $command .= " -path_base $outputRoot";
 $command .= " -dbname $dbname" if defined $dbname;
-
-# add in the elements from the selected stats above
-foreach my $entry (@$STATS, @$BINNED_STATS) {
-    my $value = $entry->{value};
-    my $flag = $entry->{flag};
-    $command .= " $flag $value";
-}
+$command .= $stats->cmdflags();
+$command .= $binnedStats->cmdflags();
 
 # Add the processed file to the database
