Index: /trunk/pois/src/poisReadStamps.c
===================================================================
--- /trunk/pois/src/poisReadStamps.c	(revision 4570)
+++ /trunk/pois/src/poisReadStamps.c	(revision 4571)
@@ -3,6 +3,11 @@
 #include "pois.h"
 
+#define MAXLINE 128			// Maximum length of a line in the stamps file
+
+
 psArray *poisReadStamps(psArray *stamps,// Stamps
 			FILE **stampFP, // File pointer for stamps file
+			const psImage *image, // Image for which to find stamps
+			const psImage *mask, // Mask image
 			const poisConfig *config // Configuration
     )
@@ -28,15 +33,16 @@
 		int xPixel, yPixel;	// Integer position
 		int result = 0;		// Result of fscanf
+		bool badPixels = false;	// Result of check on stamp footprint
+		char line[MAXLINE];	// The line from the stamps file
+		char *lineBack;		// The line back from fgets
 		do {
-		    result = fscanf(fp, "%f %f", &x, &y);
+		    lineBack = fgets(line, MAXLINE, fp);
+		    result = sscanf(line, "%f %f", &x, &y);
+
 		    // Add 0.5 for rounding, and subtract 1.0 for unit-offset to zero-offset
 		    xPixel = (int)(x - 0.5);
 		    yPixel = (int)(y - 0.5);
-		} while ((xPixel < config->footprint + config->xKernel ||
-			  yPixel < config->footprint + config->yKernel ||
-			  xPixel > config->xImage - config->footprint - config->xKernel ||
-			  yPixel > config->yImage - config->footprint - config->yKernel) &&
-			 result == 2);
-		if (result == 2) {
+		} while (! poisCheckStamp(image, mask, xPixel, yPixel, config) && result == 2 && lineBack);
+		if (result == 2 && lineBack) {
 		    stamp->x = xPixel;
 		    stamp->y = yPixel;
@@ -44,7 +50,9 @@
 		    psTrace("pois.readStamps", 7, "Stamp %d: %d,%d\n", i, stamp->x, stamp->y);
 		} else {
+		    // We've run out of stamps in the file --- probably got EOF
 		    stamp->status = POIS_STAMP_BAD;
 		}
 	    } else {
+		// Stamp file isn't open!
 		stamp->status = POIS_STAMP_BAD;
 	    }
