Index: trunk/psModules/src/detrend/pmFringeStats.c
===================================================================
--- trunk/psModules/src/detrend/pmFringeStats.c	(revision 7566)
+++ trunk/psModules/src/detrend/pmFringeStats.c	(revision 7567)
@@ -3,6 +3,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-14 22:23:18 $
+ *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-14 22:34:46 $
  *
  *  Copyright 2004 IfA
@@ -542,4 +542,23 @@
     pmFringeRegions *regions = science->regions; // The fringe regions
     int numRegions = regions->nRequested; // Number of regions
+
+    // Ensure we are dealing with the SAME fringe points for all the inputs.
+    // Otherwise, we're going to get crazy results.
+    for (long i = 0; i < numRegions; i++) {
+        float xScience = regions->x->data.F32[i]; // The x position for the science image
+        float yScience = regions->y->data.F32[i]; // The y position for the science image
+        for (long j = 0; j < fringes->n; j++) {
+            pmFringeStats *fringe = fringes->data[j]; // The fringe statistics from a fringe image
+            pmFringeRegions *fringeRegions = fringe->regions; // The fringe regions for that fringe image
+            if (fringeRegions->x->data.F32[i] != xScience ||
+                    fringeRegions->y->data.F32[i] != yScience) {
+                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Science and fringe measurement regions "
+                        "don't match.\n");
+                return NULL;
+            }
+        }
+    }
+
+    // Set up the mask
     if (!regions->mask) {
         regions->mask = psVectorAlloc(numRegions, PS_TYPE_U8);
@@ -547,5 +566,4 @@
         psVectorInit(regions->mask, 0);
     }
-
     psVector *mask = regions->mask;     // The region mask
     psStats *median = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN); // Median statistics
