Index: /branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionStamps.c
===================================================================
--- /branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionStamps.c	(revision 26804)
+++ /branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionStamps.c	(revision 26805)
@@ -89,4 +89,6 @@
     *fluxStamp = -INFINITY;             // Flux of best stamp
 
+    // fprintf (stderr, "xMin, xMax: %d, %d -> ", xMin, xMax);
+
     // Ensure we're not going to go outside the bounds of the image
     xMin = PS_MAX(border, xMin);
@@ -94,4 +96,10 @@
     yMin = PS_MAX(border, yMin);
     yMax = PS_MIN(numRows - border - 1, yMax);
+
+    if (xMax < xMin) return false;
+    if (yMax < yMin) return false;
+
+    psAssert (xMin <= xMax, "x mismatch?");
+    psAssert (yMin <= yMax, "y mismatch?");
 
     for (int y = yMin; y <= yMax; y++) {
@@ -425,5 +433,5 @@
 
                     // Search bounds
-                    int xCentre = xList->data.F32[j] + 0.5, yCentre = yList->data.F32[j] + 0.5;// Stamp centre
+                    int xCentre = xList->data.F32[j] - 0.5, yCentre = yList->data.F32[j] - 0.5;// Stamp centre
                     int search = footprint - size; // Search radius
                     int xMin = PS_MAX(border, xCentre - search);
@@ -434,4 +442,5 @@
                     goodStamp = stampSearch(&xStamp, &yStamp, &fluxStamp, image1, image2, thresh1, thresh2,
                                             subMask, xMin, xMax, yMin, yMax, numCols, numRows, border);
+                    // fprintf (stderr, "find: %d %d ==> %5.1f %5.1f (\n", xCentre, yCentre, xStamp, yStamp);
 #else
                     // Only search the exact centre pixel
@@ -440,5 +449,9 @@
                                             yList->data.F32[j], yList->data.F32[j], numCols, numRows, border);
 #endif
-                    // fprintf (stderr, "find: %d %d ==> %5.1f %5.1f\n", xCentre, yCentre, xStamp, yStamp);
+                    if (0 && goodStamp) {
+                        fprintf (stderr, "find: %6.1f < %6.1f < %6.1f, %6.1f < %6.1f %6.1f\n",
+                                 region->x0 + size, xStamp, region->x1 - size,
+                                 region->y0 + size, yStamp, region->y1 - size);
+                    }
                 }
             } else {
@@ -539,5 +552,5 @@
     for (int i = 0; i < numStars; i++) {
         float xStamp = x->data.F32[i], yStamp = y->data.F32[i]; // Coordinates of stamp
-        int xPix = xStamp + 0.5, yPix = yStamp + 0.5; // Pixel coordinate of stamp
+        int xPix = xStamp - 0.5, yPix = yStamp - 0.5; // Pixel coordinate of stamp
         if (!checkStampRegion(xPix, yPix, region)) {
             // It's not in the big region
@@ -768,10 +781,11 @@
                                             bounds.x0, bounds.x1, bounds.y0, bounds.y1);
 
-        int x = stamp->x + 0.5, y = stamp->y + 0.5; // Stamp coordinates
+        int x = stamp->x - 0.5, y = stamp->y - 0.5; // Stamp coordinates
+        // fprintf (stderr, "stamp: %5.1f %5.1f == %d %d (size: %d)\n", stamp->x, stamp->y, x, y, size);
+
         if (x < bounds.x0 + size || x > bounds.x1 - size || y < bounds.y0 + size || y > bounds.y1 - size) {
             psError(PS_ERR_UNKNOWN, false, "Stamp %d (%d,%d) is within the region border.\n", i, x, y);
             return false;
         }
-        // fprintf (stderr, "stamp: %5.1f %5.1f == %d %d\n", stamp->x, stamp->y, x, y);
 
         // Catch memory leaks --- these should have been freed and NULLed before
