Index: trunk/ippScripts/scripts/diff_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/diff_skycell.pl	(revision 20062)
+++ trunk/ippScripts/scripts/diff_skycell.pl	(revision 20101)
@@ -18,5 +18,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;
@@ -53,31 +52,9 @@
 $ipprc->redirect_output($logDest) if $redirect;
 
-my $STATS =
-   [
-       #          PPSTATS KEYWORD         STATISTIC          DIFFTOOL FLAG
-       { name => "ROBUST_MEDIAN",        type => "mean", flag => "-bg",          dtype => "float" },
-       { name => "ROBUST_STDEV",         type => "rms",  flag => "-bg_stdev",    dtype => "float" },
-       { name => "TIME_SUB",             type => "sum",  flag => "-dtime_diff",  dtype => "float" },
-       { name => "TIME_MATCH",           type => "sum",  flag => "-dtime_match", dtype => "float" },
-       { name => "TIME_PHOT",            type => "sum",  flag => "-dtime_phot",  dtype => "float" },
-       { name => "SUBTRACTION.STAMPS",   type => "mean", flag => "-stamps_num",  dtype => "int" },
-       { name => "SUBTRACTION.DEV.MEAN", type => "mean", flag => "-stamps_mean", dtype => "float" },
-       { name => "SUBTRACTION.DEV.RMS",  type => "mean", flag => "-stamps_rms",  dtype => "float" },
-       { name => "SUBTRACTION.NORM",     type => "mean", flag => "-norm",        dtype => "float" },
-       { name => "SUBTRACTION.BGDIFF",   type => "mean", flag => "-bg_diff",     dtype => "float" },
-       { name => "SUBTRACTION.MX",       type => "mean", flag => "-kernel_x",    dtype => "float" },
-       { name => "SUBTRACTION.MY",       type => "mean", flag => "-kernel_y",    dtype => "float" },
-       { name => "SUBTRACTION.MXX",      type => "mean", flag => "-kernel_xx",   dtype => "float" },
-       { name => "SUBTRACTION.MXY",      type => "mean", flag => "-kernel_xy",   dtype => "float" },
-       { name => "SUBTRACTION.MYY",      type => "mean", flag => "-kernel_yy",   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 $difftool = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1);
 my $ppSub = can_run('ppSub') or (warn "Can't find ppSub" 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.");
@@ -204,4 +181,6 @@
 my $traceDest = $ipprc->filename("TRACE.EXP", $outroot);
 
+my $cmdflags;
+
 # Perform subtraction
 unless ($no_op) {
@@ -233,14 +212,20 @@
 #    &my_die("Couldn't find expected output file: $bin1Name",    $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name);
 #    &my_die("Couldn't find expected output file: $bin2Name",    $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
-    &my_die("Couldn't find expected output file: $outputStats", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats);
-
-    # Get the statistics on the residual image
-    my $statsFile;              # File handle
-    open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $diff_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", $diff_id, $PS_EXIT_PROG_ERROR);
-    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $diff_id, $PS_EXIT_PROG_ERROR);
+
+    my $outputStatsReal = $ipprc->file_resolve($outputStats);
+    &my_die("Couldn't find expected output file: $outputStats", $diff_id, $PS_EXIT_SYS_ERROR) unless unless -f $outputStatsReal;
+
+    # measure chip stats
+    $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_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", $diff_id, $error_code);
+    }
+    foreach my $line (@$stdout_buf) {
+	$cmdflags .= " $line";
+    }
+    chomp $cmdflags;
 }
 
@@ -250,5 +235,5 @@
     {
         my $command = "$difftool -adddiffskyfile -diff_id $diff_id -uri $outputName -path_base $outroot";
-        $command .= $stats->cmdflags();
+        $command .= " $cmdflags";
         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
         $command .= " -hostname $host" if defined $host;
