Index: trunk/psphot/src/Makefile.am
===================================================================
--- trunk/psphot/src/Makefile.am	(revision 15023)
+++ trunk/psphot/src/Makefile.am	(revision 15040)
@@ -42,5 +42,4 @@
 	psphotSourceFits.c	 \
 	psphotRadiusChecks.c	 \
-	psphotSortBySN.c	 \
 	psphotOutput.c		 \
 	psphotGrowthCurve.c	 \
Index: trunk/psphot/src/psphot.h
===================================================================
--- trunk/psphot/src/psphot.h	(revision 15023)
+++ trunk/psphot/src/psphot.h	(revision 15040)
@@ -54,8 +54,4 @@
 // basic support functions
 void            psphotModelClassInit (void);
-int             pmPeakSortBySN (const void **a, const void **b);
-int             pmPeakSortByY (const void **a, const void **b);
-int             pmSourceSortBySN (const void **a, const void **b);
-int             pmSourceSortByY (const void **a, const void **b);
 bool            psphotGrowthCurve (pmReadout *readout, pmPSF *psf, bool ignore, psMaskType maskVal);
 bool            psphotMaskReadout (pmReadout *readout, psMetadata *recipe, psMaskType maskVal);
@@ -116,12 +112,12 @@
 bool            psphotMakeResiduals (psArray *sources, psMetadata *recipe, pmPSF *psf, psMaskType maskVal);
 
-bool psphotExtendedSources (pmReadout *readout, psArray *sources, psMetadata *recipe, psMaskType maskVal);
-bool psphotPSFConvModel (pmSource *source, psMetadata *recipe, psMaskType maskVal);
-psKernel *psphotKernelFromPSF (pmSource *source, int nPix);
+bool            psphotExtendedSources (pmReadout *readout, psArray *sources, psMetadata *recipe, psMaskType maskVal);
+bool            psphotPSFConvModel (pmSource *source, psMetadata *recipe, psMaskType maskVal);
+psKernel       *psphotKernelFromPSF (pmSource *source, int nPix);
 
-bool psphotPetrosian (pmSource *source, psMetadata *recipe, psMaskType maskVal);
-bool psphotIsophotal (pmSource *source, psMetadata *recipe, psMaskType maskVal);
-bool psphotAnnuli (pmSource *source, psMetadata *recipe, psMaskType maskVal);
-bool psphotKron (pmSource *source, psMetadata *recipe, psMaskType maskVal);
+bool 		psphotPetrosian (pmSource *source, psMetadata *recipe, psMaskType maskVal);
+bool 		psphotIsophotal (pmSource *source, psMetadata *recipe, psMaskType maskVal);
+bool 		psphotAnnuli (pmSource *source, psMetadata *recipe, psMaskType maskVal);
+bool 		psphotKron (pmSource *source, psMetadata *recipe, psMaskType maskVal);
 
 // structures & functions to support psf-convolved model fitting
Index: trunk/psphot/src/psphotReadout.c
===================================================================
--- trunk/psphot/src/psphotReadout.c	(revision 15023)
+++ trunk/psphot/src/psphotReadout.c	(revision 15040)
@@ -171,5 +171,6 @@
 
     // XXX test the CR/EXT measurement
-    // psphotSourceSize (readout, sources, recipe);
+    // XXX we need to call this here and after the second pass: option for starting number?
+    psphotSourceSize (readout, sources, recipe);
 
     if (!strcasecmp (breakPt, "ENSEMBLE")) {
@@ -259,5 +260,5 @@
     // plot positive sources
     if (!havePSF) {
-        psphotSourcePlots (readout, sources, recipe, maskVal);
+        // psphotSourcePlots (readout, sources, recipe, maskVal);
     }
 
Index: trunk/psphot/src/psphotSortBySN.c
===================================================================
--- trunk/psphot/src/psphotSortBySN.c	(revision 15023)
+++ trunk/psphot/src/psphotSortBySN.c	(revision 15040)
@@ -1,67 +1,1 @@
-# include "psphotInternal.h"
 
-
-// sort by SN (descending)
-int pmPeakSortBySN (const void **a, const void **b)
-{
-    pmPeak *A = *(pmPeak **)a;
-    pmPeak *B = *(pmPeak **)b;
-
-    psF32 fA = A->SN;
-    psF32 fB = B->SN;
-    if (isnan (fA)) fA = 0;
-    if (isnan (fB)) fB = 0;
-
-    psF32 diff = fA - fB;
-    if (diff > FLT_EPSILON) return (-1);
-    if (diff < FLT_EPSILON) return (+1);
-    return (0);
-}
-
-// sort by Y (ascending)
-int pmPeakSortByY (const void **a, const void **b)
-{
-    pmPeak *A = *(pmPeak **)a;
-    pmPeak *B = *(pmPeak **)b;
-
-    psF32 fA = A->y;
-    psF32 fB = B->y;
-
-    psF32 diff = fA - fB;
-    if (diff > FLT_EPSILON) return (+1);
-    if (diff < FLT_EPSILON) return (-1);
-    return (0);
-}
-
-// sort by SN (descending)
-int pmSourceSortBySN (const void **a, const void **b)
-{
-    pmSource *A = *(pmSource **)a;
-    pmSource *B = *(pmSource **)b;
-
-    psF32 fA = (A->peak == NULL) ? 0 : A->peak->SN;
-    psF32 fB = (B->peak == NULL) ? 0 : B->peak->SN;
-    if (isnan (fA)) fA = 0;
-    if (isnan (fB)) fB = 0;
-
-    psF32 diff = fA - fB;
-    if (diff > FLT_EPSILON) return (-1);
-    if (diff < FLT_EPSILON) return (+1);
-    return (0);
-}
-
-// sort by Y (ascending)
-int pmSourceSortByY (const void **a, const void **b)
-{
-    pmSource *A = *(pmSource **)a;
-    pmSource *B = *(pmSource **)b;
-
-    psF32 fA = (A->peak == NULL) ? 0 : A->peak->y;
-    psF32 fB = (B->peak == NULL) ? 0 : B->peak->y;
-
-    psF32 diff = fA - fB;
-    if (diff > FLT_EPSILON) return (+1);
-    if (diff < FLT_EPSILON) return (-1);
-    return (0);
-}
-
Index: trunk/psphot/src/psphotSourceSize.c
===================================================================
--- trunk/psphot/src/psphotSourceSize.c	(revision 15023)
+++ trunk/psphot/src/psphotSourceSize.c	(revision 15040)
@@ -7,6 +7,4 @@
 
 bool psphotSourceSize (pmReadout *readout, psArray *sources, psMetadata *recipe) {
-
-    FILE *f = fopen ("srcsize.dat", "w");
 
     // loop over all source
@@ -53,5 +51,7 @@
 	// P(chisq > chisq_obs; Ndof) = gamma_Q (Ndof/2, chisq/2)
 	// Ndof = 4 ? (four measurements, no free parameters)
-	float Ppsf = gsl_sf_gamma_inc_Q (2, 0.5*chisq);
+	// XXX this value is going to be biased low because of systematic errors.
+	// we need to calibrate it somehow
+	source->psfProb = gsl_sf_gamma_inc_Q (2, 0.5*chisq);
 
 	float fCR = 0.0;
@@ -87,14 +87,7 @@
 	    nEXT ++;
 	}
-	fCR = (nCR > 0) ? fCR / nCR : 0.0;
-	fEXT = (nEXT > 0) ? fEXT / nEXT : 0.0;
-
-	// XXX plot this as a function of flux / magnitude?
-	// XXX overlay outliers on an image?
-	
-	fprintf (f, "%f %f %f   %f %f   %f %f\n", source->peak->xf, source->peak->yf, source->peak->flux,
-		 chisq, Ppsf, fCR, fEXT);
+	source->crNsigma  = (nCR > 0)  ? fCR / nCR : 0.0;
+	source->extNsigma = (nEXT > 0) ? fEXT / nEXT : 0.0;
     }
-    fclose (f);
     return true;
 }
