Index: trunk/ippScripts/scripts/stack_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/stack_skycell.pl	(revision 19938)
+++ trunk/ippScripts/scripts/stack_skycell.pl	(revision 20101)
@@ -19,5 +19,4 @@
 use IPC::Cmd 0.36 qw( can_run run );
 use PS::IPP::Metadata::Config;
-use PS::IPP::Metadata::Stats;
 use PS::IPP::Metadata::List qw( parse_md_list );
 use Data::Dumper;
@@ -67,35 +66,9 @@
 $ipprc->redirect_output($logDest) if $redirect;
 
-my $STATS =
-   [
-       #          PPSTATS KEYWORD         STATISTIC          STACKTOOL FLAG
-       { name => "ROBUST_MEDIAN",   type => "mean",  flag => "-bg",                dtype => "float" },
-       { name => "ROBUST_STDEV",    type => "rms",   flag => "-bg_stdev",          dtype => "float" },
-       { name => "TIME_STACK",      type => "sum",   flag => "-dtime_stack",       dtype => "float" },
-       { name => "TIME_MATCH",      type => "mean",  flag => "-dtime_match_mean",  dtype => "float" },
-       { name => "TIME_MATCH",      type => "stdev", flag => "-dtime_match_stdev", dtype => "float" },
-       { name => "TIME_INITIAL",    type => "sum",   flag => "-dtime_initial",     dtype => "float" },
-       { name => "TIME_REJECT",     type => "sum",   flag => "-dtime_reject",      dtype => "float" },
-       { name => "TIME_FINAL",      type => "sum",   flag => "-dtime_final",       dtype => "float" },
-       { name => "TIME_PHOT",       type => "sum",   flag => "-dtime_phot",        dtype => "float" },
-       { name => "STAMP.MEAN",      type => "mean",  flag => "-match_mean",        dtype => "float" },
-       { name => "STAMP.MEAN",      type => "stdev", flag => "-match_stdev",       dtype => "float" },
-       { name => "STAMP.RMS",       type => "rms",   flag => "-match_rms",         dtype => "float" },
-       { name => "STAMP.NUM",       type => "mean",  flag => "-stamps_mean",       dtype => "float" },
-       { name => "STAMP.NUM",       type => "stdev", flag => "-stamps_stdev",      dtype => "float" },
-       { name => "STAMP.NUM",       type => "min",   flag => "-stamps_min",        dtype => "int" },
-       { name => "TIME_PHOT",       type => "sum",   flag => "-dtime_phot",        dtype => "float" },
-       { name => "REJECT_IMAGES",   type => "sum",   flag => "-reject_images",     dtype => "int" },
-       { name => "REJECT_PIXELS",   type => "mean",  flag => "-reject_pix_mean",   dtype => "float" },
-       { name => "REJECT_PIXELS",   type => "stdev", flag => "-reject_pix_stdev",  dtype => "float" },
-       { name => "NUM_SOURCES",     type => "sum",   flag => "-sources",           dtype => "int" },
-       { name => "GOOD_PIXEL_FRAC", type => "mean",  flag => "-good_frac",         dtype => "float" },
-   ];
-my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
-
 # Look for programs we need
 my $missing_tools;
 my $stacktool = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1);
 my $ppStack = can_run('ppStack') or (warn "Can't find ppStack" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
 if ($missing_tools) {
     warn("Can't find required tools.");
@@ -208,4 +181,6 @@
 # doesn't know how to resolve paths. (The information is stored in the configuration file)
 $configuration = $ipprc->file_resolve($configuration) if ($run_state eq 'update');
+
+my $cmdflags;
 
 # Perform stacking
@@ -244,14 +219,19 @@
 
     if ($do_stats) {
-        &my_die("Couldn't find expected output file: $outputStats", $stack_id, $PS_EXIT_SYS_ERROR)
-            unless $ipprc->file_exists($outputStats);
-        # Get the statistics on the stacked image
-        my $statsFile;              # File handle
-        open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $stack_id, $PS_EXIT_SYS_ERROR);
-        my @contents = <$statsFile>; # Contents of file
-        close $statsFile;
-        my $metadata = $mdcParser->parse(join "", @contents) or
-            &my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR);
-        $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $stack_id, $PS_EXIT_PROG_ERROR);
+	my $outputStatsReal = $ipprc->file_resolve($outputStats);
+        &my_die("Couldn't find expected output file: $outputStats", $stack_id, $PS_EXIT_SYS_ERROR) unless unless -f $outputStatsReal;
+
+	# measure chip stats
+	$command = "$ppStatsFromMetadata $outputStatsReal - STACK_SKYCELL";
+	( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	    run(command => $command, verbose => $verbose);
+	unless ($success) {
+	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+	    &my_die("Unable to perform ppStatsFromMetadata: $error_code", $stack_id, $error_code);
+	}
+	foreach my $line (@$stdout_buf) {
+	    $cmdflags .= " $line";
+	}
+	chomp $cmdflags;
     }
 }
@@ -272,5 +252,5 @@
         }
         $command .= " $mode -stack_id $stack_id";
-        $command .= $stats->cmdflags() if $do_stats;
+        $command .= " $cmdflags" if $do_stats;
         $command .= " -dbname $dbname" if defined $dbname;
 
