Index: /trunk/pois/INSTALL
===================================================================
--- /trunk/pois/INSTALL	(revision 3812)
+++ /trunk/pois/INSTALL	(revision 3813)
@@ -1,7 +1,18 @@
+You may have to update
+    ac_pkg_swig.m4      ac_python_devel.m4  
+from Pan-STARRS GHQ.
+
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+
 To build from scratch:
 
-./autogen.sh --prefix=/Users/rhl/JHB/Tree
+./autogen.sh --prefix=$HOME/JHB/Tree
 
 (or wherever you requested jhbuild to install things)
+
+N.b. As configured, autogen requires that a binary "autoconf-2.59" be present,
+and even if your autoconf is 2.59, that's not good enough.  autogen has a
+similar problem.  Fix:
+    perl -pi -e 's/(autoconf|autoheader)-2\.59/$1/' autogen.sh
 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Index: /trunk/pois/NOTES
===================================================================
--- /trunk/pois/NOTES	(revision 3812)
+++ /trunk/pois/NOTES	(revision 3813)
@@ -103,2 +103,51 @@
 
 The file src/libpois.a has to exist
+
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+
+psArray* psArrayAlloc(psU32 nalloc)
+
+fails to initialise the array to NULLs (not specified in the SDRS)
+
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+
+"bool psListAdd(psList *list, int location, void *data);
+
+the first function, psListAdd, adds an entry to the list and returns a
+boolean giving the success or failure of the operation."
+
+(SDRS).  It'd be better to define
+
+psList *psListAdd(psList *list, int location, void *data);
+and to make
+    psListAdd(NULL, location, data);
+equivalent to
+    psListAlloc(data);
+
+That makes the code to append to a list simpler; instead of
+
+     list = NULL;
+     while(foo) {
+        ...
+	foo = psFooAlloc();
+	if(list == NULL) {
+	   list = psListAlloc(foo);
+	} else {
+	   bool ok = psListAdd(list, PS_LIST_TAIL, foo);
+	   assert(ok);
+	}
+	psFree(foo);
+     }
+
+I can simply write:
+
+     list = NULL;
+     while(foo) {
+        ...
+	foo = psFooAlloc();
+        psListAdd(list, PS_LIST_TAIL, foo);
+	psFree(foo);
+     }
+
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+
Index: /trunk/pois/python/pois.py
===================================================================
--- /trunk/pois/python/pois.py	(revision 3812)
+++ /trunk/pois/python/pois.py	(revision 3813)
@@ -218,12 +218,13 @@
         for s in range(0, stamps.n):
 	    stamp = pois.poisStamp_Cast(stamps.get_data(s)) # Stamp of interest
-            if stamp.status == pois.POIS_STAMP_BAD:
-                ctype = "red"; dotType = "x"
-            else:
-                ctype = "green"; dotType = "+"
-		numStamps += 1
-
-            if display['stamps']:
-                ds9.dot(dotType, stamp.x, stamp.y, size = 5, ctype = ctype, frame = 1)
+            if stamp:
+                if stamp.status == pois.POIS_STAMP_BAD:
+                    ctype = "red"; dotType = "x"
+                else:
+                    ctype = "green"; dotType = "+"
+                    numStamps += 1
+                    
+                if display['stamps']:
+                    ds9.dot(dotType, stamp.x, stamp.y, size = 5, ctype = ctype, frame = 1)
 
 	psTrace("pois.time", 1, ("%d stamps found at %f sec\n" % (numStamps, getTime() - startTime)))
@@ -266,12 +267,16 @@
 						       kernelBasisFunctions, solution, config)
         # Have we converged?
-        if not pois.poisRejectStamps(stamps, mask, deviations, config):
+        rejected = pois.poisRejectStamps(stamps, mask, deviations, config)
+
+        if rejected == None:
             break
-
+        
         if display['stamps']:
-            for s in range(0, stamps.n):
-                stamp = pois.poisStamp_Cast(stamps.get_data(s)) # Stamp of interest
-                if stamp.status == pois.POIS_STAMP_RESET:
-                    ds9.dot("o", stamp.x, stamp.y, size = 5, ctype = "red", frame = 1)
+            iter = psLib.psListIteratorAlloc(rejected, psLib.PS_LIST_HEAD, False)
+            while True:
+                stamp = pois.poisStamp_Cast(psLib.psListGetAndIncrement(iter))
+                if not stamp:
+                    break
+                ds9.dot("o", stamp.x, stamp.y, size = 5, ctype = "red", frame = 1)
 
         if display['pause']:
Index: /trunk/pois/src/pois.c
===================================================================
--- /trunk/pois/src/pois.c	(revision 3812)
+++ /trunk/pois/src/pois.c	(revision 3813)
@@ -114,8 +114,10 @@
 
     // Iterate for a good solution
-    bool badStamps = true;		// Do we have bad stamps, such that we need to continue to iterate?
+    psList *badStamps = NULL;		// Do we have bad stamps, such that we need to continue to iterate?
     for (int iterNum = 0; iterNum < config->numIter && badStamps; iterNum++) {
 	psTrace("pois", 1, "Iteration %d...\n", iterNum);
 
+	psFree(badStamps);		// left over from last iteration
+	
 	// Find stamps
 	stamps = poisFindStamps(stamps, refImage, mask, config);
@@ -175,4 +177,5 @@
     // If there was rejection on the last round, re-solve the equation using only the good stamps
     if (badStamps) {
+	psFree(badStamps);
 	solution = poisSolveEquation(solution, stamps, config);
     }
Index: /trunk/pois/src/pois.h
===================================================================
--- /trunk/pois/src/pois.h	(revision 3812)
+++ /trunk/pois/src/pois.h	(revision 3813)
@@ -173,8 +173,8 @@
 
 // Reject stamps, based on the deviations
-bool poisRejectStamps(psArray *stamps,	// Array of stamps
-		      psImage *mask,	// Mask image
-		      const psVector *deviations, // Vector of deviations for the stamps
-		      const poisConfig *config // Configuration
+psList *restrict poisRejectStamps(psArray *stamps,	// Array of stamps
+				  psImage *mask,	// Mask image
+				  const psVector *deviations, // Vector of deviations for the stamps
+				  const poisConfig *config // Configuration
     );
 
Index: /trunk/pois/src/poisFindStamps.c
===================================================================
--- /trunk/pois/src/poisFindStamps.c	(revision 3812)
+++ /trunk/pois/src/poisFindStamps.c	(revision 3813)
@@ -33,7 +33,7 @@
     if (stamps == NULL) {
 	stamps = psArrayAlloc(nsx * nsy);
-	// Initialise
+					// Initialise; should be done by psArrayAlloc
 	for (int i = 0; i < nsx * nsy; i++) {
-	    stamps->data[i] = poisStampAlloc();
+	    stamps->data[i] = NULL;
 	}
     }
@@ -44,4 +44,7 @@
 	for (int j = 0; j < nsy; j++) {
 	    poisStamp *stamp = stamps->data[num]; // The stamp
+	    if (stamp == NULL) {
+		stamp = stamps->data[num] = poisStampAlloc();
+	    }
 
 	    // Only find a new stamp if we need to
Index: /trunk/pois/src/poisRejectStamps.c
===================================================================
--- /trunk/pois/src/poisRejectStamps.c	(revision 3812)
+++ /trunk/pois/src/poisRejectStamps.c	(revision 3813)
@@ -6,8 +6,8 @@
 #define SQUARE(x) ((x)*(x))
 
-bool poisRejectStamps(psArray *stamps,	// Array of stamps
-		      psImage *mask,	// Mask image
-		      const psVector *deviations, // Vector of deviations for the stamps
-		      const poisConfig *config // Configuration
+psList *restrict poisRejectStamps(psArray *stamps, // Array of stamps
+				  psImage *mask,	// Mask image
+				  const psVector *deviations, // Vector of deviations for the stamps
+				  const poisConfig *config // Configuration
     )
 {
@@ -21,5 +21,4 @@
     assert(deviations->type.type == PS_TYPE_F32);
 
-    bool masked = false;		// Have we masked any stamps?
     psVector *devMask = psVectorAlloc(stamps->n, PS_TYPE_U8); // Mask for statistics
 
@@ -30,5 +29,5 @@
 	poisStamp *stamp = stamps->data[i];	// The stamp
 	// Only interested in the stamps that we're actually using
-	if (stamp->status == POIS_STAMP_USED) {
+	if (stamp != NULL && stamp->status == POIS_STAMP_USED) {
 	    meanDev += SQUARE(deviations->data.F32[i]);
 	    numDev++;
@@ -41,8 +40,12 @@
 
     // Reject stamps
+    psList *rejected = NULL;		// rejected stamps
     for (int s = 0; s < deviations->n; s++) {
 	poisStamp *stamp = stamps->data[s];
+	if (stamp == NULL) {
+	    continue;
+	}
+	
 	if (stamp->status == POIS_STAMP_USED && fabsf(deviations->data.F32[s]) > limit) {
-	    masked = true;
 	    psTrace("pois.rejectStamps", 1, "Rejecting stamp %d (%d,%d): %f\n", s, stamp->x, stamp->y,
 		    deviations->data.F32[s]);
@@ -56,5 +59,13 @@
 	    
 	    // Mark stamp for replacement
-	    stamp->status = POIS_STAMP_RESET;
+	    stamps->data[s] = NULL;
+	    
+	    if (rejected == NULL) {
+		rejected = psListAlloc(stamp);
+	    } else {
+		bool failed = psListAdd(rejected, PS_LIST_TAIL, stamp);
+		assert(!failed);
+	    }
+	    psFree(stamp);
 	} // Bad stamps
     } // Iterating over stamps
@@ -62,4 +73,4 @@
     psFree(devMask);
 
-    return masked;
+    return rejected;
 }
Index: /trunk/pois/swig/poisSwig.i
===================================================================
--- /trunk/pois/swig/poisSwig.i	(revision 3812)
+++ /trunk/pois/swig/poisSwig.i	(revision 3813)
@@ -21,5 +21,5 @@
 NEWOBJECT(poisCalculateDeviations);
 NEWOBJECT(poisSolveEquation);
-
+%newobject poisRejectStamps;
 NEWOBJECT(poisImageSetVal);
 NEWOBJECT(poisImageSetValInMask);
