Index: /trunk/psModules/src/detrend/pmShutterCorrection.c
===================================================================
--- /trunk/psModules/src/detrend/pmShutterCorrection.c	(revision 12987)
+++ /trunk/psModules/src/detrend/pmShutterCorrection.c	(revision 12988)
@@ -12,4 +12,6 @@
 #include "pmHDUUtils.h"
 #include "psVectorBracket.h"
+#include "pmConceptsAverage.h"
+
 #include "pmShutterCorrection.h"
 
@@ -347,6 +349,6 @@
 #define MEASURE_SAMPLES 4
 
-psImage *pmShutterCorrectionMeasure(const psArray *readouts, int size, psStatsOptions meanStat,
-                                    psStatsOptions stdevStat, int nIter, float rej, psMaskType maskVal)
+bool pmShutterCorrectionMeasure(pmReadout *output, const psArray *readouts, int size, psStatsOptions meanStat,
+                                psStatsOptions stdevStat, int nIter, float rej, psMaskType maskVal)
 {
     PS_ASSERT_ARRAY_NON_NULL(readouts, NULL);
@@ -591,11 +593,28 @@
 
     if (psTraceGetLevel("psModules.detrend") > 5) {
-	psFits *fits = psFitsOpen("pattern.fits", "w");
-	psFitsWriteImage(fits, NULL, pattern, 0, NULL);
-	psFitsClose(fits);
+        psFits *fits = psFitsOpen("pattern.fits", "w");
+        psFitsWriteImage(fits, NULL, pattern, 0, NULL);
+        psFitsClose(fits);
     }
     psFree(pattern);
 
-    return shutter;
+    output->image = shutter;
+
+    // Update the "concepts"
+    psList *inputCells = psListAlloc(NULL); // List of cells
+    for (long i = 0; i < readouts->n; i++) {
+        pmReadout *readout = readouts->data[i]; // Readout of interest
+        psListAdd(inputCells, PS_LIST_TAIL, readout->parent);
+    }
+    bool success = pmConceptsAverageCells(output->parent, inputCells, NULL, NULL, true);
+    psFree(inputCells);
+
+    // Correct the exposure times --- they don't make sense any more.
+    psMetadataItem *item = psMetadataLookup(output->parent->concepts, "CELL.EXPOSURE");
+    item->data.F32 = NAN;
+    item = psMetadataLookup(output->parent->concepts, "CELL.DARKTIME");
+    item->data.F32 = NAN;
+
+    return success;
 
 
@@ -611,5 +630,5 @@
     psFree(samplesMean);
     psFree(samplesStdev);
-    return NULL;
+    return false;
 }
 
Index: /trunk/psModules/src/detrend/pmShutterCorrection.h
===================================================================
--- /trunk/psModules/src/detrend/pmShutterCorrection.h	(revision 12987)
+++ /trunk/psModules/src/detrend/pmShutterCorrection.h	(revision 12988)
@@ -5,6 +5,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-03-30 21:12:56 $
+ * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-04-24 21:17:19 $
  * Copyright 2006 Institute for Astronomy, University of Hawaii
  */
@@ -29,14 +29,14 @@
  *  Choose a reference location in the image (eg, the detector center) and
  *  divide by the value of that region (ie, mean or median):
- * 
+ *
  *  s(t,x,y) = S(t,x,y) / S(t,0,0)
  *  s(t,x,y) = F_o(t) f(x,y) (T_o + dT(x,y)) / F_o(t) f(0,0) (T_o + dT(0,0))
  *  s(t,x,y) = f(x,y) (T_o + dT(x,y)) / f(0,0) (T_o + dT(0,0))
- * 
+ *
  *  we can absorb the term f(0,0) into f(x,y) as we have no motivation for the
  *  scale of f(x,y).  For any single pixel, over the set of exposures, we thus
  *  need to solve for dT(x,y), dT(0,0), and f'(x,y) in the equation:
  *  s(t,x,y) = f'(x,y) (T_o + dT(x,y)) / (T_o + dT(0,0))
- * 
+ *
  *  we avoid directly fitting these values as the process would be a non-linear
  *  least-squares problem for every pixel in the image, and thus very time
@@ -48,5 +48,5 @@
  *  points covering a reasonable dynamic range, we can solve for these three
  *  values by interpolation and/or extrapolation.
- * 
+ *
  *  To take the strategy one step further, we could use the above recipe to
  *  obtain a guess for the three parameters and then apply non-linear fitting to
@@ -111,12 +111,13 @@
 /// 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
-                                    int nIter, ///< Number of iterations
-                                    float rej, ///< Rejection threshold (sigma)
-                                    psMaskType maskVal ///< Mask value
-                                   );
+bool pmShutterCorrectionMeasure(pmReadout *output, ///< Output readout
+                                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
+                                int nIter, ///< Number of iterations
+                                float rej, ///< Rejection threshold (sigma)
+                                psMaskType maskVal ///< Mask value
+    );
 
 /// Apply a shutter correction
