Index: trunk/magic/remove/src/warpedpixels.c
===================================================================
--- trunk/magic/remove/src/warpedpixels.c	(revision 20520)
+++ trunk/magic/remove/src/warpedpixels.c	(revision 20572)
@@ -1,4 +1,6 @@
 #include "streaks.h"
 #include "pmAstrometryWCS.h"
+
+// #define DEBUG_PRINT 1
 
 static void addTouchedPixels(streakFiles *sf, psString fileName);
@@ -31,9 +33,14 @@
     }
 
-    psFits *fits = psFitsOpen("warpedpixels.fits", "w");
-    psFitsWriteImage(fits, NULL, sf->warpedPixels, 0, NULL);
-    psFitsClose(fits);
-
-    exit (0);
+    bool writeTouchedPixels = false;
+    if (writeTouchedPixels) {
+        // write out the warped pixels
+        psMetadata * header = psMetadataAlloc();
+        pmAstromWriteWCS(header, sf->inAstrom->fpa, sf->chip, 0.001);
+        psFits *fits = psFitsOpen("warpedpixels.fits", "w");
+
+        psFitsWriteImage(fits, header, sf->warpedPixels, 0, NULL);
+        psFitsClose(fits);
+    }
 }
 
@@ -62,5 +69,5 @@
 
     /* now set up our wrapper to the chip astrometry to apply to the whole chip */
-    sf->astrom = streakSetAstrometry(sf->astrom, sf->inAstrom->fpa, sf->chip, false, NULL, 
+    sf->astrom = streakSetAstrometry(sf->astrom, sf->stage, sf->inAstrom->fpa, sf->chip, false, NULL, 
         sf->warpedPixels->numCols, sf->warpedPixels->numRows);
     
@@ -108,13 +115,16 @@
         type = "2";
     }
+#ifdef DEBUG_PRINT
     printf("\nSKYCELL %s Type: %s\n", fileName, type);
     for (int i=0; i<4; i++) {
         printf("%f %f\n", pt[i].x, pt[i].y);
     }
-
+#endif
     // Now set the touched pixels
     int ymin = fmax(0, pt[1].y);
     int ymax = fmin(pt[3].y, sf->warpedPixels->numRows);
+#ifdef DEBUG_PRINT
     printf("\nymin: %d ymax: %d\n", ymin, ymax);
+#endif
     for (int y = ymin ; y < ymax; y++) {
         int xleft  = xLeft(pt, y);
@@ -125,18 +135,21 @@
         }
         if (xleft > sf->warpedPixels->numCols) {
-            xleft = sf->warpedPixels->numCols - 1;
+            continue;
         }
         if (xright < 0) {
-            xright = 0;
+            continue;
         }
         if (xright >= sf->warpedPixels->numCols) {
             xright = sf->warpedPixels->numCols - 1;
         }
+#ifdef DEBUG_PRINT
         printf("  y: %d xleft: %d xright: %d\n", y, xleft, xright);
-
-        psU8 *scanline = sf->warpedPixels->data.U8[y];
-
-        for (int x = xleft ; x <= xright; x++) {
-            scanline[x] = 1;
+#endif
+
+        psU8 *rowPixels = sf->warpedPixels->data.U8[y];
+
+        int n = xright - xleft + 1;
+        if (n > 0) {
+            memset(&rowPixels[xleft], 255, n);
         }
     }
