Index: trunk/pstamp/scripts/pstamp_job_run.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_job_run.pl	(revision 38071)
+++ trunk/pstamp/scripts/pstamp_job_run.pl	(revision 38073)
@@ -92,5 +92,5 @@
 my $stack_bkg_mk_mdc = can_run('stack_bkg_mk_mdc.pl') or (warn "Can't find stack_bkg_mk_mdc.pl" and $missing_tools = 1);
 my $fpack = can_run('fpack') or (warn "Can't find fpack" and $missing_tools = 1);
-
+my $staticskytool = can_run('staticskytool') or (warn "Can't find staticskytool" and $missing_tools = 1);
 
 if ($missing_tools) {
@@ -177,4 +177,19 @@
                 # be copied from the cmf file.
                 $argString .= " -recipe PSPHOT STACKPHOT"
+            }
+        } elsif ($stage eq 'stack') {
+            # no astrom file for stack (skycal cmf) Go find a staticsky cmf and use that
+            # otherwise silently ignore the request for sources since the stack smf is not useful.
+            my $staticsky_cmf = findStaticskyCMF($params);
+            if ($staticsky_cmf) {
+                print "Using staticsky cmf file $staticsky_cmf for sources\n";
+                $argString .= " -write_cmf";
+                $fileArgs  .= " -sources $staticsky_cmf";
+                # Set psphot recipe to STACKPHOT so that the extended source paramters will
+                # be copied from the cmf file.
+                $argString .= " -recipe PSPHOT STACKPHOT";
+                push @file_list, $staticsky_cmf;
+            } else {
+                print "No skycal or staticsky cmf for $params->{stack_id} ignoring request for sources\n";
             }
         } elsif ($params->{cmf}) {
@@ -864,4 +879,34 @@
     return 0;
 }
+sub findStaticskyCMF {
+    my $params = shift;
+    my $stack_id = $params->{stack_id};
+
+    &my_die( "NO stack_id found in findStaticskyCMF\n",
+            $job_id, $PS_EXIT_PROG_ERROR, 'run') if !$stack_id;
+
+    my $command = "$staticskytool -dbname $params->{imagedb} -result -stack_id $stack_id";
+    my $results = runToolAndParse($command, $verbose);
+
+    if (!$results) {
+        print "no staticsky results found for stack $stack_id\n";
+        return undef;
+    }
+
+    my $latest;
+    my $latest_sky_id = 0;
+    foreach my $result (@$results) {
+        if ($result->{sky_id} > $latest_sky_id) {
+            $latest = $result;
+            $latest_sky_id = $result->{sky_id};
+        }
+    }
+    if ($latest) {
+        # XXXX Use proper file rule
+        return $latest->{path_base} .  ".stk.$stack_id.cmf";
+    } 
+    # Can't happen can it?
+    return undef;
+}
 
 sub my_die
