Index: trunk/ippScripts/scripts/stack_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/stack_skycell.pl	(revision 19674)
+++ trunk/ippScripts/scripts/stack_skycell.pl	(revision 19680)
@@ -55,4 +55,11 @@
 
 my $logDest = "$outroot.log";
+
+my $do_stats;
+if ($run_state eq 'new') {
+    $do_stats = 1;
+} else {
+    $logDest .= ".update";
+}
 $ipprc->redirect_output($logDest) if $redirect;
 
@@ -192,12 +199,17 @@
 my $outputStats = $ipprc->filename("SKYCELL.STATS", $outroot);
 my $traceDest = $ipprc->filename("TRACE.EXP", $outroot);
+$traceDest .= ".update" if $run_state eq 'update';
 my $configuration = $ipprc->filename("PPSTACK.CONFIG", $outroot);
+
+# for update we need to resolve the config filename here because the code that reads it
+# 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');
 
 # Perform stacking
 unless ($no_op) {
     my $command = "$ppStack $listName $outroot";
-    $command .= " -stats $outputStats";
+    $command .= " -stats $outputStats" if $do_stats;;
     $command .= " -recipe PPSUB STACK";
-    $command .= " -recipe PPSTATS WARPSTATS";
+    $command .= " -recipe PPSTATS WARPSTATS" if $do_stats;;
     $command .= " -F PSPHOT.PSF.SAVE PSPHOT.PSF.SKY.SAVE";
     $command .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF";
@@ -207,6 +219,11 @@
     $command .= " -debug-stack" if defined $debug;
     $command .= " -tracedest $traceDest -log $logDest";
-    $command .= " -dumpconfig $configuration";
     $command .= " -dbname $dbname" if defined $dbname;
+    if ($run_state eq 'new') {
+        $command .= " -dumpconfig $configuration";
+    } else {
+        $command .= " -ipprc $configuration";
+    }
+        
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -222,14 +239,16 @@
 #   &my_die("Couldn't find expected output file: $bin1Name",    $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name);
 #   &my_die("Couldn't find expected output file: $bin2Name",    $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
-    &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_die("Couldn't find expected output file: $outputStats", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats) or !$do_stats;
+
+    if ($do_stats) {
+        # 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);
+    }
 }
 
@@ -238,7 +257,15 @@
     # Add the stack result
     {
-        my $command = "$stacktool -addsumskyfile -stack_id $stack_id -uri $outputName -path_base $outroot";
-        $command .= $stats->cmdflags();
-        $command .= " -hostname $host" if defined $host;
+        my $command = "$stacktool";
+        my $mode;
+        if ($run_state eq 'new') {
+            $mode = "-addsumskyfile"; 
+            $command .= " -uri $outputName -path_base $outroot";
+            $command .= " -hostname $host" if defined $host;
+        } else {
+            $mode = "-updaterun -state full";
+        }
+        $command .= " $mode -stack_id $stack_id";
+        $command .= $stats->cmdflags() if $do_stats;
         $command .= " -dbname $dbname" if defined $dbname;
 
@@ -247,22 +274,8 @@
         unless ($success) {
             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-            &my_die("Unable to perform stacktool -addsumskyfile: $error_code", $stack_id, $error_code);
+            &my_die("Unable to perform stacktool $mode $error_code", $stack_id, $error_code);
         }
     }
 
-    # Register the run as completed
-    # XXX why is this needed?  the stackRun is set to 'full' by the stacktool -addsumskyfile command...
-    if (0) {
-        my $command = "$stacktool -updaterun -stack_id $stack_id -state full"; # Command to run stacktool
-        $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 stacktool -updaterun: $error_code\n");
-            exit($error_code);
-        }
-    }
 }
 
@@ -276,6 +289,11 @@
     carp($msg);
     if (defined $stack_id and not $no_update) {
-        my $command = "$stacktool -addsumskyfile -stack_id $stack_id -code $exit_code";
-        $command .= " -hostname $host" if defined $host;
+        my $command = "$stacktool -stack_id $stack_id -code $exit_code";
+        if ($run_state eq 'new') {
+            $command .= " -addsumskyfile";
+            $command .= " -hostname $host" if defined $host;
+        } else {
+            $command .= " -updatesumskyfile";
+        }
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
