Index: /trunk/ppImage/src/ppImage.c
===================================================================
--- /trunk/ppImage/src/ppImage.c	(revision 13900)
+++ /trunk/ppImage/src/ppImage.c	(revision 13901)
@@ -18,4 +18,5 @@
     if (config == NULL) {
         psErrorStackPrint(stderr, "Unable to parse command-line arguments.");
+        ppImageCleanup(config, NULL);
         exit(PS_EXIT_CONFIG_ERROR);
     }
@@ -26,4 +27,5 @@
     if (options == NULL) {
         psErrorStackPrint(stderr, "Unable to parse camera.");
+        ppImageCleanup(config, options);
         exit(PS_EXIT_CONFIG_ERROR);
     }
@@ -32,4 +34,5 @@
     if (!ppImageLoop(config, options)) {
         psErrorStackPrint(stderr, "Unable to loop over input");
+        ppImageCleanup(config, options);
         exit(PS_EXIT_SYS_ERROR);
     }
@@ -62,6 +65,6 @@
             if (fpa->hdu->header) fprintf (stderr, "  (%d,%d) header\n", -1, -1);
         } else {
-	    // fprintf (stderr, "  has no fpa data (%d,%d)\n", -1, -1);
-	}
+            // fprintf (stderr, "  has no fpa data (%d,%d)\n", -1, -1);
+        }
         for (int i = 0; i < fpa->chips->n; i++) {
             pmChip *chip = fpa->chips->data[i];
@@ -72,6 +75,6 @@
                 if (chip->hdu->header) fprintf (stderr, "  (%d,%d) header\n", i, -1);
             } else {
-		// fprintf (stderr, "  has no chip data (%d,%d)\n", i, -1);
-	    }
+                // fprintf (stderr, "  has no chip data (%d,%d)\n", i, -1);
+            }
             for (int j = 0; j < chip->cells->n; j++) {
                 pmCell *cell = chip->cells->data[j];
@@ -82,14 +85,14 @@
                     if (cell->hdu->header) fprintf (stderr, "  (%d,%d) header\n", i, j);
                 } else {
-		    // fprintf (stderr, "  has no cell data (%d,%d)\n", i, j);
-		}
-		for (int k = 0; k < cell->readouts->n; k++) {
-		    pmReadout *readout = cell->readouts->data[k];
-		    if (readout) {
-			if (readout->image) fprintf (stderr, "  (%d,%d,%d) image\n", i, j, k);
-			if (readout->weight) fprintf (stderr, "  (%d,%d,%d) weight\n", i, j, k);
-			if (readout->mask) fprintf (stderr, "  (%d,%d,%d) masks\n", i, j, k);
-		    }
-		}
+                    // fprintf (stderr, "  has no cell data (%d,%d)\n", i, j);
+                }
+                for (int k = 0; k < cell->readouts->n; k++) {
+                    pmReadout *readout = cell->readouts->data[k];
+                    if (readout) {
+                        if (readout->image) fprintf (stderr, "  (%d,%d,%d) image\n", i, j, k);
+                        if (readout->weight) fprintf (stderr, "  (%d,%d,%d) weight\n", i, j, k);
+                        if (readout->mask) fprintf (stderr, "  (%d,%d,%d) masks\n", i, j, k);
+                    }
+                }
             }
         }
Index: /trunk/ppImage/src/ppImage.h
===================================================================
--- /trunk/ppImage/src/ppImage.h	(revision 13900)
+++ /trunk/ppImage/src/ppImage.h	(revision 13901)
@@ -48,6 +48,8 @@
 bool ppImageAddstar (pmConfig *config);
 
-bool ppImageMosaicChip (pmConfig *config, const pmFPAview *view, char *outFile, char *inFile);
-bool ppImageMosaicFPA (pmConfig *config, char *outFile, char *inFile);
+bool ppImageMosaicChip (pmConfig *config, const ppImageOptions *options, const pmFPAview *view,
+                        const char *outFile, const char *inFile);
+bool ppImageMosaicFPA (pmConfig *config, const ppImageOptions *options,
+                       const char *outFile, const char *inFile);
 
 void ppImageFileCheck (pmConfig *config);
Index: /trunk/ppImage/src/ppImageLoop.c
===================================================================
--- /trunk/ppImage/src/ppImageLoop.c	(revision 13900)
+++ /trunk/ppImage/src/ppImageLoop.c	(revision 13901)
@@ -27,5 +27,5 @@
             return false;
         }
-	stats = psMetadataAlloc();
+        stats = psMetadataAlloc();
         psFree(resolved);
     }
@@ -34,5 +34,6 @@
     if (!status) {
         psErrorStackPrint(stderr, "Can't find input data!\n");
-        exit(EXIT_FAILURE);
+        ppImageCleanup(config, options);
+        exit(PS_EXIT_PROG_ERROR);
     }
 
@@ -42,5 +43,5 @@
     // files associated with the science image
     if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-	psFree (view);
+        psFree (view);
         return false;
     }
@@ -53,5 +54,5 @@
 
         if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-	    psFree (view);
+            psFree (view);
             return false;
         }
@@ -63,5 +64,5 @@
             }
             if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-		psFree (view);
+                psFree (view);
                 return false;
             }
@@ -78,5 +79,5 @@
             while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
                 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-		    psFree (view);
+                    psFree (view);
                     return false;
                 }
@@ -88,5 +89,5 @@
                 if (!ppImageDetrendReadout(config, options, view)) {
                     psError(PS_ERR_UNKNOWN, false, "Unable to detrend readout.\n");
-		    psFree (view);
+                    psFree (view);
                     return false;
                 }
@@ -99,5 +100,5 @@
             pmChip *fringe = pmFPAfileThisChip(config->files, view, "PPIMAGE.FRINGE");
             if (!ppImageDetrendFringeSolve(chip, fringe, options)) {
-		psFree (view);
+                psFree (view);
                 return false;
             }
@@ -116,5 +117,5 @@
                 pmCell *fringeCell = pmFPAfileThisCell(config->files, view, "PPIMAGE.FRINGE");
                 if (!ppImageDetrendFringeGenerate(cell, fringeCell)) {
-		    psFree (view);
+                    psFree (view);
                     return false;
                 }
@@ -127,20 +128,20 @@
                 if (!mdok || !output) {
                     psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find file PPIMAGE.OUTPUT.\n");
-		    psFree (view);
-                    return false;
-                }
-
-                if (!ppStats(stats, 
-			     output->fpa, 
-			     view,
-			     options->satMask | options->badMask | options->maskValue,
-			     config)) {
+                    psFree (view);
+                    return false;
+                }
+
+                if (!ppStats(stats,
+                             output->fpa,
+                             view,
+                             options->satMask | options->badMask | options->maskValue,
+                             config)) {
                     psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to generate stats for image.\n");
-		    psFree (stats);
-		    psFree (view);
-                    return false;
-                }
-            }
-	    
+                    psFree (stats);
+                    psFree (view);
+                    return false;
+                }
+            }
+
             // Add MD5 information for cell
             pmHDU *hdu = pmHDUFromCell(cell); // HDU that owns the cell
@@ -162,17 +163,17 @@
         }
 
-        if (!ppImageMosaicChip(config, view, "PPIMAGE.OUTPUT.CHIP", "PPIMAGE.OUTPUT")) {
+        if (!ppImageMosaicChip(config, options, view, "PPIMAGE.CHIP", "PPIMAGE.OUTPUT")) {
             psError(PS_ERR_UNKNOWN, false, "Unable to mosaic chip.\n");
-	    psFree (view);
+            psFree (view);
             return false;
         }
         if (!ppImageRebinChip(config, view, "PPIMAGE.BIN1")) {
             psError(PS_ERR_UNKNOWN, false, "Unable to bin chip.\n");
-	    psFree (view);
+            psFree (view);
             return false;
         }
         if (!ppImageRebinChip(config, view, "PPIMAGE.BIN2")) {
             psError(PS_ERR_UNKNOWN, false, "Unable to bin chip.\n");
-	    psFree (view);
+            psFree (view);
             return false;
         }
@@ -181,8 +182,8 @@
         if (options->doPhotom) {
             if (!ppImagePhotom(config, view)) {
-		psError(PS_ERR_UNKNOWN, false, "error running photometry.\n");
-		psFree (view);
-		return false;
-	    }
+                psError(PS_ERR_UNKNOWN, false, "error running photometry.\n");
+                psFree (view);
+                return false;
+            }
         }
 
@@ -195,5 +196,5 @@
 
             if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
-		psFree(view);
+                psFree(view);
                 return false;
             }
@@ -202,5 +203,5 @@
         // Close chip
         if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
-	    psFree(view);
+            psFree(view);
             return false;
         }
@@ -221,21 +222,21 @@
 
     // XXX an optional full-scale FPA mosaic could happen here
-    // it would require us to NOT free PPIMAGE.OUTPUT.CHIP until here
-    // ppImageMosaicFPA (config, "PPIMAGE.OUTPUT.FPA", "PPIMAGE.OUTPUT.CHIP");
-    ppImageMosaicFPA(config, "PPIMAGE.OUTPUT.FPA1", "PPIMAGE.BIN1");
-    ppImageMosaicFPA(config, "PPIMAGE.OUTPUT.FPA2", "PPIMAGE.BIN2");
+    // it would require us to NOT free PPIMAGE.CHIP until here
+    // ppImageMosaicFPA (config, "PPIMAGE.OUTPUT.FPA", "PPIMAGE.CHIP");
+    ppImageMosaicFPA(config, options, "PPIMAGE.OUTPUT.FPA1", "PPIMAGE.BIN1");
+    ppImageMosaicFPA(config, options, "PPIMAGE.OUTPUT.FPA2", "PPIMAGE.BIN2");
 
     // we perform astrometry on all chips after sources have been detected
     if (options->doAstromChip || options->doAstromMosaic) {
         if (!ppImageAstrom(config)) {
-	    psError(PS_ERR_UNKNOWN, false, "error running astrometry.\n");
-	    psFree(view);
-	    return false;
-	}
+            psError(PS_ERR_UNKNOWN, false, "error running astrometry.\n");
+            psFree(view);
+            return false;
+        }
     }
 
     // Close FPA
     if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
-	psFree(view);
+        psFree(view);
         return false;
     }
Index: /trunk/ppImage/src/ppImageMosaic.c
===================================================================
--- /trunk/ppImage/src/ppImageMosaic.c	(revision 13900)
+++ /trunk/ppImage/src/ppImageMosaic.c	(revision 13901)
@@ -5,5 +5,6 @@
 #include "ppImage.h"
 
-bool ppImageMosaicChip(pmConfig *config, const pmFPAview *view, char *outFile, char *inFile)
+bool ppImageMosaicChip(pmConfig *config, const ppImageOptions *options, const pmFPAview *view,
+                       const char *outFile, const char *inFile)
 {
     bool status;                        // Status of MD lookup
@@ -31,11 +32,12 @@
             in->name, out->name, in->xBin, in->yBin, out->xBin, out->yBin);
 
-    // XXX mosaic the chip, making a deep copy.  this has the side effect of making the 
+    // XXX mosaic the chip, making a deep copy.  this has the side effect of making the
     // output image products pure trimmed images, but also increases the memory footprint.
-    status = pmChipMosaic(outChip, inChip, true);
+    status = pmChipMosaic(outChip, inChip, true, options->blankMask);
     return status;
 }
 
-bool ppImageMosaicFPA (pmConfig *config, char *outFile, char *inFile)
+bool ppImageMosaicFPA (pmConfig *config, const ppImageOptions *options, const char *outFile,
+                       const char *inFile)
 {
     bool status;                        // Status of MD lookup
@@ -72,4 +74,4 @@
     psTrace ("pmFPAMosaic", 5, "mosaic fpa %s to %s (xbin,ybin: %d,%d to %d,%d)\n",
              in->name, out->name, in->xBin, in->yBin, out->xBin, out->yBin);
-    return pmFPAMosaic(out->fpa, in->fpa, false);
+    return pmFPAMosaic(out->fpa, in->fpa, false, options->blankMask);
 }
Index: /trunk/ppImage/src/ppImageOptions.c
===================================================================
--- /trunk/ppImage/src/ppImageOptions.c	(revision 13900)
+++ /trunk/ppImage/src/ppImageOptions.c	(revision 13901)
@@ -28,4 +28,5 @@
     options->badMask    = 0x00;         // Bad pixels
     options->flatMask   = 0x00;         // Bad flat pixels
+    options->blankMask  = 0x00;         // Blank (no data, cell gap) pixels
 
     options->doNonLin   = false;        // Non-linearity correction
@@ -147,5 +148,5 @@
 
         // What method do we use to measure the overscan statistics?
-	// XXX allow user to specify psStats types by name
+        // XXX allow user to specify psStats types by name
         psStats *overscanStats = NULL;  // Statistics for overscan
         psString stat = psMetadataLookupStr(NULL, recipe, "OVERSCAN.STAT");
@@ -175,5 +176,5 @@
     options->badMask = pmConfigMask("BAD", config);
     options->flatMask = pmConfigMask("FLAT", config);
-
+    options->blankMask = pmConfigMask("BLANK", config);
 
     options->doBias = psMetadataLookupBool(NULL, recipe, "BIAS");
Index: /trunk/ppImage/src/ppImageOptions.h
===================================================================
--- /trunk/ppImage/src/ppImageOptions.h	(revision 13900)
+++ /trunk/ppImage/src/ppImageOptions.h	(revision 13901)
@@ -9,4 +9,5 @@
     psMaskType badMask;                 // Mask value to give bad pixels
     psMaskType flatMask;                // Mask value to give bad flat pixels
+    psMaskType blankMask;               // Mask value to give blank pixels
 
     bool doBias;                        // Bias subtraction
Index: /trunk/ppImage/src/ppImageParseCamera.c
===================================================================
--- /trunk/ppImage/src/ppImageParseCamera.c	(revision 13900)
+++ /trunk/ppImage/src/ppImageParseCamera.c	(revision 13901)
@@ -24,6 +24,6 @@
     pmFPAfile *inputMask = pmFPAfileBindFromArgs(&status, input, config, "PPIMAGE.INPUT.MASK", "INPUT.MASK");
     if (!status) {
-	psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
-	return NULL;
+        psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
+        return NULL;
     }
     if (inputMask && inputMask->type != PM_FPA_FILE_MASK) {
@@ -34,6 +34,6 @@
     pmFPAfile *inputWeight = pmFPAfileBindFromArgs(&status, input, config, "PPIMAGE.INPUT.WEIGHT", "INPUT.WEIGHT");
     if (!status) {
-	psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
-	return NULL;
+        psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
+        return NULL;
     }
     if (inputWeight && inputWeight->type != PM_FPA_FILE_WEIGHT) {
@@ -52,38 +52,38 @@
     // not all input or output images are used in a given recipe
     if (options->doBias) {
-	if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.BIAS", "BIAS", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_BIAS)) {
-	    psError (PS_ERR_IO, false, "Can't find a bias image source");
-	    psFree (options);
-	    return NULL;
-	}
+        if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.BIAS", "BIAS", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_BIAS)) {
+            psError (PS_ERR_IO, false, "Can't find a bias image source");
+            psFree (options);
+            return NULL;
+        }
     }
     if (options->doDark) {
-	if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.DARK", "DARK", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_DARK)) {
-	    psError (PS_ERR_IO, false, "Can't find a dark image source");
-	    psFree (options);
-	    return NULL;
-	}
+        if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.DARK", "DARK", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_DARK)) {
+            psError (PS_ERR_IO, false, "Can't find a dark image source");
+            psFree (options);
+            return NULL;
+        }
     }
     if (options->doMask) {
-	if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.MASK", "MASK", PM_FPA_FILE_MASK, PM_DETREND_TYPE_MASK)) {
-	    psError (PS_ERR_IO, false, "Can't find a mask image source");
-	    psFree (options);
-	    return NULL;
-	}
+        if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.MASK", "MASK", PM_FPA_FILE_MASK, PM_DETREND_TYPE_MASK)) {
+            psError (PS_ERR_IO, false, "Can't find a mask image source");
+            psFree (options);
+            return NULL;
+        }
     }
     if (options->doShutter) {
-	if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.SHUTTER", "SHUTTER", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_SHUTTER)) {
-	    psError (PS_ERR_IO, false, "Can't find a flat image source");
-	    psFree (options);
-	    return NULL;
-	}
+        if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.SHUTTER", "SHUTTER", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_SHUTTER)) {
+            psError (PS_ERR_IO, false, "Can't find a flat image source");
+            psFree (options);
+            return NULL;
+        }
     }
 
     if (options->doFlat) {
-	if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.FLAT", "FLAT", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_FLAT)) {
-	    psError (PS_ERR_IO, false, "Can't find a shutter image source");
-	    psFree (options);
-	    return NULL;
-	}
+        if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.FLAT", "FLAT", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_FLAT)) {
+            psError (PS_ERR_IO, false, "Can't find a shutter image source");
+            psFree (options);
+            return NULL;
+        }
     }
 
@@ -136,8 +136,8 @@
 skip_fringe:
     if (options->doFringe) {
-	if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.FRINGE", "FRINGE", PM_FPA_FILE_FRINGE, PM_DETREND_TYPE_FRINGE)) {
-	    psError (PS_ERR_IO, false, "Can't find a fringe image source");
-	    return NULL;
-	}
+        if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.FRINGE", "FRINGE", PM_FPA_FILE_FRINGE, PM_DETREND_TYPE_FRINGE)) {
+            psError (PS_ERR_IO, false, "Can't find a fringe image source");
+            return NULL;
+        }
     }
 
@@ -178,15 +178,38 @@
 
     // XXX should these be bound explicitly to the output->fpa rather than the input->fpa?
-    pmFPAfile *byChip = pmFPAfileDefineChipMosaic(config, input->fpa, "PPIMAGE.OUTPUT.CHIP");
-    if (!byChip) {
-        psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.OUTPUT.CHIP"));
-        psFree(options);
-        return NULL;
-    }
-    if (byChip->type != PM_FPA_FILE_IMAGE) {
-        psError(PS_ERR_IO, true, "PPIMAGE.OUTPUT.CHIP is not of type IMAGE");
-        psFree(options);
-        return NULL;
-    }
+    pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, input->fpa, "PPIMAGE.CHIP");
+    if (!chipImage) {
+        psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.CHIP"));
+        psFree(options);
+        return NULL;
+    }
+    if (chipImage->type != PM_FPA_FILE_IMAGE) {
+        psError(PS_ERR_IO, true, "PPIMAGE.CHIP is not of type IMAGE");
+        psFree(options);
+        return NULL;
+    }
+    pmFPAfile *chipMask = pmFPAfileDefineOutput(config, chipImage->fpa, "PPIMAGE.CHIP.MASK");
+    if (!chipMask) {
+        psError(PS_ERR_IO, false, _("Unable to generate output file from PPIMAGE.CHIP.MASK"));
+        psFree(options);
+        return NULL;
+    }
+    if (chipMask->type != PM_FPA_FILE_MASK) {
+        psError(PS_ERR_IO, true, "PPIMAGE.CHIP.MASK is not of type MASK");
+        psFree(options);
+        return NULL;
+    }
+    pmFPAfile *chipWeight = pmFPAfileDefineOutput(config, chipImage->fpa, "PPIMAGE.CHIP.WEIGHT");
+    if (!chipWeight) {
+        psError(PS_ERR_IO, false, _("Unable to generate output file from PPIMAGE.CHIP.WEIGHT"));
+        psFree(options);
+        return NULL;
+    }
+    if (chipWeight->type != PM_FPA_FILE_WEIGHT) {
+        psError(PS_ERR_IO, true, "PPIMAGE.CHIP.WEIGHT is not of type WEIGHT");
+        psFree(options);
+        return NULL;
+    }
+
     pmFPAfile *byFPA1 = pmFPAfileDefineFPAMosaic(config, input->fpa, "PPIMAGE.OUTPUT.FPA1");
     if (!byFPA1) {
@@ -215,5 +238,5 @@
     // we create a copy of the mosaicked image for psphot so we can write out a clean image
     if (options->doPhotom) {
-        pmFPAfile *psphotInput = pmFPAfileDefineFromFPA (config, byChip->fpa, 1, 1, "PSPHOT.INPUT");
+        pmFPAfile *psphotInput = pmFPAfileDefineFromFPA (config, chipImage->fpa, 1, 1, "PSPHOT.INPUT");
         PS_ASSERT (psphotInput, false);
 
@@ -251,10 +274,10 @@
 
     // save any of these files?
-    output->save = options->BaseFITS;
-    byChip->save = options->ChipFITS;
+    output->save = outMask->save = outWeight->save = options->BaseFITS;
+    chipImage->save = chipMask->save = chipWeight->save = options->ChipFITS;
     byFPA1->save = options->FPA1FITS;
     byFPA2->save = options->FPA2FITS;
 
-    // output is used as a carrier: input to byChip -> require the data to remain at the CHIP level
+    // output is used as a carrier: input to chipImage -> require the data to remain at the CHIP level
     output->freeLevel = PS_MIN (output->freeLevel, PM_FPA_LEVEL_CHIP);
     output->dataLevel = output->freeLevel;
@@ -267,9 +290,15 @@
     outWeight->dataLevel = output->dataLevel;
 
+    // Ditto for the chip-mosaicked version
+    chipMask->freeLevel   = chipImage->freeLevel;
+    chipWeight->freeLevel = chipImage->freeLevel;
+    chipMask->dataLevel   = chipImage->dataLevel;
+    chipWeight->dataLevel = chipImage->dataLevel;
+
     // the input data is the same as the output data : force the free levels to match
     input->freeLevel = PS_MIN (output->freeLevel, input->freeLevel);
 
     // define the binned target files (which may just be carriers for some camera configurations)
-    pmFPAfile *bin1 = pmFPAfileDefineFromFPA (config, byChip->fpa, options->xBin1, options->yBin1, "PPIMAGE.BIN1");
+    pmFPAfile *bin1 = pmFPAfileDefineFromFPA (config, chipImage->fpa, options->xBin1, options->yBin1, "PPIMAGE.BIN1");
     if (!bin1) {
         psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.BIN1"));
@@ -283,5 +312,5 @@
     }
 
-    pmFPAfile *bin2 = pmFPAfileDefineFromFPA (config, byChip->fpa, options->xBin2, options->yBin2, "PPIMAGE.BIN2");
+    pmFPAfile *bin2 = pmFPAfileDefineFromFPA (config, chipImage->fpa, options->xBin2, options->yBin2, "PPIMAGE.BIN2");
     if (!bin2) {
         psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.BIN2"));
@@ -354,4 +383,6 @@
         outMask->save = false;
         outWeight->save = false;
+        chipMask->save = false;
+        chipWeight->save = false;
     }
 
Index: /trunk/ppImage/src/ppImagePhotom.c
===================================================================
--- /trunk/ppImage/src/ppImagePhotom.c	(revision 13900)
+++ /trunk/ppImage/src/ppImagePhotom.c	(revision 13901)
@@ -17,6 +17,6 @@
     pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
     if (!status) {
-	psError(PSPHOT_ERR_CONFIG, false, "PSPHOT.INPUT I/O file is not defined");
-	return false;
+        psError(PSPHOT_ERR_CONFIG, false, "PSPHOT.INPUT I/O file is not defined");
+        return false;
     }
 
@@ -28,20 +28,20 @@
     // iterate over the cells and readout for this chip
     while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
-	psLogMsg ("ppImagePhotom", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
-	if (! cell->process || ! cell->file_exists) { continue; }
+        psLogMsg ("ppImagePhotom", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+        if (! cell->process || ! cell->file_exists) { continue; }
 
-	// process each of the readouts
-	while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
-	    if (! readout->data_exists) { continue; }
+        // process each of the readouts
+        while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
+            if (! readout->data_exists) { continue; }
 
-	    // run the actual photometry analysis
-	    if (!psphotReadout (config, view)) {
-		psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
-		return false;
-	    }
-	}
+            // run the actual photometry analysis
+            if (!psphotReadout (config, view)) {
+                psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
+                return false;
+            }
+        }
     }
 
-    // the PSPHOT.INPUT file is a temporary file used to carry PPIMAGE.OUTPUT.CHIP to psphotReadout
+    // the PSPHOT.INPUT file is a temporary file used to carry PPIMAGE.CHIP to psphotReadout
     // XXX not sure that this is needed...
     pmFPAfileActivate (config->files, false, "PSPHOT.INPUT");
