Index: /trunk/pois/src/poisCheckKernel.c
===================================================================
--- /trunk/pois/src/poisCheckKernel.c	(revision 4698)
+++ /trunk/pois/src/poisCheckKernel.c	(revision 4698)
@@ -0,0 +1,64 @@
+#include <stdio.h>
+#include "pslib.h"
+#include "pois.h"
+
+bool poisCheckKernel(const psVector *solution,// Kernel solution
+		     const psArray *kernels, // Kernel basis functions
+		     const poisConfig *config // Configuration
+    )
+{
+    psTrace("pois.checkKernel", 1, "Checking kernel....\n");
+
+    // Get kernel value as a function of radius
+    psVector *radKernel = psVectorAlloc((2*config->xKernel + 1) * (2*config->yKernel + 1), PS_TYPE_F32);
+    psVector *radii = psVectorAlloc((2*config->xKernel + 1) * (2*config->yKernel + 1), PS_TYPE_F32); // Radius
+    for (int i = 0; i < solution->n - 1; i++) {
+	poisKernelBasis *kernel = kernels->data[i]; // The kernel basis function
+	if (kernel->xOrder == 0 && kernel->yOrder == 0) {
+	    int u = kernel->u;		// x offset
+	    int v = kernel->v;		// y offset
+	    float distance = sqrtf((float)(u*u) + (float)(v*v)); // Distance from the centre
+	    radKernel->data.F32[i] = solution->data.F64[i];
+	    radii->data.F32[i] = distance;
+	}
+    }
+
+    psVector *sortIndex = psVectorSortIndex(NULL, radii); // Indices from sort
+    float distance = 0.0;		// Distance from the centre that's being examined
+    float sum = 0.0;			// Sum of kernel for that distance
+    int num = 0;			// Number of pixels at that distance
+    int centreIndex = sortIndex->data.U32[0]; // Index of the centre pixel
+    int numSuspect = 0;			// Number of radii considered suspect
+    for (int i = 0; i < (2*config->xKernel + 1) * (2*config->yKernel + 1); i++) {
+	unsigned int index = sortIndex->data.U32[i];
+	if (radii->data.F32[index] != distance) {
+	    psTrace("pois.checkKernel", 7, "Radius: %f\tMean: %f\n", distance, sum/(float)num);
+	    if (fabs(sum/(float)num) > radKernel->data.F32[centreIndex]) {
+		numSuspect++;
+	    }
+	    sum = 0.0;
+	    num = 0;
+	    distance = radii->data.F32[index];
+	}
+	sum += radKernel->data.F32[index];
+	num++;
+    }
+    psTrace("pois.checkKernel", 7, "Radius: %f\tMean: %f\n", distance, sum/(float)num);
+    if (fabs(sum/(float)num) > radKernel->data.F32[centreIndex]) {
+	numSuspect++;
+    }
+
+    psFree(radKernel);
+    psFree(radii);
+    psFree(sortIndex);
+
+    psTrace("pois.checkKernel", 5, "%d radii considered suspect.\n", numSuspect);
+
+    if (numSuspect > 0) {
+	psTrace("pois.checkKernel", 3,
+		"There is significant power at large radii.  The kernel may be bad.\n");
+	return false;
+    }
+
+    return true;
+}
