Index: /trunk/psModules/src/detrend/pmShutterCorrection.c
===================================================================
--- /trunk/psModules/src/detrend/pmShutterCorrection.c	(revision 9983)
+++ /trunk/psModules/src/detrend/pmShutterCorrection.c	(revision 9984)
@@ -345,21 +345,31 @@
 #define MEASURE_SAMPLES 4
 
-psImage *pmShutterCorrectionMeasure(const psVector *exptimes, const psArray *images, const psArray *weights,
-                                    const psArray *masks, unsigned int size, psStatsOptions meanStat,
+psImage *pmShutterCorrectionMeasure(const psArray *readouts, int size, psStatsOptions meanStat,
                                     psStatsOptions stdevStat, int nIter, float rej, psMaskType maskVal)
 {
-    PS_ASSERT_VECTOR_NON_NULL(exptimes, NULL);
-    PS_ASSERT_VECTOR_TYPE(exptimes, PS_TYPE_F32, NULL);
-    PS_ASSERT_ARRAY_NON_NULL(images, NULL);
-    if (masks) {
-        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_ARRAY_NON_NULL(readouts, NULL);
+    PS_ASSERT_ARRAY_NON_EMPTY(readouts, NULL);
+    PS_ASSERT_INT_POSITIVE(size, NULL);
+
+    long num = readouts->n;             // Number of readouts
     PS_ASSERT_INT_POSITIVE(nIter, NULL);
     PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, NULL);
+
+    psArray *images = psArrayAlloc(num);// Array of images
+    psArray *masks = NULL; // Array of masks
+    psArray *weights = NULL; // Array of weights
+    psVector *exptimes = psVectorAlloc(num, PS_TYPE_F32); // Vector of exposure times
+
+    {
+        pmReadout *readout = readouts->data[0]; // Representative readout
+        if (readout->mask)
+        {
+            masks = psArrayAlloc(num);
+        }
+        if (readout->weight)
+        {
+            weights = psArrayAlloc(num);
+        }
+    }
 
     // Check input sizes, generate first-pass statistics
@@ -373,8 +383,22 @@
     int numRows = 0, numCols = 0; // Size of images
     for (long i = 0; i < images->n; i++) {
-        psImage *image = images->data[i]; // Image of interest
+        pmReadout *readout = readouts->data[i]; // Readout of interest
+        if (!readout) {
+            continue;
+        }
+
+        bool mdok;                      // Status of MD lookup
+        float exptime = psMetadataLookupF32(&mdok, readout->parent->concepts, "CELL.EXPOSURE"); // Exp. time
+        if (!mdok || !isfinite(exptime)) {
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Exposure time for readout %ld is not set.\n", i);
+            goto MEASURE_ERROR;
+        }
+        exptimes->data.F32[i] = exptime;
+
+        psImage *image = readout->image; // Image of interest
         if (!image) {
             continue;
         }
+        images->data[i] = image;
         if (image->type.type != PS_TYPE_F32) {
             psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Bad type for image: %x\n", image->type.type);
@@ -399,22 +423,53 @@
             goto MEASURE_ERROR;
         }
-        if (masks) {
-            psImage *mask = masks->data[i];
-            if (mask) {
-                if (mask->type.type != PS_TYPE_U8) {
-                    psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Bad type for mask: %x\n", mask->type.type);
-                    goto MEASURE_ERROR;
-                }
-                if (mask->numRows != numRows || mask->numCols != numCols) {
-                    psError(PS_ERR_BAD_PARAMETER_SIZE, true,
-                            "Mask sizes don't match: %dx%d vs %dx%d\n", mask->numCols, mask->numRows,
-                            numCols, numRows);
-                    goto MEASURE_ERROR;
-                }
-            }
-        }
+        psImage *mask = readout->mask; // Mask of interest
+        if (mask) {
+            if (!masks) {
+                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Not all readouts have masks.\n");
+                goto MEASURE_ERROR;
+            }
+            masks->data[i] = mask;
+
+            if (mask->type.type != PS_TYPE_U8) {
+                psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Bad type for mask: %x\n", mask->type.type);
+                goto MEASURE_ERROR;
+            }
+            if (mask->numRows != numRows || mask->numCols != numCols) {
+                psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                        "Mask sizes don't match: %dx%d vs %dx%d\n", mask->numCols, mask->numRows,
+                        numCols, numRows);
+                goto MEASURE_ERROR;
+            }
+        } else if (masks) {
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Not all readouts have masks.\n");
+            goto MEASURE_ERROR;
+        }
+
+        psImage *weight = readout->weight; // Weight map of interest
+        if (weight) {
+            if (!weights) {
+                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Not all readouts have weights.\n");
+                goto MEASURE_ERROR;
+            }
+            masks->data[i] = mask;
+
+            if (mask->type.type != PS_TYPE_F32) {
+                psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Bad type for weights: %x\n", weight->type.type);
+                goto MEASURE_ERROR;
+            }
+            if (weight->numRows != numRows || weight->numCols != numCols) {
+                psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                        "Weight sizes don't match: %dx%d vs %dx%d\n", weight->numCols, weight->numRows,
+                        numCols, numRows);
+                goto MEASURE_ERROR;
+            }
+        } else if (weights) {
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Not all readouts have weights.\n");
+            goto MEASURE_ERROR;
+        }
+
 
         // Measure statistics
-        if (!psImageStats(stats, image, masks->data[i], maskVal)) {
+        if (!psImageStats(stats, image, mask, maskVal)) {
             psWarning("Unable to measure reference statistics.\n");
         }
@@ -539,4 +594,8 @@
 MEASURE_ERROR:
     // Clean up after error
+    psFree(exptimes);
+    psFree(images);
+    psFree(masks);
+    psFree(weights);
     psFree(refs);
     psFree(regions);
Index: /trunk/psModules/src/detrend/pmShutterCorrection.h
===================================================================
--- /trunk/psModules/src/detrend/pmShutterCorrection.h	(revision 9983)
+++ /trunk/psModules/src/detrend/pmShutterCorrection.h	(revision 9984)
@@ -8,6 +8,6 @@
 /// @author Paul Price, IfA
 ///
-/// @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
-/// @date $Date: 2006-10-18 00:47:15 $
+/// @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+/// @date $Date: 2006-11-15 00:40:49 $
 ///
 /// Copyright 2006 Institute for Astronomy, University of Hawaii
@@ -110,13 +110,10 @@
 /// Measure a shutter correction image from an array of images
 ///
-/// Given an array of images with known exposure times, this function measures the shutter correction (our
-/// principal concern is for the time offset, rather than the normalisation) by measuring the reference time
-/// offset using the full non-linear fit for a small number of representative regions (middle and corners),
-/// and then using that to perform a linear fit to each pixel.
-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 for statistics for non-linear fit
+/// Given an array of readouts (with known exposure times from the cell concepts), this function measures the
+/// shutter correction (our principal concern is for the time offset, rather than the normalisation) by
+/// measuring the reference time offset using the full non-linear fit for a small number of representative
+/// regions (middle and corners), and then using that to perform a linear fit to each pixel.
+psImage *pmShutterCorrectionMeasure(const psArray *readouts, ///< Array of readouts
+                                    int size, ///< Size of samples for statistics for non-linear fit
                                     psStatsOptions meanStat, ///< Statistic to use for mean
                                     psStatsOptions stdevStat, ///< Statistic to use for stdev
