Index: trunk/psphot/src/psphotSkyReplace.c
===================================================================
--- trunk/psphot/src/psphotSkyReplace.c	(revision 6481)
+++ trunk/psphot/src/psphotSkyReplace.c	(revision 6571)
@@ -1,10 +1,21 @@
 # include "psphot.h"
 
-// generate the median in NxN boxes, clipping heavily
-// linear interpolation to generate full-scale model
-bool psphotSkyReplace (pmReadout *readout, psImage *background) { 
+// in order to  successfully replace the sky, we must define a corresponding file...
+bool psphotSkyReplace (psMetadata *config, pmFPAview *view) {
 
+    // find the currently selected readout
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, "PSPHOT");
+    pmFPA *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
+    pmReadout  *readout = pmFPAviewThisReadout (view, input);
+
+    // select the corresponding images
     psImage *image = readout->image;
     psImage *mask  = readout->mask;
+
+    // select background pixels, from output background file, or create
+    background = pmFPAfileReadoutImage (config->files, view, "PSPHOT.BACKGND", 0, 0, PS_TYPE_F32);
+    if (background == NULL) {
+	return false;
+    }
 
     // replace the background model
@@ -17,4 +28,5 @@
     }
     
+    psFree (background);
     return true;
 }
