Index: /branches/eam_branches/ipp-20101205/psphot/src/psphotReplaceUnfit.c
===================================================================
--- /branches/eam_branches/ipp-20101205/psphot/src/psphotReplaceUnfit.c	(revision 30195)
+++ /branches/eam_branches/ipp-20101205/psphot/src/psphotReplaceUnfit.c	(revision 30196)
@@ -213,4 +213,8 @@
     psAssert (maskVal, "missing mask value?");
 
+    // what fraction of the PSF is used? (radius in pixels : 2 -> 5x5 box)
+    int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE");
+    assert (status);
+
     pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
     psAssert (psf, "missing psf?");
@@ -254,5 +258,4 @@
 	  pmSourceCachePSF (source, maskVal);
 
-# if (0)
 	  psKernel *psfKernel = pmPCMkernelFromPSF(source, psfSize);
 	  if (!psfKernel) { 
@@ -260,10 +263,15 @@
 	  }
 
-	  psImage *modelFlux = getmodelflux(model);
-	  psImageConvolveFFT (source->modelFlux, modelFlux, NULL, 0, psfKernel);
+	  // generate an image of the right size
+	  psImage *rawModelFlux = psImageCopy (NULL, source->pixels, PS_TYPE_F32);
+	  psImageInit (rawModelFlux, 0.0);
+	  
+	  // insert the model image normalized to 1.0
+	  pmModelAdd (rawModelFlux, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal);
+
+	  psImageConvolveFFT (source->modelFlux, rawModelFlux, NULL, 0, psfKernel);
 	  
 	  psFree (psfKernel);
-	  psFree (modelFlux);
-# endif
+	  psFree (rawModelFlux);
       }
 
@@ -271,8 +279,4 @@
     }
 
-    // psphotSaveImage(NULL, readoutIn->image, "image.in.fits");
-    // psphotSaveImage(NULL, readoutOut->image, "image.out.sub.fits");
-    // psphotVisualShowImage (readout);
-
     psLogMsg ("psphot.replace", PS_LOG_INFO, "subtracted models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace"));
     return true;
