Index: trunk/ppStack/src/ppStackArguments.c
===================================================================
--- trunk/ppStack/src/ppStackArguments.c	(revision 14238)
+++ trunk/ppStack/src/ppStackArguments.c	(revision 14275)
@@ -19,9 +19,10 @@
     fprintf(stderr, "Usage: %s INPUTS.mdc OUTPUT_ROOT\n"
             "where INPUTS.mdc contains various METADATAs, each with:\n"
-            "\tIMAGE(STR):  Image filename\n"
-            "\tMASK(STR):   Mask filename\n"
-            "\tSEEING(F32): Seeing FWHM (pixels)\n"
-            "\tWEIGHT(F32): Relative weighting to be applied\n"
-            "\tSCALE(F32):  Relative scaling to be applied\n",
+            "\tIMAGE(STR):     Image filename\n"
+            "\tMASK(STR):      Mask filename\n"
+            "\tWEIGHT(STR)     Weight map filename\n"
+            "\tSEEING(F32):    Seeing FWHM (pixels)\n"
+            "\tWEIGHTING(F32): Relative weighting to be applied\n"
+            "\tSCALE(F32):     Relative scaling to be applied\n",
             program);
     fprintf(stderr, "\n");
Index: trunk/ppStack/src/ppStackCamera.c
===================================================================
--- trunk/ppStack/src/ppStackCamera.c	(revision 14238)
+++ trunk/ppStack/src/ppStackCamera.c	(revision 14275)
@@ -13,4 +13,6 @@
 bool ppStackCamera(pmConfig *config)
 {
+    bool haveWeights = false;           // Do we have weight maps?
+
     psMetadata *inputs = psMetadataLookupMetadata(NULL, config->arguments, "INPUTS"); // The inputs info
     psMetadataIterator *iter = psMetadataIteratorAlloc(inputs, PS_LIST_HEAD, NULL); // Iterator
@@ -36,4 +38,5 @@
         bool mdok;
         psString mask = psMetadataLookupStr(&mdok, input, "MASK"); // Name of mask
+        psString weight = psMetadataLookupStr(&mdok, input, "WEIGHT"); // Name of weight map
 
         float seeing = psMetadataLookupF32(NULL, input, "SEEING"); // Seeing FWHM
@@ -44,7 +47,7 @@
         }
 
-        float weight = psMetadataLookupF32(NULL, input, "WEIGHT"); // Relative weight
-        if (isnan(weight)) {
-            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks WEIGHT of type F32", item->name);
+        float weighting = psMetadataLookupF32(NULL, input, "WEIGHTING"); // Relative weighting
+        if (isnan(weighting)) {
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks WEIGHTING of type F32", item->name);
             psFree(iter);
             return false;
@@ -85,5 +88,6 @@
 
             bool status;
-            pmFPAfile *maskFile = pmFPAfileBindFromArgs(&status, imageFile, config, "PPSTACK.INPUT.MASK", "MASK.FILENAMES");
+            pmFPAfile *maskFile = pmFPAfileBindFromArgs(&status, imageFile, config, "PPSTACK.INPUT.MASK",
+                                                        "MASK.FILENAMES");
             if (!status) {
                 psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", i, mask);
@@ -96,8 +100,30 @@
         }
 
+        // Optionally add the weight file
+        if (weight && strlen(weight) > 0) {
+            haveWeights = true;
+            psArray *weightFiles = psArrayAlloc(1); // Array of filenames for this FPA
+            weightFiles->data[0] = psMemIncrRefCounter(weight);
+            psMetadataAddArray(config->arguments, PS_LIST_TAIL, "WEIGHT.FILENAMES", PS_META_REPLACE,
+                               "Filenames of weight files", weightFiles);
+            psFree(weightFiles);
+
+            bool status;
+            pmFPAfile *weightFile = pmFPAfileBindFromArgs(&status, imageFile, config, "PPSTACK.INPUT.WEIGHT",
+                                                          "WEIGHT.FILENAMES");
+            if (!status) {
+                psError(PS_ERR_UNKNOWN, false, "Unable to define file from weight %d (%s)", i, weight);
+                return false;
+            }
+            if (weightFile->type != PM_FPA_FILE_WEIGHT) {
+                psError(PS_ERR_IO, true, "PPSTACK.INPUT.WEIGHT is not of type WEIGHT");
+                return false;
+            }
+        }
+
         psMetadataAddF32(imageFile->fpa->analysis, PS_LIST_TAIL, "PPSTACK.SEEING", 0,
                          "Seeing for image", seeing);
-        psMetadataAddF32(imageFile->fpa->analysis, PS_LIST_TAIL, "PPSTACK.WEIGHT", 0,
-                         "Relative weight for image", weight);
+        psMetadataAddF32(imageFile->fpa->analysis, PS_LIST_TAIL, "PPSTACK.WEIGHTING", 0,
+                         "Relative weighting for image", weighting);
         psMetadataAddF32(imageFile->fpa->analysis, PS_LIST_TAIL, "PPSTACK.SCALE", 0,
                          "Relative scale for image", scale);
@@ -109,4 +135,7 @@
     if (psMetadataLookup(config->arguments, "MASK.FILENAMES")) {
         psMetadataRemoveKey(config->arguments, "MASK.FILENAMES");
+    }
+    if (psMetadataLookup(config->arguments, "WEIGHT.FILENAMES")) {
+        psMetadataRemoveKey(config->arguments, "WEIGHT.FILENAMES");
     }
 
@@ -180,4 +209,17 @@
     outMask->save = true;
 
+    // Output weight
+    if (haveWeights) {
+        pmFPAfile *outWeight = pmFPAfileDefineOutput(config, output->fpa, "PPSTACK.OUTPUT.WEIGHT");
+        if (!outWeight) {
+            psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.OUTPUT.WEIGHT"));
+            return false;
+        }
+        if (outWeight->type != PM_FPA_FILE_WEIGHT) {
+            psError(PS_ERR_IO, true, "PPSTACK.OUTPUT.WEIGHT is not of type WEIGHT");
+            return false;
+        }
+    }
+
     return true;
 }
Index: trunk/ppStack/src/ppStackReadout.c
===================================================================
--- trunk/ppStack/src/ppStackReadout.c	(revision 14238)
+++ trunk/ppStack/src/ppStackReadout.c	(revision 14275)
@@ -45,5 +45,6 @@
 
         float seeing = psMetadataLookupF32(NULL, inputFile->fpa->analysis, "PPSTACK.SEEING"); // Seeing FWHM
-        float weight = psMetadataLookupF32(NULL, inputFile->fpa->analysis, "PPSTACK.WEIGHT"); // Rel. weight
+        float weighting = psMetadataLookupF32(NULL, inputFile->fpa->analysis,
+                                              "PPSTACK.WEIGHTING"); // Relative weighting
         float scale = psMetadataLookupF32(NULL, inputFile->fpa->analysis, "PPSTACK.SCALE"); // Rel. scale
 
@@ -77,5 +78,8 @@
         totExposure += exposure;        // Total exposure time
         (void)psBinaryOp(ro->image, ro->image, "/", psScalarAlloc(exposure, PS_TYPE_F32));
-        pmStackData *data = pmStackDataAlloc(ro, seeing, weight); // Data to stack
+        if (ro->weight) {
+            (void)psBinaryOp(ro->weight, ro->weight, "/", psScalarAlloc(exposure, PS_TYPE_F32));
+        }
+        pmStackData *data = pmStackDataAlloc(ro, seeing, weighting); // Data to stack
         psArrayAdd(stack, ARRAY_BUFFER, data);
         psFree(data);                   // Drop reference
@@ -100,5 +104,5 @@
     }
 
-#if 1
+#ifdef INSPECTION_FILES
     {
         psFits *fits = psFitsOpen("combined.fits", "w");
@@ -131,5 +135,5 @@
     }
 
-#if 1
+#ifdef REJECTION_FILES
     for (int i = 0; i < num; i++) {
         pmStackData *data = stack->data[i]; // Data for this image
@@ -157,4 +161,7 @@
     // Restore image to counts using the total exposure time
     (void)psBinaryOp(outRO->image, outRO->image, "*", psScalarAlloc(totExposure, PS_TYPE_F32));
+    if (outRO->weight) {
+        (void)psBinaryOp(outRO->weight, outRO->weight, "*", psScalarAlloc(totExposure, PS_TYPE_F32));
+    }
     psMetadataAddF32(outRO->parent->concepts, PS_LIST_TAIL, "CELL.EXPOSURE", PS_META_REPLACE,
                      "Summed exposure time (sec)", totExposure);
