Index: trunk/ippScripts/scripts/camera_exp.pl
===================================================================
--- trunk/ippScripts/scripts/camera_exp.pl	(revision 19466)
+++ trunk/ippScripts/scripts/camera_exp.pl	(revision 19561)
@@ -27,5 +27,5 @@
 
 my ( $exp_tag, $cam_id, $camera, $outroot, $recipe, $dbname, $reduction, $dvodb, $verbose, $no_update,
-     $no_op, $redirect, $save_temps );
+     $no_op, $redirect, $save_temps, $run_state);
 GetOptions(
     'exp_tag=s'          => \$exp_tag, # Exposure identifier
@@ -37,4 +37,5 @@
     'reduction=s'       => \$reduction, # Reduction class
     'dvodb|w=s'         => \$dvodb,  # output DVO database
+    'run-state=s'       => \$run_state, # 'new' or 'update'
     'verbose'           => \$verbose,   # Print to stdout
     'no-update'         => \$no_update, # Update the database?
@@ -57,4 +58,7 @@
 
 my $logDest = $ipprc->filename("LOG.EXP", $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
+if ($run_state eq 'update') {
+    $logDest .= '.update';
+}
 
 $ipprc->redirect_output($logDest) if $redirect;
@@ -196,4 +200,10 @@
 my $fpaStats   = $ipprc->filename("PSASTRO.STATS",      $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
 my $traceDest  = $ipprc->filename("TRACE.EXP",          $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
+my $configuration = $ipprc->filename("PSASTRO.CONFIG",  $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
+
+if ($run_state eq 'update') {
+    $traceDest .= '.update';
+    $fpaStats .= '.update';
+}
 
 # convert supplied DVO database name to UNIX filename
@@ -210,5 +220,5 @@
 
     # Make the jpeg for binning 1
-    {
+    if ($run_state eq 'new') {
         my $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
         $command .= " -dbname $dbname" if defined $dbname;
@@ -224,5 +234,5 @@
 
     # Make the jpeg for binning 2
-    {
+    if ($run_state eq 'new') {
         my $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
         $command .= " -dbname $dbname" if defined $dbname;
@@ -244,6 +254,16 @@
         $command  = "$psastro -list $list3Name $outroot";
         $command .= " -tracedest $traceDest -log $logDest";
-        $command .= " -stats $fpaStats -recipe PPSTATS CHIPSTATS";
         $command .= " -dbname $dbname" if defined $dbname;
+
+        my $do_stats;
+        if ($run_state eq 'new') {
+            $command .= " -stats $fpaStats -recipe PPSTATS CHIPSTATS";
+            $command .= " -dumpconfig $configuration";
+            $do_stats = 1;
+        } elsif ($run_state eq 'update') {
+            $command .= " -ipprc $configuration";
+        } else {
+            &my_die("invalid value for run-state: $run_state", $cam_id, $PS_EXIT_CONFIG_ERROR);
+        }
 
         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -255,26 +275,29 @@
         # XXX do we want to give an error if astrometry fails here?
         &my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
-        &my_die("Unable to find expected output file: $fpaStats",   $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
-
-        # Get the statistics on the processed image
-        my $statsFile;              # File handle
-        open $statsFile, $ipprc->file_resolve($fpaStats) or &my_die("Can't open statistics file $fpaStats: $!", $cam_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", $cam_id, $PS_EXIT_PROG_ERROR);
-        }
-
-        # extract the stats from the metadata
-        unless ($camStats->parse($metadata)) {
-            &my_die("Failure extracting metadata from the statistics output file.\n", $cam_id, $PS_EXIT_PROG_ERROR);
+
+        if ($do_stats) {
+            &my_die("Unable to find expected output file: $fpaStats",   $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
+
+            # Get the statistics on the processed image
+            my $statsFile;              # File handle
+            open $statsFile, $ipprc->file_resolve($fpaStats) or &my_die("Can't open statistics file $fpaStats: $!", $cam_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", $cam_id, $PS_EXIT_PROG_ERROR);
+            }
+
+            # extract the stats from the metadata
+            unless ($camStats->parse($metadata)) {
+                &my_die("Failure extracting metadata from the statistics output file.\n", $cam_id, $PS_EXIT_PROG_ERROR);
+            }
         }
 
         # run addstar on the output fpaObjects (if a DVO database is defined)
-        if (defined $dvodbReal) {
+        if (defined $dvodbReal and ($run_state eq 'new')) {
 
             ## XXX the camera analysis can either save the full set of
@@ -319,12 +342,17 @@
 }
 
-my $fpaCommand = "$camtool -addprocessedexp";
-$fpaCommand .= " -cam_id $cam_id";
-$fpaCommand .= " -uri UNKNOWN";
-$fpaCommand .= " -path_base $outroot";
-$fpaCommand .= " -hostname $host" if defined $host;
+
+my $fpaCommand = "$camtool -cam_id $cam_id";
+if ($run_state eq 'new') {
+    $fpaCommand .= " -addprocessedexp";
+    $fpaCommand .= " -uri UNKNOWN";
+    $fpaCommand .= " -path_base $outroot";
+    $fpaCommand .= $chipStats->cmdflags();
+    $fpaCommand .= $camStats->cmdflags();
+    $fpaCommand .= " -hostname $host" if defined $host;
+} else {
+    $fpaCommand .= " -updaterun -state full";
+}
 $fpaCommand .= " -dbname $dbname" if defined $dbname;
-$fpaCommand .= $chipStats->cmdflags();
-$fpaCommand .= $camStats->cmdflags();
 
 # Add the result into the database
@@ -350,12 +378,17 @@
     carp($msg);
     if (defined $cam_id and not $no_update) {
-        my $command = "$camtool -addprocessedexp";
-        $command .= " -cam_id $cam_id";
-        $command .= " -uri UNKNOWN";
-        $command .= " -code $exit_code";
-        $command .= " -path_base $outroot";
+        my $command = "$camtool -cam_id $cam_id";
+        if ($run_state eq 'new') {
+            $command .= " -addprocessedexp";
+            $command .= " -uri UNKNOWN";
+            $command .= " -code $exit_code";
+            $command .= " -path_base $outroot";
+            $command .= " -path_base $outroot" if defined $outroot;
+        } else {
+            $command .= " -updateprocessedexp";
+            $command .= " -code $exit_code";
+        }
         $command .= " -hostname $host" if defined $host;
         $command .= " -dbname $dbname" if defined $dbname;
-        $command .= " -path_base $outroot" if defined $outroot;
         system ($command);
     }
