Index: /trunk/psphot/src/psphotImageMedian.c
===================================================================
--- /trunk/psphot/src/psphotImageMedian.c	(revision 12610)
+++ /trunk/psphot/src/psphotImageMedian.c	(revision 12611)
@@ -1,4 +1,4 @@
 # include "psphot.h"
-// # define TESTSAVE
+static int npass = 0;
 
 // generate the median in NxN boxes, clipping heavily
@@ -277,10 +277,15 @@
     }
 
-# ifdef TESTSAVE
-    psphotSaveImage (NULL, image, "image.fits");
-    psphotSaveImage (NULL, background->image, "back.fits");
-    psphotSaveImage (NULL, mask, "mask.fits");
-    psphotSaveImage (NULL, model->image, "backmdl.fits");
-# endif
+    if (psTraceGetLevel("psphot") > 5) {
+	char name[256];
+	sprintf (name, "image.%02d.fits", npass);
+	psphotSaveImage (NULL, image, name);
+	sprintf (name, "back.%02d.fits", npass);
+	psphotSaveImage (NULL, background->image, name);
+	sprintf (name, "mask.%02d.fits", npass);
+	psphotSaveImage (NULL, mask, name);
+	sprintf (name, "backmdl.%02d.fits", npass);
+	psphotSaveImage (NULL, model->image, name);
+    }
 
     // subtract the background model (save in backSub, if requested)
@@ -294,8 +299,10 @@
     }
 
-# ifdef TESTSAVE
-    psphotSaveImage (NULL, image, "backsub.fits");
-    exit (1);
-# endif
+    if (psTraceGetLevel("psphot") > 5) {
+	char name[256];
+	sprintf (name, "backsub.%02d.fits", npass);
+	psphotSaveImage (NULL, image, name);
+    }
+    npass ++;
 
     psLogMsg ("psphot", PS_LOG_INFO, "subtracted background model: %f sec\n", psTimerMark ("psphot"));
@@ -308,70 +315,2 @@
     return true;
 }
-
-
-# if (0)
-
-    // dimensions of input & output image
-    int Nx = image->numCols;
-    int Ny = image->numRows;
-
-    // scaling factor
-    int DX = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN");
-    int DY = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN");
-
-    // overhang : we will balance this evenly
-    int xExtra = (Nx % DX) / 2;
-    int yExtra = (Ny % DY) / 2;
-    int xOffset = (xExtra > 0) ? DX - xExtra : 0;
-    int yOffset = (yExtra > 0) ? DY - yExtra : 0;
-    xOffset -= image->col0;
-    yOffset -= image->row0;
-
-    // dimensions of binned image
-    int nx, ny;
-    if (Nx % DX == 0) {
-	nx = Nx / DX;
-    } else {
-	nx = (xExtra) ? (Nx / DX) + 2 : (Nx / DX) + 1;
-    }
-    if (Ny % DY == 0) {
-	ny = Ny / DY;
-    } else {
-	ny = (yExtra) ? (Ny / DY) + 2 : (Ny / DY) + 1;
-    }
-
-    // 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)
-    file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKMDL");
-    if (file == NULL) {
-	// we are not using PSPHOT.BACKMDL as an I/O file: define an internal version
-        model = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKMDL", nx, ny, 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
-		pmFPAfileCopyStructureView (file->fpa, inFPA, DX, DY, view);
-		model = pmFPAviewThisReadout (view, file->fpa);
-		if ((nx != model->image->numCols) || (ny != model->image->numRows)) {
-		    psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for model dimensions");
-		    return false;
-		}
-	    }
-	}
-    }
-    psF32 **modelData = model->image->data.F32;
-
-
-
-            // sx, sy are in parent coords
-            int sx = ix*DX - xOffset;
-            int sy = iy*DY - yOffset;
-            region = psRegionSet (sx, sx + 2*DX, sy, sy + 2*DY);
-
-# endif
