Index: trunk/ippScripts/scripts/stack_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/stack_skycell.pl	(revision 25518)
+++ trunk/ippScripts/scripts/stack_skycell.pl	(revision 25519)
@@ -112,4 +112,13 @@
 print "I've loaded my inputs: $stack_id\n";
 
+# Recipes to use based on reduction class
+$reduction = 'DEFAULT' unless defined $reduction;
+my $recipe_ppStack = $ipprc->reduction($reduction, 'STACK_PPSTACK'); # Recipe to use for ppStack
+my $recipe_ppSub = $ipprc->reduction($reduction, 'STACK_PPSUB'); # Recipe to use for ppSub
+my $recipe_psphot  = $ipprc->reduction($reduction, 'STACK_PSPHOT'); # Recipe to use for psphot
+unless ($recipe_ppStack and $recipe_ppSub and $recipe_psphot) {
+    &my_die("Couldn't find selected reduction for STACK_PPSTACK, STACK_PPSUB and STACK_PSPHOT: $reduction\n", $stack_id, $PS_EXIT_CONFIG_ERROR);
+}
+
 # Parse the list of input files to get the tesselation, skycell identifiers and camera
 my $skycell_id;                 # Skycell identifier
@@ -141,12 +150,18 @@
 $ipprc->define_camera($camera);
 
-# Recipes to use based on reduction class
-$reduction = 'DEFAULT' unless defined $reduction;
-my $recipe_ppStack = $ipprc->reduction($reduction, 'STACK_PPSTACK'); # Recipe to use for ppStack
-my $recipe_ppSub = $ipprc->reduction($reduction, 'STACK_PPSUB'); # Recipe to use for ppSub
-my $recipe_psphot  = $ipprc->reduction($reduction, 'STACK_PSPHOT'); # Recipe to use for psphot
-unless ($recipe_ppStack and $recipe_ppSub and $recipe_psphot) {
-    &my_die("Couldn't find selected reduction for STACK_PPSTACK, STACK_PPSUB and STACK_PSPHOT: $reduction\n", $stack_id, $PS_EXIT_CONFIG_ERROR);
-}
+my $recipe;
+{
+    my $command = "$ppConfigDump -camera $camera -recipe PPSTACK $recipe_ppStack -dump-recipe PPSTACK -";
+    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", $stack_id, $error_code);
+    }
+    my $recipe = $mdcParser->parse(join "", @$stdout_buf) or
+        &my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR);
+}
+my $convolve = metadataLookupBool($recipe, 'CONVOLVE'); # Convolve inputs?
+
 
 print "I've configured everything: $stack_id\n";
@@ -166,5 +181,5 @@
     my $mask = $ipprc->filename( "PSWARP.OUTPUT.MASK", $file->{path_base} ); # Mask name
     my $weight = $ipprc->filename( "PSWARP.OUTPUT.VARIANCE", $file->{path_base} ); # Weight name
-    my $psf = $ipprc->filename( "PSPHOT.PSF.SKY.SAVE", $file->{path_base} ); # PSF name
+    my $psf = $convolve ? $ipprc->filename( "PSPHOT.PSF.SKY.SAVE", $file->{path_base} ) : undef; # PSF name
     my $sources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $file->{path_base}); # Sources name
 
@@ -172,5 +187,5 @@
     &my_die("Mask $mask does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $mask );
     &my_die("Weight $weight does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $weight );
-    &my_die("PSF $psf does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $psf );
+    &my_die("PSF $psf does not exist", $stack_id, $PS_EXIT_SYS_ERROR) if ($convolve and not $ipprc->file_exists( $psf ));
     &my_die("Sources $sources does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $sources );
 
@@ -178,9 +193,6 @@
     print $listFile "\tMASK\tSTR\t" . $mask . "\n";
     print $listFile "\tVARIANCE\tSTR\t" . $weight . "\n";
-    print $listFile "\tPSF\tSTR\t" . $psf . "\n";
+    print $listFile "\tPSF\tSTR\t" . $psf . "\n" if $convolve;
     print $listFile "\tSOURCES\tSTR\t" . $sources . "\n";
-
-    ### XXX NEED TO UPDATE THESE appropriately
-    print $listFile "\tWEIGHTING\tF32\t" . 1.0 . "\n";
 
     print $listFile "END\n\n";
@@ -274,5 +286,5 @@
 #       &my_die("Couldn't find expected output file: $bin2Name",    $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
     }
-    
+
     print "I've stacked $listName: $stack_id\n";
 }
@@ -352,20 +364,11 @@
 
     print "Ensuring temporary images are deleted.\n";
-    my $command = "$ppConfigDump -camera $camera -recipe PPSTACK $recipe_ppStack -dump-recipe PPSTACK -";
-    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", $stack_id, $error_code);
-    }
-    my $md = $mdcParser->parse(join "", @$stdout_buf) or
-        &my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR);
-
-    my $temp_delete = metadataLookupBool($md, 'TEMP.DELETE'); # Delete temporary files?
+
+    my $temp_delete = defined($recipe) and metadataLookupBool($recipe, 'TEMP.DELETE'); # Delete temp files?
     if ($temp_delete) {
-        my $temp_dir = metadataLookupStr($md, 'TEMP.DIR'); # Directory with temporary files
-        my $temp_image = metadataLookupStr($md, 'TEMP.IMAGE'); # Suffix for image
-        my $temp_mask = metadataLookupStr($md, 'TEMP.MASK'); # Suffix for mask
-        my $temp_weight = metadataLookupStr($md, 'TEMP.VARIANCE'); # Suffix for weight
+        my $temp_dir = metadataLookupStr($recipe, 'TEMP.DIR'); # Directory with temporary files
+        my $temp_image = metadataLookupStr($recipe, 'TEMP.IMAGE'); # Suffix for image
+        my $temp_mask = metadataLookupStr($recipe, 'TEMP.MASK'); # Suffix for mask
+        my $temp_weight = metadataLookupStr($recipe, 'TEMP.VARIANCE'); # Suffix for weight
         my $temp_root = basename($outroot); # Root name for temporary files
 
