Index: trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burntool.c
===================================================================
--- trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burntool.c	(revision 23492)
+++ trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burntool.c	(revision 23493)
@@ -25,7 +25,9 @@
 {
    int i, j, k, nx, ny, err;
+   HeaderUnit ohu = fh_create();
    HeaderUnit ihu = fh_create();
    HeaderUnit ehu;
    const char* ifilename = "-";
+   const char* ofilename = NULL;
    char extname[FH_MAX_STRLEN+1], otaposn[FH_MAX_STRLEN+1];
    int cellmask[MAXCELL];
@@ -33,4 +35,5 @@
    int nextend, cellxy, cell, cellcode;
    int ext, update, restore, psfsize, psfavg;
+   int outfd;
    IMTYPE *buf;
    const char *burnfile=NULL,  *persistfile=NULL;
@@ -142,4 +145,8 @@
 	 burnfile = argv[i] + 4;
 
+/* Alternate Output file for deburned image */
+      } else if(strncmp(argv[i], "outimage=", 9) == 0) {	/* outimage=fname */
+	ofilename = argv[i] + 9;
+
 /* Input file for previous burn persistence streaks */
       } else if(strncmp(argv[i], "trailin=", 8) == 0) {	/* trailin=fname */
@@ -307,4 +314,17 @@
    } else {
       otanum = (otaposn[2] - '0') + 8*(otaposn[3] - '0');
+   }
+
+   if (ofilename) {
+     outfd = creat (ofilename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+     if (outfd == -1) {
+	 fprintf(stderr, "\rerror: Cannot open %s for output\n", ofilename);
+         exit(EXIT_FAILURE);
+      }
+
+     if (!fh_write(ihu, outfd)) {
+	 fprintf(stderr, "\rerror: Trouble writing PHU to %s\n", ofilename);
+         exit(EXIT_FAILURE);
+      }
    }
 
@@ -477,19 +497,42 @@
 /* Write the corrected data back to the FITS. */
 	 if(update) {
-	    fh_ehu(ehu, 0);	/* Seek back to the start of data */
-	    if (fh_write_padded_image(ehu, fh_file_desc(ehu), buf,
-				      naxis1*naxis2*naxis3*sizeof(short),
-				      FH_TYPESIZE_16) != FH_SUCCESS) {
+	   if (ofilename) {
+	     if (!fh_write(ehu, outfd)) {
+	       fprintf(stderr, "\rerror: Trouble writing EXT %d to %s\n", ext, ofilename);
+	       exit(EXIT_FAILURE);
+	     }
+
+	     if (fh_write_padded_image(ehu, outfd, buf,
+				       naxis1*naxis2*naxis3*sizeof(short),
+				       FH_TYPESIZE_16) != FH_SUCCESS) {
 	       fprintf(stderr, "\rerror: failed to re-write image data for extension `%s'.\n",
 		       extname);
 	       free(buf);
 	       exit(EXIT_FAILURE);
-	    }
-	 }
-      }
-
+	     }
+	   } else {
+	     fh_ehu(ehu, 0);	/* Seek back to the start of data */
+	     if (fh_write_padded_image(ehu, fh_file_desc(ehu), buf,
+				       naxis1*naxis2*naxis3*sizeof(short),
+				       FH_TYPESIZE_16) != FH_SUCCESS) {
+	       fprintf(stderr, "\rerror: failed to re-write image data for extension `%s'.\n",
+		       extname);
+	       free(buf);
+	       exit(EXIT_FAILURE);
+	     }
+	   }
+	 }
+      }
+      
       free(buf);
    }
 
+   if (ofilename) {
+     if (close(outfd)) {
+       fprintf(stderr, "\rerror: trouble writing data to output file %s\n", ofilename);
+       exit(EXIT_FAILURE);
+     }
+   }
+      
 /* Dump out the postage stamp file */
    if(psffile != NULL) {
@@ -595,4 +638,5 @@
    printf(" in=fname       Input file for previous burn persistence streaks\n");
    printf(" out=fname      Output file for burn streaks\n");
+   printf(" outimage=imname Output file for MEF image\n");
 //   printf(" trailin=fname  Input file for previous burn persistence streaks\n");
 //   printf(" trailout=fname Output file for burn streaks\n");
