Index: trunk/magic/remove/src/streaksio.c
===================================================================
--- trunk/magic/remove/src/streaksio.c	(revision 20845)
+++ trunk/magic/remove/src/streaksio.c	(revision 21085)
@@ -5,4 +5,7 @@
 static nebServer *ourNebServer = NULL;
 
+// open the files required for streaks procesing.
+// if remove is true the calling program is streaksremove and the recovery files are outputs
+// if false the recovery files are inputs
 streakFiles *openFiles(pmConfig *config, bool remove)
 {
@@ -30,4 +33,6 @@
 
     if (remove) {
+        // XXX: the recovery file should be required if stage is raw and the replace flag is set
+        // that is if the input raw image is to be destroyed
         sf->recImage = sFileOpen(config, stage, "RECOVERY", inputBasename, false);
     } else {
@@ -45,4 +50,14 @@
         }
     }
+    // If we're in streaksremove and operating on a chip stage image
+    // if we are passed a mask it is camera stage mask and we also
+    // need to destreak the chip level mask file as well
+    if (remove && sf->inMask && (stage == IPP_STAGE_CHIP)) {
+        sf->inChMask = sFileOpen(config, stage, "INPUT.CHMASK", NULL, true);
+        inputBasename = basename(sf->inChMask->name);
+        sf->outChMask = sFileOpen(config, stage, "OUTPUT", inputBasename, true);
+        sf->recChMask = sFileOpen(config, stage, "RECOVERY", inputBasename, false);
+    }
+
     sf->inWeight = sFileOpen(config, stage, "INPUT.WEIGHT", NULL, false);
     if (sf->inWeight) {
@@ -421,6 +436,16 @@
     // XXX: This function assumes that it is only used for a single
     // chip single cell FPA (i.e. a skycell)
+    assert(sf->inImage->pmfile->fpa->chips->n == 1);
+
     pmFPAview *view = sf->view;
-    assert(view->chip == 0);
+    if (view) {
+        // The view was allocated and the chip set by setupAstrometry()
+        assert(view->chip == 0);
+    } else {
+        sf->view = pmFPAviewAlloc(0);
+        view = sf->view;
+        sf->chip = pmFPAviewNextChip(view, sf->inImage->pmfile->fpa, 1);
+        assert(sf->chip != NULL);
+    }
     view->cell = 0;
     sf->cell =  pmFPAviewThisCell(view, sf->inImage->pmfile->fpa);
@@ -747,4 +772,9 @@
         closeImage(sf->recMask);
     }
+    if (sf->inChMask) {
+        closeImage(sf->inChMask);
+        closeImage(sf->outChMask);
+        closeImage(sf->recChMask);
+    }
     if (sf->inWeight) {
         closeImage(sf->inWeight);
