Index: trunk/ppImage/src/ppImageDetrendReadout.c
===================================================================
--- trunk/ppImage/src/ppImageDetrendReadout.c	(revision 24838)
+++ trunk/ppImage/src/ppImageDetrendReadout.c	(revision 24891)
@@ -64,27 +64,27 @@
     if (options->doVarianceBuild) {
         // create the target mask and variance images
-	psImage *noiseImage = NULL;
-	if (options->doNoiseMap) {
-	    // XXX convert the noiseMap image to a binned image
-	    pmReadout *noiseMap = NULL;
-	    noiseMap = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.NOISEMAP");
-	    noiseImage = psImageCopy (NULL, input->image, PS_TYPE_F32);
-	    psImageInit (noiseImage, 0.0);
-
-	    // XXX this works, but is not really quite right: the model shoud include the
-	    // offset information, we are not really getting exactly the right mapping from the
-	    // original file.
-	    psImageBinning *binning = psImageBinningAlloc();
-	    binning->nXruff = noiseMap->image->numCols;
-	    binning->nYruff = noiseMap->image->numRows;
-	    binning->nXfine = input->image->numCols;
-	    binning->nYfine = input->image->numRows;
-	    psImageBinningSetScale(binning, PS_IMAGE_BINNING_LEFT);
-
-	    psImageUnbin (noiseImage, noiseMap->image, binning);
-	    psFree (binning);
-	}
+        psImage *noiseImage = NULL;
+        if (options->doNoiseMap) {
+            // XXX convert the noiseMap image to a binned image
+            pmReadout *noiseMap = NULL;
+            noiseMap = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.NOISEMAP");
+            noiseImage = psImageCopy (NULL, input->image, PS_TYPE_F32);
+            psImageInit (noiseImage, 0.0);
+
+            // XXX this works, but is not really quite right: the model shoud include the
+            // offset information, we are not really getting exactly the right mapping from the
+            // original file.
+            psImageBinning *binning = psImageBinningAlloc();
+            binning->nXruff = noiseMap->image->numCols;
+            binning->nYruff = noiseMap->image->numRows;
+            binning->nXfine = input->image->numCols;
+            binning->nYfine = input->image->numRows;
+            psImageBinningSetScale(binning, PS_IMAGE_BINNING_LEFT);
+
+            psImageUnbin (noiseImage, noiseMap->image, binning);
+            psFree (binning);
+        }
         pmReadoutGenerateVariance(input, noiseImage, true);
-	psFree (noiseImage);
+        psFree (noiseImage);
     }
 
@@ -123,4 +123,15 @@
         }
     }
+
+    // Pattern noise correction
+    if (options->doPattern) {
+        if (!pmPatternRow(input, options->patternOrder, 
+options->patternIter, options->patternRej, options->patternMean, 
+options->patternStdev)) {
+                psFree(detview);
+                return false;
+            }
+        }
+
 
     // Normalization by a single (known) constant
