Index: trunk/ippScripts/scripts/warp_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/warp_skycell.pl	(revision 19938)
+++ trunk/ippScripts/scripts/warp_skycell.pl	(revision 20101)
@@ -22,5 +22,4 @@
 use Pod::Usage qw( pod2usage );
 use PS::IPP::Metadata::Config;
-use PS::IPP::Metadata::Stats;
 use PS::IPP::Metadata::List qw( parse_md_list );
 use PS::IPP::Config 1.01 qw( :standard );
@@ -63,18 +62,4 @@
 $ipprc->redirect_output($logDest) if $redirect;
 
-my $STATS =
-   [
-       #          PPSTATS KEYWORD         STATISTIC          WARPTOOL FLAG
-       { name => "ROBUST_MEDIAN",   type => "mean", flag => "-bg",         dtype => "float" },
-       { name => "ROBUST_STDEV",    type => "rms",  flag => "-bg_stdev",   dtype => "float" },
-       { name => "DT_WARP",         type => "sum",  flag => "-dtime_warp", dtype => "float" },
-       { name => "GOOD_PIXEL_FRAC", type => "mean", flag => "-good_frac",  dtype => "float" },
-       { name => "RANGE.XMIN",      type => "mean", flag => "-xmin",       dtype => "int"   },
-       { name => "RANGE.XMAX",      type => "mean", flag => "-xmax",       dtype => "int"   },
-       { name => "RANGE.YMIN",      type => "mean", flag => "-ymin",       dtype => "int"   },
-       { name => "RANGE.YMAX",      type => "mean", flag => "-ymax",       dtype => "int"   },
-   ];
-my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
-
 # Look for programs we need
 my $missing_tools;
@@ -82,4 +67,5 @@
 my $pswarp = can_run('pswarp') or (warn "Can't find pswarp" and $missing_tools = 1);
 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" 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.");
@@ -180,4 +166,5 @@
 
 # Run pswarp
+my $cmdflags;
 my $accept = 1;                 # Accept the skycell?
 my $do_stats;
@@ -216,18 +203,23 @@
     if ($do_stats) {
         # Check first for the stats file, and if the ACCEPT flag is set.
-        &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats);
-        # Get the statistics on the warped image
-        my $statsFile;              # File handle
-        open $statsFile, $ipprc->file_resolve($outputStats) or die "Can't open statistics file $outputStats: $!\n";
-        my @contents = <$statsFile>; # Contents of file
-        close $statsFile;
-        my $contents = join "", @contents;
-
-        my $metadata = $mdcParser->parse($contents)
-            or &my_die("Unable to parse metadata config", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR);
-        $accept = metadataLookupBool($metadata, "ACCEPT");
-
-        # $accept is set above based on the fraction of lit pixels
-        # XXX for some files, there may not be enough stars to find a good psf.  these should be dropped as well
+	my $outputStatsReal = $ipprc->file_resolve($outputStats);
+        &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;
+
+	# measure chip stats
+	$command = "$ppStatsFromMetadata $outputStatsReal - WARP_SKYFILE";
+	( $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", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR);
+	}
+	foreach my $line (@$stdout_buf) {
+	    $cmdflags .= " $line";
+	}
+	chomp $cmdflags;
+
+	# the stats includes ACCEPT as a boolean: convert the T/F value to 0/1
+        my $acceptFlag = &value_for_flag ($cmdflags, "-accept");
+	$accept = ($acceptFlag = "T") ? 1 : 0;
         if ($accept && !$ipprc->file_exists($outputPSF)) {
             $accept = 0;
@@ -235,13 +227,8 @@
 
         if ($accept) {
-            $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR);
-
             &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage);
             &my_die("Couldn't find expected output file: $outputMask", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
             &my_die("Couldn't find expected output file: $outputWeight", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight);
             &my_die("Couldn't find expected output file: $outputSources", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
-    #    &my_die("Couldn't find expected output file: $outputPSF", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputPSF);
-    #    &my_die("Couldn't find expected output file: $outputBin1", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1);
-    #    &my_die("Couldn't find expected output file: $outputBin2", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin2);
         }
 
@@ -256,5 +243,5 @@
             $command .= " -uri $outputImage" if $accept;
             $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
-            $command .= $stats->cmdflags()   if $accept;
+            $command .= " $cmdflags" if $accept;
             $command .= " -hostname $host"   if defined $host;
             $command .= " -dbname $dbname"   if defined $dbname;
@@ -285,4 +272,16 @@
         }
     }
+}
+
+sub value_for_flag
+{
+    my $cmdflags = shift;
+    my $flag = shift;
+
+    my $value = 0.0;
+    if ($cmdflags =~ m|$flag|) {
+        ($value) = $cmdflags =~ m|$flag\s+(\S+)|;
+    }
+    $value;
 }
 
