Index: /trunk/psphot/src/psphotImageMedian.c
===================================================================
--- /trunk/psphot/src/psphotImageMedian.c	(revision 15931)
+++ /trunk/psphot/src/psphotImageMedian.c	(revision 15932)
@@ -1,40 +1,4 @@
 # include "psphotInternal.h"
 static int npass = 0;
-
-// we have 4 possibilities: (INTERNAL or I/O file) and (exists or not)
-// select model pixels (from output background model file, or create internal file)
-static pmReadout *get_model_readout(const char *name, // name of internal/external file
-                                    const pmConfig *config, // configuration information
-                                    const pmFPAview *view,
-                                    pmFPA *inFPA,
-                                    const psImageBinning *binning) {
-    pmReadout *model = NULL;
-
-    bool status = true;
-    pmFPAfile *file = psMetadataLookupPtr(&status, config->files, name);
-    if (file == NULL) {
-        // we are not using PSPHOT.BACKMDL as an I/O file: define an internal version
-        model = pmFPAfileDefineInternal (config->files, name, binning->nXruff, binning->nYruff, PS_TYPE_F32);
-    } else {
-        if (file->mode == PM_FPA_MODE_INTERNAL) {
-            // we are not using PSPHOT.BACKMDL as an I/O file: already defined above
-            model = file->readout;
-        } else {
-            // we are using PSPHOT.BACKMDL as an I/O file: select readout or create
-            model = pmFPAviewThisReadout (view, file->fpa);
-            if (model == NULL) {
-                // readout does not yet exist: create from input
-                // XXX we have an inconsistency in this calculation here and in pmFPACopy
-                // XXX use the psImageBinning functions to set the output image size
-                pmFPAfileCopyStructureView (file->fpa, inFPA, binning->nXbin, binning->nYbin, view);
-                model = pmFPAviewThisReadout (view, file->fpa);
-                PS_ASSERT (binning->nXruff == model->image->numCols, false);
-                PS_ASSERT (binning->nYruff == model->image->numRows, false);
-            }
-        }
-    }
-
-    return model;
-}
 
 // generate the median in NxN boxes, clipping heavily
@@ -165,6 +129,6 @@
 
     // we save the binning structure for use in psphotMagnitudes
-    pmReadout *model = get_model_readout("PSPHOT.BACKMDL", config, view, inFPA, binning);
-    pmReadout *modelStdev = get_model_readout("PSPHOT.BACKMDL.STDEV", config, view, inFPA, binning);
+    pmReadout *model      = pmFPAGenerateReadout (config, view, "PSPHOT.BACKMDL",       inFPA, binning);
+    pmReadout *modelStdev = pmFPAGenerateReadout (config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning);
 
     psF32 **modelData = model->image->data.F32;
