Index: /branches/eam_branches/20090715/psModules/src/concepts/pmConcepts.c
===================================================================
--- /branches/eam_branches/20090715/psModules/src/concepts/pmConcepts.c	(revision 25625)
+++ /branches/eam_branches/20090715/psModules/src/concepts/pmConcepts.c	(revision 25626)
@@ -329,4 +329,5 @@
         conceptRegisterF32("FPA.TELTEMP.EXTRA", "Telescope Temperatures: extra", p_pmConceptParse_TELTEMPS, NULL, NULL, false, PM_FPA_LEVEL_FPA);
         conceptRegisterF32("FPA.PON.TIME", "Power On Time", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+	conceptRegisterS32("FPA.BURNTOOL.APPLIED", "Status of burntool processing", p_pmConceptParse_BTOOLAPP,NULL,NULL,false,PM_FPA_LEVEL_FPA);
         conceptRegisterF32("FPA.EXPOSURE", "Exposure time (sec)", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
     }
@@ -344,4 +345,5 @@
         conceptRegisterF32("CHIP.TEMP", "Temperature of chip", NULL, NULL, NULL, false, PM_FPA_LEVEL_CHIP);
         conceptRegisterStr("CHIP.ID", "Chip identifier", NULL, NULL, NULL, false, PM_FPA_LEVEL_CHIP);
+
     }
 
Index: /branches/eam_branches/20090715/psModules/src/concepts/pmConceptsRead.c
===================================================================
--- /branches/eam_branches/20090715/psModules/src/concepts/pmConceptsRead.c	(revision 25625)
+++ /branches/eam_branches/20090715/psModules/src/concepts/pmConceptsRead.c	(revision 25626)
@@ -73,5 +73,4 @@
         return false;
     }
-
     psTrace ("psModules.concepts", 3, "parsing concept: %s\n", spec->blank->name);
     if (!strcmp (spec->blank->name, "CELL.XPARITY")) {
@@ -275,4 +274,5 @@
         psMetadataItem *headerItem = NULL; // The value of the concept from the header
 
+
         psTrace ("psModules.concepts", 3, "reading concept: %s\n", name);
         if (!strcmp (name, "CELL.XPARITY")) {
@@ -307,5 +307,4 @@
             }
         }
-
         if (!headerItem) {
             psMetadataItem *formatItem = psMetadataLookup(transSpec, name); // Item with keyword
@@ -328,5 +327,4 @@
             }
             psString keywords = formatItem->data.str; // The FITS keywords
-
             // In case there are multiple headers
             psList *keys = psStringSplit(keywords, " ,;", true); // List of keywords
Index: /branches/eam_branches/20090715/psModules/src/concepts/pmConceptsStandard.c
===================================================================
--- /branches/eam_branches/20090715/psModules/src/concepts/pmConceptsStandard.c	(revision 25625)
+++ /branches/eam_branches/20090715/psModules/src/concepts/pmConceptsStandard.c	(revision 25626)
@@ -160,5 +160,4 @@
     assert(concept);
     assert(pattern);
-
     double value = NAN;
     switch (concept->type) {
@@ -632,4 +631,34 @@
     return psMetadataItemAllocS32(pattern->name, pattern->comment, binning);
 }
+
+// BTOOLAPP
+psMetadataItem *p_pmConceptParse_BTOOLAPP(const psMetadataItem *concept,
+					  const psMetadataItem *pattern,
+					  pmConceptSource source,
+					  const psMetadata *cameraFormat,
+					  const pmFPA *fpa,
+					  const pmChip *chip,
+					  const pmCell *cell)
+{
+  assert(concept);
+  assert(pattern);
+
+  int bt_status = 0;
+
+  if (concept->type != PS_DATA_BOOL) {
+    psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Type for %s (%x) is not BOOL\n",
+	    concept->name, concept->type);
+    return NULL;
+  }
+
+  if (concept->data.B == true) {
+    bt_status = -2;
+  }
+  else if (concept->data.B == false) {
+    bt_status = 1 ;
+  }
+  
+  return psMetadataItemAllocS32(concept->name, concept->comment, bt_status);
+}  
 
 // Get the current value of a concept
Index: /branches/eam_branches/20090715/psModules/src/concepts/pmConceptsStandard.h
===================================================================
--- /branches/eam_branches/20090715/psModules/src/concepts/pmConceptsStandard.h	(revision 25625)
+++ /branches/eam_branches/20090715/psModules/src/concepts/pmConceptsStandard.h	(revision 25626)
@@ -115,4 +115,16 @@
     );
 
+/// Format for the BTOOLAPP conceptn
+psMetadataItem *p_pmConceptParse_BTOOLAPP(
+    const psMetadataItem *concept, ///< Concept to format
+    const psMetadataItem *pattern,
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
+
+
 /// Parse the cell binning concepts: CELL.XBIN, CELL.YBIN
 psMetadataItem *p_pmConceptParse_CELL_Binning(
Index: /branches/eam_branches/20090715/psModules/src/imcombine/pmPSFEnvelope.c
===================================================================
--- /branches/eam_branches/20090715/psModules/src/imcombine/pmPSFEnvelope.c	(revision 25625)
+++ /branches/eam_branches/20090715/psModules/src/imcombine/pmPSFEnvelope.c	(revision 25626)
@@ -34,4 +34,5 @@
 
 // #define TESTING                         // Enable test output
+// #define PEAK_NORM                       // Normalise peaks?
 #define PEAK_FLUX 1.0e4                 // Peak flux for each source
 #define SKY_VALUE 0.0e0                 // Sky value for fake image
@@ -122,4 +123,30 @@
             continue;
         }
+
+        if (psTraceGetLevel("psModules.imcombine") >= 1) {
+            psString string = NULL;     // String with values
+            psStringAppend(&string, "PSF %d: ", i);
+            float x = numCols / 2.0, y = numRows / 2.0; // Coordinates of interest
+            for (int j = 4; j < psf->params->n; j++) {
+                pmTrend2D *trend = psf->params->data[j]; // Trend of interest
+                double val = pmTrend2DEval(trend, x, y);
+                double err;
+                switch (trend->mode) {
+                  case PM_TREND_POLY_ORD:
+                  case PM_TREND_POLY_CHEB:
+                    err = NAN;
+                    break;
+                  case PM_TREND_MAP:
+                    err = psImageUnbinPixel(x, y, trend->map->error, trend->map->binning);
+                    break;
+                  default:
+                    psAbort("Unsupported mode: %x", trend->mode);
+                }
+                psStringAppend(&string, "%lf %lf   ", val, err);
+            }
+            psTrace("psModules.imcombine", 1, "%s\n", string);
+            psFree(string);
+        }
+
         pmResiduals *resid = psf->residuals;// PSF residuals
         psf->residuals = NULL;
@@ -144,13 +171,28 @@
             float y = source->peak->yf + yOffset->data.S32[j]; // y coordinate of source
 
-            double flux = fakeRO->image->data.F32[(int)y][(int)x];
+#ifdef PEAK_NORM
+            // Perhaps I'm being paranoid, but specify a range to check
+            int uMax = PS_MIN(x + radius, numCols - 1), uMin = PS_MAX(x - radius, 0);
+            int vMax = PS_MIN(y + radius, numRows - 1), vMin = PS_MAX(y - radius, 0);
+
+            double flux = -INFINITY;    // Peak flux
+            for (int v = vMin; v <= vMax; v++) {
+                for (int u = uMin; u <= uMax; u++) {
+                    if (fakeRO->image->data.F32[v][u] > flux) {
+                        flux = fakeRO->image->data.F32[v][u];
+                    }
+                }
+            }
             if (!isfinite(flux) || flux < 0) {
                 continue;
             }
             float norm = PEAK_FLUX / flux; // Normalisation for source
+#endif
             psRegion region = psRegionSet(x - radius, x + radius, y - radius, y + radius); // PSF region
             psImage *subImage = psImageSubset(fakeRO->image, region); // Subimage of fake PSF
             psImage *subEnv = psImageSubset(envelope, region); // Subimage of envelope
+#ifdef PEAK_NORM
             psBinaryOp(subImage, subImage, "*", psScalarAlloc(norm, PS_TYPE_F32));
+#endif
             psBinaryOp(subEnv, subEnv, "MAX", subImage);
             psFree(subImage);
@@ -345,4 +387,29 @@
     psFree(try);
 
+    if (psTraceGetLevel("psModules.imcombine") >= 1) {
+        psString string = NULL;     // String with values
+        psStringAppend(&string, "Envelope PSF: ");
+        float x = numCols / 2.0, y = numRows / 2.0; // Coordinates of interest
+        for (int j = 4; j < psf->params->n; j++) {
+            pmTrend2D *trend = psf->params->data[j]; // Trend of interest
+            double val = pmTrend2DEval(trend, x, y);
+            double err;
+            switch (trend->mode) {
+              case PM_TREND_POLY_ORD:
+              case PM_TREND_POLY_CHEB:
+                err = NAN;
+                break;
+              case PM_TREND_MAP:
+                err = psImageUnbinPixel(x, y, trend->map->error, trend->map->binning);
+                break;
+              default:
+                psAbort("Unsupported mode: %x", trend->mode);
+            }
+            psStringAppend(&string, "%lf %lf   ", val, err);
+        }
+        psTrace("psModules.imcombine", 1, "%s\n", string);
+        psFree(string);
+    }
+
 #ifdef TESTING
     {
@@ -358,5 +425,5 @@
 
         pmReadout *generated = pmReadoutAlloc(NULL); // Generated image
-        pmReadoutFakeFromSources(generated, numCols, numRows, fakes, NULL, NULL, psf, NAN, radius,
+        pmReadoutFakeFromSources(generated, numCols, numRows, fakes, 0, NULL, NULL, psf, NAN, radius,
                                  false, true);
         {
Index: /branches/eam_branches/20090715/psModules/src/imcombine/pmStackReject.c
===================================================================
--- /branches/eam_branches/20090715/psModules/src/imcombine/pmStackReject.c	(revision 25625)
+++ /branches/eam_branches/20090715/psModules/src/imcombine/pmStackReject.c	(revision 25626)
@@ -43,21 +43,9 @@
     if (box > 0) {
         // Convolve a subimage, then stick it in the target
-        // XXX if (threaded) {
-        // XXX     psMutexLock(source);
-        // XXX }
         psImage *mask = psImageSubset(source, psRegionSet(xMin - box, xMax + box,
                                                           yMin - box, yMax + box)); // Mask to convolve
-        // XXX if (threaded) {
-        // XXX     psMutexUnlock(source);
-        // XXX }
         psImage *convolved = psImageConvolveMask(NULL, mask, PM_STACK_MASK_BAD, PM_STACK_MASK_CONVOLVE,
                                                  -box, box, -box, box); // Convolved mask
-        // XXX if (threaded) {
-        // XXX     psMutexLock(source);
-        // XXX }
         psFree(mask);
-        // XXX if (threaded) {
-        // XXX     psMutexUnlock(source);
-        // XXX }
 
         int numBytes = (xMax - xMin) * PSELEMTYPE_SIZEOF(PS_TYPE_IMAGE_MASK); // Number of bytes to copy
@@ -162,11 +150,8 @@
     pmReadout *inRO = pmReadoutAlloc(NULL); // Readout with input image
     inRO->image = image;
-    // XXX if (threaded) {
-    // XXX     psMutexInit(image);
-    // XXX }
     for (int i = 0; i < numRegions; i++) {
         psRegion *region = subRegions->data[i]; // Region of interest
         pmSubtractionKernels *kernels = subKernels->data[i]; // Kernel of interest
-        if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, stride, 0, 0, 1.0, 0.0,
+        if (!pmSubtractionConvolve(NULL, convRO, NULL, inRO, NULL, stride, 0, 0, 1.0, 0.0,
                                    region, kernels, false, true)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask image in region %d.", i);
@@ -211,7 +196,4 @@
         }
     }
-    // XXX if (threaded) {
-    // XXX     psMutexDestroy(image);
-    // XXX }
     psFree(inRO);
     psImage *convolved = psMemIncrRefCounter(convRO->image);
@@ -264,7 +246,4 @@
     psImage *target = psImageRecycle(convolved, numCols, numRows, PS_TYPE_IMAGE_MASK); // Grown image
     psImageInit(target, 0);
-    // XXX if (threaded) {
-    // XXX     psMutexInit(source);
-    // XXX }
     for (int i = 0; i < subRegions->n; i++) {
         psRegion *region = subRegions->data[i]; // Subtraction region
@@ -287,7 +266,5 @@
                     psArray *args = job->args; // Job arguments
                     psArrayAdd(args, 1, target);
-                    // XXX psMutexLock(source);
                     psArrayAdd(args, 1, source);
-                    // XXX psMutexUnlock(source);
                     psArrayAdd(args, 1, kernels);
                     PS_ARRAY_ADD_SCALAR(args, numCols, PS_TYPE_S32);
@@ -332,5 +309,4 @@
         }
 
-        // XXX psMutexDestroy(source);
     }
 
Index: /branches/eam_branches/20090715/psModules/src/imcombine/pmSubtractionMatch.c
===================================================================
--- /branches/eam_branches/20090715/psModules/src/imcombine/pmSubtractionMatch.c	(revision 25625)
+++ /branches/eam_branches/20090715/psModules/src/imcombine/pmSubtractionMatch.c	(revision 25626)
@@ -628,5 +628,9 @@
     variance = NULL;
 
-    if (!pmSubtractionBorder(conv1->image, conv1->variance, conv1->mask, size, maskBad)) {
+    if (conv1 && !pmSubtractionBorder(conv1->image, conv1->variance, conv1->mask, size, maskBad)) {
+        psError(PS_ERR_UNKNOWN, false, "Unable to set border of convolved image.");
+        goto MATCH_ERROR;
+    }
+    if (conv2 && !pmSubtractionBorder(conv2->image, conv2->variance, conv2->mask, size, maskBad)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to set border of convolved image.");
         goto MATCH_ERROR;
Index: /branches/eam_branches/20090715/psModules/src/objects/pmDetEff.c
===================================================================
--- /branches/eam_branches/20090715/psModules/src/objects/pmDetEff.c	(revision 25625)
+++ /branches/eam_branches/20090715/psModules/src/objects/pmDetEff.c	(revision 25626)
@@ -164,5 +164,6 @@
     }
 
-    return psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, PM_DETEFF_ANALYSIS,
-                            PS_META_REPLACE | PS_DATA_UNKNOWN, "Detection efficiency", de);
+    bool status = psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, PM_DETEFF_ANALYSIS, PS_META_REPLACE | PS_DATA_UNKNOWN, "Detection efficiency", de);
+    psFree (de);
+    return status;
 }
Index: /branches/eam_branches/20090715/psModules/src/objects/pmSourceIO.c
===================================================================
--- /branches/eam_branches/20090715/psModules/src/objects/pmSourceIO.c	(revision 25625)
+++ /branches/eam_branches/20090715/psModules/src/objects/pmSourceIO.c	(revision 25626)
@@ -986,6 +986,11 @@
 
             if (!pmReadoutReadDetEff(file->fits, readout, deteffname)) {
+#if 0
                 psError(PS_ERR_IO, false, "Unable to read detection efficiency");
                 return false;
+#else
+                // No great loss
+                psErrorClear();
+#endif
             }
         }
