Index: /branches/eam_branch_20070921/psphot/src/psphotApResid.c
===================================================================
--- /branches/eam_branch_20070921/psphot/src/psphotApResid.c	(revision 14989)
+++ /branches/eam_branch_20070921/psphot/src/psphotApResid.c	(revision 14990)
@@ -1,4 +1,5 @@
 # include "psphotInternal.h"
 
+# define SKIPSTAR(MSG) { psTrace ("psphot", 3, "invalid : %s", MSG); continue; }
 // measure the aperture residual statistics and 2D variations
 bool psphotApResid (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf, psMaskType maskVal, psMaskType mark)
@@ -63,9 +64,9 @@
         model = source->modelPSF;
 
-        if (source->type != PM_SOURCE_TYPE_STAR) continue;
-        if (source->mode &  PM_SOURCE_MODE_SATSTAR) continue;
-        if (source->mode &  PM_SOURCE_MODE_BLEND) continue;
-        if (source->mode &  PM_SOURCE_MODE_FAIL) continue;
-        if (source->mode &  PM_SOURCE_MODE_POOR) continue;
+        if (source->type != PM_SOURCE_TYPE_STAR) SKIPSTAR ("NOT STAR");
+        if (source->mode &  PM_SOURCE_MODE_SATSTAR) SKIPSTAR ("SATSTAR");
+        if (source->mode &  PM_SOURCE_MODE_BLEND) SKIPSTAR ("BLEND");
+        if (source->mode &  PM_SOURCE_MODE_FAIL) SKIPSTAR ("FAIL STAR");
+        if (source->mode &  PM_SOURCE_MODE_POOR) SKIPSTAR ("POOR STAR");
 
         // get growth-corrected, apTrend-uncorrected magnitudes in scaled apertures
@@ -73,9 +74,11 @@
         if (!pmSourceMagnitudes (source, psf, photMode, maskVal, mark)) {
             Nskip ++;
+	    psTrace ("psphot", 3, "skip : bad source mag");
             continue;
         }
 
-        if (!isfinite(source->apMag) || !isfinite(source->apMag)) {
+        if (!isfinite(source->apMag) || !isfinite(source->psfMag)) {
             Nfail ++;
+	    psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag);
             continue;
         }
@@ -87,4 +90,5 @@
         if ((MAX_AP_OFFSET > 0) && (fabs(dap) > MAX_AP_OFFSET)) {
             Nfail ++;
+	    psTrace ("psphot", 3, "fail : bad dap %f %f", dap, MAX_AP_OFFSET);
             continue;
         }
@@ -146,4 +150,5 @@
     }
 
+    // XXX catch error condition 
     psphotApResidTrend (readout, psf, Npsf, entryMin, &errorScale, &errorFloor, mask, xPos, yPos, apResid, dMag);
 
@@ -170,4 +175,5 @@
     float xc = 0.5*readout->image->numCols + readout->image->col0 + 0.5;
     float yc = 0.5*readout->image->numRows + readout->image->row0 + 0.5;
+
     psf->ApResid  = pmTrend2DEval (psf->ApTrend, xc, yc); // ap-fit at chip center
     psf->dApResid = errorFloor;
