Index: trunk/psphot/src/mark_psf_source.c
===================================================================
--- trunk/psphot/src/mark_psf_source.c	(revision 4574)
+++ trunk/psphot/src/mark_psf_source.c	(revision 4630)
@@ -15,8 +15,9 @@
 // PS_SOURCE_BRIGHTSTAR 
 # define MIN_DS 0.01
-bool mark_psf_source (psSource *source, float shapeNsigma, float SATURATE)
+bool mark_psf_source (psSource *source, float shapeNsigma, float minSN, float maxChi, float SATURATE)
 { 
+    int keep;
     float dSX, dSY, SX, SY, SN;
-    float nSx, nSy;
+    float nSx, nSy, Chi;
 
     if (source->modelPSF == NULL) return (false);
@@ -26,5 +27,5 @@
     if (source->modelPSF->params->data.F32[1] >= SATURATE) {
 	if (source->type == PS_SOURCE_PSFSTAR) {
-	    psLogMsg ("psphot", 3, "PSFSTAR marked saturated\n");
+	    psLogMsg ("psphot", 3, "PSFSTAR marked SATSTAR\n");
 	}
 	source->type = PS_SOURCE_SATSTAR;
@@ -32,6 +33,6 @@
     } 
     if (source->type == PS_SOURCE_SATSTAR) {
-	psLogMsg ("psphot", 4, "SATSTAR marked bright (fitted peak below saturation)\n");
-	source->type = PS_SOURCE_BRIGHTSTAR;
+	psLogMsg ("psphot", 4, "SATSTAR marked GOODSTAR (fitted peak below saturation)\n");
+	source->type = PS_SOURCE_GOODSTAR;
     }
 
@@ -41,4 +42,5 @@
     dSX = source->modelPSF->dparams->data.F32[4];
     dSY = source->modelPSF->dparams->data.F32[5];
+    Chi = source->modelPSF->chisq / source->modelPSF->nDOF;
 
     nSx = dSX / hypot (MIN_DS, 1 / (SX * SN));
@@ -48,25 +50,40 @@
     // dsx_o = hypot (1/(SX*SN), MIN_DSX)
 
-    // assign PS_SOURCE_BRIGHTSTAR to bright objects within PSF region of dparams[]
-    if ((fabs(nSx) < shapeNsigma) && (fabs(nSy) < shapeNsigma)) {
+    // assign PS_SOURCE_GOODSTAR to bright objects within PSF region of dparams[]
+    keep = TRUE;
+    keep &= (fabs(nSx) < shapeNsigma);
+    keep &= (fabs(nSy) < shapeNsigma);
+    keep &= (SN > minSN);
+    keep &= (Chi < maxChi);
+    if (keep) {
 	if (source->type == PS_SOURCE_PSFSTAR) return (true);
-	source->type = PS_SOURCE_BRIGHTSTAR;
+	source->type = PS_SOURCE_GOODSTAR;
 	return (true);
     }
     
     if (source->type == PS_SOURCE_PSFSTAR) {
-	psLogMsg ("psphot", 3, "PSFSTAR demoted based on dSx, dSy\n");
+	psLogMsg ("psphot", 3, "PSFSTAR demoted based on fit quality\n");
     }
 
+    // object appears to be small, suspected defect
+    if ((nSx <= -shapeNsigma) || (nSy <= -shapeNsigma)) {
+	source->type = PS_SOURCE_DEFECT;
+	return (false);
+    }
+
+    // object appears to be large, suspected galaxy
     if ((nSx >= shapeNsigma) || (nSy >= shapeNsigma)) {
 	source->type = PS_SOURCE_GALAXY;
 	return (false);
     }
-    // replace DEFECT with COSMIC?
-    if ((nSx <= -shapeNsigma) || (nSy <= -shapeNsigma)) {
-	source->type = PS_SOURCE_DEFECT;
+
+    // object appears to be extremely faint: what is this?
+    if (SN < minSN) {
+	source->type = PS_SOURCE_FAINTSTAR;
 	return (false);
     }
-    psTrace (".psphot.mark_psf_source", 2, "unexpected result: unmarked object\n");
+
+    // these are pooly fitted, probable stars near other stars?
+    source->type = PS_SOURCE_POOR_FIT_PSF;
     return (false);
 }	
