Index: trunk/ppImage/src/ppImageBurntoolApply.c
===================================================================
--- trunk/ppImage/src/ppImageBurntoolApply.c	(revision 35685)
+++ trunk/ppImage/src/ppImageBurntoolApply.c	(revision 42395)
@@ -49,4 +49,7 @@
     psF32 satVal = psMetadataLookupF32(NULL, readout->parent->concepts, "CELL.SATURATION");
 
+    /* The new burntool tables and method coming into play in 2022 has a slightly different format (an extra column). Need to differentiate */
+    psS16 BURNTOOL_STATE_GOOD = psMetadataLookupS16(NULL, config->camera, "BURNTOOL.STATE.GOOD");
+
     for (int p = 0; p < burntoolData->npersist; p++) {
         OBJBOX *box = &(burntoolData->persist[p]);
@@ -61,10 +64,14 @@
 
         y0 = box->y0;
-        y1 = (box->up) ? ny-1 : 0;
-        dy = (y0<y1) ? +1 : -1;
-        if(box->up) {
-            ys = box->sy;
+        if (BURNTOOL_STATE_GOOD >= 15) {
+          y1 = box->eyfit;
         } else {
-            ys = box->ey;
+          y1 = (box->up) ? ny-1 : 0;
+        }
+        dy = (box->up) ? +1 : -1;
+        if (BURNTOOL_STATE_GOOD >= 15) {
+          ys = (box->up) ? box->sy : box->y0;
+        } else {
+          ys = (box->up) ? box->y1m : box->y1p;
         }
 
@@ -91,5 +98,5 @@
         for(k=0; k<box->nfit; k++) {
             i = box->xfit[k];
-            for(j=box->yfit[k]; dy*j<=dy*y1; j+=dy) {
+            for(j=ys; dy*j<=dy*y1; j+=dy) {
                 psF32 inputPixel = image->data.F32[j][i];
                 if (false && inputPixel >= satVal) {
@@ -150,5 +157,11 @@
             return NULL;
         }
-        if (persist_read(OTA, burntoolFileName, 1)) {
+
+        /* The new burntool tables and method coming into play in 2022 has a slightly different format (an extra column). Need to differentiate */
+        psS16 BURNTOOL_STATE_GOOD = psMetadataLookupS16(NULL, config->camera, "BURNTOOL.STATE.GOOD");
+        int oldfile = 1; 
+        if (BURNTOOL_STATE_GOOD >= 15) oldfile = 0;
+
+        if (persist_read(OTA, burntoolFileName, 1,oldfile)) {
             psError(PS_ERR_UNKNOWN, "true", "failed to read burntool file");
             return NULL;
@@ -174,4 +187,7 @@
   /* Set the maskValue from the recipes. */
   psImageMaskType maskValue = options->burntoolMask;
+
+  /* The new burntool tables and method coming into play in 2022 has a slightly different format (an extra column). Need to differentiate */
+  psS16 BURNTOOL_STATE_GOOD = psMetadataLookupS16(NULL, config->camera, "BURNTOOL.STATE.GOOD");
 
   burntool_cell = (view->cell % 8) * 8 + (view->cell - (view->cell % 8)) / 8;
@@ -206,24 +222,53 @@
                   );
 #endif
+
+
+        /* do separate masking strategy for old (14 and lower) and new burntool tables*/
+        if (BURNTOOL_STATE_GOOD >= 15) {
+	 printf("DET: New burntool style %d\n",BURNTOOL_STATE_GOOD);
           for (int i = box->sxfit; i<= box->exfit; i++) {
-
+              if (box->up == 0) {
+                  for (int j = box->eyfit; j <= box->y0; j++) {
+                    #if 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 = box->sy; j < box->eyfit ; j++) {
+                    #if 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 {
+	 printf("DET: Old burntool style %d\n",BURNTOOL_STATE_GOOD);
+          for (int i = box->sxfit; i<= box->exfit; i++) {
               if (box->up == 0) {
                   for (int j = 0; j <= box->y1p; j++) {
-#if PPIMAGE_BURNTOOL_DEBUG
+                    #if 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
+                    #endif
                       image->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= maskValue;
                   }
               } else {
                   for (int j = box->y1m; j < image->numRows ; j++) {
-#if PPIMAGE_BURNTOOL_DEBUG
+                    #if 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
+                    #endif
                       image->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= maskValue;
-                 }
-             }
-         }
+                  }
+              }
+          }
+        }
+
+
       }
   }
@@ -235,5 +280,5 @@
 /****************************************************************/
 /* persist_read(): Read all the persistence trails from a file */
-STATIC int persist_read(CELL *cell, const char *infile, int apply)
+STATIC int persist_read(CELL *cell, const char *infile, int apply, int oldfile)
 {
    int i, k, nbox=0;
@@ -257,5 +302,24 @@
    while(fgets(line, 1024, fp) != NULL) {
       if(line[0] == '#') continue;
-      sscanf(line, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %lf %d %d %d %d",
+
+      /* read-in of new burntool tables (including the eyfit column)*/
+      if(!oldfile) {
+        sscanf(line, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %lf %d %d %d %d %d",
+	     &boxbuf[nbox].cell, &boxbuf[nbox].time,
+	     &boxbuf[nbox].cx, &boxbuf[nbox].cy,
+	     &boxbuf[nbox].max, &boxbuf[nbox].y0,
+	     &boxbuf[nbox].sx, &boxbuf[nbox].sy, 
+	     &boxbuf[nbox].ex, &boxbuf[nbox].ey,
+	     &boxbuf[nbox].y0m, &boxbuf[nbox].y0p,
+	     &boxbuf[nbox].y1m, &boxbuf[nbox].y1p,
+	     &boxbuf[nbox].x0m, &boxbuf[nbox].x0p,
+	     &boxbuf[nbox].x1m, &boxbuf[nbox].x1p,
+	     &boxbuf[nbox].func, &boxbuf[nbox].up,
+	     &boxbuf[nbox].slope, &boxbuf[nbox].nfit,
+	     &boxbuf[nbox].sxfit, &boxbuf[nbox].exfit,
+	     &boxbuf[nbox].fiterr,&boxbuf[nbox].eyfit);
+
+      } else {
+        sscanf(line, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %lf %d %d %d %d",
 	     &boxbuf[nbox].cell, &boxbuf[nbox].time,
 	     &boxbuf[nbox].cx, &boxbuf[nbox].cy,
@@ -271,4 +335,6 @@
 	     &boxbuf[nbox].sxfit, &boxbuf[nbox].exfit,
 	     &boxbuf[nbox].fiterr);
+      }
+
       if(boxbuf[nbox].nfit > 0) {
 	 boxbuf[nbox].zero = (double *)calloc(boxbuf[nbox].nfit, sizeof(double));
@@ -431,4 +497,5 @@
 	       box[j].sxfit = MIN(box[j].sxfit, box[k].sxfit);
 	       box[j].exfit = MAX(box[j].exfit, box[k].exfit);
+	       box[j].eyfit = MIN(box[j].eyfit, box[k].eyfit);
 
 	       box[k].exfit = box[k].sxfit - 1;
@@ -459,5 +526,5 @@
 /****************************************************************/
 /* persist_write(): Write all the persistence data for the next image */
-STATIC int persist_write(CELL *cell, const char *outfile)
+STATIC int persist_write(CELL *cell, const char *outfile, int oldfile)
 {
    int i, k, j, err=0;
@@ -474,5 +541,11 @@
    fprintf(fp,  "# Cell: %d  sky= %d   rms= %d   bias= %d\n", 
 	   cell[0].cell, cell[0].sky, cell[0].rms, cell[0].bias);
-   fprintf(fp, "#Cell time    cx  cy  max   y0   sx  sy   ex  ey  y0m y0p y1m y1p x0m x0p x1m x1p F up    slope nfit sxf exf\n");
+
+   /*write new burntool tables (including the eyfit column)*/
+   if(!oldfile) {
+     fprintf(fp, "#Cell time    cx  cy  max   y0   sx  sy   ex  ey  y0m y0p y1m y1p x0m x0p x1m x1p F up    slope nfit sxf exf fiterr eyf\n");
+   } else {
+     fprintf(fp, "#Cell time    cx  cy  max   y0   sx  sy   ex  ey  y0m y0p y1m y1p x0m x0p x1m x1p F up    slope nfit sxf exf fiterr\n");
+   }
 
    for(j=0; j<MAXCELL; j++) {
@@ -494,5 +567,23 @@
 	    if(cell[j].persist[k].nfit <= 0) continue;
 	 }
-	 fprintf(fp, "%3d %7d  %3d %3d %5d %3d  %3d %3d  %3d %3d  %3d %3d %3d %3d %3d %3d %3d %3d  %1d %1d %9.6f %3d %3d %3d %d\n",
+ 
+         /*write new burntool tables (including the eyfit column)*/
+         if(!oldfile) {
+	   fprintf(fp, "%3d %7d  %3d %3d %5d %3d  %3d %3d  %3d %3d  %3d %3d %3d %3d %3d %3d %3d %3d  %1d %1d %9.6f %3d %3d %3d %d %3d\n",
+		 j, cell[j].persist[k].time, 
+		 cell[j].persist[k].cx, cell[j].persist[k].cy, 
+		 cell[j].persist[k].max, cell[j].persist[k].y0,
+		 cell[j].persist[k].sx, cell[j].persist[k].sy, 
+		 cell[j].persist[k].ex, cell[j].persist[k].ey,
+		 cell[j].persist[k].y0m, cell[j].persist[k].y0p,
+		 cell[j].persist[k].y1m, cell[j].persist[k].y1p,
+		 cell[j].persist[k].x0m, cell[j].persist[k].x0p,
+		 cell[j].persist[k].x1m, cell[j].persist[k].x1p,
+		 cell[j].persist[k].func, cell[j].persist[k].up, 
+		 cell[j].persist[k].slope, cell[j].persist[k].nfit,
+		 cell[j].persist[k].sxfit, cell[j].persist[k].exfit, 
+		 cell[j].persist[k].fiterr, cell[j].persist[k].eyfit);
+         } else {
+	   fprintf(fp, "%3d %7d  %3d %3d %5d %3d  %3d %3d  %3d %3d  %3d %3d %3d %3d %3d %3d %3d %3d  %1d %1d %9.6f %3d %3d %3d %d\n",
 		 j, cell[j].persist[k].time, 
 		 cell[j].persist[k].cx, cell[j].persist[k].cy, 
@@ -508,4 +599,6 @@
 		 cell[j].persist[k].sxfit, cell[j].persist[k].exfit, 
 		 cell[j].persist[k].fiterr);
+         } 
+
 	 for(i=0; i<cell[j].persist[k].nfit; i++) {
 	    fprintf(fp, "%3d %3d %8.4f\n", cell[j].persist[k].xfit[i], 
@@ -531,5 +624,22 @@
 
 	 i = (cell[j].burn[k].ex - cell[j].burn[k].sx + 1) / 2;
-	 fprintf(fp, "%3d %7d  %3d %3d %5d %3d  %3d %3d  %3d %3d  %3d %3d %3d %3d %3d %3d %3d %3d  %1d %1d %9.6f %3d %3d %3d %d\n", 
+
+         if(!oldfile) {
+	   fprintf(fp, "%3d %7d  %3d %3d %5d %3d  %3d %3d  %3d %3d  %3d %3d %3d %3d %3d %3d %3d %3d  %1d %1d %9.6f %3d %3d %3d %d %3d\n", 
+		 j, cell[j].burn[k].time, 
+		 cell[j].burn[k].cx, cell[j].burn[k].cy,
+		 cell[j].burn[k].max, cell[j].burn[k].y0,
+		 cell[j].burn[k].sx, cell[j].burn[k].sy, 
+		 cell[j].burn[k].ex, cell[j].burn[k].ey,
+		 cell[j].burn[k].y0m, cell[j].burn[k].y0p,
+		 cell[j].burn[k].y1m, cell[j].burn[k].y1p,
+		 cell[j].burn[k].x0m, cell[j].burn[k].x0p,
+		 cell[j].burn[k].x1m, cell[j].burn[k].x1p,
+		 cell[j].burn[k].func, cell[j].burn[k].up, 
+		 cell[j].burn[k].slope, cell[j].burn[k].nfit,
+		 cell[j].burn[k].sxfit, cell[j].burn[k].exfit, 
+		 cell[j].burn[k].fiterr, cell[j].burn[k].eyfit);
+         } else {
+	   fprintf(fp, "%3d %7d  %3d %3d %5d %3d  %3d %3d  %3d %3d  %3d %3d %3d %3d %3d %3d %3d %3d  %1d %1d %9.6f %3d %3d %3d %d\n", 
 		 j, cell[j].burn[k].time, 
 		 cell[j].burn[k].cx, cell[j].burn[k].cy,
@@ -545,4 +655,6 @@
 		 cell[j].burn[k].sxfit, cell[j].burn[k].exfit, 
 		 cell[j].burn[k].fiterr);
+         } 
+
 	 for(i=0; i<cell[j].burn[k].nfit; i++) {
 	    fprintf(fp, "%3d %3d %8.4f\n", cell[j].burn[k].xfit[i], 
