Index: trunk/psModules/src/detrend/pmFringeStats.c
===================================================================
--- trunk/psModules/src/detrend/pmFringeStats.c	(revision 7828)
+++ trunk/psModules/src/detrend/pmFringeStats.c	(revision 7836)
@@ -3,6 +3,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-07-06 03:29:28 $
+ *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-07-07 03:26:22 $
  *
  *  Copyright 2004 IfA
@@ -151,15 +151,18 @@
     psStats *medianSd = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); // Median and SD
 
-    // Measure the sky over the image
+    // Measure the sky in each smoothing box
     psImage *sky = psImageAlloc(fringe->nX, fringe->nY, PS_TYPE_F32);
     for (int i = 0; i < fringe->nY; i++) {
-        int y0 = (float)i * (float)image->numRows / (float)fringe->nY;
-        int y1 = (float)(i + 1) * (float)image->numRows / (float)fringe->nY;
+        int y0 = image->row0 + (float)i * (float)image->numRows / (float)fringe->nY;
+        int y1 = image->row0 + (float)(i + 1) * (float)image->numRows / (float)fringe->nY;
         for (int j = 0; j < fringe->nX; j++) {
-            int x0 = (float)j * (float)image->numCols / (float)fringe->nX;
-            int x1 = (float)(j + 1) * (float)image->numCols / (float)fringe->nX;
+            int x0 = image->col0 + (float)j * (float)image->numCols / (float)fringe->nX;
+            int x1 = image->col0 + (float)(j + 1) * (float)image->numCols / (float)fringe->nX;
             psRegion region = psRegionSet(x0, x1, y0, y1);
             psImage *subImage = psImageSubset(image, region); // Subimage of the sky region
-            psImage *subMask = psImageSubset(mask, region); // Subimage of the sky region
+            psImage *subMask = NULL;
+            if (mask) {
+                subMask = psImageSubset(mask, region); // Subimage of the sky region
+            }
             psImageStats(median, subImage, subMask, maskVal);
             sky->data.F32[i][j] = median->sampleMedian;
@@ -168,8 +171,13 @@
 
     for (int i = 0; i < fringe->x->n; i++) {
-        psRegion region = psRegionSet(xPt[i] - dX, xPt[i] + dX + 1, yPt[i] - dY, yPt[i] + dY + 1);
-        region = psRegionForImage(image, region);
+        psRegion region = psRegionSet(image->col0 + xPt[i] - dX,
+                                      image->col0 + xPt[i] + dX + 1,
+                                      image->row0 + yPt[i] - dY,
+                                      image->row0 + yPt[i] + dY + 1);
         psImage *subImage = psImageSubset(image, region);
-        psImage *subMask = psImageSubset(mask, region);
+        psImage *subMask = NULL;
+        if (mask) {
+            subMask = psImageSubset(mask, region);
+        }
         psImageStats(medianSd, subImage, subMask, maskVal);
         psFree(subImage);
@@ -220,14 +228,4 @@
     PS_ASSERT_VECTOR_SIZE(df, numRows, false);
 
-    if (extname && strlen(extname) > 0) {
-        if (!psFitsMoveExtName(fits, extname)) {
-            psError(PS_ERR_IO, false, "Unable to move to extension %s\n", extname);
-            return false;
-        }
-    } else if (!psFitsMoveExtNum(fits, 0, false)) {
-        psError(PS_ERR_IO, false, "Unable to move to PHU\n");
-        return false;
-    }
-
     // We need to write:
     // Scalars: dX, dY, nX, nY
