Index: /trunk/psModules/src/detrend/pmPattern.c
===================================================================
--- /trunk/psModules/src/detrend/pmPattern.c	(revision 24898)
+++ /trunk/psModules/src/detrend/pmPattern.c	(revision 24899)
@@ -7,6 +7,30 @@
 
 
+// Mask a row as bad
+static void patternMaskRow(pmReadout *ro, // Readout to mask
+                           int y,         // Row to mask
+                           psImageMaskType bad // Mask value to give
+                           )
+{
+    psImage *image = ro->image;         // Image to mask
+    psAssert(image, "Require image");
+    psAssert(y < image->numRows, "Row not in image");
+
+    int numCols = image->numCols;       // Size of image
+    for (int x = 0; x < numCols; x++) {
+        image->data.F32[y][x] = NAN;
+    }
+    if (ro->mask) {
+        psImage *mask = ro->mask;       // Mask image to mask
+        for (int x = 0; x < numCols; x++) {
+            mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= bad;
+        }
+    }
+    return;
+}
+
 bool pmPatternRow(pmReadout *ro, int order, int iter, float rej,
-                  psStatsOptions clipMean, psStatsOptions clipStdev)
+                  psStatsOptions clipMean, psStatsOptions clipStdev,
+                  psImageMaskType maskBad)
 {
     PM_ASSERT_READOUT_NON_NULL(ro, false);
@@ -47,24 +71,19 @@
         if (num < order + 1) {
             // Not enough points to fit
+            patternMaskRow(ro, y, maskBad);
             continue;
         }
         if (!psVectorClipFitPolynomial1D(poly, clip, mask, 0xFF, data, NULL, indices)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to fit polynomial to row %d", y);
-            psFree(indices);
-            psFree(clip);
-            psFree(mask);
-            psFree(poly);
-            psFree(data);
-            return false;
+            psWarning("Unable to fit polynomial to row %d", y);
+            psErrorClear();
+            patternMaskRow(ro, y, maskBad);
+            continue;
         }
         psVector *solution = psPolynomial1DEvalVector(poly, indices); // Solution vector
         if (!solution) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to evaluate polynomial for row %d", y);
-            psFree(indices);
-            psFree(clip);
-            psFree(mask);
-            psFree(poly);
-            psFree(data);
-            return false;
+            psWarning("Unable to evaluate polynomial for row %d", y);
+            psErrorClear();
+            patternMaskRow(ro, y, maskBad);
+            continue;
         }
 
Index: /trunk/psModules/src/detrend/pmPattern.h
===================================================================
--- /trunk/psModules/src/detrend/pmPattern.h	(revision 24898)
+++ /trunk/psModules/src/detrend/pmPattern.h	(revision 24899)
@@ -24,6 +24,7 @@
     int iter,                           ///< Number of clipping iterations
     float rej,                          ///< Rejection threshold for clipping
-    psStatsOptions clipMean,             ///< Statistic to use for mean
-    psStatsOptions clipStdev             ///< Statistic to use for standard deviation
+    psStatsOptions clipMean,            ///< Statistic to use for mean
+    psStatsOptions clipStdev,           ///< Statistic to use for standard deviation
+    psImageMaskType maskBad             ///< Mask value to give bad pixels
     );
 
