Index: trunk/ippScripts/scripts/diff_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/diff_skycell.pl	(revision 17671)
+++ trunk/ippScripts/scripts/diff_skycell.pl	(revision 17787)
@@ -31,5 +31,5 @@
     'outroot=s'         => \$outroot, # Output root name
     'verbose'           => \$verbose,   # Print to stdout
-    'no-update'         => \$no_update,	# Don't update the database?
+    'no-update'         => \$no_update, # Don't update the database?
     'no-op'             => \$no_op, # Don't do any operations?
 ) or pod2usage( 2 );
@@ -39,13 +39,16 @@
     -msg => "Required options: --diff_id",
     -exitval => 3,
-	  ) unless defined $diff_id
+          ) unless defined $diff_id
     and defined $outroot;
 
-my $STATS = 
-   [   
+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 => "DT_DIFF",         type => "sum",  flag => "-dtime_diff", dtype => "float" },
+       { name => "DT_DIFF",         type => "sum",  flag => "-dtime_diff", dtype => "float" },
+       { name => "SUBTRACTION.NUM", type => "mean", flag => "-stamps_num", dtype => "int" },
+       { name => "SUBTRACTION.RMS", type => "mean", flag => "-stamps_rms", dtype => "float" },
+       { name => "NUM_SOURCES",     type => "sum",  flag => "-sources",    dtype => "int" },
        { name => "GOOD_PIXEL_FRAC", type => "mean", flag => "-good_frac",  dtype => "float" },
    ];
@@ -56,11 +59,11 @@
 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);
-if ($missing_tools) { 
+if ($missing_tools) {
     warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR); 
+    exit($PS_EXIT_CONFIG_ERROR);
 }
 
 # Get list of components for subtraction
-my $mdcParser = PS::IPP::Metadata::Config->new;	# Parser for metadata config files
+my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 my $files;
 {
@@ -68,14 +71,14 @@
     $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to perform difftool -inputskyfile: $error_code", $diff_id, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform difftool -inputskyfile: $error_code", $diff_id, $error_code);
     }
 
     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
-	&my_die("Unable to parse metadata config doc", $diff_id, $PS_EXIT_PROG_ERROR);
-    $files = parse_md_list($metadata) or 
-	&my_die("Unable to parse metadata list", $diff_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata config doc", $diff_id, $PS_EXIT_PROG_ERROR);
+    $files = parse_md_list($metadata) or
+        &my_die("Unable to parse metadata list", $diff_id, $PS_EXIT_PROG_ERROR);
 }
 
@@ -86,49 +89,49 @@
 my ($input, $inputMask, $inputWeight, $inputPath, $inputPSF); # Input files and path
 my ($template, $templateMask, $templateWeight, $templatePath, $templateSources); # Template files and path
-my $tess_id;			# Tesselation identifier
-my $skycell_id;			# Skycell identifier
-my $camera;			# Camera
+my $tess_id;                    # Tesselation identifier
+my $skycell_id;                 # Skycell identifier
+my $camera;                     # Camera
 foreach my $file (@$files) {
     if (defined $file->{template} and $file->{template}) {
-	$template = $file->{uri};
-	$templatePath = $file->{path_base};
-	if ($file->{warp_id} == 0) {
-	    $templateMask = "PPSTACK.OUTPUT.MASK";
-	    $templateWeight = "PPSTACK.OUTPUT.WEIGHT";
-	    $templateSources = "PSPHOT.OUTPUT";
-	} else {
-	    $templateMask = "PSWARP.OUTPUT.MASK";
-	    $templateWeight = "PSWARP.OUTPUT.WEIGHT";
-	    $templateSources = "PSWARP.OUTPUT.SOURCES";
-	}
-    } else {
-	$input = $file->{uri};
-	$inputPath = $file->{path_base};
-	if ($file->{warp_id} == 0) {
-	    $inputMask = "PPSTACK.OUTPUT.MASK";
-	    $inputWeight = "PPSTACK.OUTPUT.WEIGHT";
-	    $inputPSF = "PSPHOT.PSF.SAVE";
-	} else {
-	    $inputMask = "PSWARP.OUTPUT.MASK";
-	    $inputWeight = "PSWARP.OUTPUT.WEIGHT";
-	    $inputPSF = "PSPHOT.PSF.SAVE";
-	}
+        $template = $file->{uri};
+        $templatePath = $file->{path_base};
+        if ($file->{warp_id} == 0) {
+            $templateMask = "PPSTACK.OUTPUT.MASK";
+            $templateWeight = "PPSTACK.OUTPUT.WEIGHT";
+            $templateSources = "PSPHOT.OUTPUT";
+        } else {
+            $templateMask = "PSWARP.OUTPUT.MASK";
+            $templateWeight = "PSWARP.OUTPUT.WEIGHT";
+            $templateSources = "PSWARP.OUTPUT.SOURCES";
+        }
+    } else {
+        $input = $file->{uri};
+        $inputPath = $file->{path_base};
+        if ($file->{warp_id} == 0) {
+            $inputMask = "PPSTACK.OUTPUT.MASK";
+            $inputWeight = "PPSTACK.OUTPUT.WEIGHT";
+            $inputPSF = "PSPHOT.PSF.SAVE";
+        } else {
+            $inputMask = "PSWARP.OUTPUT.MASK";
+            $inputWeight = "PSWARP.OUTPUT.WEIGHT";
+            $inputPSF = "PSPHOT.PSF.SAVE";
+        }
     }
     if (defined $tess_id) {
-	&my_die("Tesselation identifiers don't match", $diff_id, $PS_EXIT_SYS_ERROR) unless
-	    $file->{tess_id} eq $tess_id;
-    } else {
-	$tess_id = $file->{tess_id};
+        &my_die("Tesselation identifiers don't match", $diff_id, $PS_EXIT_SYS_ERROR) unless
+            $file->{tess_id} eq $tess_id;
+    } else {
+        $tess_id = $file->{tess_id};
     }
     if (defined $skycell_id) {
-	&my_die("Skycell identifiers don't match", $diff_id, $PS_EXIT_SYS_ERROR) unless
-	    $file->{skycell_id} eq $skycell_id;
-    } else {
-	$skycell_id = $file->{skycell_id};
+        &my_die("Skycell identifiers don't match", $diff_id, $PS_EXIT_SYS_ERROR) unless
+            $file->{skycell_id} eq $skycell_id;
+    } else {
+        $skycell_id = $file->{skycell_id};
     }
     if (defined $camera) {
-	&my_die("Cameras don't match", $diff_id, $PS_EXIT_SYS_ERROR) unless $file->{camera} eq $camera;
-    } else {
-	$camera = $file->{camera};
+        &my_die("Cameras don't match", $diff_id, $PS_EXIT_SYS_ERROR) unless $file->{camera} eq $camera;
+    } else {
+        $camera = $file->{camera};
     }
 
@@ -181,8 +184,8 @@
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to perform ppSub: $error_code", $diff_id, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform ppSub: $error_code", $diff_id, $error_code);
     }
     &my_die("Couldn't find expected output file: $outputName", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
@@ -195,10 +198,10 @@
 
     # Get the statistics on the residual image
-    my $statsFile;		# File handle
+    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);
+        &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);
 }
@@ -208,28 +211,28 @@
     # Add the subtraction result
     {
-	my $command = "$difftool -adddiffskyfile -diff_id $diff_id -uri $outputName -path_base $outroot";
-	$command .= $stats->cmdflags();
-	$command .= " -dbname $dbname" if defined $dbname;
-	
-	my ( $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 difftool -adddiffskyfile: $error_code", $diff_id, $error_code);
-	}
+        my $command = "$difftool -adddiffskyfile -diff_id $diff_id -uri $outputName -path_base $outroot";
+        $command .= $stats->cmdflags();
+        $command .= " -dbname $dbname" if defined $dbname;
+
+        my ( $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 difftool -adddiffskyfile: $error_code", $diff_id, $error_code);
+        }
     }
 
     # Register the run as completed
     {
-	my $command = "$difftool -updaterun -diff_id $diff_id -state stop"; # Command to run difftool
-	$command .= " -dbname $dbname" if defined $dbname;
-
-	my ( $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);
-	    warn("Unable to perform difftool -updaterun: $error_code\n");
-	    exit($error_code);
-	}
+        my $command = "$difftool -updaterun -diff_id $diff_id -state stop"; # Command to run difftool
+        $command .= " -dbname $dbname" if defined $dbname;
+
+        my ( $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);
+            warn("Unable to perform difftool -updaterun: $error_code\n");
+            exit($error_code);
+        }
     }
 }
@@ -238,12 +241,12 @@
 sub my_die
 {
-    my $msg = shift;		# Warning message on die
-    my $diff_id = shift;	# Diff identifier
-    my $exit_code = shift;	# Exit code to add
+    my $msg = shift;            # Warning message on die
+    my $diff_id = shift;        # Diff identifier
+    my $exit_code = shift;      # Exit code to add
 
     warn($msg);
     if (defined $diff_id and not $no_update) {
-	my $command = "$difftool -adddiffskyfile -diff_id $diff_id -code $exit_code";
-	$command .= " -dbname $dbname" if defined $dbname;
+        my $command = "$difftool -adddiffskyfile -diff_id $diff_id -code $exit_code";
+        $command .= " -dbname $dbname" if defined $dbname;
         run(command => $command, verbose => $verbose);
     }
