Index: trunk/ippScripts/scripts/chip_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/chip_imfile.pl	(revision 19333)
+++ trunk/ippScripts/scripts/chip_imfile.pl	(revision 19397)
@@ -59,4 +59,5 @@
 
 my $logDest = $ipprc->filename("LOG.IMFILE", $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
+$logDest .= "_update" if $run_state eq "update";
 
 $ipprc->redirect_output($logDest) if $redirect;
@@ -134,4 +135,5 @@
 my $outputStats   = $ipprc->filename("PPIMAGE.STATS",       $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
 my $traceDest     = $ipprc->filename("TRACE.IMFILE",        $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $configuration = $ipprc->filename("PPIMAGE.CONFIG",      $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
 
 # Run ppImage
@@ -140,25 +142,27 @@
     ## XXX also stats: output should be implied by $outroot
     my $command;
+    my $do_stats = 1;
 
     if ($run_state eq "new") {
 	$command  = "$ppImage -file $uri $outroot";
 	$command .= " -recipe PPIMAGE $recipe";
+	$command .= " -threads $threads" if defined $threads;
+	$command .= " -dbname $dbname" if defined $dbname;
+        $command .= " -dumpconfig $configuration";
+	$command .= " -tracedest $traceDest -log $logDest";
+    } else {
+
+        $do_stats = 0; # XXX write stats to an alternate file and compare?
+
+	$command  = "$ppImage -file $uri $outroot";
+	$command .= " -ipprc $configuration";
+	$command .= " -threads $threads" if defined $threads;
+	$command .= " -dbname $dbname" if defined $dbname;
+	$command .= " -tracedest ${traceDest}_update -log $logDest";
+	$command .= " -Db PPIMAGE:PHOTOM FALSE";
+    }
+    if ($do_stats) {
 	$command .= " -recipe PPSTATS CHIPSTATS";
 	$command .= " -stats $outputStats";
-	$command .= " -threads $threads" if defined $threads;
-	$command .= " -dbname $dbname" if defined $dbname;
-	$command .= " -tracedest $traceDest -log $logDest";
-    } else {
-	## for the UPDATE processing, we need to determine the config file
-	my $configuration = $ipprc->filename("PPIMAGE.CONFIG", $outroot, $class_id) or 
-	    &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
-
-	$command  = "$ppImage -file $uri $outroot";
-	$command .= " -ipprc $configuration";
-	# $command .= " -stats $outputStats"; XXX write stats to an alternate file and compare?
-	$command .= " -threads $threads" if defined $threads;
-	$command .= " -dbname $dbname" if defined $dbname;
-	# $command .= " -tracedest $traceDest -log $logDest"; XXX use an alternate trace and log file?
-	$command .= "-Db PPIMAGE:PHOTOM FALSE";
     }
 
@@ -199,35 +203,46 @@
     &my_die("Couldn't find expected output file: $outputBin1\n",   $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1);
     &my_die("Couldn't find expected output file: $outputBin2\n",   $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin2);
-    &my_die("Couldn't find expected output file: $outputStats\n",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats);
-
-    # Get the statistics on the processed image
-    my $statsFile;              # File handle
-    open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-    my @contents = <$statsFile>; # Contents of file
-    close $statsFile;
-
-    # parse the statistics MDC file
-    my $mdcParser = PS::IPP::Metadata::Config->new();   # Parser for metadata config files
-    my $metadata = $mdcParser->parse(join "", @contents);
-    unless ($metadata) {
-        &my_die("Unable to parse metadata config doc", $exp_id, $chip_id, $class_id, $PS_EXIT_PROG_ERROR);
-    }
-
-    # extract the stats from the metadata
-    unless ($stats->parse($metadata)) {
-        &my_die("Failure extracting metadata from the statistics output file.\n", $exp_id, $chip_id, $class_id, $PS_EXIT_PROG_ERROR);
-    }
-}
-
-# command to update database
-my $command = "$chiptool -addprocessedimfile";
-$command .= " -exp_id $exp_id";
-$command .= " -chip_id $chip_id";
-$command .= " -class_id $class_id";
-$command .= " -uri $outputImage";
-$command .= " -path_base $outroot";
-$command .= " -hostname $host" if defined $host;
-$command .= " -dbname $dbname" if defined $dbname;
-$command .= $stats->cmdflags();
+
+    if ($do_stats) {
+        &my_die("Couldn't find expected output file: $outputStats\n",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats);
+
+        # Get the statistics on the processed image
+        my $statsFile;              # File handle
+        open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+        my @contents = <$statsFile>; # Contents of file
+        close $statsFile;
+
+        # parse the statistics MDC file
+        my $mdcParser = PS::IPP::Metadata::Config->new();   # Parser for metadata config files
+        my $metadata = $mdcParser->parse(join "", @contents);
+        unless ($metadata) {
+            &my_die("Unable to parse metadata config doc", $exp_id, $chip_id, $class_id, $PS_EXIT_PROG_ERROR);
+        }
+
+        # extract the stats from the metadata
+        unless ($stats->parse($metadata)) {
+            &my_die("Failure extracting metadata from the statistics output file.\n", $exp_id, $chip_id, $class_id, $PS_EXIT_PROG_ERROR);
+        }
+    }
+}
+
+my $command;
+if ($run_state eq 'new') {
+    # command to update database
+    $command = "$chiptool -addprocessedimfile";
+    $command .= " -exp_id $exp_id";
+    $command .= " -chip_id $chip_id";
+    $command .= " -class_id $class_id";
+    $command .= " -uri $outputImage";
+    $command .= " -path_base $outroot";
+    $command .= " -hostname $host" if defined $host;
+    $command .= " -dbname $dbname" if defined $dbname;
+    $command .= $stats->cmdflags();
+} else {
+    $command = "$chiptool -tofullimfile";
+    $command .= " -chip_id $chip_id";
+    $command .= " -class_id $class_id";
+    $command .= " -dbname $dbname" if defined $dbname;
+}
 
 # Add the processed file to the database
@@ -251,16 +266,21 @@
     my $class_id = shift; # Class identifier
     my $exit_code = shift; # Exit code to add
-    # outputImage and outroot are globals
+    # run_state, outputImage, and outroot are globals
 
     carp($msg);
     if (defined $chip_id and defined $class_id and not $no_update) {
-        my $command = "$chiptool -addprocessedimfile";
-        $command .= " -exp_id $exp_id";
+        my $command;
+        if ($run_state eq 'new') {
+            $command = "$chiptool -addprocessedimfile";
+            $command .= " -exp_id $exp_id";
+            $command .= " -uri $outputImage";
+            $command .= " -path_base $outroot";
+            $command .= " -hostname $host" if defined $host;
+        } else {
+            $command .= "$chiptool -updateprocessedimfile";
+        }
         $command .= " -chip_id $chip_id";
         $command .= " -class_id $class_id";
         $command .= " -code $exit_code";
-        $command .= " -uri $outputImage";
-        $command .= " -path_base $outroot";
-        $command .= " -hostname $host" if defined $host;
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
