Index: trunk/ippScripts/scripts/addstar_run.pl
===================================================================
--- trunk/ippScripts/scripts/addstar_run.pl	(revision 25299)
+++ trunk/ippScripts/scripts/addstar_run.pl	(revision 25816)
@@ -28,10 +28,6 @@
 # Look for programs we need
 my $missing_tools;
-#my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
 my $addtool = can_run('addtool') or (warn "Can't find addtool" and $missing_tools = 1);
-#my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" 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);
-#my $psastro = can_run('psastro') or (warn "Can't find psastro" and $missing_tools = 1);
 my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1);
 if ($missing_tools) {
@@ -40,10 +36,9 @@
 }
 
-my ( $exp_tag, $add_id, $camera, $outroot, $camroot, $recipe, $dbname, $reduction, $dvodb, $verbose, $no_update,
-     $no_op, $redirect, $save_temps, $run_state);
+my ( $exp_tag, $add_id, $camera, $outroot, $camroot, $dbname, $reduction, $dvodb, $image_only, $verbose, $no_update,
+     $no_op, $redirect, $save_temps);
 GetOptions(
     'exp_tag=s'          => \$exp_tag, # Exposure identifier
     'add_id=s'          => \$add_id, # Camtool identifier
-    'recipe=s'          => \$recipe, # Recipe to use
     'camera|c=s'        => \$camera, # Camera
     'dbname|d=s'        => \$dbname, # Database name
@@ -52,5 +47,5 @@
     'reduction=s'       => \$reduction, # Reduction class
     'dvodb|w=s'         => \$dvodb,  # output DVO database
-    'run-state=s'       => \$run_state, # 'new' or 'update'
+    'image-only'        => \$image_only,   # Print to stdout
     'verbose'           => \$verbose,   # Print to stdout
     'no-update'         => \$no_update, # Update the database?
@@ -74,9 +69,4 @@
 my $logDest = $ipprc->filename("LOG.EXP", $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
 
-if (not defined $run_state) { $run_state = 'new'; }
-if ($run_state eq 'update') {
-    $logDest .= '.update';
-}
-
 if ($redirect) {
     $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $add_id, $PS_EXIT_SYS_ERROR );
@@ -89,34 +79,9 @@
 $reduction = 'DEFAULT' unless defined $reduction;
 
+# XXX This is now not used: do we still need it?
 my $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use
 &my_die("Unrecognised ADDSTAR recipe", $add_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_addstar;
 
-#my $recipe_psastro = $ipprc->reduction($reduction, 'PSASTRO'); # Recipe to use
-#&my_die("Unrecognised PSASTRO recipe", $cam_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro;
-
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
-
-my $cmdflags;
-
-# Get list of component files
-my $files;                      # Array of component files
-{
-    my $command = "$addtool -pendingexp -add_id $add_id"; # Command to run
-    $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 addtool: $error_code", $add_id, $error_code);
-    }
-    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
-        &my_die("Unable to parse metadata config doc", $add_id, $PS_EXIT_PROG_ERROR);
-    
-    # extract the metadata for the files into a hash list
-    $files = parse_md_list($metadata) or
-        &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR);   
-}
-
-my $chipObjectsExist = 0;
 
 # Output products
@@ -126,8 +91,4 @@
 my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT",     $camroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
 my $traceDest  = $ipprc->filename("TRACE.EXP",          $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
-
-if ($run_state eq 'update') {
-    $traceDest .= '.update';
-}
 
 # convert supplied DVO database name to UNIX filename
@@ -141,38 +102,28 @@
 
 unless ($no_op) {
-    if (defined $dvodbReal and ($run_state eq 'new')) {
-	## XXX the camera analysis can either save the full set of
-	## detections, or just the image metadata, in the dvodb
+    if (defined $dvodbReal) {
+
+	## addstar can either save the full set of detections, or just
+	## the image metadata, in the dvodb.  this is set in the
+	## database table addRun
 	
-	## get the addstar recipe for this camera and CAMERA reduction
-	my $command = "$ppConfigDump -camera $camera -recipe ADDSTAR $recipe_addstar -dump-recipe ADDSTAR -";
-	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 ppConfigDump: $error_code", $add_id, $PS_EXIT_SYS_ERROR);
-	}
-	my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
-	    &my_die("Unable to parse metadata config doc", $add_id, $PS_EXIT_SYS_ERROR);
-	
-	## allow the dvodb to save only images, or the full detection set
-	my $imagesOnly = metadataLookupBool($recipeData, 'IMAGES.ONLY');
-	
-	# XXX this construct requires the user to have a valid .ptolemyrc
-	# XXX which in turn points at ippconfig/dvo.site
+	# addstar requires the user to have a valid .ptolemyrc which
+	# in turn points at ippconfig/dvo.site
+
+	# get the names for the camera and the real input file
+	my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
+	my $realFile = $ipprc->file_resolve($fpaObjects);
+
 	# require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
-	# XXX this needs to be converted to addstar_client...
-
-	my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
-	$command  = "$addstar -D CAMERA $camdir -update";
-	$command .= " -image" if $imagesOnly;
+	my $command  = "$addstar -update"; # XXX optionally set -update?
+	$command .= " -D CAMERA $camdir";
 	$command .= " -D CATDIR $dvodbReal";
-	
-	my $realFile = $ipprc->file_resolve($fpaObjects);
 	$command .= " $realFile";
+	$command .= " -use-name $fpaObjects"; # DVO wants the neb-name as a file reference
+	$command .= " -image" if $image_only;
 	
 	my $mjd_addstar_start = DateTime->now->mjd;   # MJD of starting script
 	
-	( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run(command => $command, verbose => $verbose);
 	unless ($success) {
@@ -184,15 +135,9 @@
 }
 
-
 # This needs to be updated when addtool is written. BROKEN
 my $fpaCommand = "$addtool -add_id $add_id";
-if ($run_state eq 'new') {
-    $fpaCommand .= " -addprocessedexp";
-    $fpaCommand .= " -path_base $outroot";
-    $fpaCommand .= " $cmdflags";
-    $fpaCommand .= " -dtime_addstar $dtime_addstar";
-} else {
-    $fpaCommand .= " -updaterun -state full";
-}
+$fpaCommand .= " -addprocessedexp";
+$fpaCommand .= " -path_base $outroot";
+$fpaCommand .= " -dtime_addstar $dtime_addstar";
 $fpaCommand .= " -dbname $dbname" if defined $dbname;
 
@@ -223,15 +168,8 @@
 # This needs to be updated when addtool is written. BROKEN
         my $command = "$addtool -add_id $add_id";
-        if ($run_state eq 'new') {
-            $command .= " -addprocessedexp";
-            $command .= " -uri UNKNOWN";
-            $command .= " -fault $exit_code";
-            $command .= " -path_base $outroot";
-            $command .= " -path_base $outroot" if defined $outroot;
-            $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
-        } else {
-            $command .= " -updateprocessedexp";
-            $command .= " -fault $exit_code";
-        }
+	$command .= " -addprocessedexp";
+	$command .= " -fault $exit_code";
+	$command .= " -path_base $outroot" if defined $outroot;
+	$command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
@@ -239,5 +177,4 @@
     exit $exit_code;
 }
-
 
 END {
