Index: /branches/eam_branches/ipp-20110404/psphot/src/Makefile.am
===================================================================
--- /branches/eam_branches/ipp-20110404/psphot/src/Makefile.am	(revision 31312)
+++ /branches/eam_branches/ipp-20110404/psphot/src/Makefile.am	(revision 31313)
@@ -167,4 +167,5 @@
 	psphotSourcePlots.c	       \
 	psphotRadialPlot.c	       \
+	psphotKronMasked.c             \
 	psphotDeblendSatstars.c	       \
 	psphotMosaicSubimage.c	       \
Index: /branches/eam_branches/ipp-20110404/psphot/src/psphot.h
===================================================================
--- /branches/eam_branches/ipp-20110404/psphot/src/psphot.h	(revision 31312)
+++ /branches/eam_branches/ipp-20110404/psphot/src/psphot.h	(revision 31313)
@@ -149,4 +149,7 @@
 bool            psphotPSFstats (pmReadout *readout, pmPSF *psf);
 bool            psphotMomentsStats (pmReadout *readout, psArray *sources);
+
+bool            psphotKronMasked (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotKronMaskedReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, pmReadout *readout, psArray *sources, pmPSF *psf);
 
 // in psphotGuessModel.c
Index: /branches/eam_branches/ipp-20110404/psphot/src/psphotBlendFit.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psphot/src/psphotBlendFit.c	(revision 31312)
+++ /branches/eam_branches/ipp-20110404/psphot/src/psphotBlendFit.c	(revision 31313)
@@ -280,8 +280,6 @@
         if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
             if (psphotFitBlob (readout, source, newSources, psf, fitOptions, maskVal, markVal)) {
-                source->type = PM_SOURCE_TYPE_EXTENDED;
                 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
                 Next ++;
-                source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
                 continue;
             }
@@ -291,5 +289,4 @@
                 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
                 Npsf ++;
-                source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
                 continue;
             }
Index: /branches/eam_branches/ipp-20110404/psphot/src/psphotFitSourcesLinear.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psphot/src/psphotFitSourcesLinear.c	(revision 31312)
+++ /branches/eam_branches/ipp-20110404/psphot/src/psphotFitSourcesLinear.c	(revision 31313)
@@ -164,4 +164,5 @@
 
 	// check the integral of the model : is it large enough?
+	// apply mask?
 	float modelSum = 0.0;
 	for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
@@ -171,5 +172,4 @@
 	}
 	if (modelSum < 0.5) continue; // skip sources with no model constraint (somewhat arbitrary limit)
-	// if (modelSum < 0.01) continue; // skip sources with no model constraint (somewhat arbitrary limit)
 	if (modelSum < 0.8) {
 	    fprintf (stderr, "low-sig model @ %f, %f (%f sum, %f peak)\n",
@@ -177,10 +177,17 @@
 	}
 
-        pmModel *model = pmSourceGetModel (NULL, source);
+	bool isPSF = false;
+        pmModel *model = pmSourceGetModel (&isPSF, source);
 
         psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
         psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, model->fitRadius, "OR", markVal);
 
-        source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
+	// we call this function multiple times. for the first time, we have only PSF models for all objects
+	// the second time has extended sources.  If we ever fit the PSF model, we should raise this bit
+	source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
+	if (isPSF) {
+	    source->mode |= PM_SOURCE_MODE_PSFMODEL;
+	}	    
+	
         psArrayAdd (fitSources, 100, source);
     }
Index: /branches/eam_branches/ipp-20110404/psphot/src/psphotFitSourcesLinearStack.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psphot/src/psphotFitSourcesLinearStack.c	(revision 31312)
+++ /branches/eam_branches/ipp-20110404/psphot/src/psphotFitSourcesLinearStack.c	(revision 31313)
@@ -69,4 +69,17 @@
             if (!pmSourceCacheModel (source, maskVal)) continue;
           }
+
+	  // check the integral of the model : is it large enough?
+	  float modelSum = 0.0;
+	  for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
+	      for (int ix = 0; ix < source->modelFlux->numCols; ix++) {
+		  modelSum += source->modelFlux->data.F32[iy][ix];
+	      }
+	  }
+	  if (modelSum < 0.5) continue; // skip sources with no model constraint (somewhat arbitrary limit)
+	  if (modelSum < 0.8) {
+	      fprintf (stderr, "low-sig model @ %f, %f (%f sum, %f peak)\n",
+		       source->peak->xf, source->peak->yf, modelSum, source->peak->rawFlux);
+	  }
 
           source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
Index: /branches/eam_branches/ipp-20110404/psphot/src/psphotMagnitudes.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psphot/src/psphotMagnitudes.c	(revision 31312)
+++ /branches/eam_branches/ipp-20110404/psphot/src/psphotMagnitudes.c	(revision 31313)
@@ -177,5 +177,9 @@
 
         status = pmSourceMagnitudes (source, psf, photMode, maskVal, markVal, source->apRadius);
-        if (status && isfinite(source->apMag)) Nap ++;
+        if (status && isfinite(source->apMag)) {
+	    Nap ++;
+	} else {
+	    fprintf (stderr, "failed to measure mag for source @ %f,%f\n", source->peak->xf, source->peak->yf);
+	}
 
         // clear the mask bit
Index: /branches/eam_branches/ipp-20110404/psphot/src/psphotReadout.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psphot/src/psphotReadout.c	(revision 31312)
+++ /branches/eam_branches/ipp-20110404/psphot/src/psphotReadout.c	(revision 31313)
@@ -146,4 +146,6 @@
     }
 
+    // psphotKronMasked(config, view, filerule);
+
     // find blended neighbors of very saturated stars (detections->newSources)
     // if (!psphotDeblendSatstars (config, view, filerule)) {
Index: /branches/eam_branches/ipp-20110404/psphot/src/psphotSourceFits.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psphot/src/psphotSourceFits.c	(revision 31312)
+++ /branches/eam_branches/ipp-20110404/psphot/src/psphotSourceFits.c	(revision 31313)
@@ -146,4 +146,5 @@
     pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     source->mode |=  PM_SOURCE_MODE_BLEND_FIT;
+    source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
     return true;
 }
@@ -186,4 +187,5 @@
 
     // build cached model and subtract
+    source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
     pmSourceCacheModel (source, maskVal);
     pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
@@ -319,4 +321,5 @@
     source->type = PM_SOURCE_TYPE_EXTENDED;
     source->mode |= PM_SOURCE_MODE_EXTMODEL;
+    source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
 
     // build cached model and subtract
@@ -346,4 +349,5 @@
     source->modelPSF = psMemIncrRefCounter (DBL->data[0]);
     source->mode     |= PM_SOURCE_MODE_PAIR;
+    source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
 
     // copy most data from the primary source (modelEXT, blends stay NULL)
Index: /branches/eam_branches/ipp-20110404/psphot/src/psphotSourceStats.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psphot/src/psphotSourceStats.c	(revision 31312)
+++ /branches/eam_branches/ipp-20110404/psphot/src/psphotSourceStats.c	(revision 31313)
@@ -98,6 +98,8 @@
 
     // generate the array of sources, define the associated pixel
+    bool firstPass = false;
     if (!detections->newSources) {
         detections->newSources = psArrayAllocEmpty (peaks->n);
+	firstPass = true;
     }
     sources = detections->newSources;
@@ -125,4 +127,8 @@
         if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) {
 	    fprintf (stderr, "moment failure\n");
+	}
+
+	if (firstPass) {
+            source->mode2 |= PM_SOURCE_MODE2_PASS1_SRC;
 	}
 
Index: /branches/eam_branches/ipp-20110404/psphot/test/tap_psphot_stackphot.pro
===================================================================
--- /branches/eam_branches/ipp-20110404/psphot/test/tap_psphot_stackphot.pro	(revision 31312)
+++ /branches/eam_branches/ipp-20110404/psphot/test/tap_psphot_stackphot.pro	(revision 31313)
@@ -1,4 +1,6 @@
 #!/usr/bin/env mana
 # -*-sh-*-
+
+$KAPA = kapa -noX
 
 # config for ppImage to generate chip, mask, weight
