Index: trunk/ippScripts/scripts/staticsky.pl
===================================================================
--- trunk/ippScripts/scripts/staticsky.pl	(revision 31247)
+++ trunk/ippScripts/scripts/staticsky.pl	(revision 31271)
@@ -100,15 +100,4 @@
 # Recipes to use based on reduction class
 $reduction = 'DEFAULT' unless defined $reduction;
-my $recipe_psphot  = $ipprc->reduction($reduction, 'STACKPHOT_PSPHOT'); # Recipe to use for psphot
-my $recipe_ppsub   = $ipprc->reduction($reduction, 'STACKPHOT_PPSUB'); # Recipe to use for ppsub
-my $recipe_ppstack = $ipprc->reduction($reduction, 'STACKPHOT_PPSTACK'); # Recipe to use for ppstack
-unless ($recipe_psphot) {
-    &my_die("Couldn't find selected reduction for STACKPHOT: $reduction\n", $sky_id, $PS_EXIT_CONFIG_ERROR);
-}
-
-print "reduction:      $reduction\n";
-print "recipe_psphot:  $recipe_psphot\n";
-print "recipe_ppsub:   $recipe_ppsub\n";
-print "recipe_ppstack: $recipe_ppstack\n";
 
 
@@ -118,4 +107,15 @@
 
 if ($nInputs > 1) {
+        my $recipe_psphot  = $ipprc->reduction($reduction, 'STACKPHOT_PSPHOT'); # Recipe to use for psphot
+        my $recipe_ppsub   = $ipprc->reduction($reduction, 'STACKPHOT_PPSUB'); # Recipe to use for ppsub
+        my $recipe_ppstack = $ipprc->reduction($reduction, 'STACKPHOT_PPSTACK'); # Recipe to use for ppstack
+        unless ($recipe_psphot) {
+            &my_die("Couldn't find selected reduction for STACKPHOT: $reduction\n", $sky_id, $PS_EXIT_CONFIG_ERROR);
+        }
+
+        print "reduction:      $reduction\n";
+        print "recipe_psphot:  $recipe_psphot\n";
+        print "recipe_ppsub:   $recipe_ppsub\n";
+        print "recipe_ppstack: $recipe_ppstack\n";
         my $configuration = $ipprc->filename("PSPHOT.STACK.CONFIG", $outroot);
 
@@ -177,6 +177,4 @@
             $command .= " -tracedest $traceDest -log $logDest";
             # $command .= " -dbname $dbname" if defined $dbname;
-            # $command .= " -image_id $diff_skyfile_id" if defined $diff_skyfile_id;
-            # $command .= " -source_id $source_id" if defined $source_id;
 
             unless ($no_op) {
@@ -242,5 +240,14 @@
 } else {
         # single input. Run psphot
-        my $configuration = $ipprc->filename("PSPHOT.STACK.CONFIG", $outroot);
+        # find the recipe
+        my $recipe_psphot  = $ipprc->reduction($reduction, 'STACKPHOT_SINGLE_PSPHOT'); # Recipe to use for psphot
+        unless ($recipe_psphot) {
+            &my_die("Couldn't find selected reduction for STACKPHOT: $reduction\n", $sky_id, $PS_EXIT_CONFIG_ERROR);
+        }
+
+        print "reduction:      $reduction\n";
+        print "recipe_psphot:  $recipe_psphot\n";
+
+        my $configuration = $ipprc->filename("PSPHOT.SKY.CONFIG", $outroot);
 
         my $file = $files->[0];
@@ -274,8 +281,6 @@
         }
 
-        my $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF",      $path_base ); # Sources name
-
-        # XXX is this the correct PSF file?
-        my $psfCnv    = $ipprc->filename("PPSTACK.TARGET.PSF",      $path_base ); # PSF name
+        my $output_sources_filerule = "PSPHOT.OUT.CMF.MEF";
+        my $output_psf_filerule = "PSPHOT.PSF.SKY.SAVE";
 
         # XXX we could make some different choices if some inputs do not exist...
@@ -283,8 +288,4 @@
         &my_die("Couldn't find input: $mask",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$mask");
         &my_die("Couldn't find input: $variance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$variance");
-        &my_die("Couldn't find input: $psfCnv",    $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$psfCnv");
-        &my_die("Couldn't find input: $sources",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$sources");
-
-        # my $cmdflags;
 
         # Perform stack photometry analysis
@@ -298,4 +299,6 @@
             $command .= " -dumpconfig $configuration" if $configuration;
             $command .= " -tracedest $traceDest -log $logDest";
+            $command .= " -F PSPHOT.OUTPUT $output_sources_filerule";
+            $command .= " -F PSPHOT.PSF.SAVE $output_psf_filerule";
 
             unless ($no_op) {
@@ -303,56 +306,17 @@
                 unless ($success) {
                     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-                    &my_die("Unable to perform psphotStack: $error_code", $sky_id, $error_code);
+                    &my_die("Unable to perform psphot: $error_code", $sky_id, $error_code);
                 }
 
-                # my $outputStatsReal = $ipprc->file_resolve($outputStats);
-                # &my_die("Couldn't find expected output file: $outputStats", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal);
-
-                # measure chip stats
-                # $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL";
-                # ( $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 ppStatsFromMetadata: $error_code", $sky_id, $error_code);
-                # }
-                # foreach my $line (@$stdout_buf) {
-                #     $cmdflags .= " $line";
-                # }
-                # chomp $cmdflags;
-
-                # my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
-
                 my $quality = 0;
-                if (0 and !$quality) {
-
-                    # Get the output filenames
-                    # we have one set of output files per input file set
-                    for (my $i = 0; $i < @$files; $i++) {
-                        my $outputName     = $ipprc->filename("PSPHOT.STACK.OUTPUT.IMAGE", $outroot, $i);
-                        my $outputMask     = $ipprc->filename("PSPHOT.STACK.OUTPUT.MASK", $outroot, $i);
-                        my $outputVariance = $ipprc->filename("PSPHOT.STACK.OUTPUT.VARIANCE", $outroot, $i);
-                        my $outputSources  = $ipprc->filename("PSPHOT.STACK.OUTPUT", $outroot, $i);
-
-                        # XXX these are optional and not generated by default
-                        # &my_die("Couldn't find expected output file: $outputName", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
-                        # &my_die("Couldn't find expected output file: $outputMask", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
-                        # &my_die("Couldn't find expected output file: $outputVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
-                        &my_die("Couldn't find expected output file: $outputSources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
-                    }
-
-                    #my $configuration  = $ipprc->filename("PPSUB.CONFIG", $outroot);
-                    #my $outputStats    = $ipprc->filename("SKYCELL.STATS", $outroot);
-                    #my $traceDest      = $ipprc->filename("TRACE.EXP", $outroot);
-
-                    my $chisqName     = $ipprc->filename("PSPHOT.CHISQ.IMAGE", $outroot);
-                    my $chisqMask     = $ipprc->filename("PSPHOT.CHISQ.MASK", $outroot);
-                    my $chisqVariance = $ipprc->filename("PSPHOT.CHISQ.VARIANCE", $outroot);
-
-                    # XXX check the recipe -- should we expect these to exist?
-                    # &my_die("Couldn't find expected output file: $chisqName", 	  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqName);
-                    # &my_die("Couldn't find expected output file: $chisqMask", 	  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqMask);
-                    # &my_die("Couldn't find expected output file: $chisqVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqVariance);
+                if (!$quality) {
+                    my $outputSources  = $ipprc->filename($output_sources_filerule, $outroot);
+                    &my_die("Couldn't find expected output file: $outputSources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
+                    my $outputPSF  = $ipprc->filename($output_psf_filerule, $outroot);
+                    &my_die("Couldn't find expected output file: $outputPSF", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputPSF);
                 }
+
+                &my_die("Couldn't find expected output file: $configuration", $sky_id, $PS_EXIT_SYS_ERROR) 
+                    unless $ipprc->file_exists($configuration);
             } else {
                 print "Not executing: $command\n";
