Index: trunk/ippScripts/scripts/camera_exp.pl
===================================================================
--- trunk/ippScripts/scripts/camera_exp.pl	(revision 15387)
+++ trunk/ippScripts/scripts/camera_exp.pl	(revision 16018)
@@ -28,4 +28,6 @@
 		       $PS_EXIT_DATA_ERROR
 		       $PS_EXIT_TIMEOUT_ERROR
+		       metadataLookupStr
+		       metadataLookupBool
 		       caturi
 		       );
@@ -51,7 +53,7 @@
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage(
-    -msg => "Required options: --exp_tag --cam_id --camera",
-    -exitval => 3,
-) unless defined $exp_tag
+	  -msg => "Required options: --exp_tag --cam_id --camera",
+	  -exitval => 3,
+	  ) unless defined $exp_tag
     and defined $cam_id
     and defined $camera;
@@ -70,6 +72,6 @@
 # values to extract from output metadata and the stats to calculate
 my $CHIPSTATS = 
-   [   
-       #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
+    [   
+	#          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
 	{ name => "bg",             type => "mean",  flag => "-bg",            	dtype => "float" },
 	{ name => "bg_mean_stdev",  type => "stdev", flag => "-bg_mean_stdev", 	dtype => "float" },
@@ -90,5 +92,5 @@
 #       { name => "fringe_1",       type => "rms",   flag => "-fringe_1",      	dtype => "float" },  
 #       { name => "fringe_0",       type => "stdev", flag => "-fringe_2",      	dtype => "float" },  
-   ];
+	];
 my $chipStats = PS::IPP::Metadata::Stats->new($CHIPSTATS); # Stats parser
 
@@ -97,4 +99,5 @@
 my $camtool = can_run('camtool') or (warn "Can't find camtool" 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);
 
 # test for addstar and psastro:
@@ -149,5 +152,5 @@
     print $list3File ($chipObjects . "\n");
 
-     # if any of the output chip astrometry files exist, we can run psastro / addstar below
+    # if any of the output chip astrometry files exist, we can run psastro / addstar below
     if ($ipprc->file_exists($chipObjects)) {
 	$chipObjectsExist = 1;
@@ -203,12 +206,30 @@
     }
 
-    # only run psastro / addstar if any of the output chip astrometry files exist
+    # check recipe for PSASTRO.MOSAIC.MODE; run mosaic astrometry if
+    # requested by the camera's PSASTRO recipe
+    my $mosaicAstrom;		# run mosaic-level astrometry?
+    {
+        my $command = "$ppConfigDump -camera $camera -dump-recipe PSASTRO -";
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	    run(command => $command, verbose => 1);
+        unless ($success) {
+	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+	    &my_die("Unable to perform ppConfigDump: $error_code", $cam_id, $error_code);
+        }
+        my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
+	    &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_PROG_ERROR);
+        $mosaicAstrom = metadataLookupBool($metadata, 'PSASTRO.MOSAIC.MODE');
+    }
+
+    # only run psastro / addstar if any of the output chip astrometry files exist (should we test for successful astrometry?)
     if ($chipObjectsExist) {
-	# run psastro +mosastro on the set of chips or copy the chipObjects to fpaObjects
-	# XXX note that this is wrong if imfiles are cells
-	# XXX add a ppStats call which will collect the astrometry stats
-	if (scalar @$files > 1) {
-	    my $command = "$psastro -list $list3Name $outputRoot +mosastro -chipastro " . 
-		"-F PSASTRO.OUTPUT PSASTRO.OUTPUT.MEF";
+	if ($mosaicAstrom) {
+	    # run psastro +mosastro on the set of chips or copy the chipObjects to fpaObjects
+	    # XXX note that this is wrong if imfiles are cells
+	    # XXX add a ppStats call which will collect the astrometry stats
+	    my $command;
+	    $command  = "$psastro -list $list3Name $outputRoot";
+	    $command .= " +mosastro -chipastro";
+	    $command .= " -F PSASTRO.OUTPUT PSASTRO.OUTPUT.MEF";
 	    $command .= " -tracedest $traceDest -log $logDest";
 	    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -218,19 +239,27 @@
 		&my_die("Unable to perform psastro: $error_code", $cam_id, $error_code);
 	    }
-	} else {
-	    $ipprc->file_copy($chipObjects, $fpaObjects) unless $chipObjects eq $fpaObjects;
+	    # 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: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
-
+	
+	# do we supply chipObjects or fpaObjects to addstar?
 	# run addstar on either the single chip output or the single fpa output
-	# XXX this construct requires the user to have a valid .ptolemyrc 
-	# XXX which in turn points at ippconfig/dvo.site
-	
-	# 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...
 	if (defined $dvodbReal) {
+	    # XXX this construct requires the user to have a valid .ptolemyrc 
+	    # XXX which in turn points at ippconfig/dvo.site
+	    # 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
-	    my $command = "$addstar -D CAMERA $camdir " . $ipprc->file_resolve($fpaObjects);
+	    my $command;
+	    $command  = "$addstar -D CAMERA $camdir ";
 	    $command .= " -D CATDIR $dvodbReal";
+
+	    if ($mosaicAstrom) {
+		$command .= " $ipprc->file_resolve($fpaObjects)";
+	    } else {
+		print STDERR "ERROR: addstar needs to be update to support the -list input structure\n";
+		$command .= " -list $list3File";
+	    }
 
 	    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -242,5 +271,4 @@
 	}
     }
-    
 }
 
