Index: /branches/eam_branches/20091201/psModules/src/detrend/pmPattern.c
===================================================================
--- /branches/eam_branches/20091201/psModules/src/detrend/pmPattern.c	(revision 26844)
+++ /branches/eam_branches/20091201/psModules/src/detrend/pmPattern.c	(revision 26845)
@@ -158,5 +158,13 @@
     int numCols = image->numCols, numRows = image->numRows; // Size of image
 
-    psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, numCols - 1); // Polynomial to apply
+    if (corr->numRows != numRows) {
+        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                "Number of rows of image (%d) does not match number of rows of pattern correction (%d)\n",
+                numRows, corr->numRows);
+        return false;
+    }
+
+    int order = corr->numCols - 1;                                        // Polynomial order
+    psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, order); // Polynomial to apply
     psVector *indices = psVectorAlloc(numCols, PS_TYPE_F32); // Indices for polynomial
     float norm = 2.0 / (float)numCols;  // Normalisation for indices
@@ -166,5 +174,5 @@
 
     for (int y = 0; y < numRows; y++) {
-        memcpy(poly->coeff, corr->data.F64[y], numCols * PSELEMTYPE_SIZEOF(PS_TYPE_F64));
+        memcpy(poly->coeff, corr->data.F64[y], order * PSELEMTYPE_SIZEOF(PS_TYPE_F64));
         psVector *solution = psPolynomial1DEvalVector(poly, indices); // Solution vector
         if (!solution) {
