Index: /branches/eam_branches/eam_branch_20090312/ppImage/src/ppImageCheckCTE.c
===================================================================
--- /branches/eam_branches/eam_branch_20090312/ppImage/src/ppImageCheckCTE.c	(revision 23319)
+++ /branches/eam_branches/eam_branch_20090312/ppImage/src/ppImageCheckCTE.c	(revision 23320)
@@ -11,5 +11,5 @@
     // this step is complete optional.
     if (!options->checkCTE) {
-	return true;
+        return true;
     }
 
@@ -34,17 +34,20 @@
     psImageBinningSetSkip(binning, image);
 
-    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PPIMAGE.INPUT");
-    pmReadout *modelReadout = pmFPAGenerateReadout(config, view, "PPIMAGE.CTEMAP", input->fpa, binning);
-    psImage *output = modelReadout->image;
-
     pmCell *inCell  = pmFPAfileThisCell (config->files, view, "PPIMAGE.INPUT");
     pmCell *outCell = pmFPAfileThisCell (config->files, view, "PPIMAGE.CTEMAP");
-    if (!pmCellCopyStructure (outCell, inCell, binning->nXbin, binning->nYbin)) {
+    if (!pmCellCopyStructure(outCell, inCell, binning->nXbin, binning->nYbin)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to copy cell structure.");
         return false;
     }
 
-    // Binned version of image
-    // psImage *output = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32);
+    pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPIMAGE.CTEMAP");
+    psImage *output = outRO->image;
+
+    // Don't care about the bias: get rid of it, if present
+    psFree(outRO->bias);
+    outRO->bias = psListAlloc(NULL);
+    psMetadataItem *biassec = psMetadataLookup(outCell->concepts, "CELL.BIASSEC");
+    psFree(biassec->data.V);
+    biassec->data.V = psListAlloc(NULL);
 
     psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
@@ -57,8 +60,12 @@
         for (int ix = 0; ix < output->numCols; ix++) {
 
-	    // convert the ruff grid cell to the equivalent fine grid cell
+            // convert the ruff grid cell to the equivalent fine grid cell
             ruffRegion = psRegionSet (ix, ix + 1, iy, iy + 1);
             fineRegion = psImageBinningSetFineRegion (binning, ruffRegion);
             fineRegion = psRegionForImage (image, fineRegion);
+            if (fineRegion.x0 >= image->numCols || fineRegion.x1 >= image->numCols ||
+                fineRegion.y0 >= image->numRows || fineRegion.y1 >= image->numRows) {
+                continue;
+            }
 
             psImage *subset  = psImageSubset (image, fineRegion);
@@ -68,23 +75,23 @@
             }
             psImage *submask = NULL;
-	    if (mask) {
-		submask = psImageSubset (mask, fineRegion);
-	    }
+            if (mask) {
+                submask = psImageSubset (mask, fineRegion);
+            }
 
             // reset the default values
-	    statsDefaults->tmpData = stats->tmpData; // XXX this is fairly hackish: tmpData is internal storage for stats; the assign drops the reference...
+            statsDefaults->tmpData = stats->tmpData; // XXX this is fairly hackish: tmpData is internal storage for stats; the assign drops the reference...
             *stats = *statsDefaults;
-	    statsDefaults->tmpData = NULL;
-	    
-	    psImageStats (stats, subset, submask, 0);
+            statsDefaults->tmpData = NULL;
 
-	    // XXX need to apply the gain as well
-	    output->data.F32[iy][ix] = PS_SQR(stats->sampleStdev) / stats->sampleMedian;
-	    
-	    psFree (subset);
-	    psFree (submask);
-	}
+            psImageStats (stats, subset, submask, 0);
+
+            // XXX need to apply the gain as well
+            output->data.F32[iy][ix] = PS_SQR(stats->sampleStdev) / stats->sampleMedian;
+
+            psFree (subset);
+            psFree (submask);
+        }
     }
-    
+
     psFree (binning);
     psFree (stats);
