Index: trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burnparams.h
===================================================================
--- trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burnparams.h	(revision 25070)
+++ trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burnparams.h	(revision 25299)
@@ -55,3 +55,5 @@
 EXTERN int EXPIRE_TRAIL_TIME;	/* Expire trails after this interval */
 
+EXTERN int PERSIST_RETAIN;	/* Retain bad-slope persistence fits */
+
 #endif /* _INCLUDED_burnparams_ */
Index: trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burntool.c
===================================================================
--- trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burntool.c	(revision 25070)
+++ trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burntool.c	(revision 25299)
@@ -100,4 +100,6 @@
    EXPIRE_TRAIL_TIME = 2000;	/* Expire a persist after this [sec] */
 
+   PERSIST_RETAIN = 0;		/* Retain persists with bad slopes? */
+
 /* Parse the args */
    cellxy = -1;
@@ -174,4 +176,8 @@
       } else if(strncmp(argv[i], "infits=", 7) == 0) { /* infits=fname */
 	 persistfitsfile = argv[i] + 7;
+
+/* Keep persistence streaks which had a bad slope? */
+      } else if(strncmp(argv[i], "persist=", 8) == 0) {/* persist={t|f} */
+	 PERSIST_RETAIN = argv[i][8] == 'y' || argv[i][8] == '1' || argv[i][8] == 't';
 
 /* Output file for PSF gallery */
Index: trunk/extsrc/gpcsw/gpcsrc/fits/burntool/man/burntool.1
===================================================================
--- trunk/extsrc/gpcsw/gpcsrc/fits/burntool/man/burntool.1	(revision 25070)
+++ trunk/extsrc/gpcsw/gpcsrc/fits/burntool/man/burntool.1	(revision 25299)
@@ -53,4 +53,12 @@
 	power laws; downward burns as exponentials.
 	
+	The fit to downward, persistence burns may have an unreasonable "slope"
+	(meaning exponential sign), increasing away from the burn origin.
+	These are discarded unless "persist=t" is invoked.  It is possible
+	for the fit to be fooled by uncataloged stars, so the persistence
+	can be kept in the output file with "persist=t" (although no fit
+	correction is applied) and they will propagate from input to output
+	until they finally achieve a legal fit with negligible amplitude.
+
 	Burntool also identifies really blasted areas which are saturated from
 	top to bottom.  These cannot be fitted, but are carried along for
@@ -231,4 +239,8 @@
                 'in' takes precedence.
 
+	persist={t|f}
+		Retain persistence streaks whose fit slope turned out to be
+		unreasonable.
+
 	out=fname      
 		Output file for burn streaks
@@ -332,4 +344,5 @@
 BUGS:
 	090224: Still in development
+	090810: Squished a few memory bugs
 
 SEE ALSO:
Index: trunk/extsrc/gpcsw/gpcsrc/fits/burntool/persist_fits.c
===================================================================
--- trunk/extsrc/gpcsw/gpcsrc/fits/burntool/persist_fits.c	(revision 25070)
+++ trunk/extsrc/gpcsw/gpcsrc/fits/burntool/persist_fits.c	(revision 25299)
@@ -222,6 +222,14 @@
       for(k=0; k<cell[j].npersist; k++) 
       {
-         if(cell[j].persist[k].fiterr) continue;
-         if(cell[j].persist[k].nfit <= 0) continue;
+	 if(PERSIST_RETAIN) {
+/* Keep fits which have a dubious slope */
+	    if(cell[j].persist[k].fiterr != FIT_SLOPE_ERROR) {
+	       if(cell[j].persist[k].fiterr) continue;
+	       if(cell[j].persist[k].nfit <= 0) continue;
+	    }
+	 } else {
+	    if(cell[j].persist[k].fiterr) continue;
+	    if(cell[j].persist[k].nfit <= 0) continue;
+	 }
          num_areas++;
          num_fits += cell[j].persist[k].nfit;
@@ -232,7 +240,16 @@
       {
 	 if(!cell[j].burn[k].burned) continue;
-	 if(cell[j].burn[k].fiterr && 
-	    cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
-	 if(cell[j].burn[k].nfit <= 0) continue;
+	 if(PERSIST_RETAIN) {
+/* Keep fits which have a dubious slope */
+	    if(cell[j].burn[k].fiterr != FIT_SLOPE_ERROR) {
+	       if(cell[j].burn[k].fiterr && 
+		  cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
+	       if(cell[j].burn[k].nfit <= 0) continue;
+	    }
+	 } else {
+	    if(cell[j].burn[k].fiterr && 
+	       cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
+	    if(cell[j].burn[k].nfit <= 0) continue;
+	 }
          num_areas++;
          num_fits += cell[j].burn[k].nfit;
@@ -329,6 +346,14 @@
       for(k=0; k<cell[j].npersist; k++) 
       {
-         if(cell[j].persist[k].fiterr) continue;
-         if(cell[j].persist[k].nfit <= 0) continue;     
+	 if(PERSIST_RETAIN) {
+/* Keep fits which have a dubious slope */
+	    if(cell[j].persist[k].fiterr != FIT_SLOPE_ERROR) {
+	       if(cell[j].persist[k].fiterr) continue;
+	       if(cell[j].persist[k].nfit <= 0) continue;     
+	    }
+	 } else {
+	    if(cell[j].persist[k].fiterr) continue;
+	    if(cell[j].persist[k].nfit <= 0) continue;     
+	 }
 
          result = write_area_row(hu, data, table, row++, &(cell[j].persist[k]));
@@ -340,7 +365,16 @@
       {
 	 if(!cell[j].burn[k].burned) continue;
-	 if(cell[j].burn[k].fiterr && 
-	    cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
-	 if(cell[j].burn[k].nfit <= 0) continue;
+	 if(PERSIST_RETAIN) {
+/* Keep fits which have a dubious slope */
+	    if(cell[j].burn[k].fiterr != FIT_SLOPE_ERROR) {
+	       if(cell[j].burn[k].fiterr && 
+		  cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
+	       if(cell[j].burn[k].nfit <= 0) continue;
+	    }
+	 } else {
+	    if(cell[j].burn[k].fiterr && 
+	       cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
+	    if(cell[j].burn[k].nfit <= 0) continue;
+	 }
 
          result = write_area_row(hu, data, table, row++, &(cell[j].burn[k]));
@@ -426,5 +460,12 @@
       for(k=0; k<cell[j].npersist; k++) 
       {
-         if(cell[j].persist[k].fiterr) continue;
+	 if(PERSIST_RETAIN) {
+/* Keep fits which have a dubious slope */
+	    if(cell[j].persist[k].fiterr != FIT_SLOPE_ERROR) {
+	       if(cell[j].persist[k].fiterr) continue;
+	    }
+	 } else {
+	    if(cell[j].persist[k].fiterr) continue;
+	 }
 	 for(i=0; i<cell[j].persist[k].nfit; i++) 
          {
@@ -441,6 +482,14 @@
       {
 	 if(!cell[j].burn[k].burned) continue;
-	 if(cell[j].burn[k].fiterr && 
-	    cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
+	 if(PERSIST_RETAIN) {
+/* Keep fits which have a dubious slope */
+	    if(cell[j].burn[k].fiterr != FIT_SLOPE_ERROR) {
+	       if(cell[j].burn[k].fiterr && 
+		  cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
+	    }
+	 } else {
+	    if(cell[j].burn[k].fiterr && 
+	       cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
+	 }
 
 	 for(i=0; i<cell[j].burn[k].nfit; i++) 
Index: trunk/extsrc/gpcsw/gpcsrc/fits/burntool/persistio.c
===================================================================
--- trunk/extsrc/gpcsw/gpcsrc/fits/burntool/persistio.c	(revision 25070)
+++ trunk/extsrc/gpcsw/gpcsrc/fits/burntool/persistio.c	(revision 25299)
@@ -51,15 +51,16 @@
 	     &boxbuf[nbox].slope, &boxbuf[nbox].nfit,
 	     &boxbuf[nbox].sxfit, &boxbuf[nbox].exfit);
-      if(boxbuf[nbox].nfit <= 0) continue;
-      boxbuf[nbox].zero = (double *)calloc(boxbuf[nbox].nfit, sizeof(double));
-      boxbuf[nbox].xfit = (int *)calloc(boxbuf[nbox].nfit, sizeof(int));
-      boxbuf[nbox].yfit = (int *)calloc(boxbuf[nbox].nfit, sizeof(int));
-      for(i=0; i<boxbuf[nbox].nfit; i++) {
-	 if(fgets(line, 1024, fp) == NULL) {
-	    fprintf(stderr, "\rerror: short read of burn lines\n");
-	    return(-1);
-	 }
-	 sscanf(line, "%d %d %lf\n", &boxbuf[nbox].xfit[i], 
-		&boxbuf[nbox].yfit[i], &boxbuf[nbox].zero[i]);
+      if(boxbuf[nbox].nfit > 0) {
+	 boxbuf[nbox].zero = (double *)calloc(boxbuf[nbox].nfit, sizeof(double));
+	 boxbuf[nbox].xfit = (int *)calloc(boxbuf[nbox].nfit, sizeof(int));
+	 boxbuf[nbox].yfit = (int *)calloc(boxbuf[nbox].nfit, sizeof(int));
+	 for(i=0; i<boxbuf[nbox].nfit; i++) {
+	    if(fgets(line, 1024, fp) == NULL) {
+	       fprintf(stderr, "\rerror: short read of burn lines\n");
+	       return(-1);
+	    }
+	    sscanf(line, "%d %d %lf\n", &boxbuf[nbox].xfit[i], 
+		   &boxbuf[nbox].yfit[i], &boxbuf[nbox].zero[i]);
+	 }
       }
       boxbuf[nbox].fiterr = 0;
@@ -147,8 +148,10 @@
       for(kp=0; kp<n; kp++) {
 	 k = boxid[kp];
-	 zk = box[k].zero[box[k].nfit/2];
+	 zk = 0.0;
+	 if(box[k].nfit > 0) zk = box[k].zero[box[k].nfit/2];
 	 for(jp=kp+1; jp<n; jp++) {
 	    j = boxid[jp];
-	    zj = box[j].zero[box[j].nfit/2];
+	    zj = 0.0;
+	    if(box[j].nfit > 0) zj = box[j].zero[box[j].nfit/2];
 	    if(ABS(yctr[jp]-yctr[kp]) > DIFFERENT_STREAK) {
 /* Trim back the feebler streak */
@@ -238,6 +241,15 @@
 /* First: patched up persists */
       for(k=0; k<cell[j].npersist; k++) {
-	 if(cell[j].persist[k].fiterr) continue;
-	 if(cell[j].persist[k].nfit <= 0) continue;
+
+	 if(PERSIST_RETAIN) {
+/* Keep fits which have a dubious slope */
+	    if(cell[j].persist[k].fiterr != FIT_SLOPE_ERROR) {
+	       if(cell[j].persist[k].fiterr) continue;
+	       if(cell[j].persist[k].nfit <= 0) continue;
+	    }
+	 } else {
+	    if(cell[j].persist[k].fiterr) continue;
+	    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\n",
 		 j, cell[j].persist[k].time, 
@@ -262,7 +274,16 @@
       for(k=0; k<cell[j].nburn; k++) {
 	 if(!cell[j].burn[k].burned) continue;
-	 if(cell[j].burn[k].fiterr && 
-	    cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
-	 if(cell[j].burn[k].nfit <= 0) continue;
+	 if(PERSIST_RETAIN) {
+/* Keep fits which have a dubious slope */
+	    if(cell[j].burn[k].fiterr != FIT_SLOPE_ERROR) {
+	       if(cell[j].burn[k].fiterr && 
+		  cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
+	       if(cell[j].burn[k].nfit <= 0) continue;
+	    }
+	 } else {
+	    if(cell[j].burn[k].fiterr && 
+	       cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
+	    if(cell[j].burn[k].nfit <= 0) continue;
+	 }
 
 	 i = (cell[j].burn[k].ex - cell[j].burn[k].sx + 1) / 2;
Index: trunk/extsrc/gpcsw/gpcsrc/fits/burntool/trailfit.c
===================================================================
--- trunk/extsrc/gpcsw/gpcsrc/fits/burntool/trailfit.c	(revision 25070)
+++ trunk/extsrc/gpcsw/gpcsrc/fits/burntool/trailfit.c	(revision 25299)
@@ -226,4 +226,6 @@
 /* FIXME: sanity check fits */
    if(slope >= FIT_MAX_SLOPE || slope < FIT_MIN_SLOPE) {
+      box->slope = slope;
+      box->nfit = 0;
       box->fiterr = FIT_SLOPE_ERROR;
       return(-1);
