Index: trunk/psphot/src/psphotModelBackground.c
===================================================================
--- trunk/psphot/src/psphotModelBackground.c	(revision 37940)
+++ trunk/psphot/src/psphotModelBackground.c	(revision 38387)
@@ -519,4 +519,56 @@
 }
 
+// load a background model for readout number index; save an associated pmFPAfile for possible output
+bool psphotLoadBackgroundModelReadoutFileIndex (pmConfig *config, const pmFPAview *view, const char *filename, int index)
+{
+    // find the currently selected readout
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
+    psAssert (file, "missing file?");
+
+    pmFPA *inFPA = file->fpa;
+    pmReadout *readout = pmFPAviewThisReadout(view, inFPA);
+    psAssert (readout, "missing readout?");
+
+    // Set up the background model file
+    // Here we are assuming that the recipe being used is the same as when the original analysis that generated
+    // the background model was done
+    psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters
+    psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING", PS_DATA_UNKNOWN | PS_META_REPLACE, "Background binning", binning);
+    psFree(binning);
+    pmReadout *model = pmFPAGenerateReadout(config, view, psphotGetFilerule("PSPHOT.BACKMDL"), inFPA, binning, index);
+    pmReadout *modelStdev = pmFPAGenerateReadout(config, view, psphotGetFilerule("PSPHOT.BACKMDL.STDEV"), inFPA, binning, index);
+
+    // Copy the image from the input model file to the model file
+    // XXX: Check for nulls and that the image sizes match
+    pmFPAfile *bgFile = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.BACKMDL.RAW", 0);   // File with bg
+    pmChip    *bgChip  = pmFPAviewThisChip(view, bgFile->fpa);
+    pmReadout *bgReadout = pmFPAviewThisReadout(view, bgChip->parent);
+
+    // Copy the image from the input model readout to the model readout
+    model->image = psImageCopy(model->image, bgReadout->image, model->image->type.type);
+    // For now also copy the input into the stdev image. Is this used for anything?
+    modelStdev->image = psImageCopy(modelStdev->image, bgReadout->image, modelStdev->image->type.type);
+
+    return true;
+}
+
+bool psphotLoadBackgroundModel (pmConfig *config, const pmFPAview *view, const char *filerule)
+{
+    int num = psphotFileruleCount(config, filerule);
+
+    fprintf (stdout, "\n");
+    psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Model Background ---");
+
+    // loop over the available readouts
+    for (int i = 0; i < num; i++) {
+        if (!psphotLoadBackgroundModelReadoutFileIndex(config, view, filerule, i)) {
+            int lastError = psErrorCodeLast();
+	    psError (lastError ? lastError : PSPHOT_ERR_CONFIG, false, "failed to model background for %s entry %d", filerule, i);
+            return false;
+        }
+    }
+    return true;
+}
+
 // code for in-line plotting from above
 // turn on stats tracing in desired cells
