Index: trunk/ippScripts/scripts/skycalibration.pl
===================================================================
--- trunk/ippScripts/scripts/skycalibration.pl	(revision 32968)
+++ trunk/ippScripts/scripts/skycalibration.pl	(revision 32972)
@@ -48,4 +48,6 @@
     print "  --outroot (root)        : Output root name\n";
     print "  --path_base (path_base) : path_base of input\n";
+    print "  --filter (filter)       : filter of input\n";
+    print "  --singlefilter          : the input is the result of a single filter analysis";
     print "  --reduction (class)     : Reduction class\n";
     print "  --verbose               : Be extra verbose\n";
@@ -58,5 +60,5 @@
 }
 
-my ($skycal_id, $stack_id, $camera, $dbname, $threads, $outroot, $path_base, $filter, $reduction, $verbose, $no_update, $no_op, $redirect, $save_temps);
+my ($skycal_id, $stack_id, $camera, $dbname, $threads, $outroot, $path_base, $filter, $singlefilter, $reduction, $verbose, $no_update, $no_op, $redirect, $save_temps);
 GetOptions(
     'skycal_id=s'       => \$skycal_id, # sky calibration run id
@@ -69,4 +71,5 @@
     'filter=s'          => \$filter,    # filter for input stack
     'reduction=s'       => \$reduction, # Reduction class
+    'singlefilter'      => \$singlefilter, # input was from single filter analysis
     'verbose'           => \$verbose,   # Print to stdout
     'no-update'         => \$no_update, # Don't update the database?
@@ -111,7 +114,5 @@
 my $recipe_psastro  = $ipprc->reduction($reduction, 'STATICSKY_CALIBRATION'); # Recipe to use for psastro
 unless ($recipe_psastro) {
-    # XXX: ADD to reduction: hard code recipe for now
-    $recipe_psastro = 'STATICSKY_CAL';
-#            &my_die("Couldn't find selected reduction for STACKPHOT: $reduction\n", $skycal_id, $PS_EXIT_CONFIG_ERROR);
+    &my_die("Couldn't find selected reduction for STATICSKY_CALIBRATION: $reduction\n", $skycal_id, $PS_EXIT_CONFIG_ERROR);
 }
 
@@ -123,48 +124,61 @@
 # find input file
 # First check the expected file name where the stack_id is the FILE_ID
-my $file  = $ipprc->filename('PSPHOT.STACK.OUTPUT', $path_base, $stack_id);
-if (! $ipprc->file_resolve($file)) {
-    # XXX: Beginning of section that can go eventually
-
-    # no file with the expected name found
-    # assume that the input is from an early staticsky run that did not use stack_id as the FILE_ID
-    # but instead used FILE_ID = [0 .. num_filters-1]
-    print "\nfailed to resolve $file\n";
-    if (!$filter) {
-        &my_die("filter not supplied unable to identify appropriate staticsky input.", $skycal_id, $PS_EXIT_SYS_ERROR);
-    }
-    print "Trying old FILE_ID\n";
-    my $max_filters = 5;
-    for (my $i=0; $i < $max_filters; $i++) {
-        my $file_id = sprintf "%03d", $i;
-        $file  = $ipprc->filename('PSPHOT.STACK.OUTPUT', $path_base, $file_id);
-        my $resolved = $ipprc->file_resolve($file);
-        if (!$resolved) {
-            # we fail here assumming that if file_id N doesn't exist, neither to N+1
-            print "\nfailed to resolve $file\n\n";
-            &my_die("unable to identify appropriate staticsky input.", $skycal_id, $PS_EXIT_SYS_ERROR);
-        }
-        # Check the filter id for this file
-        my $command = "$fhead $resolved | grep FILTERID";
-        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-            run(command => $command, verbose => 0);
-        unless ($success) {
-            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-            &my_die("Unable to perform $command: $error_code", $skycal_id, $PS_EXIT_SYS_ERROR);
-        }
-        # Expected output: HIERARCH FPA.FILTERID = 'r.00000 ' / Filter used (parsed, abstract name)
-        my ($undef, undef, undef, $filt) = split " ", join("", @$stdout_buf);
-        my $this_filter = substr $filt, 1, 7;
-
-        # if it matches we're done
-        last if $this_filter eq $filter;
-
-        # nope loop around to try the next one
-        print "Input file for $filter is not $file ($this_filter)\n";
-        $file = undef;
-    }
-    print "\nInput file for $stack_id filter: $filter: $file\n";
-
-    # XXX: End of section that can go eventually
+my $file;
+if (!$singlefilter) {
+    $file = $ipprc->filename('PSPHOT.STACK.OUTPUT', $path_base, $stack_id);
+    if (! $ipprc->file_resolve($file)) {
+        # XXX: Beginning of section that can be removed eventually
+
+        # no file with the expected name found
+        # assume that the input is from an early staticsky run that did not use stack_id as the FILE_ID
+        # but instead used FILE_ID = [0 .. num_filters-1]
+        print "\nfailed to resolve $file\n";
+        if (!$filter) {
+            &my_die("filter not supplied unable to identify appropriate staticsky input.", $skycal_id, $PS_EXIT_SYS_ERROR);
+        }
+        print "Trying old style FILE_ID\n";
+        my $max_filters = 5;
+        for (my $i=0; $i < $max_filters; $i++) {
+            my $file_id = sprintf "%03d", $i;
+            $file  = $ipprc->filename('PSPHOT.STACK.OUTPUT', $path_base, $file_id);
+            my $resolved = $ipprc->file_resolve($file);
+            if (!$resolved) {
+                # we fail here assumming that if file_id N doesn't exist, neither to N+1
+                print "\nfailed to resolve $file\n\n";
+                &my_die("unable to identify appropriate staticsky input.", $skycal_id, $PS_EXIT_SYS_ERROR);
+            }
+            # Check the filter id for this file
+            my $command = "$fhead $resolved | grep FILTERID";
+            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                run(command => $command, verbose => 0);
+            unless ($success) {
+                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                &my_die("Unable to perform $command: $error_code", $skycal_id, $PS_EXIT_SYS_ERROR);
+            }
+            # Expected output: HIERARCH FPA.FILTERID = 'r.00000 ' / Filter used (parsed, abstract name)
+            my ($undef, undef, undef, $filt) = split " ", join("", @$stdout_buf);
+            my $this_filter = substr $filt, 1, 7;
+
+            # if it matches we're done
+            last if $this_filter eq $filter;
+
+            # nope loop around to try the next one
+            print "Input file for $filter is not $file ($this_filter)\n";
+            $file = undef;
+        }
+        print "\nInput file for $stack_id filter: $filter: $file\n";
+
+        # XXX: End of section that can be removed eventually
+    }
+} else {
+    # input is from a single filter static sky run use a different file rule
+    # XXX: can't we just make staticsky.pl use the same file rule?
+    $file = $ipprc->filename('PSPHOT.OUT.CMF.MEF', $path_base);
+    &my_die("Unable to find input for $stack_id $filter", $skycal_id, $PS_EXIT_SYS_ERROR) 
+        unless $ipprc->file_exists($file);
+}
+
+if (!$file) {
+    &my_die("Unable to find input for $stack_id $filter", $skycal_id, $PS_EXIT_SYS_ERROR);
 }
 
@@ -192,5 +206,7 @@
 
         {
-            my $command = "$ppStatsFromMetadata $stats - STATICSKY_CAL";
+            my $resolved = $ipprc->file_resolve($stats) 
+                or  &my_die("failed to resolve stats file: $stats", $skycal_id, $PS_EXIT_SYS_ERROR) ;
+            my $command = "$ppStatsFromMetadata $resolved - STATICSKY_CAL";
             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
             unless ($success) {
