Index: /branches/eam_branches/ipp-20111122/psModules/src/astrom/pmAstrometryWCS.c
===================================================================
--- /branches/eam_branches/ipp-20111122/psModules/src/astrom/pmAstrometryWCS.c	(revision 32852)
+++ /branches/eam_branches/ipp-20111122/psModules/src/astrom/pmAstrometryWCS.c	(revision 32853)
@@ -487,4 +487,6 @@
 
     if (fpa->toSky == NULL) {
+	psFree(fpa->toTPA);
+	psFree(fpa->fromTPA);
         fpa->toTPA = psPlaneTransformIdentity (1);
         fpa->fromTPA = psPlaneTransformIdentity (1);
Index: /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourceMasks.h
===================================================================
--- /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourceMasks.h	(revision 32852)
+++ /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourceMasks.h	(revision 32853)
@@ -46,4 +46,5 @@
     PM_SOURCE_MODE2_DIFF_WITH_DOUBLE = 0x00000002, ///< diff source matched to positive detections in both images
     PM_SOURCE_MODE2_MATCHED          = 0x00000004, ///< diff source matched to positive detections in both images
+    PM_SOURCE_MODE2_DIFF_SELF_MATCH  = 0x00000800, ///< positive detection match is probably this source 
 
     PM_SOURCE_MODE2_ON_SPIKE         = 0x00000008, ///< > 25% of (PSF-weighted) pixels land on diffraction spike
Index: /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.c	(revision 32852)
+++ /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.c	(revision 32853)
@@ -56,4 +56,6 @@
 static psImageMaskType maskBurntool = 0;
 static psImageMaskType maskConvPoor = 0;
+static psImageMaskType maskGhost    = 0;
+static psImageMaskType maskGlint    = 0;
 
 bool pmSourceMagnitudesInit (pmConfig *config, psMetadata *recipe)
@@ -68,4 +70,6 @@
 	maskBurntool = pmConfigMaskGet("BURNTOOL", config);
 	maskConvPoor = pmConfigMaskGet("CONV.POOR", config);
+	maskGhost    = pmConfigMaskGet("GHOST", config);
+	maskGlint    = pmConfigMaskGet("GHOST", config);
 	maskSuspect  = maskSpike | maskStarCore | maskBurntool | maskConvPoor;
     }
@@ -533,4 +537,32 @@
     }
 
+    // Check that if the peak is on/off a ghost, glint, or diffraction spike.  In regular IPP
+    // processing, these values are only set in the image mask after the 'camera' stage
+
+    int xChip = source->peak->x;
+    int yChip = source->peak->y;
+
+    bool onChip = true;
+    onChip &= (xChip >= 0);
+    onChip &= (xChip < mask->numCols);
+    onChip &= (yChip >= 0);
+    onChip &= (yChip < mask->numRows);
+    if (!onChip) {
+	// if the source is off the edge of the chip, raise a different bit?
+	source->mode |= PM_SOURCE_MODE_OFF_CHIP;
+    } else {
+	psImageMaskType maskValue = mask->data.PS_TYPE_IMAGE_MASK_DATA[yChip][xChip];
+	if (maskValue & maskGhost) {
+	    source->mode |= PM_SOURCE_MODE_ON_GHOST;
+	}
+	pmSourceMode PM_SOURCE_MODE_ON_GLINT = PM_SOURCE_MODE_ON_GHOST;
+	if (maskValue & maskGlint) {
+	    source->mode |= PM_SOURCE_MODE_ON_GLINT;
+	}
+	if (maskValue & maskSpike) {
+	    source->mode |= PM_SOURCE_MODE_ON_SPIKE;
+	}
+    }
+
     return (true);
 }
