Index: trunk/ppImage/src/Makefile.am
===================================================================
--- trunk/ppImage/src/Makefile.am	(revision 24911)
+++ trunk/ppImage/src/Makefile.am	(revision 25299)
@@ -54,4 +54,5 @@
 	ppImageDefineFile.c \
 	ppImageSetMaskBits.c \
+	ppImageBurntoolMask.c \
 	ppImageParityFlip.c \
 	ppImageCheckCTE.c \
Index: trunk/ppImage/src/ppImage.h
===================================================================
--- trunk/ppImage/src/ppImage.h	(revision 24911)
+++ trunk/ppImage/src/ppImage.h	(revision 25299)
@@ -26,4 +26,5 @@
     bool doMaskBuild;                   // Build internal mask
     bool doVarianceBuild;               // Build internal variance map
+    bool doMaskBurntool;                // mask potential burntool trails
     bool doMaskSat;                     // mask saturated pixels
     bool doMaskLow;                     // mask low pixels
@@ -74,5 +75,5 @@
     psImageMaskType darkMask;           // Mask value to give bad dark pixels
     psImageMaskType blankMask;          // Mask value to give blank pixels
-
+    psImageMaskType burntoolMask;       // Suspect pixels that fall where a burntool trail is expected.
     // non-linear correction parameters
     psDataType nonLinearType;
@@ -82,5 +83,5 @@
     // options for the analysis
     pmOverscanOptions *overscan;        // Overscan options
-
+    int burntoolTrails;
     // binning parameters
     int xBin1;                          // x-binning, scale 1
@@ -156,4 +157,6 @@
 bool ppImageCheckCTE(pmConfig *config, ppImageOptions *options, pmFPAview *view);
 
+bool ppImageBurntoolMask(pmConfig *config, ppImageOptions *options, pmFPAview *view, pmReadout *mask);
+
 // Record which detrend file was used for the detrending
 bool ppImageDetrendRecord(
Index: trunk/ppImage/src/ppImageBurntoolMask.c
===================================================================
--- trunk/ppImage/src/ppImageBurntoolMask.c	(revision 25299)
+++ trunk/ppImage/src/ppImageBurntoolMask.c	(revision 25299)
@@ -0,0 +1,100 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* #define PPIMAGE_BURNTOOL_DEBUG 1 */
+
+#include "ppImage.h"
+
+bool ppImageBurntoolMask (pmConfig *config, ppImageOptions *options, pmFPAview *view,pmReadout *mask) {
+  bool status = true;
+  int burntool_cell;
+  /* Find input filename */
+  pmFPAfile *inputFile = psMetadataLookupPtr(&status , config->files, "PPIMAGE.INPUT");
+  if (!status) {
+    psError(PS_ERR_IO,false, "Unable to identify inputFile");
+    return(false);
+  }
+  psFits *fits = inputFile->fits;
+
+  /* Read input header, and find the burntool data table. */
+  if (!psFitsMoveExtName(fits,"burntool_areas")) {
+    psError(PS_ERR_IO,false, "Unable to find extension burntool_areas");
+    return(false);
+  }
+  long Nrows = psFitsTableSize(fits);  
+
+  long row = 0;
+
+  psLogMsg ("ppImageBurntoolMask", 4, "Inside burntool mask %ld", Nrows);
+
+  /* Redirects and Memory juggling. */
+  view->readout = 0;
+  psImage *image = mask->mask;
+
+  
+  /* Set the maskValue from the recipes. */
+  psImageMaskType maskValue = options->burntoolMask;
+#ifdef PPIMAGE_BURNTOOL_DEBUG
+  psLogMsg("ppImageBurntoolMask", 4, "Status: %ld %d\n",Nrows,maskValue);
+#endif
+
+  burntool_cell = view->cell;
+  burntool_cell = (view->cell % 8) * 8 + (view->cell - (view->cell % 8)) / 8;
+  psLogMsg("ppImageBurntoolMask", 4, "Cell mapping: %d %d %d\n",view->cell,burntool_cell,-1);
+  for (row = 0; row < Nrows; row++) {
+    psMetadata *rowMD = psFitsReadTableRow(fits,row);
+
+    if (psMetadataLookupS32(&status,rowMD,"cell") == burntool_cell) {
+      if (((options->burntoolTrails & 0x01)&&(psMetadataLookupS32(&status,rowMD,"nfit") == 0))||
+	  ((options->burntoolTrails & 0x02)&&(psMetadataLookupS32(&status,rowMD,"up") == 1))||
+	  ((options->burntoolTrails & 0x04)&&(psMetadataLookupS32(&status,rowMD,"up") == 0))) {
+	/*       If the fit fails, burntool reports zero here.  This
+		 signifies that it expected to see a trail (else why
+		 fit) but did not find it when it attempted to
+		 correct. */
+#ifdef PPIMAGE_BURNTOOL_DEBUG
+	psLogMsg ("ppImageBurntoolMask", 4, "Masking! %d (%d %d %d) %d %d",
+		  psMetadataLookupS32(&status,rowMD,"cell"),
+		  ((options->burntoolTrails & 0x0001)&&(psMetadataLookupS32(&status,rowMD,"nfit") == 0)),
+		  ((options->burntoolTrails & 0x02)&&(psMetadataLookupS32(&status,rowMD,"up") == 1)),
+		  ((options->burntoolTrails & 0x04)&&(psMetadataLookupS32(&status,rowMD,"up") == 0)),
+		  options->burntoolTrails,
+		  maskValue
+		  );
+#endif
+	for (int i = psMetadataLookupS32(&status,rowMD,"sxfit");
+	     i <= psMetadataLookupS32(&status,rowMD,"exfit");
+	     i++) {
+
+	  if (psMetadataLookupS32(&status,rowMD,"up") == 0) {
+	    for (int j = 0; j <= psMetadataLookupS32(&status,rowMD,"y1p"); j++) {
+/* #ifdef PPIMAGE_BURNTOOL_DEBUG */
+/* 	      psLogMsg("ppImageBurntoolMask", 4, "Noisy!: %d %d %d %d\n", */
+/* 		       i,j,image->data.PS_TYPE_IMAGE_MASK_DATA[j][i],maskValue); */
+/* #endif */
+	      image->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= maskValue;
+	    }
+	  }
+	  else {
+	    for (int j = psMetadataLookupS32(&status,rowMD,"y1m"); j < image->numRows ; j++) {
+/* #ifdef PPIMAGE_BURNTOOL_DEBUG */
+/* 	      psLogMsg("ppImageBurntoolMask", 4, "Noisy!: %d %d %d %d\n", */
+/* 		       i,j,image->data.PS_TYPE_IMAGE_MASK_DATA[j][i],maskValue); */
+/* #endif */
+	      image->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= maskValue;
+	    }
+	  }
+	}
+
+      }
+    }
+    psFree(rowMD);
+  }
+
+  return(status);
+}
+	    
+
+
+    
Index: trunk/ppImage/src/ppImageDetrendReadout.c
===================================================================
--- trunk/ppImage/src/ppImageDetrendReadout.c	(revision 24911)
+++ trunk/ppImage/src/ppImageDetrendReadout.c	(revision 25299)
@@ -26,4 +26,8 @@
         pmMaskBadPixels(input, mask, options->maskValue);
     }
+    if (options->doMaskBurntool) {
+      ppImageBurntoolMask(config,options,view,input);
+    }
+
 
 # if 0
Index: trunk/ppImage/src/ppImageOptions.c
===================================================================
--- trunk/ppImage/src/ppImageOptions.c	(revision 24911)
+++ trunk/ppImage/src/ppImageOptions.c	(revision 25299)
@@ -21,4 +21,5 @@
     options->doMaskSat       = false;   // mask saturated pixels
     options->doMaskLow       = false;   // mask low pixels
+    options->doMaskBurntool  = false;   // mask potential burntool trails
     options->doVarianceBuild = false;   // Build internal variance
     options->doMask          = false;   // Mask bad pixels
@@ -64,5 +65,6 @@
     options->blankMask       = 0x00;    // Blank (no data, cell gap) pixels (supplied to pmChipMosaic, pmFPAMosaic)
     options->markValue       = 0x00;    // A safe bit for internal marking
-
+    options->burntoolMask    = 0x00;    // Suspect pixels that fall where a burntool trail is expected.
+    options->burntoolTrails  = 0x00;    // Which types of burntool areas to mask.
     // crosstalk options
     options->doCrosstalkMeasure = false;   // measure crosstalk
@@ -219,4 +221,5 @@
     options->doMaskSat   = psMetadataLookupBool(NULL, recipe, "MASK.SATURATED");
     options->doMaskLow   = psMetadataLookupBool(NULL, recipe, "MASK.LOW");
+    options->doMaskBurntool = psMetadataLookupBool(NULL, recipe, "MASK.BURNTOOL");
     options->doVarianceBuild = psMetadataLookupBool(NULL, recipe, "VARIANCE.BUILD");
 
@@ -245,13 +248,19 @@
     options->applyParity = psMetadataLookupBool(NULL, recipe, "APPLY.CELL.PARITY");
 
+    options->burntoolTrails = psMetadataLookupU16(&status, recipe, "BURNTOOL.TRAILS");
+    if (!status) {
+      psWarning("BURNTOOL.TRAILS not found in recipe: setting to default value.\n");
+    }
+    
     // binned image options
     options->xBin1 = psMetadataLookupS32(&status, recipe, "BIN1.XBIN");
     if (!status) {
         psWarning("BIN1.XBIN not found in recipe: setting to default value.\n");
+	options->xBin1 = 4;
     }
     options->yBin1 = psMetadataLookupS32(&status, recipe, "BIN1.YBIN");
     if (!status) {
         psWarning("BIN1.YBIN not found in recipe: setting to default value.\n");
-        options->yBin1 = 16;
+        options->yBin1 = 4;
     }
 
Index: trunk/ppImage/src/ppImageSetMaskBits.c
===================================================================
--- trunk/ppImage/src/ppImageSetMaskBits.c	(revision 24911)
+++ trunk/ppImage/src/ppImageSetMaskBits.c	(revision 25299)
@@ -38,4 +38,8 @@
     psAssert (options->lowMask, "low mask not set");
 
+    // mask for suspect regions due to burntool
+    options->burntoolMask = pmConfigMaskGet("BURNTOOL",config);
+    psAssert (options->burntoolMask, "burntool mask not set");
+    
     // save MASK and MARK on the PSPHOT recipe
     psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
