Index: /trunk/psModules/src/detrend/pmShutterCorrection.c
===================================================================
--- /trunk/psModules/src/detrend/pmShutterCorrection.c	(revision 9339)
+++ /trunk/psModules/src/detrend/pmShutterCorrection.c	(revision 9340)
@@ -362,4 +362,5 @@
 psImage *pmShutterCorrectionMeasure(const psVector *exptimes, // Exposure times
                                     const psArray *images, // Input images
+                                    const psArray *weights, // Weight images
                                     const psArray *masks, // Mask images
                                     unsigned int size, // Size of samples
@@ -377,6 +378,11 @@
         PS_ASSERT_ARRAYS_SIZE_EQUAL(images, masks, NULL);
     }
+    if (weights) {
+        PS_ASSERT_ARRAYS_SIZE_EQUAL(images, weights, NULL);
+    }
     long num = images->n;               // Number of images
     PS_ASSERT_VECTOR_SIZE(exptimes, num, NULL);
+    PS_ASSERT_INT_POSITIVE(nIter, 0, NULL);
+    PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, NULL);
 
     // Check input sizes, generate first-pass statistics
@@ -493,4 +499,18 @@
     psTrace("psModules.detrend", 3, "Mean reference value: %f\n", meanRef);
 
+    // Check the weights
+    if (weights && nIter > 1) {
+        for (int i = 0; i < weights->n && nIter > 1; i++) {
+            psImage *weight = weights->data[i]; // Weight image
+            if (!weight) {
+                // We don't have weights, so no realistic errors: turn off iteration
+                if (nIter > 0) {
+                    psWarning("Not all images have weights --- turning weighting off.\n");
+                }
+                nIter = 1;
+            }
+        }
+    }
+
     psImage *shutter = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Shutter correction image
     //psImage *pattern = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Illumination pattern
@@ -503,10 +523,15 @@
             for (int i = 0; i < num; i++) {
                 psImage *image = images->data[i]; // Image of interest
+                counts->data.F32[i] = image->data.F32[y][x] * refs->data.F32[i];
                 psImage *maskImage;     // Mask image
                 if (masks && (maskImage = masks->data[i])) {
                     mask->data.U8[i] = maskImage->data.U8[y][x];
                 }
-                counts->data.F32[i] = image->data.F32[y][x] * refs->data.F32[i];
-                errors->data.F32[i] = sqrtf(image->data.F32[y][x]) * refs->data.F32[i];
+                psImage *weight;        // Weight image
+                if (weights && (weight = weights->data[i])) {
+                    errors->data.F32[i] = sqrtf(weight->data.F32[y][x]) * refs->data.F32[i];
+                } else {
+                    errors->data.F32[i] = sqrtf(image->data.F32[y][x]) * refs->data.F32[i];
+                }
             }
 
Index: /trunk/psModules/src/detrend/pmShutterCorrection.h
===================================================================
--- /trunk/psModules/src/detrend/pmShutterCorrection.h	(revision 9339)
+++ /trunk/psModules/src/detrend/pmShutterCorrection.h	(revision 9340)
@@ -48,6 +48,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-06 03:06:30 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-06 03:33:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -99,4 +99,5 @@
 psImage *pmShutterCorrectionMeasure(const psVector *exptimes, // Exposure times
                                     const psArray *images, // Input images
+                                    const psArray *weights, // Weight images
                                     const psArray *masks, // Mask images
                                     unsigned int size, // Size of samples
