Index: trunk/psphot/src/apply_psf_model.c
===================================================================
--- trunk/psphot/src/apply_psf_model.c	(revision 4582)
+++ trunk/psphot/src/apply_psf_model.c	(revision 4630)
@@ -22,4 +22,6 @@
     float shapeNsigma = psMetadataLookupF32 (&status, config, "PSF_SHAPE_NSIGMA");
     float OUTER       = psMetadataLookupF32 (&status, config, "OUTER_RADIUS");
+    float FIT_MIN_SN  = psMetadataLookupF32 (&status, config, "FIT_MIN_SN");
+    float FIT_MAX_CHI = psMetadataLookupF32 (&status, config, "FIT_MAX_CHI");
 
     // set the object surface-brightness limit for fitted pixels
@@ -34,9 +36,11 @@
 
 	// skip non-astronomical objects (very likely defects)
-	if (source->type == PS_SOURCE_DEFECT) continue;
+	if (source->type == PS_SOURCE_DEFECT) continue; // XX should I try these anyway?
 	if (source->type == PS_SOURCE_SATURATED) continue;
 
+	source->modelPSF = NULL;
+
 	// use the source moments, etc to guess basic model parameters
-	psModel  *model  = pmSourceModelGuess (source, psf->type); 
+	psModel *model  = pmSourceModelGuess (source, psf->type); 
 
 	// set PSF parameters for this model
@@ -44,5 +48,4 @@
 	x = model->params->data.F32[2];
 	y = model->params->data.F32[3];
-	// XXX I need to check if the model center has moved too much relative to the peak
 
 	// set the fit radius based on the object flux limit and the model
@@ -50,6 +53,5 @@
 	model->radius = modelRadius (model->params, FLUX_LIMIT) + FIT_PADDING;
 	if (isnan(model->radius)) {
-	  fprintf (stderr, "error in radius\n");
-	  continue;
+	  psAbort ("apply_psf_model", "error in radius");
 	}
 	
@@ -65,7 +67,6 @@
 	psImageKeepCircle (source->mask, x, y, model->radius, AND, 0x7f);
 	if (!status || (model->params->data.F32[1] < 0)) {
-	  // if the fit fails, we need to change the classification
 	  psLogMsg ("psphot", 3, "PSF fit failed for %f, %f (%d iterations)\n", x, y, model->nIter);
-	  source->type = PS_SOURCE_OTHER;  // better choice?
+	  source->type = PS_SOURCE_FAIL_FIT_PSF;  // better choice?
 	  continue;
 	}
@@ -75,5 +76,5 @@
 	Nfit ++;
 
-	mark_psf_source (source, shapeNsigma, SATURATE);
+	mark_psf_source (source, shapeNsigma, FIT_MIN_SN, FIT_MAX_CHI, SATURATE);
 	if (subtract_psf_source (source)) {
 	  Nsub ++;
