Index: /trunk/psModules/src/imcombine/pmSubtractionMatch.c
===================================================================
--- /trunk/psModules/src/imcombine/pmSubtractionMatch.c	(revision 14581)
+++ /trunk/psModules/src/imcombine/pmSubtractionMatch.c	(revision 14582)
@@ -44,26 +44,10 @@
 
 
-bool pmSubtractionMatch(pmReadout *convolved,
-                        const pmReadout *reference,
-                        const pmReadout *input,
-                        int footprint,
-                        float regionSize,
-                        float stampSpacing,
-                        float threshold,
-                        psString stampsName,
-                        float targetWidth,
-                        pmSubtractionKernelsType type,
-                        int size,
-                        int order,
-                        const psVector *isisWidths,
-                        const psVector *isisOrders,
-                        int inner,
-                        int ringsOrder,
-                        int binning,
-                        int iter,
-                        float rej,
-                        psMaskType maskBad,
-                        psMaskType maskBlank
-    )
+bool pmSubtractionMatch(pmReadout *convolved, const pmReadout *reference, const pmReadout *input,
+                        int footprint, float regionSize, float stampSpacing, float threshold,
+                        psString stampsName, float targetWidth, pmSubtractionKernelsType type,
+                        int size, int order, const psVector *isisWidths, const psVector *isisOrders,
+                        int inner, int ringsOrder, int binning, int iter, float rej, psMaskType maskBad,
+                        psMaskType maskBlank)
 {
     PS_ASSERT_PTR_NON_NULL(convolved, false);
@@ -164,5 +148,5 @@
     pmSubtractionKernels *kernels = pmSubtractionKernelsGenerate(type, size, order, isisWidths, isisOrders,
                                                                  inner, binning, ringsOrder);
-    psMetadataAddStr(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.DESCRIPTION", 0,
+    psMetadataAddStr(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.KERNEL.DESCRIPTION", 0,
                      "Subtraction kernel description", kernels->description);
     psArray *stamps = NULL;             // Stamps for matching PSF
@@ -175,4 +159,5 @@
     float xRegionSize = 0, yRegionSize = 0; // Size of iso-kernel regions
     psRegion *region = NULL;            // Iso-kernel region
+    psString regionString = NULL;       // String for region
     if (isfinite(regionSize) || regionSize == 0.0) {
         xRegions = numCols / regionSize + 1;
@@ -191,8 +176,8 @@
                 *region = psRegionSet((int)(i * xRegionSize), (int)((i + 1) * xRegionSize),
                                       (int)(j * yRegionSize), (int)((j + 1) * yRegionSize));
-                psString string = psRegionToString(*region);
+                psFree(regionString);
+                regionString = psRegionToString(*region);
                 psTrace("psModules.imcombine", 3, "Iso-kernel region: %s out of %d,%d\n",
-                        string, numCols, numRows);
-                psFree(string);
+                        regionString, numCols, numRows);
             }
 
@@ -267,5 +252,6 @@
                     goto ERROR;
                 }
-                psLogMsg("psModules.imcombine", PS_LOG_INFO, "%d stamps rejected on iteration %d.", numRejected, k);
+                psLogMsg("psModules.imcombine", PS_LOG_INFO, "%d stamps rejected on iteration %d.",
+                         numRejected, k);
 
                 memCheck("  reject stamps");
@@ -312,9 +298,7 @@
                 }
 
-                psString comment = NULL;// Comment for metadata
-                psString regionString = psRegionToString(*region); // String for region
+                psString comment = NULL; // Comment for metadata
                 psStringAppend(&comment, "Subtraction kernel for region %s", regionString);
-                psFree(regionString);
-                psMetadataAddPtr(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.KERNEL",
+                psMetadataAddPtr(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.KERNEL.IMAGE",
                                  PS_META_DUPLICATE_OK, comment, convKernels);
                 psFree(comment);
@@ -351,17 +335,33 @@
             }
 
+            {
+                psString comment = NULL; // Comment for metadata
+                psStringAppend(&comment, "Subtraction solution for region %s", regionString);
+                psMetadataAddVector(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.SOLUTION",
+                                    PS_META_DUPLICATE_OK, comment, solution);
+                psFree(comment);
+            }
+
             psFree(solution);
             solution = NULL;
+
+            // There is data in the readout now
+            convolved->data_exists = true;
+            convolved->parent->data_exists = true;
+            convolved->parent->parent->data_exists = true;
         }
     }
     psFree(kernels);
+    kernels = NULL;
 
     psFree(region);
     region = NULL;
+    psFree(regionString);
+    regionString = NULL;
     psFree(subMask);
     subMask = NULL;
 
     if (!pmSubtractionBorder(convolved->image, convolved->weight, convolved->mask, kernels, maskBlank)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to set border region of convolved image.");
+        psError(PS_ERR_UNKNOWN, false, "Unable to set border of convolved image.");
         goto ERROR;
     }
@@ -374,4 +374,5 @@
 ERROR:
     psFree(region);
+    psFree(regionString);
     psFree(subMask);
     psFree(kernels);
