Index: branches/eam_branches/psphot.20100506/src/psphotExtendedSourceAnalysisByObject.c
===================================================================
--- branches/eam_branches/psphot.20100506/src/psphotExtendedSourceAnalysisByObject.c	(revision 27939)
+++ branches/eam_branches/psphot.20100506/src/psphotExtendedSourceAnalysisByObject.c	(revision 27950)
@@ -1,9 +1,6 @@
 # include "psphotInternal.h"
 
-// ?? these cannot happen here --> we would need to do this in psphotExtendedSourceAnalysis
-// XXX option to choose a consistent position
 // XXX option to choose a consistent elliptical contour
 // XXX SDSS uses the r-band petrosian radius to measure petrosian fluxes in all bands
-// XXX consistent choice of extendedness...
 
 // aperture-like measurements for extended sources
@@ -64,5 +61,5 @@
 
     // source analysis is done in S/N order (brightest first)
-    // XXX add this in (need to put S/N in pmPhotObj) : objects = psArraySort (objects, pmPhotObjSortBySN);
+    objects = psArraySort (objects, pmPhotObjSortBySN);
 
     // process the objects in order.  
@@ -72,6 +69,10 @@
 	if (!object->sources) continue;
 
+	// we need to decide for an object if we are going to measure all sources or not
+	// simple rule : if *any* of the sources would be measured, measure the object
+
 	// choose the sources of interest
-	for (int j = 0; j < object->sources->n; j++) {
+	bool measureSource = false;
+	for (int j = 0; !measureSource && (j < object->sources->n); j++) {
 
 	    pmSource *source = object->sources->data[j];
@@ -88,4 +89,14 @@
 	    assert (source->peak); // how can a source not have a peak?
 	    if (source->peak->SN < SN_LIM) continue;
+	    measureSource = true;
+	}
+	if (!measureSource) continue;
+
+	// choose the sources of interest
+	for (int j = 0; j < object->sources->n; j++) {
+
+	    pmSource *source = object->sources->data[j];
+	    psAssert (source, "programming error"); // all entries in object->sources must exist, right?
+	    psAssert (source->peak, "programming error"); // how can a source not have a peak?
 
 	    // replace object in image
@@ -146,19 +157,2 @@
     return true;
 }
-
-// sort by X (ascending)
-# if (0)
-int pmPhotObjSortBySN (const void **a, const void **b)
-{
-    pmPhotObj *objA = *(pmPhotObj **)a;
-    pmPhotObj *objB = *(pmPhotObj **)b;
-
-    psF32 fA = objA->x;
-    psF32 fB = objB->x;
-
-    psF32 diff = fA - fB;
-    if (diff > FLT_EPSILON) return (+1);
-    if (diff < FLT_EPSILON) return (-1);
-    return (0);
-}
-# endif
