Index: /branches/eam_branches/ipp-20110505/psModules/src/objects/pmSourceMasks.h
===================================================================
--- /branches/eam_branches/ipp-20110505/psModules/src/objects/pmSourceMasks.h	(revision 31653)
+++ /branches/eam_branches/ipp-20110505/psModules/src/objects/pmSourceMasks.h	(revision 31654)
@@ -53,4 +53,8 @@
 
     PM_SOURCE_MODE2_PASS1_SRC        = 0x00000080, ///< source detected in first pass analysis
+
+    PM_SOURCE_MODE2_HAS_BRIGHTER_NEIGHBOR = 0x00000100, ///< peak is not the brightest in its footprint
+    PM_SOURCE_MODE2_BRIGHT_NEIGHBOR_1     = 0x00000200, ///< flux_n / (r^2 flux_p) > 1
+    PM_SOURCE_MODE2_BRIGHT_NEIGHBOR_10    = 0x00000400, ///< flux_n / (r^2 flux_p) > 10
 } pmSourceMode2;
 
Index: /branches/eam_branches/ipp-20110505/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /branches/eam_branches/ipp-20110505/psModules/src/objects/pmSourcePhotometry.c	(revision 31653)
+++ /branches/eam_branches/ipp-20110505/psModules/src/objects/pmSourcePhotometry.c	(revision 31654)
@@ -191,4 +191,6 @@
     }
 
+    pmSourceNeighborFlags (source);
+
     // measure the aperture magnitude, if (SN > AP_MIN_SN)
     if (!isfinite(SN)) {
@@ -264,4 +266,41 @@
 
 */
+
+bool pmSourceNeighborFlags (pmSource *source) {
+
+    return false;
+
+    // source must have a peak to have a footprint
+    if (!source) return false;
+    if (!source->peak) return false;
+    if (!source->peak->footprint) return false;
+    if (!source->peak->footprint->peaks) return false;
+    if (!source->peak->footprint->peaks->n) return false;
+
+    // find the brightest peak (first peak)
+    pmPeak *brightPeak = source->peak->footprint->peaks->data[0];
+
+    // are we the brightest peak?
+    if (source->peak == brightPeak) return true;
+
+    // if not, raise a flag:
+    source->mode2 |= PM_SOURCE_MODE2_HAS_BRIGHTER_NEIGHBOR;
+
+    // but, this is a common situation.  more interesting is if the ratio flux_n / (r^2 flux_o) is large
+
+    float radius2 = PS_SQR(source->peak->xf - brightPeak->xf) + PS_SQR(source->peak->yf - brightPeak->yf);
+
+    float ratio = brightPeak->rawFlux / (source->peak->rawFlux * radius2);
+
+    if (ratio > 1) {
+	source->mode2 |= PM_SOURCE_MODE2_BRIGHT_NEIGHBOR_1;
+    }
+
+    if (ratio > 10) {
+	source->mode2 |= PM_SOURCE_MODE2_BRIGHT_NEIGHBOR_10;
+    }
+
+    return true;
+}
 
 // return source model magnitude
Index: /branches/eam_branches/ipp-20110505/psModules/src/objects/pmSourcePhotometry.h
===================================================================
--- /branches/eam_branches/ipp-20110505/psModules/src/objects/pmSourcePhotometry.h	(revision 31653)
+++ /branches/eam_branches/ipp-20110505/psModules/src/objects/pmSourcePhotometry.h	(revision 31654)
@@ -79,4 +79,6 @@
 double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
 
+bool pmSourceNeighborFlags (pmSource *source);
+
 // retire these:
 // double pmSourceCrossProduct(const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum);
