Index: trunk/magic/remove/src/streaksremove.c
===================================================================
--- trunk/magic/remove/src/streaksremove.c	(revision 21042)
+++ trunk/magic/remove/src/streaksremove.c	(revision 21085)
@@ -85,5 +85,5 @@
     int totalStreakPixels = 0;
 
-    // Iterate through each component of the input (only one except for raw stage)
+    // Iterate through each component of the input (there is only one except for raw images)
     do {
         bool exciseImageCube = false;
@@ -223,5 +223,6 @@
     fprintf(stderr, "\t-remove: remove the original image after processing (requires -replace)\n");
     fprintf(stderr, "\t-keepnonwarped: do not exise pixels that were not part of difference processing\n");
-    fprintf(stderr, "\t-transparent val: instead of setting exicsed pixel to NAN add val\n");
+    fprintf(stderr, "\t-transparent val: instead of setting excicsed pixel to NAN add val\n");
+    fprintf(stderr, "\t-chip_mask MASK.fits: name of mask for chip stage (camera stage mask is passed tih -mask)\n");
 
     exit(2);
@@ -333,4 +334,5 @@
         psArgumentRemove(argnum, &argc, argv);
         bool nebulousMask = IN_NEBULOUS(argv[argnum]);
+        // This isn't a strict requirement if stage == IPP_STAGE_CHIP
         if (nebulousMask != nebulousImage) {
             psError(PS_ERR_UNKNOWN, true, "mask image must be %snebulous path with %s image path\n",
@@ -340,4 +342,21 @@
         psMetadataAddStr(config->arguments, PS_LIST_TAIL, "INPUT.MASK", 0,
                 "name of input mask image", argv[argnum]);
+        psArgumentRemove(argnum, &argc, argv);
+    }
+
+    if ((argnum = psArgumentGet(argc, argv, "-chip_mask"))) {
+        if (stage != IPP_STAGE_CHIP) {
+            psError(PS_ERR_UNKNOWN, true, "-chip_mask only allowed at chip stage");
+            usage();
+        }
+        psArgumentRemove(argnum, &argc, argv);
+        bool nebulousMask = IN_NEBULOUS(argv[argnum]);
+        if (nebulousMask != nebulousImage) {
+            psError(PS_ERR_UNKNOWN, true, "chip mask image must be %snebulous path with %s image path\n",
+                nebulousImage ? "" : "non ", nebulousImage ? "nebulous" : "regular");
+            usage();
+        }
+        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "INPUT.CHMASK", 0,
+                "name of input chip mask image", argv[argnum]);
         psArgumentRemove(argnum, &argc, argv);
     }
@@ -429,6 +448,7 @@
         streaksExit("", PS_EXIT_UNKNOWN_ERROR);
     }
+    // For the chip level files, copy the WCS from the astrometry file to the header
+    // XXX: do we want to do this for raw images as well?
     if (sf->stage == IPP_STAGE_CHIP) {
-        // For the chip level files, copy the WCS from the astrometry file to the header
         if (!sf->bilevelAstrometry) {
             updateAstrometry = true;
@@ -481,6 +501,13 @@
             pmAstromWriteWCS(sf->outMask->header, sf->inAstrom->fpa, sf->chip, 0.001);
         }
-
         setupImageRefs(sf->outMask, sf->recMask, sf->inMask, sf->extnum, exciseAll);
+        if (sf->outChMask) {
+            sf->outChMask->header = (psMetadata *) psMemIncrRefCounter(sf->outMask->header);
+            sf->outChMask->image = (psImage *) psMemIncrRefCounter(sf->outMask->image);
+            if (sf->recChMask) {
+                sf->recChMask->header = (psMetadata *) psMemIncrRefCounter(sf->recMask->header);
+                sf->recChMask->image = (psImage *) psMemIncrRefCounter(sf->recMask->image);
+            }
+        }
 
 #ifdef STREAKS_COMPRESS_OUTPUT
@@ -490,4 +517,11 @@
         if (sf->recMask) {
             psFitsSetCompression(sf->recMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
+        }
+        if (sf->outChMask) {
+            copyFitsOptions(sf->outChMask, sf->recChMask, sf->inMask);
+            psFitsSetCompression(sf->outChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
+            if (sf->recChMask) {
+                psFitsSetCompression(sf->recChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
+            }
         }
 #endif
@@ -567,4 +601,8 @@
         writeImage(sf->outMask, extname, sf->extnum);
         writeImage(sf->recMask, extname, sf->extnum);
+        if (sf->stage == IPP_STAGE_CHIP) {
+            writeImage(sf->outChMask, extname, sf->extnum);
+            writeImage(sf->recChMask, extname, sf->extnum);
+        }
     }
     if (sf->outWeight) {
