Index: trunk/ppStack/src/ppStackReadout.c
===================================================================
--- trunk/ppStack/src/ppStackReadout.c	(revision 20710)
+++ trunk/ppStack/src/ppStackReadout.c	(revision 20711)
@@ -22,8 +22,9 @@
     psArray *subRegions = args->data[3]; // Regions for PSF-matching
     psArray *subKernels = args->data[4]; // Kernels for PSF-matching
-    psVector *addVariance = args->data[5]; // Additional variance when rejecting
-
-    psArray *inspect = ppStackReadoutInitial(config, outRO, thread->readouts,
-                                             subRegions, subKernels, addVariance);
+    psVector *weightings = args->data[5]; // Weightings (1/noise^2) for each image
+    psVector *addVariance = args->data[6]; // Additional variance when rejecting
+
+    psArray *inspect = ppStackReadoutInitial(config, outRO, thread->readouts, subRegions, subKernels,
+                                             weightings, addVariance);
 
     job->results = inspect;
@@ -42,6 +43,8 @@
     pmReadout *outRO = args->data[2];   // Output readout
     psArray *rejected = args->data[3];  // Rejected pixels
-
-    bool status = ppStackReadoutFinal(config, outRO, thread->readouts, rejected); // Status of operation
+    psVector *weightings = args->data[4];  // Weighting (1/noise^2) for each image
+
+    bool status = ppStackReadoutFinal(config, outRO, thread->readouts, rejected,
+                                      weightings); // Status of operation
 
     thread->busy = false;
@@ -77,5 +80,6 @@
 
 psArray *ppStackReadoutInitial(const pmConfig *config, pmReadout *outRO, const psArray *readouts,
-                               const psArray *regions, const psArray *kernels, const psVector *addVariance)
+                               const psArray *regions, const psArray *kernels, const psVector *weightings,
+                               const psVector *addVariance)
 {
     assert(config);
@@ -86,4 +90,5 @@
     assert(readouts->n == regions->n);
     assert(regions->n == kernels->n);
+    assert(weightings && weightings->n == readouts->n && weightings->type.type == PS_TYPE_F32);
     assert(addVariance && addVariance->n == readouts->n && addVariance->type.type == PS_TYPE_F32);
     static int sectionNum = 0;          // Section number; for debugging outputs
@@ -118,4 +123,6 @@
         }
 
+#if 0
+        // This doesn't seem to work, so getting the weightings directly from a vector
         float weighting = psMetadataLookupF32(&mdok, ro->analysis, "PPSTACK.WEIGHTING"); // Relative weight
         if (!mdok || !isfinite(weighting)) {
@@ -125,4 +132,5 @@
             psLogMsg("ppStack", PS_LOG_INFO, "Weighting for image %d is %f", i, weighting);
         }
+#endif
 
         // Ensure there is a mask, or pmStackCombine will complain
@@ -132,5 +140,5 @@
         }
 
-        stack->data[i] = pmStackDataAlloc(ro, weighting, addVariance->data.F32[i]);
+        stack->data[i] = pmStackDataAlloc(ro, weightings->data.F32[i], addVariance->data.F32[i]);
     }
 
@@ -176,5 +184,5 @@
 
 bool ppStackReadoutFinal(const pmConfig *config, pmReadout *outRO, const psArray *readouts,
-                         const psArray *rejected)
+                         const psArray *rejected, const psVector *weightings)
 {
     assert(config);
@@ -183,4 +191,5 @@
     assert(rejected);
     assert(readouts->n == rejected->n);
+    assert(weightings && weightings->n == readouts->n && weightings->type.type == PS_TYPE_F32);
 
     static int sectionNum = 0;
@@ -212,4 +221,6 @@
         assert(ro);
 
+#if 0
+        // This doesn't seem to work, so getting the weightings directly from a vector
         bool mdok;                      // Status of MD lookup
         float weighting = psMetadataLookupF32(&mdok, ro->analysis, "PPSTACK.WEIGHTING"); // Relative weight
@@ -218,4 +229,5 @@
             weighting = 1.0;
         }
+#endif
 
         // Ensure there is a mask, or pmStackCombine will complain
@@ -225,5 +237,5 @@
         }
 
-        pmStackData *data = pmStackDataAlloc(ro, weighting, NAN);
+        pmStackData *data = pmStackDataAlloc(ro, weightings->data.F32[i], NAN);
         data->reject = psMemIncrRefCounter(rejected->data[i]);
         stack->data[i] = data;
