Index: /branches/pap_branch_20090128/pswarp/src/pswarpDefineSkycell.c
===================================================================
--- /branches/pap_branch_20090128/pswarp/src/pswarpDefineSkycell.c	(revision 21234)
+++ /branches/pap_branch_20090128/pswarp/src/pswarpDefineSkycell.c	(revision 21235)
@@ -59,7 +59,6 @@
     psFitsClose(fits);
 
-    // XXX format needs to be equivalent to SIMPLE
-    // determine the current format from the header
-    // determine camera if not specified already
+    // We need to force the format for the skycell to be equivalent to SIMPLE.  Determine
+    // the current format from the header; Determine camera if not specified already
     // XXX EAM : this operation should be defined as a pmConfig function (pmConfigCopy?)
     skyConfig = pmConfigAlloc();
Index: /branches/pap_branch_20090128/pswarp/src/pswarpFileNames.h
===================================================================
--- /branches/pap_branch_20090128/pswarp/src/pswarpFileNames.h	(revision 21235)
+++ /branches/pap_branch_20090128/pswarp/src/pswarpFileNames.h	(revision 21235)
@@ -0,0 +1,51 @@
+/** this file contains the lists of file rules used by pswarpLoop at different analysis steps
+    we use these lists to turn on or off different I/O files at different stages **/
+
+// Lists must end with a NULL
+
+// Lists of file rules for the detectors and skycells, and an independent list of everything else
+
+
+// Lists of file rules for the detectors
+static char *detectorFiles[] = {
+  "PSWARP.INPUT",
+  "PSWARP.MASK",
+  "PSWARP.VARIANCE",
+  NULL
+};
+
+// Lists of file rules for the skycells
+static char *skycellFiles[] = {
+  "PSWARP.OUTPUT",
+  "PSWARP.OUTPUT.MASK",
+  "PSWARP.OUTPUT.VARIANCE",
+  NULL
+};
+
+// Lists of file rules for photometry
+static char *photFiles[] = {
+  "PSPHOT.INPUT",
+  "PSPHOT.OUTPUT",
+#if PSPHOT_FIND_PSF
+  "PSPHOT.INPUT.CMF",
+#endif
+  "PSPHOT.RESID",
+  "PSPHOT.BACKMDL",
+  "PSPHOT.BACKMDL.STDEV",
+  "PSPHOT.BACKGND",
+  "PSPHOT.BACKSUB",
+  "PSPHOT.PSF.SAVE",
+  "SOURCE.PLOT.MOMENTS",
+  "SOURCE.PLOT.PSFMODEL",
+  "SOURCE.PLOT.APRESID",
+  NULL
+};
+
+// Lists of file rules for the detectors and skycells, and an independent list of everything else
+static char *independentFiles[] = {
+  "PSWARP.ASTROM", // Read independently from the input pixels
+  "PSWARP.SKYCELL", // Don't care about the skycell once we have its WCS
+  "PSWARP.OUTPUT.SOURCES", // Save these independently so we can do the PSF
+  NULL
+};
+
Index: /branches/pap_branch_20090128/pswarp/src/pswarpLoop.c
===================================================================
--- /branches/pap_branch_20090128/pswarp/src/pswarpLoop.c	(revision 21234)
+++ /branches/pap_branch_20090128/pswarp/src/pswarpLoop.c	(revision 21235)
@@ -1,26 +1,12 @@
 #include "pswarp.h"
 #include <ppStats.h>
+#include "pswarpFileNames.h"            // Lists of file rules used at different stages
 
 #define WCS_NONLIN_TOL 0.001            // Non-linear tolerance for header WCS
-#define PSPHOT_FIND_PSF 0               // Use psphot's findPSF function?
-//#define TESTING 1                       // Testing output?
-
-// Lists of file rules for the detectors and skycells, and an independent list of everything else
-// Lists must end with a NULL
-static char *detectorFiles[] = { "PSWARP.INPUT", "PSWARP.MASK", "PSWARP.VARIANCE", NULL };
-static char *skycellFiles[] = { "PSWARP.OUTPUT", "PSWARP.OUTPUT.MASK", "PSWARP.OUTPUT.VARIANCE", NULL };
-static char *photFiles[] = { "PSPHOT.INPUT", "PSPHOT.OUTPUT",
-#if PSPHOT_FIND_PSF
-                             "PSPHOT.INPUT.CMF",
-#endif
-                             "PSPHOT.RESID",
-                             "PSPHOT.BACKMDL", "PSPHOT.BACKMDL.STDEV", "PSPHOT.BACKGND", "PSPHOT.BACKSUB",
-                             "PSPHOT.PSF.SAVE", "SOURCE.PLOT.MOMENTS", "SOURCE.PLOT.PSFMODEL",
-                             "SOURCE.PLOT.APRESID", NULL };
-static char *independentFiles[] = { "PSWARP.ASTROM", // Read independently from the input pixels
-                                    "PSWARP.SKYCELL", // Don't care about the skycell once we have its WCS
-                                    "PSWARP.OUTPUT.SOURCES", // Save these independently so we can do the PSF
-                                    NULL };
-
+#define PSPHOT_FIND_PSF 1               // Use psphot's findPSF function?
+#define TESTING 0                       // Testing output?
+
+
+// XXX these are generic functions which should be moved to psModules
 // Activate a list of files
 static void fileActivation(pmConfig *config, // Configuration
@@ -80,5 +66,5 @@
 
     // output mask bits
-    psMaskType maskValue = psMetadataLookupU8(&status, recipe, "MASK.OUTPUT");
+    psImageMaskType maskValue = psMetadataLookupImageMask(&status, recipe, "MASK.OUTPUT");
     psAssert (status, "MASK.OUTPUT was not defined");
 
@@ -141,4 +127,5 @@
 
     // Read the input astrometry
+    // XXX rather than use the activations here, this should just explicitly loop over the desired filerule
     {
         pmFPAfileActivate(config->files, true, "PSWARP.ASTROM");
@@ -373,5 +360,5 @@
         pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa);
         float vf = psMetadataLookupF32(NULL, photRO->parent->concepts, "CELL.VARFACTOR"); // Variance factor
-        psBinaryOp(photRO->weight, photRO->weight, "*", psScalarAlloc(vf, PS_TYPE_F32));
+        psBinaryOp(photRO->variance, photRO->variance, "*", psScalarAlloc(vf, PS_TYPE_F32));
 
         if (!psphotReadoutFindPSF(config, view)) {
@@ -386,5 +373,5 @@
 #endif
 
-#ifdef TESTING
+#if (TESTING)
         {
             #define PSF_SIZE 20         // Half-size of PSF
Index: /branches/pap_branch_20090128/pswarp/src/pswarpPixelFraction.c
===================================================================
--- /branches/pap_branch_20090128/pswarp/src/pswarpPixelFraction.c	(revision 21234)
+++ /branches/pap_branch_20090128/pswarp/src/pswarpPixelFraction.c	(revision 21235)
@@ -20,5 +20,5 @@
     PS_ASSERT_IMAGE_NON_NULL(readout->mask, false);
     PS_ASSERT_IMAGES_SIZE_EQUAL(readout->mask, readout->image, false);
-    PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_MASK, false);
+    PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_IMAGE_MASK, false);
 
     if (stats) {
@@ -40,5 +40,5 @@
 
     // output mask bits
-    psMaskType maskValue = psMetadataLookupU8(&status, recipe, "MASK.OUTPUT"); 
+    psImageMaskType maskValue = psMetadataLookupImageMask(&status, recipe, "MASK.OUTPUT"); 
     psAssert (status, "MASK.OUTPUT was not defined");
 
@@ -55,5 +55,5 @@
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskValue) {
+            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskValue) {
                 numBad++;
             } else {
Index: /branches/pap_branch_20090128/pswarp/src/pswarpSetMaskBits.c
===================================================================
--- /branches/pap_branch_20090128/pswarp/src/pswarpSetMaskBits.c	(revision 21234)
+++ /branches/pap_branch_20090128/pswarp/src/pswarpSetMaskBits.c	(revision 21235)
@@ -8,10 +8,9 @@
 // updated in the config metadata.
 
-bool pswarpSetMaskBits (pmConfig *config)
-{
-    psImageMaskType maskIn = 0x00;      // mask for the input image
-    psImageMaskType markIn = 0x00;      // mark for the input image
-    psImageMaskType maskOut = 0x00;     // mask for the output image
-    psImageMaskType markOut = 0x00;     // mark for the output image
+bool pswarpSetMaskBits (pmConfig *config) {
+
+    psImageMaskType maskIn = 0x00;                      // mask for the input image
+    psImageMaskType markIn = 0x00;                      // mark for the input image
+    psImageMaskType maskOut = 0x00;                     // mask for the output image
 
     // this function sets the required single-image mask bits
@@ -22,5 +21,5 @@
 
     // mask for non-linear flat regions (default to DETECTOR if not defined)
-    psMaskType badMask = pmConfigMaskGet("BAD.WARP", config);
+    psImageMaskType badMask = pmConfigMaskGet("BAD.WARP", config);
     if (!badMask) {
         badMask = 0x01;
@@ -30,5 +29,5 @@
 
     // mask for non-linear flat regions (default to DETECTOR if not defined)
-    psMaskType poorMask = pmConfigMaskGet("POOR.WARP", config);
+    psImageMaskType poorMask = pmConfigMaskGet("POOR.WARP", config);
     if (!poorMask) {
         poorMask = 0x02;
@@ -38,15 +37,15 @@
 
     // search for an unset bit to use for MARK:
-    markOut = 0x80;
+    psImageMaskType markOut   = 0x00;
+    psImageMaskType markTrial = 0x01;
 
-    int nBits = sizeof(psMaskType) * 8;
+    int nBits = sizeof(psImageMaskType) * 8;
     for (int i = 0; !markOut && (i < nBits); i++) {
-        if (maskOut & markOut) {
-            markOut >>= 1;
+        if (maskOut & markTrial) {
+            markTrial <<= 1;
         } else {
-            markOut = markOut;
+            markOut = markTrial;
         }
     }
-
     if (!markOut) {
         psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!");
@@ -63,8 +62,8 @@
     // set maskOut and markOut in the psphot recipe
     // NOTE: psphot works on the output images, not input images, so set the MARK and MASK correctly here
-    psMetadataAddU8 (warpRecipe, PS_LIST_TAIL, "MASK.INPUT",  PS_META_REPLACE, "user-defined mask", maskIn);
-    psMetadataAddU8 (warpRecipe, PS_LIST_TAIL, "MARK.INPUT",  PS_META_REPLACE, "user-defined mask", markIn);
-    psMetadataAddU8 (warpRecipe, PS_LIST_TAIL, "MASK.OUTPUT", PS_META_REPLACE, "user-defined mask", maskOut);
-    psMetadataAddU8 (warpRecipe, PS_LIST_TAIL, "MARK.OUTPUT", PS_META_REPLACE, "user-defined mask", markOut);
+    psMetadataAddImageMask (warpRecipe, PS_LIST_TAIL, "MASK.INPUT",  PS_META_REPLACE, "user-defined mask", maskIn);
+    psMetadataAddImageMask (warpRecipe, PS_LIST_TAIL, "MARK.INPUT",  PS_META_REPLACE, "user-defined mask", markIn);
+    psMetadataAddImageMask (warpRecipe, PS_LIST_TAIL, "MASK.OUTPUT", PS_META_REPLACE, "user-defined mask", maskOut);
+    psMetadataAddImageMask (warpRecipe, PS_LIST_TAIL, "MARK.OUTPUT", PS_META_REPLACE, "user-defined mask", markOut);
 
     // update the psphot recipe
@@ -77,6 +76,6 @@
     // set maskOut and markOut in the psphot recipe
     // NOTE: psphot works on the output images, not input images, so set the MARK and MASK correctly here
-    psMetadataAddU8 (psphotRecipe, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "user-defined mask", markOut);
-    psMetadataAddU8 (psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskOut);
+    psMetadataAddImageMask (psphotRecipe, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "user-defined mask", markOut);
+    psMetadataAddImageMask (psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskOut);
 
     return true;
Index: /branches/pap_branch_20090128/pswarp/src/pswarpTransformReadout.c
===================================================================
--- /branches/pap_branch_20090128/pswarp/src/pswarpTransformReadout.c	(revision 21234)
+++ /branches/pap_branch_20090128/pswarp/src/pswarpTransformReadout.c	(revision 21235)
@@ -22,7 +22,7 @@
 
     // output mask bits
-    psMaskType maskIn   = psMetadataLookupU8(&mdok, recipe, "MASK.INPUT");
-    psMaskType maskPoor = pmConfigMaskGet("POOR.WARP", config);
-    psMaskType maskBad  = pmConfigMaskGet("BAD.WARP", config);
+    psImageMaskType maskIn   = psMetadataLookupImageMask(&mdok, recipe, "MASK.INPUT");
+    psImageMaskType maskPoor = pmConfigMaskGet("POOR.WARP", config);
+    psImageMaskType maskBad  = pmConfigMaskGet("BAD.WARP", config);
     psAssert(mdok, "MASK.INPUT was not defined");
 
@@ -80,5 +80,5 @@
     }
     if ((input->mask || maskPoor || maskBad) && !output->mask) {
-        output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_MASK);
+        output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_IMAGE_MASK);
         psImageInit(output->mask, maskBad);
     }
Index: /branches/pap_branch_20090128/pswarp/src/pswarpTransformTile.c
===================================================================
--- /branches/pap_branch_20090128/pswarp/src/pswarpTransformTile.c	(revision 21234)
+++ /branches/pap_branch_20090128/pswarp/src/pswarpTransformTile.c	(revision 21235)
@@ -49,6 +49,6 @@
     psF32 **outImageData     = args->output->image->data.F32;
     psF32 **outVarData       = (args->output->variance) ? args->output->variance->data.F32 : NULL;
-    psMaskType **outMaskData = (args->output->mask)   ? args->output->mask->data.PS_TYPE_MASK_DATA : NULL;
-    psMaskType **inMaskData  = (args->input->mask)    ? args->input->mask->data.PS_TYPE_MASK_DATA : NULL;
+    psImageMaskType **outMaskData = (args->output->mask)   ? args->output->mask->data.PS_TYPE_IMAGE_MASK_DATA : NULL;
+    psImageMaskType **inMaskData  = (args->input->mask)    ? args->input->mask->data.PS_TYPE_IMAGE_MASK_DATA : NULL;
 
     pswarpMap *map = args->grid->maps[args->gridX][args->gridY]; // Map for this tile
@@ -67,5 +67,5 @@
 
             // Only transform those pixels requested
-            if (region && region->data.U8[y][x]) {
+            if (region && region->data.PS_TYPE_IMAGE_MASK_DATA[y][x]) {
                 continue;
             }
