Index: trunk/ippScripts/scripts/camera_exp.pl
===================================================================
--- trunk/ippScripts/scripts/camera_exp.pl	(revision 17224)
+++ trunk/ippScripts/scripts/camera_exp.pl	(revision 17521)
@@ -38,5 +38,5 @@
 
 my ( $exp_tag, $cam_id, $camera, $outroot, $recipe, $dbname, $reduction, $dvodb, $verbose, $no_update,
-     $no_op );
+     $no_op, $save_temps );
 GetOptions(
 	   'exp_tag=s'          => \$exp_tag, # Exposure identifier
@@ -51,4 +51,5 @@
 	   'no-update'         => \$no_update, # Update the database?
 	   'no-op'             => \$no_op, # Don't do any operations?
+	   'save-temps'        => \$save_temps, # Save temporary files?
 	   ) or pod2usage( 2 );
 
@@ -75,5 +76,5 @@
 
 # values to extract from output metadata and the stats to calculate
-# these should be coming from the psastro results for Nimfile > 1, 
+# these should be coming from the psastro results
 my $CHIPSTATS = 
     [   
@@ -150,8 +151,9 @@
 
 ### not needed to have such an extensive temp file name.
-my ($list1File, $list1Name) = tempfile( "$exp_tag.cm.$cam_id.b1.list.XXXX", UNLINK => 1 ); # For binning 1
-my ($list2File, $list2Name) = tempfile( "$exp_tag.cm.$cam_id.b2.list.XXXX", UNLINK => 1 ); # For binning 2
-my ($list3File, $list3Name) = tempfile( "$exp_tag.cm.$cam_id.b3.list.XXXX", UNLINK => 1 ); # For astrometry
-
+my ($list1File, $list1Name) = tempfile( "$exp_tag.cm.$cam_id.b1.list.XXXX", UNLINK => !$save_temps ); # For binning 1
+my ($list2File, $list2Name) = tempfile( "$exp_tag.cm.$cam_id.b2.list.XXXX", UNLINK => !$save_temps ); # For binning 2
+my ($list3File, $list3Name) = tempfile( "$exp_tag.cm.$cam_id.b3.list.XXXX", UNLINK => !$save_temps ); # For astrometry
+
+# XXX we perform astrometry iff photometry output exists
 my $chipObjects; 
 my $chipObjectsExist = 0;
@@ -161,10 +163,11 @@
 
     # If there is only one chip, we use this name for the input to addstar
-    $chipObjects = $ipprc->filename("PSASTRO.OUTPUT", $file->{path_base}, $class_id);
+    # we expect the chip analysis stage to produce psphot output (cmf file) and two binned images
+    $chipObjects = $ipprc->filename("PSPHOT.OUTPUT", $file->{path_base}, $class_id);
     print $list1File ($ipprc->filename("PPIMAGE.BIN1", $file->{path_base}, $class_id) . "\n");
     print $list2File ($ipprc->filename("PPIMAGE.BIN2", $file->{path_base}, $class_id) . "\n");
     print $list3File ($ipprc->convert_filename_absolute($chipObjects) . "\n");
 
-    # if any of the output chip astrometry files exist, we can run psastro / addstar below
+    # if any of the output chip photometry files exist, we can run psastro / addstar below
     if ($ipprc->file_exists($chipObjects)) {
 	$chipObjectsExist = 1;
@@ -178,7 +181,8 @@
 $ipprc->outroot_prepare($outroot);
 
+# the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs
 my $jpeg1      = $ipprc->filename("PPIMAGE.JPEG1", 	$outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
 my $jpeg2      = $ipprc->filename("PPIMAGE.JPEG2", 	$outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
-my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT.MEF", $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
+my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT",     $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 $logDest    = $ipprc->filename("LOG.EXP", 	        $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
@@ -198,4 +202,6 @@
     {
 	my $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
+	$command .= " -dbname $dbname" if defined $dbname;
+
 	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run(command => $command, verbose => $verbose);
@@ -210,4 +216,6 @@
     {
 	my $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
+	$command .= " -dbname $dbname" if defined $dbname;
+
 	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run(command => $command, verbose => $verbose);
@@ -219,43 +227,23 @@
     }
 
-    # 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 => $verbose);
-        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) {
-	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 $outroot";
-	    $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 ) =
-		run(command => $command, verbose => $verbose);
-	    unless ($success) {
-		$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-		&my_die("Unable to perform psastro: $error_code", $cam_id, $error_code);
-	    }
-	    # 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);
+	# run psastro on the chipObjects, producing fpaObjects
+	# XXX add a ppStats call which will collect the astrometry stats
+	my $command;
+	$command  = "$psastro -list $list3Name $outroot";
+	$command .= " -tracedest $traceDest -log $logDest";
+	$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 psastro: $error_code", $cam_id, $error_code);
 	}
+	# 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);
 	
-	# do we supply chipObjects or fpaObjects to addstar?
-	# run addstar on either the single chip output or the single fpa output
+	# run addstar on the output fpaObjects (if a DVO database is defined)
 	if (defined $dvodbReal) {
 	    # XXX this construct requires the user to have a valid .ptolemyrc 
@@ -269,10 +257,6 @@
 	    $command .= " -D CATDIR $dvodbReal";
 
-	    if ($mosaicAstrom) {
-		my $realFile = $ipprc->file_resolve($fpaObjects);
-		$command .= " $realFile";
-	    } else {
-		$command .= " -list $list3Name";
-	    }
+	    my $realFile = $ipprc->file_resolve($fpaObjects);
+	    $command .= " $realFile";
 
 	    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
