Index: /branches/eam_branches/20090715/psphot/src/psphotApResid.c
===================================================================
--- /branches/eam_branches/20090715/psphot/src/psphotApResid.c	(revision 25697)
+++ /branches/eam_branches/20090715/psphot/src/psphotApResid.c	(revision 25698)
@@ -190,4 +190,10 @@
 		 source->modelPSF->params->data.F32[PM_PAR_7]);
 # endif
+	if (!isfinite(source->psfMag)) psAbort ("nan in psfMag");
+	if (!isfinite(source->errMag)) psAbort ("nan in errMag");
+	if (!isfinite(source->apMag)) psAbort ("nan in apMag");
+	if (!isfinite(model->params->data.F32[PM_PAR_XPOS])) psAbort ("nan in xPos");
+	if (!isfinite(model->params->data.F32[PM_PAR_YPOS])) psAbort ("nan in yPos");
+
         psVectorAppend (mag, source->psfMag);
         psVectorAppend (dMag,source->errMag);
@@ -241,4 +247,10 @@
 	}
 
+	// apply ApTrend results
+	// float xc = 0.5*readout->image->numCols + readout->image->col0 + 0.5;
+	// float yc = 0.5*readout->image->numRows + readout->image->row0 + 0.5;
+	// float ApResid = pmTrend2DEval (psf->ApTrend, xc, yc); // ap-fit at chip center
+	// if (!isfinite(ApResid)) psAbort("nan apresid @ center");
+
         // store the minimum errorFloor and best ApTrend to keep
         if (errorFloor < errorFloorMin) {
@@ -320,4 +332,9 @@
 	psFree (apTrend);
 	return NULL;
+    }
+    if (apTrend->mode == PM_TREND_MAP) {
+	// p_psImagePrint (2, apTrend->map->map, "ApTrend Before"); // XXX TEST:
+	psImageMapRepair (apTrend->map->map);
+	// p_psImagePrint (2, apTrend->map->map, "ApTrend After"); // XXX TEST:
     }
 
