Index: trunk/psphot/src/psphotMarkPSF.c
===================================================================
--- trunk/psphot/src/psphotMarkPSF.c	(revision 5672)
+++ trunk/psphot/src/psphotMarkPSF.c	(revision 5772)
@@ -1,3 +1,7 @@
 # include "psphot.h"
+
+// given a pmSource which has been fitted using modelPSF, evaluate the
+// resulting fit: did the fit succeed? is this object PSF-like? is this object 
+// extended?  return status is TRUE for a valid PSF, FALSE otherwise.
 
 // identify objects consistent with PSF shape/magnitude distribution
@@ -14,9 +18,7 @@
 // this includes a minimum buffer (DS) for the brighter objects
 
-// saturated stars should fall outside (but are already IDed)
-// galaxies should be larger, cosmic rays smaller, but need to test?
+// saturated stars should fall outside (larger), but have peaks above SATURATE
+// galaxies should be larger, cosmic rays smaller
 // we also reject objects with S/N too low or ChiSquare to high
-
-// any object which meets the criterion is marked as PM_SOURCE_BRIGHTSTAR 
 
 // floor for DS value 
@@ -33,11 +35,16 @@
 
     // do we actually have a valid PSF model?
-    if (model == NULL) return (false);
+    if (model == NULL) {
+	source->mode &= ~PM_SOURCE_FITTED;
+	return false;
+    }
 
     // did the model fit fail for one or another reason?
     switch (model->status) {
+      case PM_MODEL_UNTRIED:
+	source->mode &= ~PM_SOURCE_FITTED; 
+	return false;
       case PM_MODEL_BADARGS:
-      case PM_MODEL_UNTRIED:
-	source->type = PM_SOURCE_FAIL_FIT_PSF;  // better choice?
+	source->mode |= PM_SOURCE_FAIL; 
 	return false;
       case PM_MODEL_SUCCESS:
@@ -46,5 +53,5 @@
       case PM_MODEL_OFFIMAGE:
 	psLogMsg ("psphot", 5, "PSF fit failed for %f, %f (%d iterations)\n", model->params->data.F32[2], model->params->data.F32[3], model->nIter);
-	source->type = PM_SOURCE_FAIL_FIT_PSF;  // better choice?
+	source->mode |= PM_SOURCE_FAIL;
 	return false;
       default:
@@ -52,26 +59,31 @@
     }
 
+    // unless we prove otherwise, this object is a star.
+    source->type = PM_SOURCE_STAR;
+
     // if the object has fitted peak above saturation, label as SATSTAR
     // this is a valid PSF object, but ignore the other quality tests
     // remember: fit does not use saturated pixels (masked)
+    // XXX no extended object can saturate and stay extended...
     if (model->params->data.F32[1] >= SATURATE) {
-	if (source->type == PM_SOURCE_PSFSTAR) {
+	if (source->mode & PM_SOURCE_PSFSTAR) {
 	    psLogMsg ("psphot", 5, "PSFSTAR marked SATSTAR\n");
 	}
-	source->type = PM_SOURCE_SATSTAR;
-	return (true);
+	source->mode &= ~PM_SOURCE_PSFSTAR;
+	source->mode |=  PM_SOURCE_SATSTAR;
+	return true;
     } 
 
     // if the object has a fitted peak below 0, the fit did not converge cleanly
     if (model->params->data.F32[1] < 0) {
-	source->type = PM_SOURCE_FAIL_FIT_PSF;
-	return (false);
+	source->mode |= PM_SOURCE_FAIL;
+	return false;
     } 
 
     // if the source was predicted to be a SATSTAR, but it fitted below saturation, 
     // make a note to the user
-    if (source->type == PM_SOURCE_SATSTAR) {
-	psLogMsg ("psphot", 5, "SATSTAR marked GOODSTAR (fitted peak below saturation)\n");
-	source->type = PM_SOURCE_GOODSTAR;
+    if (source->mode & PM_SOURCE_SATSTAR) {
+	psLogMsg ("psphot", 5, "SATSTAR marked normal (fitted peak below saturation)\n");
+	source->mode &= ~PM_SOURCE_SATSTAR;
     }
 
@@ -93,11 +105,11 @@
     keep &= (SN > minSN);
     keep &= (Chi < maxChi);
-    if (keep) {
-	if (source->type == PM_SOURCE_PSFSTAR) return (true);
-	source->type = PM_SOURCE_GOODSTAR;
-	return (true);
-    }
-    
-    if (source->type == PM_SOURCE_PSFSTAR) {
+    if (keep) return true;
+
+    // this source is not a star, unflag as PSFSTAR
+    // XXX : if this object was used to build the PSF, this flag should
+    //       be set even if the object is not a star...
+    if (source->mode & PM_SOURCE_PSFSTAR) {
+	source->mode &= ~PM_SOURCE_PSFSTAR;
 	psLogMsg ("psphot", 5, "PSFSTAR demoted based on fit quality\n");
     }
@@ -106,5 +118,5 @@
     if ((nSx <= -shapeNsigma) || (nSy <= -shapeNsigma)) {
 	source->type = PM_SOURCE_DEFECT;
-	return (false);
+	return false;
     }
 
@@ -112,15 +124,9 @@
     if ((nSx >= shapeNsigma) || (nSy >= shapeNsigma)) {
 	source->type = PM_SOURCE_GALAXY;
-	return (false);
+	return false;
     }
 
-    // object appears to be extremely faint: what is this?
-    if (SN < minSN) {
-	source->type = PM_SOURCE_FAINTSTAR;
-	return (false);
-    }
-
-    // these are pooly fitted, probable stars near other stars?
-    source->type = PM_SOURCE_POOR_FIT_PSF;
-    return (false);
+    // poor-quality fit; only keep if nothing else works...
+    source->mode |= PM_SOURCE_POOR;
+    return false;
 }	
