Index: /trunk/ppArith/src/ppArithReadout.c
===================================================================
--- /trunk/ppArith/src/ppArithReadout.c	(revision 21182)
+++ /trunk/ppArith/src/ppArithReadout.c	(revision 21183)
@@ -26,5 +26,5 @@
         outImage = output->mask;
         if (!outImage) {
-            output->mask = outImage = psImageAlloc(inImage1->numCols, inImage1->numRows, PS_TYPE_MASK);
+            output->mask = outImage = psImageAlloc(inImage1->numCols, inImage1->numRows, PS_TYPE_IMAGE_MASK);
         }
         if (!output->image) {
@@ -37,5 +37,5 @@
         outImage = output->image;
         if (!outImage) {
-            output->mask = outImage = psImageAlloc(inImage1->numCols, inImage1->numRows, PS_TYPE_MASK);
+            output->mask = outImage = psImageAlloc(inImage1->numCols, inImage1->numRows, PS_TYPE_IMAGE_MASK);
         }
     }
Index: /trunk/ppImage/src/ppImage.h
===================================================================
--- /trunk/ppImage/src/ppImage.h	(revision 21182)
+++ /trunk/ppImage/src/ppImage.h	(revision 21183)
@@ -58,10 +58,10 @@
 
     // make values for abstract concepts of masking
-    psMaskType maskValue;               // apply this bit-mask to choose masked bits
-    psMaskType markValue;               // apply this bit-mask to choose masked bits
-    psMaskType satMask;                 // Mask value to give saturated pixels
-    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
+    psImageMaskType maskValue;               // apply this bit-mask to choose masked bits
+    psImageMaskType markValue;               // apply this bit-mask to choose masked bits
+    psImageMaskType satMask;                 // Mask value to give saturated pixels
+    psImageMaskType badMask;                 // Mask value to give bad pixels
+    psImageMaskType flatMask;                // Mask value to give bad flat pixels
+    psImageMaskType blankMask;               // Mask value to give blank pixels
 
     // non-linear correction parameters
Index: /trunk/ppImage/src/ppImageCleanup.c
===================================================================
--- /trunk/ppImage/src/ppImageCleanup.c	(revision 21182)
+++ /trunk/ppImage/src/ppImageCleanup.c	(revision 21183)
@@ -23,5 +23,6 @@
     // fprintf (stderr, "Found %d leaks at %s\n", Nleaks, "ppImage");
 
-    fprintf(stderr, "Found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "ppImage");
+    // fprintf(stderr, "Found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "ppImage");
+    fprintf(stderr, "Found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "ppImage");
 
     return;
Index: /trunk/ppImage/src/ppImageLoop.c
===================================================================
--- /trunk/ppImage/src/ppImageLoop.c	(revision 21182)
+++ /trunk/ppImage/src/ppImageLoop.c	(revision 21183)
@@ -126,7 +126,7 @@
 	}
 
-        // measure various statistics for this image
+        // measure various pixel-based statistics for this image
         if (!ppImagePixelStats(config, stats, options, view)) {
-            ESCAPE("Unable to measures stats for image");
+            ESCAPE("Unable to measures pixel stats for image");
         }
         if (!ppImageMosaicChip(config, options, view, "PPIMAGE.CHIP", "PPIMAGE.OUTPUT")) {
@@ -209,7 +209,7 @@
     }
 
-    // Write out summary statistics
+    // Calculate summary statistics from FPA Metadata
     if (!ppImageMetadataStats(config, stats, options)) {
-        ESCAPE("Unable to write statistics file.");
+        ESCAPE("Unable to determine FPA-level metadata statistics.");
     }
 
@@ -218,5 +218,4 @@
         ESCAPE("save failure for FPA");
     }
-
     psFree(view);
 
@@ -230,4 +229,5 @@
         }
     }
+    psFree (stats);
 
     return true;
Index: /trunk/ppImage/src/ppImageReplaceBackground.c
===================================================================
--- /trunk/ppImage/src/ppImageReplaceBackground.c	(revision 21182)
+++ /trunk/ppImage/src/ppImageReplaceBackground.c	(revision 21183)
@@ -30,8 +30,8 @@
     // XXX Should this be options->maskValue or options->maskValue & ~options->satMask?
     //     The latter will leave saturated pixels high
-    psMaskType maskVal = options->maskValue;
+    psImageMaskType maskVal = options->maskValue;
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMetadataAddU8(psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskVal);
+    psMetadataAddImageMask(psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskVal);
 
     // Since we are working on a chip-mosaicked image, there should only be a single cell and readout
@@ -146,5 +146,5 @@
             if (!isfinite(value)) {
                 image->data.F32[y][x] = NAN;
-                mask->data.PS_TYPE_MASK_DATA[y][x] |= options->badMask;
+                mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= options->badMask;
             } else {
                 image->data.F32[y][x] -= value;
@@ -157,5 +157,5 @@
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            if (mask && mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) {
+            if (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
                 image->data.F32[y][x] = 0.0;
             } else {
@@ -163,5 +163,5 @@
                 if (!isfinite(value)) {
                     image->data.F32[y][x] = NAN;
-                    mask->data.PS_TYPE_MASK_DATA[y][x] |= options->badMask;
+                    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= options->badMask;
                 } else {
                     image->data.F32[y][x] -= value;
Index: /trunk/ppImage/src/ppImageSetMaskBits.c
===================================================================
--- /trunk/ppImage/src/ppImageSetMaskBits.c	(revision 21182)
+++ /trunk/ppImage/src/ppImageSetMaskBits.c	(revision 21183)
@@ -38,6 +38,6 @@
 
     // set maskValue and markValue in the psphot recipe
-    psMetadataAddU8 (recipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", options->maskValue);
-    psMetadataAddU8 (recipe, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "user-defined mask", options->markValue);
+    psMetadataAddImageMask (recipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", options->maskValue);
+    psMetadataAddImageMask (recipe, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "user-defined mask", options->markValue);
 
     return true;
Index: /trunk/ppMerge/src/ppMergeArguments.c
===================================================================
--- /trunk/ppMerge/src/ppMergeArguments.c	(revision 21182)
+++ /trunk/ppMerge/src/ppMergeArguments.c	(revision 21183)
@@ -94,6 +94,6 @@
         } \
     } \
-    psMaskType mask = pmConfigMask(str, config); \
-    psMetadataAddU8(config->arguments, PS_LIST_TAIL, RECIPENAME, 0, NULL, mask); \
+    psImageMaskType mask = pmConfigMask(str, config); \
+    psMetadataAddImageMask(config->arguments, PS_LIST_TAIL, RECIPENAME, 0, NULL, mask); \
 }
 
Index: /trunk/ppMerge/src/ppMergeLoop.c
===================================================================
--- /trunk/ppMerge/src/ppMergeLoop.c	(revision 21182)
+++ /trunk/ppMerge/src/ppMergeLoop.c	(revision 21183)
@@ -38,6 +38,6 @@
 
     // set the mask and mark bit values based on the named masks
-    psMaskType maskVal;
-    psMaskType markVal;
+    psImageMaskType maskVal;
+    psImageMaskType markVal;
     if (!pmConfigMaskSetBits (&maskVal, &markVal, config)) {
 	psError (PS_ERR_UNKNOWN, true, "Unable to define the mask bit values");
Index: /trunk/ppMerge/src/ppMergeLoop_Threaded.c
===================================================================
--- /trunk/ppMerge/src/ppMergeLoop_Threaded.c	(revision 21182)
+++ /trunk/ppMerge/src/ppMergeLoop_Threaded.c	(revision 21183)
@@ -54,6 +54,6 @@
 
     // set the mask and mark bit values based on the named masks
-    psMaskType maskVal;
-    psMaskType markVal;
+    psImageMaskType maskVal;
+    psImageMaskType markVal;
     if (!pmConfigMaskSetBits (&maskVal, &markVal, config)) {
         psError (PS_ERR_UNKNOWN, true, "Unable to define the mask bit values");
@@ -257,5 +257,5 @@
                       psArrayAdd(job->args, 1, psScalarAlloc(iter, PS_TYPE_S32));
                       psArrayAdd(job->args, 1, psScalarAlloc(rej, PS_TYPE_F32));
-                      psArrayAdd(job->args, 1, psScalarAlloc(maskVal, PS_TYPE_U8));
+                      psArrayAdd(job->args, 1, psScalarAlloc(maskVal, PS_TYPE_IMAGE_MASK));
 
                       // call: pmDarkCombine(outCell, fileGroup->readouts, iter, rej, maskVal);
@@ -276,5 +276,5 @@
                       psArrayAdd(job->args, 1, psScalarAlloc(iter, PS_TYPE_S32));
                       psArrayAdd(job->args, 1, psScalarAlloc(rej, PS_TYPE_F32));
-                      psArrayAdd(job->args, 1, psScalarAlloc(maskVal, PS_TYPE_U8));
+                      psArrayAdd(job->args, 1, psScalarAlloc(maskVal, PS_TYPE_IMAGE_MASK));
 
                       // call: pmShutterCorrectionGenerate(outRO, pattern, fileGroup->readouts, shutterRef,
Index: /trunk/ppMerge/src/ppMergeMask.c
===================================================================
--- /trunk/ppMerge/src/ppMergeMask.c	(revision 21182)
+++ /trunk/ppMerge/src/ppMergeMask.c	(revision 21183)
@@ -26,6 +26,6 @@
     float smoothScale = psMetadataLookupF32(&mdok, config->arguments, "MASK.SMOOTH.SCALE"); // Radius to grow mask
 
-    psMaskType markVal;
-    psMaskType maskValRaw;
+    psImageMaskType markVal;
+    psImageMaskType maskValRaw;
     if (!pmConfigMaskSetBits (&maskValRaw, &markVal, config)) {
 	psError (PS_ERR_UNKNOWN, true, "Unable to define the mask bit values");
@@ -34,5 +34,5 @@
 
     char *maskOutName = psMetadataLookupStr (&mdok, config->arguments, "MASK.SET.VALUE");
-    psMaskType maskValOut = pmConfigMaskGet (maskOutName, config);
+    psImageMaskType maskValOut = pmConfigMaskGet (maskOutName, config);
     if (!maskValOut) {
 	psError (PS_ERR_UNKNOWN, true, "Undefined output mask bit value");
@@ -137,6 +137,6 @@
                 int x = pixel % numCols;
                 int y = pixel / numCols;
-                if (mask && (mask->data.PS_TYPE_MASK_DATA[y][x] & maskValRaw)) continue;
-		if (outMask && (outMask->data.PS_TYPE_MASK_DATA[y][x] & maskValOut)) continue;
+                if (mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskValRaw)) continue;
+		if (outMask && (outMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskValOut)) continue;
 		if (!isfinite(image->data.F32[y][x])) continue;
 
Index: /trunk/ppMerge/src/ppMergeScaleZero.c
===================================================================
--- /trunk/ppMerge/src/ppMergeScaleZero.c	(revision 21182)
+++ /trunk/ppMerge/src/ppMergeScaleZero.c	(revision 21183)
@@ -80,5 +80,5 @@
                 pmReadout *readout = cell->readouts->data[0]; // Readout of interest
 
-                psMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask
+                psImageMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask
 
                 switch (type) {
Index: /trunk/ppMerge/src/ppMergeSetThreads.c
===================================================================
--- /trunk/ppMerge/src/ppMergeSetThreads.c	(revision 21182)
+++ /trunk/ppMerge/src/ppMergeSetThreads.c	(revision 21183)
@@ -29,5 +29,5 @@
     psScalar *maskVal           = job->args->data[4];
 
-    bool status = pmDarkCombine(outCell, fileGroup->readouts, iter->data.S32, rej->data.F32, maskVal->data.U8);
+    bool status = pmDarkCombine(outCell, fileGroup->readouts, iter->data.S32, rej->data.F32, maskVal->data.PS_TYPE_IMAGE_MASK_DATA);
 
     // after we are done, tell the I/O system that this file group is done
@@ -49,5 +49,5 @@
     psScalar *maskVal             = job->args->data[7];
 
-    bool status = pmShutterCorrectionGenerate(output, pattern, fileGroup->readouts, shutterRef->data.F32, data, iter->data.S32, rej->data.F32, maskVal->data.U8);
+    bool status = pmShutterCorrectionGenerate(output, pattern, fileGroup->readouts, shutterRef->data.F32, data, iter->data.S32, rej->data.F32, maskVal->data.PS_TYPE_IMAGE_MASK_DATA);
 
     // after we are done, tell the I/O system that this file group is done
Index: /trunk/ppMerge/src/ppMergeThreadLauncher.c
===================================================================
--- /trunk/ppMerge/src/ppMergeThreadLauncher.c	(revision 21182)
+++ /trunk/ppMerge/src/ppMergeThreadLauncher.c	(revision 21183)
@@ -60,5 +60,5 @@
 	    psScalar *maskVal     	= job->args->data[6];
 
-	    bool status = pmDarkCombine(outCell, fileGroup->readouts, darkOrdinates, darkNorm, iter->data.S32, rej->data.F32, maskVal->data.U8);
+	    bool status = pmDarkCombine(outCell, fileGroup->readouts, darkOrdinates, darkNorm, iter->data.S32, rej->data.F32, maskVal->data.PS_TYPE_IMAGE_MASK_DATA);
 	    if (!status) {
 		self->fault = true;
@@ -82,5 +82,5 @@
 	    psScalar *maskVal     	  = job->args->data[6];
 
-	    bool status = pmShutterCorrectionGenerate(output, NULL, fileGroup->readouts, shutterRef->data.F32, data, iter->data.S32, rej->data.F32, maskVal->data.U8);
+	    bool status = pmShutterCorrectionGenerate(output, NULL, fileGroup->readouts, shutterRef->data.F32, data, iter->data.S32, rej->data.F32, maskVal->data.PS_TYPE_IMAGE_MASK_DATA);
 	    if (!status) {
 		self->fault = true;
Index: /trunk/ppSim/src/ppSim.h
===================================================================
--- /trunk/ppSim/src/ppSim.h	(revision 21182)
+++ /trunk/ppSim/src/ppSim.h	(revision 21183)
@@ -130,6 +130,5 @@
 bool ppSimInsertGalaxies (pmReadout *readout, psImage *expCorr, psArray *galaxies, pmConfig *config);
 
-bool ppSimMosaicChip(pmConfig *config, const psMaskType blankMask, const pmFPAview *view,
-		     const char *outFile, const char *inFile);
+bool ppSimMosaicChip(pmConfig *config, const psImageMaskType blankMask, const pmFPAview *view, const char *outFile, const char *inFile);
 
 bool ppSimPhotom (pmConfig *config, pmFPAview *view);
Index: /trunk/ppSim/src/ppSimMosaicChip.c
===================================================================
--- /trunk/ppSim/src/ppSimMosaicChip.c	(revision 21182)
+++ /trunk/ppSim/src/ppSimMosaicChip.c	(revision 21183)
@@ -2,5 +2,5 @@
 
 // XXX this is essentially identical to ppImageMosaicChip
-bool ppSimMosaicChip(pmConfig *config, const psMaskType blankMask, const pmFPAview *view,
+bool ppSimMosaicChip(pmConfig *config, const psImageMaskType blankMask, const pmFPAview *view,
                        const char *outFile, const char *inFile)
 {
Index: /trunk/ppSim/src/ppSimPhotom.c
===================================================================
--- /trunk/ppSim/src/ppSimPhotom.c	(revision 21182)
+++ /trunk/ppSim/src/ppSimPhotom.c	(revision 21183)
@@ -15,5 +15,5 @@
     psphotInit ();
 
-    int blankMask = 0;		// XXX not sure what this should be set to...
+    psImageMaskType blankMask = 1;		// XXX not sure what this should be set to...
     ppSimMosaicChip(config, blankMask, view, "PPSIM.FORCE.CHIP", "PPSIM.INPUT");
     ppSimMosaicChip(config, blankMask, view, "PPSIM.FAKE.CHIP", "PPSIM.OUTPUT");
Index: /trunk/ppSim/src/ppSimPhotomReadout.c
===================================================================
--- /trunk/ppSim/src/ppSimPhotomReadout.c	(revision 21182)
+++ /trunk/ppSim/src/ppSimPhotomReadout.c	(revision 21183)
@@ -96,5 +96,5 @@
 
     // XXX fake sources should measure peak->x,y, force sources should not
-    psMaskType maskVal = 0xff; 
+    psImageMaskType maskVal = 0xff; 
     psImage *significance = psphotSignificanceImage (readout, recipe, 1, maskVal);
     ppSimDetections (significance, recipe, fakeSources);
Index: /trunk/ppSim/src/ppSimPhotomReadoutFake.c
===================================================================
--- /trunk/ppSim/src/ppSimPhotomReadoutFake.c	(revision 21182)
+++ /trunk/ppSim/src/ppSimPhotomReadoutFake.c	(revision 21183)
@@ -76,5 +76,5 @@
 
     // XXX fake sources should measure peak->x,y, force sources should not
-    psMaskType maskVal = 0xff; 
+    psImageMaskType maskVal = 0xff; 
     psImage *significance = psphotSignificanceImage (readout, recipe, 1, maskVal);
     ppSimDetections (significance, recipe, fakeSources);
Index: /trunk/ppSim/src/ppSimPhotomReadoutForce.c
===================================================================
--- /trunk/ppSim/src/ppSimPhotomReadoutForce.c	(revision 21182)
+++ /trunk/ppSim/src/ppSimPhotomReadoutForce.c	(revision 21183)
@@ -69,5 +69,5 @@
 
     // XXX fake sources should measure peak->x,y, force sources should not
-    psMaskType maskVal = 0xff; 
+    psImageMaskType maskVal = 0xff; 
     psImage *significance = psphotSignificanceImage (readout, recipe, 1, maskVal);
     ppSimDetections (significance, recipe, forceSources);
Index: /trunk/ppStack/src/ppStackArguments.c
===================================================================
--- /trunk/ppStack/src/ppStackArguments.c	(revision 21182)
+++ /trunk/ppStack/src/ppStackArguments.c	(revision 21183)
@@ -79,6 +79,6 @@
         } \
     } \
-    psMaskType value = pmConfigMaskGet(name, config); \
-    psMetadataAddU8(recipe, PS_LIST_TAIL, RECIPENAME, PS_META_REPLACE, NULL, value); \
+    psImageMaskType value = pmConfigMaskGet(name, config); \
+    psMetadataAddImageMask(recipe, PS_LIST_TAIL, RECIPENAME, PS_META_REPLACE, NULL, value); \
 }
 
Index: /trunk/ppStack/src/ppStackLoop.c
===================================================================
--- /trunk/ppStack/src/ppStackLoop.c	(revision 21182)
+++ /trunk/ppStack/src/ppStackLoop.c	(revision 21183)
@@ -403,5 +403,5 @@
     int numGood = 0;                    // Number of good frames
     int numCols = 0, numRows = 0;       // Size of image
-    psVector *inputMask = psVectorAlloc(num, PS_TYPE_U8); // Mask for inputs
+    psVector *inputMask = psVectorAlloc(num, PS_TYPE_VECTOR_MASK); // Mask for inputs
     psVectorInit(inputMask, 0);
     psVector *matchChi2 = psVectorAlloc(num, PS_TYPE_F32); // chi^2 for stamps when matching
@@ -449,5 +449,5 @@
                           sourceLists->data[i], targetPSF, rng, config)) {
             psErrorStackPrint(stderr, "Unable to match image %d --- ignoring.", i);
-            inputMask->data.U8[i] = PPSTACK_MASK_MATCH;
+            inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PPSTACK_MASK_MATCH;
             psErrorClear();
             continue;
@@ -536,5 +536,5 @@
         psVector *values = psVectorAllocEmpty(num, PS_TYPE_F32); // Values to sort
         for (int i = 0; i < num; i++) {
-            if (inputMask->data.PS_TYPE_MASK_DATA[i] & PPSTACK_MASK_ALL) {
+            if (inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_ALL) {
                 continue;
             }
@@ -569,10 +569,10 @@
             numGood = 0;                    // Number of good images
             for (int i = 0; i < num; i++) {
-                if (inputMask->data.PS_TYPE_MASK_DATA[i] & PPSTACK_MASK_ALL) {
+	      if (inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_ALL) {
                     continue;
                 }
                 if (matchChi2->data.F32[i] > thresh) {
                     numRej++;
-                    inputMask->data.PS_TYPE_MASK_DATA[i] |= PPSTACK_MASK_CHI2;
+                    inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= PPSTACK_MASK_CHI2;
                     psLogMsg("ppStack", PS_LOG_INFO, "Rejecting image %d because of large matching chi^2: %f",
                              i, matchChi2->data.F32[i]);
@@ -647,5 +647,5 @@
 
         psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits to mask for bad
-        psMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
+        psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
         if (!pmReadoutStackDefineOutput(outRO, col0, row0, numCols, numRows, true, true, maskBad)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to prepare output.");
@@ -728,5 +728,5 @@
         inspect = psArrayAlloc(num);
         for (int i = 0; i < num; i++) {
-            if (inputMask->data.U8[i]) {
+            if (inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
                 continue;
             }
@@ -739,5 +739,5 @@
             psArray *results = job->results; // Results of job
             for (int i = 0; i < num; i++) {
-                if (inputMask->data.U8[i]) {
+                if (inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
                     continue;
                 }
@@ -765,5 +765,5 @@
         // Count images rejected out of hand
         for (int i = 0; i < num; i++) {
-            if (inputMask->data.U8[i]) {
+            if (inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
                 numRejected++;
             }
@@ -771,5 +771,5 @@
 
         for (int i = 0; i < num; i++) {
-            if (inputMask->data.U8[i]) {
+            if (inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
                 continue;
             }
@@ -816,5 +816,5 @@
         // Reject bad pixels
         for (int i = 0; i < num; i++) {
-            if (inputMask->data.U8[i]) {
+            if (inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
                 continue;
             }
@@ -859,5 +859,5 @@
                 psWarning("Rejection on image %d didn't work --- reject entire image.", i);
                 numRejected++;
-                inputMask->data.U8[i] = PPSTACK_MASK_REJECT;
+                inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PPSTACK_MASK_REJECT;
             } else {
                 float frac = reject->n / (float)(numCols * numRows); // Pixel fraction
@@ -870,5 +870,5 @@
                     // reject == NULL means reject image completely
                     reject = NULL;
-                    inputMask->data.U8[i] = PPSTACK_MASK_BAD;
+                    inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PPSTACK_MASK_BAD;
                     numRejected++;
                 }
@@ -982,5 +982,5 @@
     {
         psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits for bad
-        psMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
+        psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
         if (!pmReadoutMaskApply(outRO, maskBad)) {
             psWarning("Unable to apply mask");
@@ -992,5 +992,5 @@
     bool wcsDone = false;           // Have we done the WCS?
     for (int i = 0; i < num; i++) {
-        if (inputMask->data.U8[i]) {
+        if (inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
             continue;
         }
@@ -1056,5 +1056,5 @@
         pmCell *cell1 = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT.JPEG1");
         pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT.JPEG2");
-        psMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
+        psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
 
         pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts
@@ -1078,5 +1078,5 @@
         int renormNum = psMetadataLookupS32(&mdok, recipe, "RENORM.NUM"); // Number of samples
         float renormWidth = psMetadataLookupS32(&mdok, recipe, "RENORM.WIDTH"); // Width of Gaussian phot
-        psMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
+        psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
         if (!pmReadoutWeightRenormPhot(outRO, maskValue, renormNum, renormWidth,
                                        renormMean, renormStdev, NULL)) {
@@ -1124,5 +1124,5 @@
         psTrace("ppStack", 1, "Gathering statistics on stacked image....\n");
         psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits for bad
-        psMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
+        psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
 
         ppStatsFPA(stats, outRO->parent->parent->parent, view, maskBad, config);
Index: /trunk/ppStack/src/ppStackMatch.c
===================================================================
--- /trunk/ppStack/src/ppStackMatch.c	(revision 21182)
+++ /trunk/ppStack/src/ppStackMatch.c	(revision 21183)
@@ -104,5 +104,5 @@
 
 // Generate a background model of the readout we're matching
-psImage *stackBackgroundModel(pmReadout *ro, psMaskType maskVal, const psArray *sources, int size)
+psImage *stackBackgroundModel(pmReadout *ro, psImageMaskType maskVal, const psArray *sources, int size)
 {
     psImage *image = ro->image, *mask = ro->mask; // Image and mask of readout
@@ -169,9 +169,9 @@
 
     psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.VAL"); // Name of bits to mask going in
-    psMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch
+    psImageMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch
     psString maskPoorStr = psMetadataLookupStr(NULL, recipe, "MASK.POOR"); // Name of bits to mask for poor
-    psMaskType maskPoor = pmConfigMaskGet(maskPoorStr, config); // Bits to mask for poor pixels
+    psImageMaskType maskPoor = pmConfigMaskGet(maskPoorStr, config); // Bits to mask for poor pixels
     psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits to mask for bad
-    psMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
+    psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
 
     bool mdok;                          // Status of MD lookup
Index: /trunk/ppStack/src/ppStackPhotometry.c
===================================================================
--- /trunk/ppStack/src/ppStackPhotometry.c	(revision 21182)
+++ /trunk/ppStack/src/ppStackPhotometry.c	(revision 21183)
@@ -45,5 +45,5 @@
         return false;
     }
-    psMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask
+    psImageMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask
 
     psImage *image = ro->image, *mask = ro->mask; // Image and mask from readout
@@ -85,5 +85,5 @@
             float dy2 = PS_SQR(y - v); // Distance from centroid
             for (int u = xMin; u <= xMax; u++) {
-                if (mask->data.PS_TYPE_MASK_DATA[v][u] & maskVal) {
+                if (mask->data.PS_TYPE_IMAGE_MASK_DATA[v][u] & maskVal) {
                     numBadPix++;
                     continue;
@@ -133,8 +133,8 @@
 
     // set maskValue and markValue in the psphot recipe
-    psMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
-    psMaskType markValue = pmConfigMaskGet("MARK.VALUE", config); // Bits to use for marking
-    psMetadataAddU8 (recipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "Bits to mask", maskValue);
-    psMetadataAddU8 (recipe, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "Bits to use for mark", markValue);
+    psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
+    psImageMaskType markValue = pmConfigMaskGet("MARK.VALUE", config); // Bits to use for marking
+    psMetadataAddImageMask (recipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "Bits to mask", maskValue);
+    psMetadataAddImageMask (recipe, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "Bits to use for mark", markValue);
 
     if (!psphotReadout(config, view)) {
Index: /trunk/ppStack/src/ppStackReadout.c
===================================================================
--- /trunk/ppStack/src/ppStackReadout.c	(revision 21182)
+++ /trunk/ppStack/src/ppStackReadout.c	(revision 21183)
@@ -114,7 +114,7 @@
 
     psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.VAL"); // Name of bits to mask going in
-    psMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch
+    psImageMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch
     psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits to mask for bad
-    psMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
+    psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
 
     int num = readouts->n;              // Number of inputs
@@ -141,5 +141,5 @@
         // Ensure there is a mask, or pmStackCombine will complain
         if (!ro->mask) {
-            ro->mask = psImageAlloc(ro->image->numCols, ro->image->numRows, PS_TYPE_MASK);
+            ro->mask = psImageAlloc(ro->image->numCols, ro->image->numRows, PS_TYPE_IMAGE_MASK);
             psImageInit(ro->mask, 0);
         }
@@ -208,7 +208,7 @@
 
     psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.VAL"); // Name of bits to mask going in
-    psMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch
+    psImageMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch
     psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits to mask for bad
-    psMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
+    psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
 
     int num = readouts->n;              // Number of inputs
@@ -238,5 +238,5 @@
         // Ensure there is a mask, or pmStackCombine will complain
         if (!ro->mask) {
-            ro->mask = psImageAlloc(ro->image->numCols, ro->image->numRows, PS_TYPE_MASK);
+            ro->mask = psImageAlloc(ro->image->numCols, ro->image->numRows, PS_TYPE_IMAGE_MASK);
             psImageInit(ro->mask, 0);
         }
Index: /trunk/ppStack/src/ppStackSources.c
===================================================================
--- /trunk/ppStack/src/ppStackSources.c	(revision 21182)
+++ /trunk/ppStack/src/ppStackSources.c	(revision 21183)
@@ -109,5 +109,5 @@
             psVectorInit(mag, NAN);
             for (int j = 0; j < match->num; j++) {
-                if (match->mask->data.PS_TYPE_MASK_DATA[j]) {
+                if (match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) {
                     continue;
                 }
Index: /trunk/ppStats/src/ppStats.h
===================================================================
--- /trunk/ppStats/src/ppStats.h	(revision 21182)
+++ /trunk/ppStats/src/ppStats.h	(revision 21183)
@@ -24,5 +24,5 @@
     bool doFirstReadout3D;		// for 3D data, use the first readout?
     float sample;                       // Fraction of cell to sample for statistics
-    psMaskType maskVal;                 // Mask value for images
+    psImageMaskType maskVal;		// Mask value for images
     psList *chips;                      // Chips to look at
     psList *cells;                      // Cells to look at
@@ -45,5 +45,5 @@
                        pmFPA *fpa,         // FPA for which to get statistics
                        pmFPAview *view,    // View for analysis
-                       psMaskType maskVal, // Value to mask
+                       psImageMaskType maskVal, // Value to mask
                        pmConfig *config    // Configuration
     );
@@ -77,5 +77,5 @@
                           pmFPA *fpa,         // FPA for which to get statistics
                           pmFPAview *view,    // View for analysis
-                          psMaskType maskVal, // Value to mask
+                          psImageMaskType maskVal, // Value to mask
                           pmConfig *config    // Configuration
     );
@@ -85,5 +85,5 @@
                             pmFPA *fpa,         // FPA for which to get statistics
                             pmFPAview *view,    // View for analysis
-                            psMaskType maskVal, // Value to mask
+                            psImageMaskType maskVal, // Value to mask
                             pmConfig *config    // Configuration
     );
Index: /trunk/ppStats/src/ppStatsFPA.c
===================================================================
--- /trunk/ppStats/src/ppStatsFPA.c	(revision 21182)
+++ /trunk/ppStats/src/ppStatsFPA.c	(revision 21183)
@@ -4,5 +4,5 @@
 		       pmFPA *fpa,         // FPA for which to get statistics
 		       pmFPAview *view,    // View for analysis
-		       psMaskType maskVal, // Value to mask
+		       psImageMaskType maskVal, // Value to mask
 		       pmConfig *config    // Configuration
     )
Index: /trunk/ppStats/src/ppStatsMetadata.c
===================================================================
--- /trunk/ppStats/src/ppStatsMetadata.c	(revision 21182)
+++ /trunk/ppStats/src/ppStatsMetadata.c	(revision 21183)
@@ -5,5 +5,5 @@
 			    pmFPA *fpa,         // FPA for which to get statistics
 			    pmFPAview *view,    // View for analysis
-			    psMaskType maskVal, // Value to mask
+			    psImageMaskType maskVal, // Value to mask
 			    pmConfig *config    // Configuration
     )
Index: /trunk/ppStats/src/ppStatsPixels.c
===================================================================
--- /trunk/ppStats/src/ppStatsPixels.c	(revision 21182)
+++ /trunk/ppStats/src/ppStatsPixels.c	(revision 21183)
@@ -5,5 +5,5 @@
 			  pmFPA *fpa,         // FPA for which to get statistics
 			  pmFPAview *view,    // View for analysis
-			  psMaskType maskVal, // Value to mask
+			  psImageMaskType maskVal, // Value to mask
 			  pmConfig *config    // Configuration
     )
Index: /trunk/ppStats/src/ppStatsReadout.c
===================================================================
--- /trunk/ppStats/src/ppStatsReadout.c	(revision 21182)
+++ /trunk/ppStats/src/ppStatsReadout.c	(revision 21183)
@@ -63,8 +63,7 @@
         int sampleSpace = 1.0 / data->sample; // Space between samples
         psVector *sampleValues = psVectorAlloc(numSamples, PS_TYPE_F32); // Vector of samples
-        psVector *sampleMask = psVectorAlloc(numSamples, PS_TYPE_MASK);  // Corresponding mask
-        if (!mask) {
-            psVectorInit(sampleMask, 0);
-        }
+        psVector *sampleMask = psVectorAlloc(numSamples, PS_TYPE_VECTOR_MASK);  // Corresponding mask
+	psVectorInit(sampleMask, 0);
+
         for (int i = 0; i < numSamples; i++) {
             int j = i * sampleSpace;
@@ -72,17 +71,25 @@
             int x = j % image->numCols;
             sampleValues->data.F32[i] = image->data.F32[y][x];
-            if ((!mask || !(mask->data.PS_TYPE_MASK_DATA[y][x] & data->maskVal)) &&
-                !isfinite(sampleValues->data.F32[i])) {
-                if (!warnNonFinite) {
-                    psWarning("Unmasked non-finite value detected at %d,%d; suppressing further warnings",
-                              x, y);
-                    warnNonFinite = true;
-                }
-                sampleMask->data.PS_TYPE_MASK_DATA[i] = data->maskVal;
-            } else if (mask) {
-                sampleMask->data.PS_TYPE_MASK_DATA[i] = mask->data.PS_TYPE_MASK_DATA[y][x];
-            }
-        }
-        if (!psVectorStats(data->stats, sampleValues, NULL, sampleMask, data->maskVal)) {
+
+	    // ignore the sampleMask if there is no input mask
+	    if (!mask) continue;
+
+	    // if this pixel is masked, set the sample mask
+            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & data->maskVal) {
+		sampleMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 1;
+		continue;
+	    }
+
+	    // mask any unmasked NAN/INF values
+            if (!isfinite(sampleValues->data.F32[i])) {
+		// warn for the first unmasked NAN/INF value
+		if (!warnNonFinite) {
+		    psWarning("Unmasked non-finite value detected at %d,%d; suppressing further warnings", x, y);
+		    warnNonFinite = true;
+		}
+                sampleMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 1;
+            } 
+        }
+        if (!psVectorStats(data->stats, sampleValues, NULL, sampleMask, 1)) {
             psWarning("Unable to perform statistics on readout %s.\n", readoutName);
             psErrorClear();
@@ -179,5 +186,5 @@
                 for (int j = 0; j < readout->mask->numRows; j++) {
                     for (int i = 0; i < readout->mask->numCols; i++) {
-                        if (readout->mask->data.PS_TYPE_MASK_DATA[j][i] & data->maskVal) {
+                        if (readout->mask->data.PS_TYPE_IMAGE_MASK_DATA[j][i] & data->maskVal) {
                             numBad++;
                         }
Index: /trunk/ppSub/src/ppSubArguments.c
===================================================================
--- /trunk/ppSub/src/ppSubArguments.c	(revision 21182)
+++ /trunk/ppSub/src/ppSubArguments.c	(revision 21183)
@@ -216,6 +216,6 @@
     psMetadataAddF32(arguments, PS_LIST_TAIL, "-rej", 0, "Rejection thresold (sigma)", NAN);
     psMetadataAddF32(arguments, PS_LIST_TAIL, "-sys", 0, "Relative systematic error in kernel", NAN);
-    psMetadataAddU8(arguments,  PS_LIST_TAIL, "-mask-bad", 0, "Mask value for bad pixels", 0);
-    psMetadataAddU8(arguments,  PS_LIST_TAIL, "-mask-poor", 0, "Mask value for poor pixels", 0);
+    psMetadataAddImageMask(arguments,  PS_LIST_TAIL, "-mask-bad", 0, "Mask value for bad pixels", 0);
+    psMetadataAddImageMask(arguments,  PS_LIST_TAIL, "-mask-poor", 0, "Mask value for poor pixels", 0);
     psMetadataAddF32(arguments,  PS_LIST_TAIL, "-poor-frac", 0, "Fraction of weight for poor pixels", NAN);
     psMetadataAddF32(arguments, PS_LIST_TAIL, "-badfrac", 0, "Maximum fraction of bad pixels to accept", 1.0);
Index: /trunk/ppSub/src/ppSubBackground.c
===================================================================
--- /trunk/ppSub/src/ppSubBackground.c	(revision 21182)
+++ /trunk/ppSub/src/ppSubBackground.c	(revision 21183)
@@ -30,8 +30,8 @@
 
     psString maskBadStr = psMetadataLookupStr(NULL, ppSubRecipe, "MASK.BAD"); // Name of bits to mask for bad
-    psMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
+    psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMetadataAddU8(psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskBad);
+    psMetadataAddImageMask(psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskBad);
 
     psImage *image = ro->image, *mask = ro->mask; // Image and mask of interest
@@ -59,5 +59,5 @@
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            if (mask && mask->data.PS_TYPE_MASK_DATA[y][x] & maskBad) {
+            if (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskBad) {
                 image->data.F32[y][x] = 0.0;
             } else {
@@ -65,5 +65,5 @@
                 if (!isfinite(value)) {
                     image->data.F32[y][x] = NAN;
-                    mask->data.PS_TYPE_MASK_DATA[y][x] |= maskBad;
+                    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= maskBad;
                 } else {
                     image->data.F32[y][x] -= value;
Index: /trunk/ppSub/src/ppSubReadout.c
===================================================================
--- /trunk/ppSub/src/ppSubReadout.c	(revision 21182)
+++ /trunk/ppSub/src/ppSubReadout.c	(revision 21183)
@@ -103,9 +103,9 @@
     float penalty = psMetadataLookupF32(NULL, recipe, "PENALTY"); // Penalty for wideness
     psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.IN"); // Name of bits to mask going in
-    psMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch
+    psImageMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch
     psString maskPoorStr = psMetadataLookupStr(NULL, recipe, "MASK.POOR"); // Name of bits to mask for poor
-    psMaskType maskPoor = pmConfigMaskGet(maskPoorStr, config); // Bits to mask for poor pixels
+    psImageMaskType maskPoor = pmConfigMaskGet(maskPoorStr, config); // Bits to mask for poor pixels
     psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits to mask for bad
-    psMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
+    psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
     float badFrac = psMetadataLookupF32(NULL, recipe, "BADFRAC"); // Maximum bad fraction
     const char *stampsName = psMetadataLookupStr(&mdok, config->arguments, "STAMPS"); // Filename for stamps
@@ -146,5 +146,5 @@
             pmReadoutSetMask(inRO, pmConfigMaskGet("SAT", config), pmConfigMaskGet("BAD", config));
         } else {
-            inRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+            inRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
             psImageInit(inRO->mask, 0);
         }
@@ -154,5 +154,5 @@
             pmReadoutSetMask(refRO, pmConfigMaskGet("SAT", config), pmConfigMaskGet("BAD", config));
         } else {
-            refRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+            refRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
             psImageInit(refRO->mask, 0);
         }
@@ -363,10 +363,10 @@
         }
         if (minuend->mask) {
-            outRO->mask = psImageCopy(outRO->mask, minuend->mask, PS_TYPE_MASK);
+            outRO->mask = psImageCopy(outRO->mask, minuend->mask, PS_TYPE_IMAGE_MASK);
         }
         outRO->data_exists = outCell->data_exists = outCell->parent->data_exists = true;
 
         if (psMetadataLookupBool(&mdok, recipe, "RENORM")) {
-            psMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
+            psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
             if (!pmReadoutWeightRenormPhot(outRO, maskValue, renormNum, renormWidth,
                                            renormMean, renormStdev, NULL)) {
@@ -399,8 +399,8 @@
 
         // set maskValue and markValue in the psphot recipe
-        psMaskType maskValue = maskVal;
-        psMaskType markValue = pmConfigMaskGet("MARK.VALUE", config); // Bits to use for marking
-        psMetadataAddU8(psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "Bits to mask", maskValue);
-        psMetadataAddU8(psphotRecipe, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "Bits to use for marking",
+        psImageMaskType maskValue = maskVal;
+        psImageMaskType markValue = pmConfigMaskGet("MARK.VALUE", config); // Bits to use for marking
+        psMetadataAddImageMask(psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "Bits to mask", maskValue);
+        psMetadataAddImageMask(psphotRecipe, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "Bits to use for marking",
                         markValue);
 
@@ -477,6 +477,6 @@
     for (int y = 0; y < outRO->image->numRows; y++) {
         for (int x = 0; x < outRO->image->numCols; x++) {
-            if (isnan(outRO->image->data.F32[y][x]) && !(outRO->mask->data.U8[y][x] & maskVal)) {
-                printf("Unmasked NAN at %d %d --> %d\n", x, y, outRO->mask->data.U8[y][x]);
+            if (isnan(outRO->image->data.F32[y][x]) && !(outRO->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal)) {
+                printf("Unmasked NAN at %d %d --> %d\n", x, y, outRO->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x]);
             }
         }
@@ -568,5 +568,5 @@
 
         if (psMetadataLookupBool(&mdok, recipe, "RENORM")) {
-            psMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
+            psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
             if (!pmReadoutWeightRenormPhot(outRO, maskValue, renormNum, renormWidth,
                                            renormMean, renormStdev, NULL)) {
@@ -669,5 +669,5 @@
     // Renormalising for pixels, because that's what magic desires
     if (psMetadataLookupBool(&mdok, recipe, "RENORM")) {
-        psMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
+        psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
         if (!pmReadoutWeightRenormPixels(outRO, maskValue, renormMean, renormStdev, NULL)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to renormalise variances.");
Index: /trunk/psLib/src/fft/psImageFFT.c
===================================================================
--- /trunk/psLib/src/fft/psImageFFT.c	(revision 21182)
+++ /trunk/psLib/src/fft/psImageFFT.c	(revision 21183)
@@ -6,6 +6,6 @@
 /// @author Robert DeSonia, MHPCC
 ///
-/// @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
-/// @date $Date: 2008-11-06 23:36:20 $
+/// @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
+/// @date $Date: 2009-01-27 06:39:37 $
 ///
 /// Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -318,5 +318,5 @@
 
 
-psImage *psImageConvolveFFT(psImage *out, const psImage *in, const psImage *mask, psMaskType maskVal,
+psImage *psImageConvolveFFT(psImage *out, const psImage *in, const psImage *mask, psImageMaskType maskVal,
                             const psKernel *kernel)
 {
@@ -326,5 +326,5 @@
     if (mask) {
         PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
         PS_ASSERT_IMAGES_SIZE_EQUAL(mask, in, NULL);
     }
@@ -464,5 +464,5 @@
         for (int y = 0; y < numRows; y++) {
             for (int x = 0; x < numCols; x++) {
-                if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) {
+                if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
                     data[x + paddedCols * y] = 0;
                 }
Index: /trunk/psLib/src/fft/psImageFFT.h
===================================================================
--- /trunk/psLib/src/fft/psImageFFT.h	(revision 21182)
+++ /trunk/psLib/src/fft/psImageFFT.h	(revision 21183)
@@ -5,6 +5,6 @@
 /// @author Robert DeSonia, MHPCC
 ///
-/// @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
-/// @date $Date: 2008-04-04 22:44:56 $
+/// @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+/// @date $Date: 2009-01-27 06:39:37 $
 /// Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
 ///
@@ -70,5 +70,5 @@
     const psImage *in,                  ///< Image to convolve
     const psImage *mask,                ///< Corresponding mask
-    psMaskType maskVal,                 ///< Value to mask
+    psImageMaskType maskVal,		///< Value to mask
     const psKernel *kernel              ///< kernel to colvolve with
 );
Index: /trunk/psLib/src/fits/psFitsImage.c
===================================================================
--- /trunk/psLib/src/fits/psFitsImage.c	(revision 21182)
+++ /trunk/psLib/src/fits/psFitsImage.c	(revision 21183)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-09-05 08:08:33 $
+ *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -251,5 +251,5 @@
                                           const psImage *image, // Image to convert
                                           const psImage *mask, // Mask image, or NULL
-                                          psMaskType maskVal, // Value to mask
+                                          psImageMaskType maskVal, // Value to mask
                                           psRandom *rng, // Random number generator
                                           bool newScaleZero // Determine a new BSCALE and BZERO?
@@ -506,5 +506,5 @@
 
 bool psFitsWriteImageWithMask(psFits *fits, psMetadata *header, const psImage *input,
-                              const psImage *mask, psMaskType maskVal, int numZPlanes,
+                              const psImage *mask, psImageMaskType maskVal, int numZPlanes,
                               const char *extname)
 {
@@ -525,5 +525,5 @@
 
 bool psFitsInsertImageWithMask(psFits *fits, psMetadata *header, const psImage *image,
-                               const psImage *mask, psMaskType maskVal, int numZPlanes,
+                               const psImage *mask, psImageMaskType maskVal, int numZPlanes,
                                const char *extname, bool after)
 {
@@ -532,5 +532,5 @@
     PS_ASSERT_IMAGE_NON_NULL(image, false);
     if (mask) {
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(mask, image, false);
     }
@@ -706,5 +706,5 @@
 }
 
-bool psFitsUpdateImageWithMask(psFits *fits, const psImage *input, const psImage *mask, psMaskType maskVal,
+bool psFitsUpdateImageWithMask(psFits *fits, const psImage *input, const psImage *mask, psImageMaskType maskVal,
                                int x0, int y0, int z)
 {
@@ -713,5 +713,5 @@
     PS_ASSERT_IMAGE_NON_NULL(input, false);
     if (mask) {
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(mask, input, false);
     }
@@ -896,5 +896,5 @@
 
 bool psFitsWriteImageCubeWithMask(psFits *fits, psMetadata *header, const psArray *input,
-                                  const psArray *masks, psMaskType maskVal, const char *extname)
+                                  const psArray *masks, psImageMaskType maskVal, const char *extname)
 {
     PS_ASSERT_FITS_NON_NULL(fits, false);
@@ -976,5 +976,5 @@
 
 bool psFitsUpdateImageCubeWithMask(psFits *fits, const psArray *input,
-                                   const psArray *masks, psMaskType maskVal, int x0, int y0)
+                                   const psArray *masks, psImageMaskType maskVal, int x0, int y0)
 {
     PS_ASSERT_FITS_NON_NULL(fits, false);
Index: /trunk/psLib/src/fits/psFitsImage.h
===================================================================
--- /trunk/psLib/src/fits/psFitsImage.h	(revision 21182)
+++ /trunk/psLib/src/fits/psFitsImage.h	(revision 21183)
@@ -4,6 +4,6 @@
  * @author Robert DeSonia, MHPCC
  *
- * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-09-05 08:08:33 $
+ * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -74,5 +74,5 @@
     const psImage *input,               ///< the image to output
     const psImage *mask,                ///< the mask image
-    psMaskType maskVal,                 ///< value to mask
+    psImageMaskType maskVal,		///< value to mask
     int depth,                          ///< the number of z-planes of the FITS image data cube
     const char *extname                 ///< FITS extension name
@@ -101,5 +101,5 @@
     const psImage *input,               ///< the image to output
     const psImage *mask,                ///< the mask image
-    psMaskType maskVal,                 ///< value to mask
+    psImageMaskType maskVal,		///< value to mask
     int depth,                          ///< the number of z-planes of the FITS image data cube
     const char *extname,                ///< FITS extension name
@@ -128,5 +128,5 @@
     const psImage *input,               ///< the image to output
     const psImage *mask,                ///< the mask image
-    psMaskType maskVal,                 ///< value to mask
+    psImageMaskType maskVal,		///< value to mask
     int x0,                             ///< psImage's x-axis origin in FITS image coordinates
     int y0,                             ///< psImage's y-axis origin in FITS image coordinates
@@ -157,5 +157,5 @@
     const psArray *input,               ///< Array of images
     const psArray *masks,               ///< Array of masks
-    psMaskType maskVal,                 ///< Value to mask
+    psImageMaskType maskVal,		///< Value to mask
     const char *extname                 ///< Name of extension
     );
@@ -175,5 +175,5 @@
     const psArray *input,               ///< Array of images
     const psArray *masks,               ///< Array of masks
-    psMaskType maskVal,                 ///< Value to mask
+    psImageMaskType maskVal,		///< Value to mask
     int x0,                             ///< x origin of images in FITS image coordinates
     int y0                              ///< y origin of images in FITS image coordinates
Index: /trunk/psLib/src/fits/psFitsScale.c
===================================================================
--- /trunk/psLib/src/fits/psFitsScale.c	(revision 21182)
+++ /trunk/psLib/src/fits/psFitsScale.c	(revision 21183)
@@ -100,5 +100,5 @@
                        const psImage *image, // Image to scale
                        const psImage *mask, // Mask image
-                       psMaskType maskVal, // Value to mask
+                       psImageMaskType maskVal, // Value to mask
                        const psFitsOptions *options // FITS options
     )
@@ -167,5 +167,5 @@
 
 bool psFitsScaleDetermine(double *bscale, double *bzero, long *blank, const psImage *image,
-                          const psImage *mask, psMaskType maskVal, const psFits *fits)
+                          const psImage *mask, psImageMaskType maskVal, const psFits *fits)
 {
     PS_ASSERT_PTR_NON_NULL(bscale, false);
@@ -174,5 +174,5 @@
     PS_ASSERT_IMAGE_NON_NULL(image, false);
     if (mask) {
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(mask, image, false);
     }
Index: /trunk/psLib/src/fits/psFitsScale.h
===================================================================
--- /trunk/psLib/src/fits/psFitsScale.h	(revision 21182)
+++ /trunk/psLib/src/fits/psFitsScale.h	(revision 21183)
@@ -13,5 +13,5 @@
                           const psImage *image, ///< Image to scale
                           const psImage *mask, ///< Mask image
-                          psMaskType maskVal, ///< Value to mask
+                          psImageMaskType maskVal, ///< Value to mask
                           const psFits *fits ///< FITS options
     );
Index: /trunk/psLib/src/imageops/psImageBackground.c
===================================================================
--- /trunk/psLib/src/imageops/psImageBackground.c	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageBackground.c	(revision 21183)
@@ -18,10 +18,10 @@
 // XXX allow the user to choose the stats method?
 // (SAMPLE_MEAN, CLIPPED_MEAN, ROBUST_MEDIAN, FITTED_MEAN)
-bool psImageBackground(psStats *stats, psVector **sample, const psImage *image, const psImage *mask, psMaskType maskValue, psRandom *rng)
+bool psImageBackground(psStats *stats, psVector **sample, const psImage *image, const psImage *mask, psImageMaskType maskValue, psRandom *rng)
 {
     PS_ASSERT_IMAGE_NON_NULL(image, NULL);
     if (mask) {
         PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_U8, NULL);
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
         PS_ASSERT_IMAGES_SIZE_EQUAL(mask, image, NULL);
     }
@@ -63,5 +63,5 @@
         int iy = pixel / nx;
 
-        if (!isfinite(image->data.F32[iy][ix]) || (mask && mask->data.U8[iy][ix] & maskValue)) {
+        if (!isfinite(image->data.F32[iy][ix]) || (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskValue)) {
             continue;
         }
Index: /trunk/psLib/src/imageops/psImageBackground.h
===================================================================
--- /trunk/psLib/src/imageops/psImageBackground.h	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageBackground.h	(revision 21183)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  $Date: 2008-01-17 22:07:33 $
+ *  $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  $Date: 2009-01-27 06:39:37 $
  *  Copyright 2004-2005 IfA, University of Hawaii
  */
@@ -27,5 +27,5 @@
                        const psImage *image, // Image for which to get the background
                        const psImage *mask, // Mask image
-                       psMaskType maskValue, // Mask pixels which this mask value
+                       psImageMaskType maskValue, // Mask pixels which this mask value
                        psRandom *rng // Random number generator (for pixel selection)
                       );
Index: /trunk/psLib/src/imageops/psImageConvolve.c
===================================================================
--- /trunk/psLib/src/imageops/psImageConvolve.c	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageConvolve.c	(revision 21183)
@@ -7,6 +7,6 @@
 /// @author Eugene Magnier, IfA
 ///
-/// @version $Revision: 1.81 $ $Name: not supported by cvs2svn $
-/// @date $Date: 2008-11-26 00:43:12 $
+/// @version $Revision: 1.82 $ $Name: not supported by cvs2svn $
+/// @date $Date: 2009-01-27 06:39:37 $
 ///
 /// Copyright 2004-2007 Institute for Astronomy, University of Hawaii
@@ -319,9 +319,9 @@
 }
 
-psImage *psImageConvolveMaskDirect(psImage *out, const psImage *mask, psMaskType maskVal,
-                                   psMaskType setVal, int xMin, int xMax, int yMin, int yMax)
+psImage *psImageConvolveMaskDirect(psImage *out, const psImage *mask, psImageMaskType maskVal,
+                                   psImageMaskType setVal, int xMin, int xMax, int yMin, int yMax)
 {
     PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
     if (out == mask && ((maskVal & setVal) || !setVal)) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
@@ -352,10 +352,10 @@
     if (!out) {
         // Propagate the non-masked values
-        out = (psImage*)psBinaryOp(NULL, (const psPtr)mask, "&", psScalarAlloc(~maskVal, PS_TYPE_MASK));
+        out = (psImage*)psBinaryOp(NULL, (const psPtr)mask, "&", psScalarAlloc(~maskVal, PS_TYPE_IMAGE_MASK));
     }
 
     // Dereference mask images
-    psMaskType **maskData = mask->data.PS_TYPE_MASK_DATA;
-    psMaskType **outData = out->data.PS_TYPE_MASK_DATA;
+    psImageMaskType **maskData = mask->data.PS_TYPE_IMAGE_MASK_DATA;
+    psImageMaskType **outData = out->data.PS_TYPE_IMAGE_MASK_DATA;
 
     if (setVal) {
@@ -376,5 +376,5 @@
         for (int row = 0; row < numRows; row++) {
             for (int col = 0; col < numCols; col++) {
-                psMaskType pixel = outData[row][col]; // Pixel value to set
+                psImageMaskType pixel = outData[row][col]; // Pixel value to set
                 if (pixel & maskVal) {
                     // Already done this one
@@ -395,9 +395,9 @@
 
 
-psImage *psImageConvolveMaskFFT(psImage *out, const psImage *mask, psMaskType maskVal,
-                                psMaskType setVal, int xMin, int xMax, int yMin, int yMax, float thresh)
+psImage *psImageConvolveMaskFFT(psImage *out, const psImage *mask, psImageMaskType maskVal,
+                                psImageMaskType setVal, int xMin, int xMax, int yMin, int yMax, float thresh)
 {
     PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
     PS_ASSERT_FLOAT_LARGER_THAN(thresh, 0.0, NULL);
     PS_ASSERT_FLOAT_LESS_THAN(thresh, 1.0, NULL);
@@ -431,5 +431,5 @@
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) {
+            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
                 onoff->data.F32[y][x] = 1.0;
             }
@@ -452,10 +452,10 @@
 
     if (!out) {
-        out = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+        out = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
     }
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            out->data.PS_TYPE_MASK_DATA[y][x] = (convolved->data.F32[y][x] >= thresh) ?
-                (mask->data.PS_TYPE_MASK_DATA[y][x] | setVal) : mask->data.PS_TYPE_MASK_DATA[y][x];
+            out->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = (convolved->data.F32[y][x] >= thresh) ?
+                (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] | setVal) : mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x];
         }
     }
@@ -651,5 +651,5 @@
 case PS_TYPE_##TYPE: { \
     psImage *calculation = psImageAlloc(numRows, numCols, PS_TYPE_##TYPE); /* Calculation image; BW */ \
-    psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_MASK); /* Mask for calculation image; BW */ \
+    psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_IMAGE_MASK); /* Mask for calculation image; BW */ \
     \
     /** Smooth in X direction **/ \
@@ -658,5 +658,5 @@
             int xMin = PS_MAX(i - size, 0); \
             int xMax = PS_MIN(i + size, xLast); \
-            const psMaskType *maskData = &mask->data.PS_TYPE_MASK_DATA[j][xMin]; \
+            const psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[j][xMin]; \
             const ps##TYPE *imageData = &image->data.TYPE[j][xMin]; \
             int uMin = - PS_MIN(i, size); /* Minimum kernel index */ \
@@ -673,8 +673,8 @@
                 /* BW */ \
                 calculation->data.TYPE[i][j] = sumIG / sumG; \
-                calcMask->data.PS_TYPE_MASK_DATA[i][j] = 0; \
+                calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] = 0; \
             } else { \
                 /* BW */ \
-                calcMask->data.PS_TYPE_MASK_DATA[i][j] = 0xFF; \
+                calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] = 0xFF; \
             } \
         } \
@@ -688,5 +688,5 @@
             int yMin = PS_MAX(j - size, 0); \
             int yMax = PS_MIN(j + size, yLast); \
-            const psMaskType *maskData = &calcMask->data.PS_TYPE_MASK_DATA[i][yMin]; /* BW */ \
+            const psImageMaskType *maskData = &calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][yMin]; /* BW */ \
             const ps##TYPE *imageData = &calculation->data.TYPE[i][yMin]; /* BW */ \
             int vMin = - PS_MIN(j, size); /* Minimum kernel index */ \
@@ -714,5 +714,5 @@
                            const psImage *image,
                            const psImage *mask,
-                           psMaskType maskVal,
+                           psImageMaskType maskVal,
                            float sigma,
                            float numSigma,
@@ -721,5 +721,5 @@
     PS_ASSERT_IMAGE_NON_NULL(image, NULL);
     PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
     PS_ASSERT_IMAGES_SIZE_EQUAL(image, mask, NULL);
 
@@ -751,5 +751,5 @@
       case PS_TYPE_F32: {
           psImage *calculation = psImageAlloc(numRows, numCols, PS_TYPE_F32); /* Calculation image; BW */
-          psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_MASK); /* Mask for calculation image; BW */
+          psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_IMAGE_MASK); /* Mask for calculation image; BW */
 
           /** Smooth in X direction **/
@@ -758,5 +758,5 @@
                   int xMin = PS_MAX(i - size, 0);
                   int xMax = PS_MIN(i + size, xLast);
-                  const psMaskType *maskData = &mask->data.PS_TYPE_MASK_DATA[j][xMin];
+                  const psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[j][xMin];
                   const psF32 *imageData = &image->data.F32[j][xMin];
                   int uMin = - PS_MIN(i, size); /* Minimum kernel index */
@@ -776,8 +776,8 @@
                       /* BW */
                       calculation->data.F32[i][j] = sumIG / sumG;
-                      calcMask->data.PS_TYPE_MASK_DATA[i][j] = 0;
+                      calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] = 0;
                   } else {
                       /* BW */
-                      calcMask->data.PS_TYPE_MASK_DATA[i][j] = 0xFF;
+                      calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] = 0xFF;
                   }
               }
@@ -791,5 +791,5 @@
                   int yMin = PS_MAX(j - size, 0);
                   int yMax = PS_MIN(j + size, yLast);
-                  const psMaskType *maskData = &calcMask->data.PS_TYPE_MASK_DATA[i][yMin]; /* BW */
+                  const psImageMaskType *maskData = &calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][yMin]; /* BW */
                   const psF32 *imageData = &calculation->data.F32[i][yMin]; /* BW */
                   int vMin = - PS_MIN(j, size); /* Minimum kernel index */
@@ -832,5 +832,5 @@
                                      const psImage *image,
                                      const psImage *mask,
-                                     psMaskType maskVal,
+                                     psImageMaskType maskVal,
                                      psVector *gaussNorm,
                                      float minGauss,
@@ -848,5 +848,5 @@
             int xMin = PS_MAX(i - size, 0);
             int xMax = PS_MIN(i + size, xLast);
-            const psMaskType *maskData = &mask->data.PS_TYPE_MASK_DATA[j][xMin];
+            const psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[j][xMin];
             const psF32 *imageData = &image->data.F32[j][xMin];
             int uMin = - PS_MIN(i, size); /* Minimum kernel index */
@@ -863,8 +863,8 @@
                 /* BW */
                 calculation->data.F32[i][j] = sumIG / sumG;
-                calcMask->data.PS_TYPE_MASK_DATA[i][j] = 0;
+                calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] = 0;
             } else {
                 /* BW */
-                calcMask->data.PS_TYPE_MASK_DATA[i][j] = 0xFF;
+                calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] = 0xFF;
             }
         }
@@ -876,5 +876,5 @@
                                      psImage *calculation,
                                      psImage *calcMask,
-                                     psMaskType maskVal,
+                                     psImageMaskType maskVal,
                                      psVector *gaussNorm,
                                      float minGauss,
@@ -892,5 +892,5 @@
             int yMin = PS_MAX(j - size, 0);
             int yMax = PS_MIN(j + size, yLast);
-            const psMaskType *maskData = &calcMask->data.PS_TYPE_MASK_DATA[i][yMin]; /* BW */
+            const psImageMaskType *maskData = &calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][yMin]; /* BW */
             const psF32 *imageData = &calculation->data.F32[i][yMin]; /* BW */
             int vMin = - PS_MIN(j, size); /* Minimum kernel index */
@@ -921,5 +921,5 @@
     const psImage *mask   = job->args->data[3]; // input mask
 
-    psMaskType maskVal    = PS_SCALAR_VALUE(job->args->data[4],U8);
+    psImageMaskType maskVal    = PS_SCALAR_VALUE(job->args->data[4],PS_TYPE_IMAGE_MASK_DATA);
     psVector *gaussNorm   = job->args->data[5]; // gauss kernel
     float minGauss        = PS_SCALAR_VALUE(job->args->data[6],F32);
@@ -941,5 +941,5 @@
     psImage *calculation  = job->args->data[1]; // calculation image
     psImage *calcMask     = job->args->data[2]; // calculation mask
-    psMaskType maskVal    = PS_SCALAR_VALUE(job->args->data[3],U8);
+    psImageMaskType maskVal    = PS_SCALAR_VALUE(job->args->data[3],PS_TYPE_IMAGE_MASK_DATA);
 
     psVector *gaussNorm   = job->args->data[4]; // gauss kernel
@@ -956,5 +956,5 @@
                                     const psImage *image,
                                     const psImage *mask,
-                                    psMaskType maskVal,
+                                    psImageMaskType maskVal,
                                     float sigma,
                                     float numSigma,
@@ -963,5 +963,5 @@
     PS_ASSERT_IMAGE_NON_NULL(image, NULL);
     PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
     PS_ASSERT_IMAGES_SIZE_EQUAL(image, mask, NULL);
 
@@ -999,5 +999,5 @@
       case PS_TYPE_F32: {
           psImage *calculation = psImageAlloc(numRows, numCols, PS_TYPE_F32); /* Calculation image; BW */
-          psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_MASK); /* Mask for calculation image; BW */
+          psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_IMAGE_MASK); /* Mask for calculation image; BW */
 
           /** Smooth in X direction **/
@@ -1011,5 +1011,5 @@
               psArrayAdd(job->args, 1, (psImage *) image); // cast away const
               psArrayAdd(job->args, 1, (psImage *) mask); // cast away const
-              PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_U8);
+              PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
               psArrayAdd(job->args, 1, gaussNorm);
               PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
@@ -1046,5 +1046,5 @@
               psArrayAdd(job->args, 1, calculation);
               psArrayAdd(job->args, 1, calcMask);
-              PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_U8);
+              PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
               psArrayAdd(job->args, 1, gaussNorm);
               PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
@@ -1091,5 +1091,5 @@
 bool psImageSmoothMaskF32 (psImage *image,
                            psImage *mask,
-                           psMaskType maskVal,
+                           psImageMaskType maskVal,
                            double  sigma,
                            double  Nsigma)
@@ -1122,5 +1122,5 @@
     psVector *calculation = psVectorAlloc(Nx, PS_TYPE_F32);
     for (int j = 0; j < Ny; j++) {
-        psU8  *vm = mask->data.U8[j];
+        psImageMaskType  *vm = mask->data.PS_TYPE_IMAGE_MASK_DATA[j];
         psF32 *vi = image->data.F32[j];
         psF32 *vo = calculation->data.F32;
@@ -1128,5 +1128,5 @@
         for (int i = 0; i < Nx; i++, vi++, vo++, vm++) {
             int offset = PS_MIN (i, Nrange);
-            psU8  *sm = vm - offset;
+            psImageMaskType  *sm = vm - offset;
             psF32 *si = vi - offset;
             psF32 *sg = gauss - offset;
@@ -1171,5 +1171,5 @@
         int yMax = PS_MIN (j + Nrange + 1, Ny);
         for (int n = yMin; n < yMax; n++) {
-            psU8  *vm = mask->data.U8[n];
+            psImageMaskType  *vm = mask->data.PS_TYPE_IMAGE_MASK_DATA[n];
             psF32 *vi = image->data.F32[n];
             psF32 *vo = output->data.F32;
@@ -1214,11 +1214,11 @@
                                      const psImage *input, // Input image
                                      int start, int stop, // Range of rows
-                                     psMaskType maskVal, // Value to mask; NOTE subtle difference!
+                                     psImageMaskType maskVal, // Value to mask; NOTE subtle difference!
                                      int xMin, int xMax // Range in x for kernel
                                      )
 {
     // Dereference mask images
-    psMaskType **inputData = input->data.PS_TYPE_MASK_DATA;
-    psMaskType **targetData = target->data.PS_TYPE_MASK_DATA;
+    psImageMaskType **inputData = input->data.PS_TYPE_IMAGE_MASK_DATA;
+    psImageMaskType **targetData = target->data.PS_TYPE_IMAGE_MASK_DATA;
 
     int numCols = input->numCols;       // Number of columns
@@ -1241,5 +1241,5 @@
                 min = PS_MAX(0, min);
                 max = PS_MIN(numCols - 1, max);
-                memset(&targetData[y][min], 0xff, (max - min + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_MASK));
+                memset(&targetData[y][min], 0xff, (max - min + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_IMAGE_MASK));
             }
         }
@@ -1247,5 +1247,5 @@
             // Mask from the minimum to the end of the row
             min = PS_MAX(0, min);
-            memset(&targetData[y][min], 0xff, (numCols - min) * PSELEMTYPE_SIZEOF(PS_TYPE_MASK));
+            memset(&targetData[y][min], 0xff, (numCols - min) * PSELEMTYPE_SIZEOF(PS_TYPE_IMAGE_MASK));
         }
     }
@@ -1256,11 +1256,11 @@
                                      const psImage *input, // Input image
                                      int start, int stop, // Range of rows
-                                     psMaskType setVal, // Value to set; NOTE subtle difference!
+                                     psImageMaskType setVal, // Value to set; NOTE subtle difference!
                                      int yMin, int yMax // Range in y for kernel
                                      )
 {
     // Dereference mask images
-    psMaskType **inputData = input->data.PS_TYPE_MASK_DATA;
-    psMaskType **targetData = target->data.PS_TYPE_MASK_DATA;
+    psImageMaskType **inputData = input->data.PS_TYPE_IMAGE_MASK_DATA;
+    psImageMaskType **targetData = target->data.PS_TYPE_IMAGE_MASK_DATA;
 
     int numRows = input->numRows;       // Number of rows
@@ -1308,5 +1308,5 @@
     int start = PS_SCALAR_VALUE(args->data[2], S32); // Row/col to start at
     int stop = PS_SCALAR_VALUE(args->data[3], S32); // Row/col to stop at
-    psMaskType maskVal = PS_SCALAR_VALUE(args->data[4], U8); // Value to mask/set
+    psImageMaskType maskVal = PS_SCALAR_VALUE(args->data[4], PS_TYPE_IMAGE_MASK_DATA); // Value to mask/set
     int kernelMin = PS_SCALAR_VALUE(args->data[5], S32); // Minimum range for kernel
     int kernelMax = PS_SCALAR_VALUE(args->data[6], S32); // Maximum range for kernel
@@ -1317,12 +1317,12 @@
 }
 
-psImage *psImageConvolveMask(psImage *out, const psImage *mask, psMaskType maskVal,
-                             psMaskType setVal, int xMin, int xMax, int yMin, int yMax)
+psImage *psImageConvolveMask(psImage *out, const psImage *mask, psImageMaskType maskVal,
+                             psImageMaskType setVal, int xMin, int xMax, int yMin, int yMax)
 {
     PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
     if (out) {
         PS_ASSERT_IMAGE_NON_NULL(out, NULL);
-        PS_ASSERT_IMAGE_TYPE(out, PS_TYPE_MASK, NULL);
+        PS_ASSERT_IMAGE_TYPE(out, PS_TYPE_IMAGE_MASK, NULL);
         PS_ASSERT_IMAGES_SIZE_EQUAL(out, mask, NULL);
         if (out == mask && ((maskVal & setVal) || !setVal)) {
@@ -1354,5 +1354,5 @@
 
     // Propagate the non-masked values
-    out = (psImage*)psBinaryOp(out, (const psPtr)mask, "&", psScalarAlloc(~setVal, PS_TYPE_MASK));
+    out = (psImage*)psBinaryOp(out, (const psPtr)mask, "&", psScalarAlloc(~setVal, PS_TYPE_IMAGE_MASK));
 
     if (!setVal) {
@@ -1360,5 +1360,5 @@
     }
 
-    psImage *conv = psImageAlloc(numCols, numRows, PS_TYPE_MASK); // Temporary convolved image
+    psImage *conv = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); // Temporary convolved image
     psImageInit(conv, 0);
 
@@ -1377,5 +1377,5 @@
             PS_ARRAY_ADD_SCALAR(job->args, start, PS_TYPE_S32);
             PS_ARRAY_ADD_SCALAR(job->args, stop, PS_TYPE_S32);
-            PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_MASK);
+            PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK);
             PS_ARRAY_ADD_SCALAR(job->args, xMin, PS_TYPE_S32);
             PS_ARRAY_ADD_SCALAR(job->args, xMax, PS_TYPE_S32);
@@ -1415,5 +1415,5 @@
             PS_ARRAY_ADD_SCALAR(job->args, start, PS_TYPE_S32);
             PS_ARRAY_ADD_SCALAR(job->args, stop, PS_TYPE_S32);
-            PS_ARRAY_ADD_SCALAR(job->args, setVal, PS_TYPE_MASK);
+            PS_ARRAY_ADD_SCALAR(job->args, setVal, PS_TYPE_IMAGE_MASK);
             PS_ARRAY_ADD_SCALAR(job->args, yMin, PS_TYPE_S32);
             PS_ARRAY_ADD_SCALAR(job->args, yMax, PS_TYPE_S32);
@@ -1460,5 +1460,5 @@
                 min = PS_MAX(0, min);
                 max = PS_MIN(numCols - 1, max);
-                memset(&convData[y][min], 0xff, (max - min + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_MASK));
+                memset(&convData[y][min], 0xff, (max - min + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_IMAGE_MASK));
             }
         }
@@ -1466,5 +1466,5 @@
             // Mask from the minimum to the end of the row
             min = PS_MAX(0, min);
-            memset(&convData[y][min], 0xff, (numCols - min) * PSELEMTYPE_SIZEOF(PS_TYPE_MASK));
+            memset(&convData[y][min], 0xff, (numCols - min) * PSELEMTYPE_SIZEOF(PS_TYPE_IMAGE_MASK));
         }
     }
Index: /trunk/psLib/src/imageops/psImageConvolve.h
===================================================================
--- /trunk/psLib/src/imageops/psImageConvolve.h	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageConvolve.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author Robert DeSonia, MHPCC
  *
- * @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-11-26 00:43:12 $
+ * @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -148,6 +148,6 @@
 psImage *psImageConvolveMask(psImage *out, ///< Output image, or NULL
                              const psImage *mask, ///< Mask to convolve
-                             psMaskType maskVal, ///< Mask value to convolve
-                             psMaskType setVal, ///< Mask value to set; 0 to propagate maskVal
+                             psImageMaskType maskVal, ///< Mask value to convolve
+                             psImageMaskType setVal, ///< Mask value to set; 0 to propagate maskVal
                              int xMin, int xMax, int yMin, int yMax ///< Convolution bounds
     );
@@ -160,6 +160,6 @@
 psImage *psImageConvolveMaskDirect(psImage *out, ///< Output image, or NULL
                                    const psImage *mask, ///< Mask to convolve
-                                   psMaskType maskVal, ///< Mask value to convolve
-                                   psMaskType setVal, ///< Mask value to set; 0 to propagate maskVal
+                                   psImageMaskType maskVal, ///< Mask value to convolve
+                                   psImageMaskType setVal, ///< Mask value to set; 0 to propagate maskVal
                                    int xMin, int xMax, int yMin, int yMax ///< Convolution bounds
     );
@@ -174,6 +174,6 @@
 psImage *psImageConvolveMaskFFT(psImage *out, ///< Output image, or NULL
                                 const psImage *mask, ///< Mask to convolve
-                                psMaskType maskVal, ///< Mask value to convolve
-                                psMaskType setVal, ///< Mask value to set; 0 to use maskVal
+                                psImageMaskType maskVal, ///< Mask value to convolve
+                                psImageMaskType setVal, ///< Mask value to set; 0 to use maskVal
                                 int xMin, int xMax, int yMin, int yMax, ///< Convolution bounds
                                 float thresh ///< Threshold (0..1) for convolved floating-point image
@@ -201,5 +201,5 @@
     const psImage *image,               ///< Input image (F32 or F64)
     const psImage *mask,                ///< Mask image
-    psMaskType maskVal,                 ///< Mask value
+    psImageMaskType maskVal,		///< Mask value
     float sigma,                        ///< Width of the smoothing kernel (pixels)
     float numSigma,                     ///< Size of the smoothing box (sigma)
@@ -211,5 +211,5 @@
                                     const psImage *image,
                                     const psImage *mask,
-                                    psMaskType maskVal,
+                                    psImageMaskType maskVal,
                                     float sigma,
                                     float numSigma,
@@ -219,5 +219,5 @@
     psImage *image,                    ///< the image to be smoothed
     psImage *mask,                     ///< optional mask
-    psMaskType maskVal,
+    psImageMaskType maskVal,		///< masked bits
     double  sigma,                     ///< the width of the smoothing kernel in pixels
     double  Nsigma                     ///< the size of the smoothing box in sigmas
Index: /trunk/psLib/src/imageops/psImageGeomManip.c
===================================================================
--- /trunk/psLib/src/imageops/psImageGeomManip.c	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageGeomManip.c	(revision 21183)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-10-21 22:10:53 $
+ *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -39,5 +39,5 @@
                       const psImage* in,
                       const psImage* mask,
-                      psMaskType maskVal,
+                      psImageMaskType maskVal,
                       int scale,
                       const psStats* stats)
@@ -47,8 +47,8 @@
     psS32 outRows;
     psS32 outCols;
-    psVector* vec;                     // vector to hold the values of a single bin.
-    psVector* maskVec = NULL;          // vector to hold the mask of a single bin.
-    psMaskType* maskData = NULL;
-    psStats* myStats;
+    psVector *vec;                     // vector to hold the values of a single bin.
+    psVector *maskVec = NULL;          // vector to hold the mask of a single bin.
+    psVectorMaskType *maskData = NULL;
+    psStats *myStats;
 
     if (in == NULL) {
@@ -86,16 +86,16 @@
 
     if (mask != NULL) {
-        if (mask->type.type != PS_TYPE_MASK) {
+        if (mask->type.type != PS_TYPE_IMAGE_MASK) {
             char* typeStr;
             PS_TYPE_NAME(typeStr,mask->type.type);
             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
                     _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
-                    typeStr, PS_TYPE_MASK_NAME);
+                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
             psFree(out);
             psFree(vec);
             return NULL;
         }
-        maskVec = psVectorAllocEmpty(scale * scale, PS_TYPE_MASK);
-        maskData = maskVec->data.PS_TYPE_MASK_DATA;
+        maskVec = psVectorAllocEmpty(scale * scale, PS_TYPE_VECTOR_MASK);
+        maskData = maskVec->data.PS_TYPE_VECTOR_MASK_DATA;
     }
 
@@ -114,5 +114,5 @@
         ps##TYPE *outRowData; \
         ps##TYPE *vecData = vec->data.TYPE; \
-        psMaskType *inRowMask = NULL; \
+        psImageMaskType *inRowMask = NULL; \
         for (psS32 row = 0; row < outRows; row++) { \
             outRowData = out->data.TYPE[row]; \
@@ -126,9 +126,9 @@
                     ps##TYPE* inRowData = in->data.TYPE[inRow]; \
                     if (mask != NULL) { \
-                        inRowMask = mask->data.PS_TYPE_MASK_DATA[inRow]; \
+                        inRowMask = mask->data.PS_TYPE_IMAGE_MASK_DATA[inRow]; \
                     } \
                     for (psS32 inCol = inCurrentCol; inCol < inNextCol && inCol < inCols; inCol++) { \
                         if (maskData != NULL) { \
-                            maskData[n] = inRowMask[inCol]; \
+                            maskData[n] = (inRowMask[inCol] & maskVal); \
                         } \
                         vecData[n++] = inRowData[inCol]; \
@@ -139,5 +139,5 @@
                     maskVec->n = n; \
                 } \
-                psVectorStats(myStats, vec, NULL, maskVec, maskVal); \
+                 psVectorStats(myStats, vec, NULL, maskVec, 0xff); /* the mask vector has only 0 or 1 */ \
                 outRowData[col] = (ps##TYPE)psStatsGetValue(myStats, statistic); \
             } \
@@ -659,5 +659,5 @@
 
 bool psImageShiftMask(psImage **out, psImage **outMask, const psImage* in, const psImage *inMask,
-                      psMaskType maskVal, float dx, float dy, double exposed, psMaskType blank,
+                      psImageMaskType maskVal, float dx, float dy, double exposed, psImageMaskType blank,
                       psImageInterpolateMode mode)
 {
@@ -667,5 +667,5 @@
         PS_ASSERT_IMAGE_NON_NULL(inMask, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(in, inMask, false);
-        PS_ASSERT_IMAGE_TYPE(inMask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(inMask, PS_TYPE_IMAGE_MASK, false);
     }
 
@@ -675,5 +675,5 @@
     *out = psImageRecycle(*out, numCols, numRows, type);
     if (outMask) {
-        *outMask = psImageRecycle(*outMask, numCols, numRows, PS_TYPE_MASK);
+        *outMask = psImageRecycle(*outMask, numCols, numRows, PS_TYPE_IMAGE_MASK);
     }
 
@@ -702,10 +702,10 @@
     for (int row = 0; row < numRows; row++) { \
         ps##TYPE* outRow = (*out)->data.TYPE[row]; \
-        psMaskType *outMaskRow = (outMask ? (*outMask)->data.PS_TYPE_MASK_DATA[row] : NULL); \
+        psImageMaskType *outMaskRow = (outMask ? (*outMask)->data.PS_TYPE_IMAGE_MASK_DATA[row] : NULL); \
         float y = row + 0.5 - dy; \
         for (int col = 0; col < numCols; col++) { \
             float x = col + 0.5 - dx; \
             double value; \
-            psMaskType valueMask = 0; \
+            psImageMaskType valueMask = 0; \
             if (!psImageInterpolate(&value, NULL, &valueMask, x, y, interp)) { \
                 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); \
@@ -750,5 +750,5 @@
                           const psImage *input,
                           const psImage *inputMask,
-                          psMaskType inputMaskVal,
+                          psImageMaskType inputMaskVal,
                           const psPlaneTransform *outToIn,
                           psRegion region,
@@ -778,10 +778,10 @@
             return NULL;
         }
-        if (inputMask->type.type != PS_TYPE_MASK) {
+        if (inputMask->type.type != PS_TYPE_IMAGE_MASK) {
             char* typeStr;
             PS_TYPE_NAME(typeStr,inputMask->type.type);
             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
                     _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
-                    typeStr, PS_TYPE_MASK_NAME);
+                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
             psFree(output);
             return NULL;
Index: /trunk/psLib/src/imageops/psImageGeomManip.h
===================================================================
--- /trunk/psLib/src/imageops/psImageGeomManip.h	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageGeomManip.h	(revision 21183)
@@ -6,6 +6,6 @@
  * @author Robert DeSonia, MHPCC
  *
- * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-03-11 00:41:30 $
+ * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -36,5 +36,5 @@
     const psImage* in,                 ///< input image
     const psImage* mask,               ///< mask for input image.  If NULL, no masking is done.
-    psMaskType maskVal,                ///< the bits to check in mask.
+    psImageMaskType maskVal,		///< the bits to check in mask.
     int scale,                         ///< the scale to rebin for each dimension
     const psStats* stats
@@ -106,8 +106,8 @@
     const psImage* in,                  ///< Input image
     const psImage *inMask,              ///< Input mask, or NULL
-    psMaskType maskVal,                 ///< Value to mask
+    psImageMaskType maskVal,		///< Value to mask
     float dx, float dy,                 ///< Shift to apply
     double exposed,                     ///< Value to give exposed pixels
-    psMaskType blank,                   ///< Mask value for exposed pixels
+    psImageMaskType blank,		///< Mask value for exposed pixels
     psImageInterpolateMode mode         ///< Interpolation mode
     );
@@ -159,5 +159,5 @@
     const psImage *input,              ///< psImage to apply transform to
     const psImage *inputMask,          ///< if not NULL, mask of input psImage
-    psMaskType inputMaskVal,           ///< masking value for inputMask
+    psImageMaskType inputMaskVal,	///< masking value for inputMask
     const psPlaneTransform *outToIn,   ///< the transform to apply
     psRegion region,                   ///< the size of the transformed image
Index: /trunk/psLib/src/imageops/psImageInterpolate.c
===================================================================
--- /trunk/psLib/src/imageops/psImageInterpolate.c	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageInterpolate.c	(revision 21183)
@@ -7,6 +7,6 @@
  *  @author Paul Price, IfA
  *
- *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-11-15 03:09:34 $
+ *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
@@ -205,7 +205,7 @@
 psImageInterpolation *psImageInterpolationAlloc(psImageInterpolateMode mode,
                                                 const psImage *image, const psImage *variance,
-                                                const psImage *mask, psMaskType maskVal,
+                                                const psImage *mask, psImageMaskType maskVal,
                                                 double badImage, double badVariance,
-                                                psMaskType badMask, psMaskType poorMask,
+                                                psImageMaskType badMask, psImageMaskType poorMask,
                                                 float poorFrac, int numKernels)
 {
@@ -274,5 +274,5 @@
 // Interpolation engine for flat mode (nearest pixel)
 static inline psImageInterpolateStatus interpolateFlat(double *imageValue, double *varianceValue,
-                                                       psMaskType *maskValue, float x, float y,
+                                                       psImageMaskType *maskValue, float x, float y,
                                                        const psImageInterpolation *interp)
 {
@@ -331,5 +331,5 @@
         if (maskValue) {
             if (interp->mask) {
-                *maskValue = interp->mask->data.PS_TYPE_MASK_DATA[yInt][xInt];
+                *maskValue = interp->mask->data.PS_TYPE_IMAGE_MASK_DATA[yInt][xInt];
             } else {
                 *maskValue = 0;
@@ -456,5 +456,5 @@
 // Interpolation engine for separable interpolation kernels
 static psImageInterpolateStatus interpolateSeparable(double *imageValue, double *varianceValue,
-                                                     psMaskType *maskValue, float x, float y,
+                                                     psImageMaskType *maskValue, float x, float y,
                                                      const psImageInterpolation *interp)
 {
@@ -465,5 +465,5 @@
     const psImage *mask = interp->mask; // Image mask
     const psImage *variance = interp->variance; // Image variance
-    psMaskType maskVal = interp->maskVal; // Value to mask
+    psImageMaskType maskVal = interp->maskVal; // Value to mask
     bool wantVariance = variance && varianceValue; // Does the user want the variance value?
     bool haveMask = mask && maskVal; // Does the user want the variance value?
@@ -582,5 +582,5 @@
                   const ps##TYPE *imageData = &image->data.TYPE[yPix][xMin]; \
                   const ps##TYPE *varianceData = &variance->data.TYPE[yPix][xMin]; \
-                  const psMaskType *maskData = &mask->data.PS_TYPE_MASK_DATA[yPix][xMin]; \
+                  const psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[yPix][xMin]; \
                   const psF32 *xKernelData = xKernel; \
                   const psF32 *xKernel2Data = xKernel2; \
@@ -642,5 +642,5 @@
               /* Dereferenced versions of inputs */ \
               const ps##TYPE *imageData = &image->data.TYPE[yPix][xMin]; \
-              const psMaskType *maskData = &mask->data.PS_TYPE_MASK_DATA[yPix][xMin]; \
+              const psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[yPix][xMin]; \
               const psF32 *xKernelData = xKernel; \
               const psF32 *xKernel2Data = xKernel2; \
@@ -713,5 +713,5 @@
 // Interpolation engine for (separable) interpolation kernels
 static psImageInterpolateStatus interpolateKernel(double *imageValue, double *varianceValue,
-                                                  psMaskType *maskValue, float x, float y,
+                                                  psImageMaskType *maskValue, float x, float y,
                                                   const psImageInterpolation *interp)
 {
@@ -722,5 +722,5 @@
     const psImage *mask = interp->mask; // Image mask
     const psImage *variance = interp->variance; // Image variance
-    psMaskType maskVal = interp->maskVal; // Value to mask
+    psImageMaskType maskVal = interp->maskVal; // Value to mask
     bool wantVariance = variance && varianceValue; // Does the user want the variance value?
     bool haveMask = mask && maskVal; // Does the user want the variance value?
@@ -790,5 +790,5 @@
                       float kernelValue = kernel[j][i]; /* Value of kernel */ \
                       float kernelValue2 = PS_SQR(kernelValue); /* Square of kernel */ \
-                      if (mask->data.PS_TYPE_MASK_DATA[yPix][xPix] & maskVal) { \
+                      if (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPix][xPix] & maskVal) { \
                           sumBad += kernelValue2; \
                       } else { \
@@ -820,5 +820,5 @@
                   float kernelValue = kernel[j][i]; /* Value of kernel */ \
                   float kernelValue2 = PS_SQR(kernelValue); /* Square of kernel */ \
-                  if (mask->data.PS_TYPE_MASK_DATA[yPix][xPix] & maskVal) { \
+                  if (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPix][xPix] & maskVal) { \
                       sumBad += kernelValue2; \
                   } else { \
@@ -866,5 +866,5 @@
 
 
-psImageInterpolateStatus psImageInterpolate(double *imageValue, double *varianceValue, psMaskType *maskValue,
+psImageInterpolateStatus psImageInterpolate(double *imageValue, double *varianceValue, psImageMaskType *maskValue,
                                             float x, float y, const psImageInterpolation *interp)
 {
@@ -885,5 +885,5 @@
     if (maskValue && mask) {
         PS_ASSERT_IMAGE_NON_NULL(mask, PS_INTERPOLATE_STATUS_ERROR);
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, PS_INTERPOLATE_STATUS_ERROR);
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, PS_INTERPOLATE_STATUS_ERROR);
         psAssert(image->numCols == mask->numCols && image->numRows == mask->numRows, "Image and mask sizes");
     }
Index: /trunk/psLib/src/imageops/psImageInterpolate.h
===================================================================
--- /trunk/psLib/src/imageops/psImageInterpolate.h	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageInterpolate.h	(revision 21183)
@@ -7,6 +7,6 @@
  * @author Paul Price, Institute for Astronomy
  *
- * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-10-22 19:21:06 $
+ * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  * Copyright 2004-2007 Institute for Astronomy, University of Hawaii
  */
@@ -50,9 +50,9 @@
     const psImage *variance;            ///< Variance image for interpolation
     const psImage *mask;                ///< Mask image for interpolation
-    psMaskType maskVal;                 ///< Value to mask
+    psImageMaskType maskVal;		///< Value to mask
     double badImage;                    ///< Image value if x,y location is not good
     double badVariance;                 ///< Variance value if x,y location is not good
-    psMaskType badMask;                 ///< Mask value to give bad pixels
-    psMaskType poorMask;                ///< Mask value to give poor pixels
+    psImageMaskType badMask;		///< Mask value to give bad pixels
+    psImageMaskType poorMask;		///< Mask value to give poor pixels
     float poorFrac;                     ///< Fraction of flux in bad pixels before output is marked bad
     bool shifting;                      ///< Shifting images? Don't interpolate if the shift is exact.
@@ -69,9 +69,9 @@
     const psImage *variance,            // Variance image
     const psImage *mask,                // Mask image
-    psMaskType maskVal,                 // Value to mask
+    psImageMaskType maskVal,                 // Value to mask
     double badImage,                    // Value for image if bad
     double badVariance,                 // Value for variance if bad
-    psMaskType badMask,                 // Mask value for bad pixels
-    psMaskType poorMask,                // Mask value for poor pixels
+    psImageMaskType badMask,                 // Mask value for bad pixels
+    psImageMaskType poorMask,                // Mask value for poor pixels
     float poorFrac,                     // Fraction of flux for question
     int numKernels                      // Number of interpolation kernels to pre-calculate
@@ -83,5 +83,5 @@
     double *imageValue,                 ///< Return value for image
     double *varianceValue,              ///< Return value for variance
-    psMaskType *maskValue,              ///< Return value for mask
+    psImageMaskType *maskValue,              ///< Return value for mask
     float x, float y,                   ///< Location to which to interpolate
     const psImageInterpolation *options ///< Options
Index: /trunk/psLib/src/imageops/psImageMap.c
===================================================================
--- /trunk/psLib/src/imageops/psImageMap.c	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageMap.c	(revision 21183)
@@ -7,6 +7,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-01-27 00:00:21 $
+ *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -145,5 +145,5 @@
     }
 
-    psImage *mask = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_MASK);
+    psImage *mask = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_IMAGE_MASK);
     psImage *xCoord = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_F32);
     psImage *yCoord = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_F32);
@@ -212,5 +212,5 @@
             // this will not in general be properly weighted...
             if (psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {
-                mask->data.U8[iy][ix] = 0;
+                mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 0;
                 // XXX ensure only one option is selected, or save both position and width
                 map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options);
@@ -224,5 +224,5 @@
                 yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
             } else {
-                mask->data.U8[iy][ix] = 1;
+                mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 1;
             }
 
@@ -353,5 +353,5 @@
 }
 
-psVector *psImageMapEvalVector(const psImageMap *map, const psVector *mask, psMaskType maskValue, const psVector *x, const psVector *y)
+psVector *psImageMapEvalVector(const psImageMap *map, const psVector *mask, psVectorMaskType maskValue, const psVector *x, const psVector *y)
 {
     PS_ASSERT_IMAGE_MAP_NON_NULL(map, NULL);
@@ -365,5 +365,5 @@
 
     for (int i = 0; i < x->n; i++) {
-      if (mask && (mask->data.U8[i] & maskValue)) {
+      if (mask && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) {
 	result->data.F32[i] = 0.0;
       } else {	
Index: /trunk/psLib/src/imageops/psImageMapFit.c
===================================================================
--- /trunk/psLib/src/imageops/psImageMapFit.c	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageMapFit.c	(revision 21183)
@@ -7,6 +7,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-01-27 00:00:21 $
+ *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -47,5 +47,5 @@
 
 // map defines the output image dimensions and scaling.
-bool psImageMapFit(psImageMap *map, const psVector *mask, psMaskType maskValue,
+bool psImageMapFit(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
                    const psVector *x, const psVector *y, const psVector *f, const psVector *df)
 {
@@ -145,5 +145,5 @@
             for (int i = 0; i < x->n; i++) {
 
-                if (mask && (mask->data.U8[i] & maskValue)) continue;
+                if (mask && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) continue;
 
                 // base coordinate offset for this point (x,y) relative to this map element (n,m)
@@ -338,5 +338,5 @@
 
 // measure residuals on each pass and clip outliers based on stats
-bool psImageMapClipFit(psImageMap *map, psStats *stats, psVector *inMask, psMaskType maskValue,
+bool psImageMapClipFit(psImageMap *map, psStats *stats, psVector *inMask, psVectorMaskType maskValue,
                        const psVector *x, const psVector *y, const psVector *f, const psVector *df)
 {
@@ -377,5 +377,5 @@
     psVector *mask = inMask;
     if (!inMask) {
-        mask = psVectorAlloc (x->n, PS_TYPE_U8);
+        mask = psVectorAlloc (x->n, PS_TYPE_VECTOR_MASK);
         psVectorInit (mask, 0);
     }
@@ -429,5 +429,5 @@
         for (psS32 i = 0; i < resid->n; i++) {
             // XXX this prevents recovery of previously masked values
-            if (mask->data.U8[i] & maskValue) {
+            if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue) {
                 continue;
             }
@@ -435,5 +435,5 @@
             if ((resid->data.F32[i] - meanValue > maxClipValue) || (resid->data.F32[i] - meanValue < minClipValue)) {
                 psTrace("psLib.imageops", 6, "Masking element %d  : %f vs %f : resid is %f\n", i, f->data.F32[i], fit->data.F32[i], resid->data.F32[i]);
-                mask->data.U8[i] |= 0x01;
+                mask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= 0x01;
                 continue;
             }
@@ -455,5 +455,5 @@
 
 // map defines the output image dimensions and scaling.
-bool psImageMapFit1DinY(psImageMap *map, const psVector *mask, psMaskType maskValue,
+bool psImageMapFit1DinY(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
                         const psVector *x, const psVector *y, const psVector *f, const psVector *df)
 {
@@ -490,5 +490,5 @@
         for (int i = 0; i < y->n; i++) {
 
-            if (mask && (mask->data.U8[i] & maskValue)) continue;
+            if (mask && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) continue;
 
             float dy = psImageBinningGetRuffY (map->binning, y->data.F32[i]) - (m + 0.5);
@@ -603,5 +603,5 @@
 
 // map defines the output image dimensions and scaling.
-bool psImageMapFit1DinX(psImageMap *map, const psVector *mask, psMaskType maskValue,
+bool psImageMapFit1DinX(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
                         const psVector *x, const psVector *y, const psVector *f, const psVector *df)
 {
@@ -638,5 +638,5 @@
         for (int i = 0; i < x->n; i++) {
 
-            if (mask && (mask->data.U8[i] & maskValue)) continue;
+            if (mask && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) continue;
 
             float dx = psImageBinningGetRuffX (map->binning, x->data.F32[i]) - (m + 0.5);
Index: /trunk/psLib/src/imageops/psImageMapFit.h
===================================================================
--- /trunk/psLib/src/imageops/psImageMapFit.h	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageMapFit.h	(revision 21183)
@@ -10,5 +10,5 @@
 bool psImageMapFit(psImageMap *map,
                    const psVector *mask,
-                   psMaskType maskValue,
+                   psVectorMaskType maskValue, // 
                    const psVector *x,
                    const psVector *y,
@@ -21,5 +21,5 @@
                        psStats *stats,
                        psVector *mask,  // WARNING: Mask is modified!
-                       psMaskType maskValue,
+                       psVectorMaskType maskValue,
                        const psVector *x,
                        const psVector *y,
@@ -30,5 +30,5 @@
 bool psImageMapFit1DinY(psImageMap *map,
                         const psVector *mask,
-                        psMaskType maskValue,
+                        psVectorMaskType maskValue,
                         const psVector *x,
                         const psVector *y,
@@ -39,5 +39,5 @@
 bool psImageMapFit1DinX(psImageMap *map,
                         const psVector *mask,
-                        psMaskType maskValue,
+                        psVectorMaskType maskValue,
                         const psVector *x,
                         const psVector *y,
Index: /trunk/psLib/src/imageops/psImageMaskOps.c
===================================================================
--- /trunk/psLib/src/imageops/psImageMaskOps.c	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageMaskOps.c	(revision 21183)
@@ -8,6 +8,6 @@
  *  @author David Robbins, MHPCC
  *
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-07-12 21:08:33 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -37,5 +37,5 @@
                        psRegion region,
                        const char *op,
-                       psMaskType maskValue)
+                       psImageMaskType maskValue)
 {
     if (image == NULL) {
@@ -53,5 +53,5 @@
 	  if ((i + image->col0) < region.x0) continue; \
 	  if ((i + image->col0) > region.x1) continue; /* is this correct (not >= ?) */ \
-	  image->data.PS_TYPE_MASK_DATA[j][i] OP maskValue; \
+	  image->data.PS_TYPE_IMAGE_MASK_DATA[j][i] OP maskValue; \
 	} \
       }
@@ -84,5 +84,5 @@
                        psRegion region,
                        const char *op,
-                       psMaskType maskValue)
+                       psImageMaskType maskValue)
 {
     if (image == NULL) {
@@ -100,5 +100,5 @@
 	    (i + image->col0) < region.x0 || \
 	    (i + image->col0) > region.x1 ) { \
-	  image->data.PS_TYPE_MASK_DATA[j][i] OP maskValue; \
+	  image->data.PS_TYPE_IMAGE_MASK_DATA[j][i] OP maskValue; \
 	} } }
 
@@ -131,5 +131,5 @@
                        double radius,
                        const char *op,
-                       psMaskType maskValue)
+                       psImageMaskType maskValue)
 {
     if (image == NULL) {
@@ -150,5 +150,5 @@
             r2 = PS_SQR(dx) + PS_SQR(dy); \
             if (r2 <= R2) { \
-	      image->data.PS_TYPE_MASK_DATA[iy][ix] OP maskValue; \
+	      image->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] OP maskValue; \
             } } }
 
@@ -182,5 +182,5 @@
                        double radius,
                        const char *op,
-                       psMaskType maskValue)
+                       psImageMaskType maskValue)
 {
 
@@ -201,5 +201,5 @@
             r2 = PS_SQR(dx) + PS_SQR(dy); \
             if (r2 > R2) { \
-	      image->data.PS_TYPE_MASK_DATA[iy][ix] OP maskValue; \
+	      image->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] OP maskValue; \
             } } }
 
@@ -228,7 +228,7 @@
 psImage *psImageGrowMask(psImage *out,
                          const psImage *in,
-                         psMaskType maskVal,
+                         psImageMaskType maskVal,
                          unsigned int growSize,
-                         psMaskType growVal)
+                         psImageMaskType growVal)
 {
     if (in == NULL) {
@@ -237,7 +237,7 @@
         return NULL;
     }
-    if (in->type.type != PS_TYPE_MASK) {
+    if (in->type.type != PS_TYPE_IMAGE_MASK) {
         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                "Invalid input image.  Input image type must match psMaskType.\n");
+                "Invalid input image.  Input image type must match psImageMaskType.\n");
         return NULL;
     }
@@ -261,6 +261,6 @@
     for (k = 0; k < in->numRows; k++) {
         for (l = 0; l < in->numCols; l++) {
-            out->data.PS_TYPE_MASK_DATA[k][l] = in->data.PS_TYPE_MASK_DATA[k][l];
-            changed->data.PS_TYPE_MASK_DATA[k][l] = 0;
+            out->data.PS_TYPE_IMAGE_MASK_DATA[k][l] = in->data.PS_TYPE_IMAGE_MASK_DATA[k][l];
+            changed->data.PS_TYPE_IMAGE_MASK_DATA[k][l] = 0;
         }
     }
@@ -268,6 +268,6 @@
     for (int i = 0; i < in->numRows; i++) {
         for (int j = 0; j < in->numCols; j++) {
-            if ( (in->data.PS_TYPE_MASK_DATA[i][j] & maskVal) != 0 &&
-                    changed->data.PS_TYPE_MASK_DATA[i][j] == 0) {
+            if ( (in->data.PS_TYPE_IMAGE_MASK_DATA[i][j] & maskVal) != 0 &&
+                    changed->data.PS_TYPE_IMAGE_MASK_DATA[i][j] == 0) {
                 m = i - growSize;
                 if (m < 0) {
@@ -281,7 +281,7 @@
                     for (l = n; l <= (j + growSize) && l < in->numCols; l++) {
                         if (((k-i)*(k-i) + (l-j)*(l-j)) <= (growSize*growSize)) {
-                            out->data.PS_TYPE_MASK_DATA[k][l] |= growVal;
-                            if ( (in->data.PS_TYPE_MASK_DATA[i][j] & maskVal) == 0 ) {
-                                changed->data.PS_TYPE_MASK_DATA[k][l] = 1;
+                            out->data.PS_TYPE_IMAGE_MASK_DATA[k][l] |= growVal;
+                            if ( (in->data.PS_TYPE_IMAGE_MASK_DATA[i][j] & maskVal) == 0 ) {
+                                changed->data.PS_TYPE_IMAGE_MASK_DATA[k][l] = 1;
                             }
                         }
Index: /trunk/psLib/src/imageops/psImageMaskOps.h
===================================================================
--- /trunk/psLib/src/imageops/psImageMaskOps.h	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageMaskOps.h	(revision 21183)
@@ -6,6 +6,6 @@
  * @author David Robbins, MHPCC
  *
- * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-23 22:47:23 $
+ * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  *
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -32,5 +32,5 @@
     psRegion region,                   ///< the specified region
     const char *op,                    ///< the logical operation
-    psMaskType maskValue               ///< the specified bits
+    psImageMaskType maskValue		///< the specified bits
 );
 
@@ -44,5 +44,5 @@
     psRegion region,                   ///< the specified region
     const char *op,                    ///< the logical operation
-    psMaskType maskValue               ///< the specified bits
+    psImageMaskType maskValue		///< the specified bits
 );
 
@@ -58,5 +58,5 @@
     double radius,                     ///< the radius of the specified circle
     const char *op,                    ///< the logical operation
-    psMaskType maskValue               ///< the specified bits
+    psImageMaskType maskValue		///< the specified bits
 );
 
@@ -72,5 +72,5 @@
     double radius,                     ///< the radius of the specified circle
     const char *op,                    ///< the logical operation
-    psMaskType maskValue               ///< the specified bits
+    psImageMaskType maskValue		///< the specified bits
 );
 
@@ -89,7 +89,7 @@
     psImage *out,                      ///< the image to set and return
     const psImage *in,                 ///< the input to image
-    psMaskType maskVal,                ///< the specified mask value
+    psImageMaskType maskVal,		///< the specified mask value
     unsigned int growSize,             ///< the range of values from maskVal
-    psMaskType growVal                 ///< the output value to set
+    psImageMaskType growVal		///< the output value to set
 );
 
Index: /trunk/psLib/src/imageops/psImagePixelExtract.c
===================================================================
--- /trunk/psLib/src/imageops/psImagePixelExtract.c	(revision 21182)
+++ /trunk/psLib/src/imageops/psImagePixelExtract.c	(revision 21183)
@@ -8,6 +8,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-10-22 02:10:37 $
+ *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -206,5 +206,5 @@
                        const psImage* input,
                        const psImage* mask,
-                       psMaskType maskVal,
+                       psImageMaskType maskVal,
                        psRegion region,
                        psImageCutDirection direction,
@@ -357,10 +357,10 @@
             return NULL;
         }
-        if (mask->type.type != PS_TYPE_MASK) {
+        if (mask->type.type != PS_TYPE_IMAGE_MASK) {
             char* typeStr;
             PS_TYPE_NAME(typeStr,mask->type.type);
             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
                     _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
-                    typeStr, PS_TYPE_MASK_NAME);
+                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
             psFree(out);
             return NULL;
@@ -394,5 +394,5 @@
         psVector* imgVec = psVectorAlloc(numRows, type);
         psVector* maskVec = NULL;
-        psMaskType* maskData = NULL;
+        psImageMaskType* maskData = NULL;
         psPixelCoord* outPosition = NULL;
 
@@ -416,25 +416,29 @@
 
         if (mask != NULL) {
-            maskVec = psVectorAlloc(numRows, mask->type.type);
-        }
-        #define PSIMAGE_CUT_VERTICAL(TYPE) \
+            maskVec = psVectorAlloc(numRows, PS_TYPE_VECTOR_MASK);
+        }
+
+#define PSIMAGE_CUT_VERTICAL(TYPE) \
     case PS_TYPE_##TYPE: { \
-            psMaskType* maskVecData = NULL; \
-            for (psS32 c=col0;c<col1;c++) { \
+            psVectorMaskType* maskVecData = NULL; \
+            for (psS32 c = col0; c < col1; c++) { \
                 ps##TYPE *imgData = input->data.TYPE[row0] + c; \
                 ps##TYPE *imgVecData = imgVec->data.TYPE; \
                 if (maskVec != NULL) { \
-                    maskVecData = maskVec->data.U8; \
-                    maskData = (psMaskType* )(mask->data.U8[row0]) + c; \
+                    maskVecData = maskVec->data.PS_TYPE_VECTOR_MASK_DATA; \
+                    maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[row0][c]; /* XXX double check this... */ \
+                    /** old entry: maskData = (psMaskType* )(mask->data.PS_TYPE_IMAGE_MASK_DATA[row0]) + c; */ \
                 } \
-                for (psS32 r=row0;r<row1;r++) { \
-                    *(imgVecData++) = *imgData; \
+                for (psS32 r = row0; r < row1; r++) { \
+                   *imgVecData = *imgData; \
+                    imgVecData ++; \
                     imgData += inCols; \
                     if (maskVecData != NULL) { \
-                        *(maskVecData++) = *maskData; \
+                        *maskVecData = (*maskData & maskVal); \
+                        maskVecData ++; \
                         maskData += inCols; \
                     } \
                 } \
-                psVectorStats(myStats,imgVec,NULL,maskVec,maskVal); \
+                psVectorStats(myStats, imgVec, NULL, maskVec, 0xff); \
                 *outData = psStatsGetValue(myStats, statistic); \
                 if (outPosition != NULL) { \
@@ -471,6 +475,8 @@
         psFree(imgVec);
         psFree(maskVec);
+
     } else if (direction == PS_CUT_Y_POS || direction == PS_CUT_Y_NEG) {
         // Cut in Y direction
+        // XXX use this if we drop the hackish stuff below: psVector* imgVec = psVectorAlloc(numCols, type);
         psVector* imgVec = NULL;
         psVector* maskVec = NULL;
@@ -479,12 +485,10 @@
 
         // fill in psVector to fake out the statistics functions.
+	// XXX EAM : this seems rather hackish: just use the needed psVectorAlloc (like above)?
         imgVec = psAlloc(sizeof(psVector));
         imgVec->type = input->type;
         P_PSVECTOR_SET_NALLOC(imgVec,numCols);
-        if (mask != NULL) {
-            maskVec = psAlloc(sizeof(psVector));
-            maskVec->type = mask->type;
-            P_PSVECTOR_SET_NALLOC(maskVec,numCols);
-        }
+        imgVec->n = imgVec->nalloc;
+
         // recycle output to make a proper sized/type output structure
         // n.b. type is double as that is the type given for all stats in
@@ -492,6 +496,4 @@
         out = psVectorRecycle(out, numRows, PS_TYPE_F64);
         out->n = numRows;
-        imgVec->n = imgVec->nalloc;
-        maskVec->n = maskVec->nalloc;
         if (coords != NULL) {
             coords = psPixelsRealloc(coords, numRows);
@@ -507,12 +509,30 @@
         }
 
+        if (mask != NULL) {
+            maskVec = psVectorAlloc(numRows, PS_TYPE_VECTOR_MASK);
+	    // XXX the old code (below) faked out the mask vector
+            // maskVec = psAlloc(sizeof(psVector));
+            // maskVec->type = mask->type;
+            // P_PSVECTOR_SET_NALLOC(maskVec,numCols);
+	    // maskVec->n = maskVec->nalloc;
+        }
+
         for (psS32 r = row0; r < row1; r++) {
             // point the vector struct to the
             // data to calculate the stats
             imgVec->data.U8 = (psPtr )(input->data.U8[r] + col0 * elementSize);
+
+	    // set the vector mask pixels based on the image pixels
             if (maskVec != NULL) {
-                maskVec->data.U8 = (psPtr )(mask->data.U8[r] + col0 * sizeof(psMaskType));
-            }
-            psVectorStats(myStats, imgVec, NULL, maskVec, maskVal);
+		psVectorMaskType *maskVecData = maskVec->data.PS_TYPE_VECTOR_MASK_DATA;
+		psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[r][col0];
+                for (psS32 c = col0; c < col1; c++) { 
+		    *maskVecData = (*maskData & maskVal); 
+		    maskVecData ++; 
+		    maskData ++;
+                } 
+	    }
+
+            psVectorStats(myStats, imgVec, NULL, maskVec, 0xff);
             *outData = psStatsGetValue(myStats, statistic);
             if (outPosition != NULL) {
@@ -544,5 +564,5 @@
                      const psImage* input,
                      const psImage* mask,
-                     psMaskType maskVal,
+                     psImageMaskType maskVal,
                      psRegion region,
                      unsigned int nSamples,
@@ -651,10 +671,10 @@
             return NULL;
         }
-        if (mask->type.type != PS_TYPE_MASK) {
+        if (mask->type.type != PS_TYPE_IMAGE_MASK) {
             char* typeStr;
             PS_TYPE_NAME(typeStr,mask->type.type);
             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
                     _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
-                    typeStr, PS_TYPE_MASK_NAME);
+                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
             psFree(out);
             return NULL;
@@ -739,5 +759,5 @@
                            const psImage* input,
                            const psImage* mask,
-                           psMaskType maskVal,
+                           psImageMaskType maskVal,
                            float x,
                            float y,
@@ -765,10 +785,10 @@
             return NULL;
         }
-        if (mask->type.type != PS_TYPE_MASK) {
+        if (mask->type.type != PS_TYPE_IMAGE_MASK) {
             char* typeStr;
             PS_TYPE_NAME(typeStr,mask->type.type);
             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
                     _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
-                    typeStr, PS_TYPE_MASK_NAME);
+                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
             psFree(out);
             return NULL;
@@ -868,5 +888,5 @@
         if (mask != NULL) {
             bufferMask[lcv] = psVectorAllocEmpty(1+4*(rSq[lcv+1]-rSq[lcv]),
-                                                 PS_TYPE_MASK);
+                                                 PS_TYPE_VECTOR_MASK);
         }
     }
@@ -877,7 +897,7 @@
     for (psS32 row=startRow; row <= endRow; row++) {
         psF32* inRow = input->data.F32[row];
-        psMaskType* maskRow = NULL;
+        psImageMaskType* maskRow = NULL;
         if (mask != NULL) {
-            maskRow = mask->data.PS_TYPE_MASK_DATA[row];
+            maskRow = mask->data.PS_TYPE_IMAGE_MASK_DATA[row];
         }
         for (psS32 col=startCol; col <= endCol; col++) {
@@ -899,5 +919,5 @@
 
                     if (maskRow != NULL) {
-                        bufferMask[r]->data.PS_TYPE_MASK_DATA[n] = maskRow[col];
+                        bufferMask[r]->data.PS_TYPE_VECTOR_MASK_DATA[n] = (maskRow[col] & maskVal);
                         bufferMask[r]->n = n+1;
                     }
@@ -913,5 +933,5 @@
 
     for (psS32 r = 0; r < numOut; r++) {
-        psVectorStats(myStats,buffer[r], NULL, bufferMask[r],maskVal);
+        psVectorStats(myStats, buffer[r], NULL, bufferMask[r], 0xff);
         outData[r] = psStatsGetValue(myStats, statistic);
     }
Index: /trunk/psLib/src/imageops/psImagePixelExtract.h
===================================================================
--- /trunk/psLib/src/imageops/psImagePixelExtract.h	(revision 21182)
+++ /trunk/psLib/src/imageops/psImagePixelExtract.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author Robert DeSonia, MHPCC
  *
- * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-23 22:47:23 $
+ * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  *
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -84,5 +84,5 @@
     const psImage* input,              ///< the input image in which to perform the slice
     const psImage* mask,               ///< the mask for the input image.
-    psMaskType maskVal,                ///< the mask value to apply to the mask
+    psImageMaskType maskVal,		///< the mask value to apply to the mask
     psRegion region,                   ///< the slice region
     psImageCutDirection direction,     ///< the slice dimension and direction
@@ -112,5 +112,5 @@
     const psImage* input,              ///< the input image in which to perform the cut
     const psImage* mask,               ///< the mask for the input image.
-    psMaskType maskVal,                ///< the mask value to apply to the mask
+    psImageMaskType maskVal,		///< the mask value to apply to the mask
     psRegion region,                   ///< the start and end points to cut along
     unsigned int nSamples,             ///< the number of samples along the cut
@@ -135,5 +135,5 @@
     const psImage* input,              ///< the input image in which to perform the cut
     const psImage* mask,               ///< the mask for the input image.
-    psMaskType maskVal,                ///< the mask value to apply to the mask
+    psImageMaskType maskVal,		///< the mask value to apply to the mask
     float x,                           ///< the column of the center of the cut circle
     float y,                           ///< the row of the center of the cut circle
Index: /trunk/psLib/src/imageops/psImagePixelInterpolate.c
===================================================================
--- /trunk/psLib/src/imageops/psImagePixelInterpolate.c	(revision 21182)
+++ /trunk/psLib/src/imageops/psImagePixelInterpolate.c	(revision 21183)
@@ -11,6 +11,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-10-09 19:25:44 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -54,5 +54,5 @@
 		    /* do not test self */ \
 		    if (!jx && !jy) { continue; } \
-		    if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; } \
+		    if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; } \
 		    nGood ++; \
 		} \
@@ -67,5 +67,5 @@
 // just the mask, the output image contains enum values which define the type of interpolation which
 // can be performed
-psImage *psImagePixelInterpolateState (int *nBad, int *nPoor, psImage *mask, psMaskType maskVal) {
+psImage *psImagePixelInterpolateState (int *nBad, int *nPoor, psImage *mask, psImageMaskType maskVal) {
 
     psImage *result = psImageAlloc (mask->numCols, mask->numRows, PS_TYPE_S32);
@@ -79,5 +79,5 @@
 
 	    // state of the good pixels (unmasked)
-	    if (!(mask->data.PS_TYPE_MASK_DATA[iy][ix] & maskVal)) { 
+	    if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal)) { 
 		// count good neighbor pixels (+ self)
 		int nGood = 0;
@@ -94,5 +94,5 @@
 			if (jx + ix < 0) { continue; }
 			if (jx + ix >= mask->numCols) { continue; }
-			if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
+			if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
 			nGood ++;
 			minX = PS_MIN (minX, jx);
@@ -137,5 +137,5 @@
 
 // interpolate the poor pixels using the available options
-bool psImagePixelInterpolatePoor (psImage *image, psImage *state, psImage *mask, psMaskType maskVal) {
+bool psImagePixelInterpolatePoor (psImage *image, psImage *state, psImage *mask, psImageMaskType maskVal) {
 
     assert (image->numCols == state->numCols);
@@ -185,5 +185,5 @@
 			  if (!jx && !jy) { continue; } 
 			  // skip masked pixels
-			  if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
+			  if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
 			  x->data.F32[n] = jx;
 			  y->data.F32[n] = jy;
@@ -241,5 +241,5 @@
     
 // interpolate the good pixels to their true centers
-bool psImagePixelInterpolateCenter (psImage *value, psImage *xCoord, psImage *yCoord, psImage *state, psImage *mask, psMaskType maskVal) {
+bool psImagePixelInterpolateCenter (psImage *value, psImage *xCoord, psImage *yCoord, psImage *state, psImage *mask, psImageMaskType maskVal) {
 
     assert (value->numCols == state->numCols);
@@ -299,5 +299,5 @@
 			  if (jx + ix >= value->numCols) { continue; } 
 			  // skip masked pixels
-			  if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
+			  if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
 			  x->data.F32[n] = xCoord->data.F32[iy+jy][ix+jx];
 			  y->data.F32[n] = yCoord->data.F32[iy+jy][ix+jx];
@@ -331,5 +331,5 @@
 			  if (jx + ix >= value->numCols) { continue; } 
 			  // skip masked pixels
-			  if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
+			  if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
 			  x->data.F32[n] = xCoord->data.F32[iy+jy][ix+jx];
 			  y->data.F32[n] = yCoord->data.F32[iy+jy][ix+jx];
@@ -363,5 +363,5 @@
     for (int iy = 0; iy < value->numRows; iy++) {
 	for (int ix = 0; ix < value->numCols; ix++) {
-	  if (mask->data.PS_TYPE_MASK_DATA[iy][ix] & maskVal) { continue; }
+	  if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) { continue; }
 	  value->data.F32[iy][ix] = output->data.F32[iy][ix];
 	}
Index: /trunk/psLib/src/imageops/psImagePixelInterpolate.h
===================================================================
--- /trunk/psLib/src/imageops/psImagePixelInterpolate.h	(revision 21182)
+++ /trunk/psLib/src/imageops/psImagePixelInterpolate.h	(revision 21183)
@@ -7,6 +7,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-20 23:54:25 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -34,7 +34,7 @@
 } psImagePixelInterpolateType;
 
-psImage *psImagePixelInterpolateState (int *nBad, int *nPoor, psImage *mask, psMaskType maskVal);
-bool psImagePixelInterpolatePoor (psImage *image, psImage *state, psImage *mask, psMaskType maskVal);
-bool psImagePixelInterpolateCenter (psImage *value, psImage *xCoord, psImage *yCoord, psImage *state, psImage *mask, psMaskType maskVal);
+psImage *psImagePixelInterpolateState (int *nBad, int *nPoor, psImage *mask, psImageMaskType maskVal);
+bool psImagePixelInterpolatePoor (psImage *image, psImage *state, psImage *mask, psImageMaskType maskVal);
+bool psImagePixelInterpolateCenter (psImage *value, psImage *xCoord, psImage *yCoord, psImage *state, psImage *mask, psImageMaskType maskVal);
 
 /// @}
Index: /trunk/psLib/src/imageops/psImageStats.c
===================================================================
--- /trunk/psLib/src/imageops/psImageStats.c	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageStats.c	(revision 21183)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.106 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-03-14 00:39:50 $
+ *  @version $Revision: 1.107 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -53,5 +53,5 @@
                       const psImage* in,
                       const psImage* mask,
-                      psMaskType maskVal)
+                      psImageMaskType maskVal)
 {
     psVector *junkData = NULL;
@@ -62,7 +62,70 @@
     PS_ASSERT_IMAGE_NON_NULL(in, false)
     if (mask != NULL) {
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(in, mask, false);
     }
+
+    if (in->parent == NULL) {
+        // stuff the image data into a psVector struct.
+	// XXX this is a bit hackish: does it save much time? (avoids a Nx*Ny alloc)
+        junkData = (psVector *) psAlloc(sizeof(psVector));
+        junkData->type = in->type;
+        P_PSVECTOR_SET_NALLOC(junkData,in->numRows * in->numCols);
+        junkData->n = junkData->nalloc;
+        junkData->data.U8 = in->data.V[0];      // since psImage data is contiguous...
+    } else {
+        // image not necessarily contiguous
+        int numRows = in->numRows;
+        int numCols = in->numCols;
+        int rowSize = numCols * (PSELEMTYPE_SIZEOF(in->type.type));
+
+        junkData = psVectorAlloc(numRows*numCols, in->type.type);
+
+        psU8* data = junkData->data.U8;
+        for (int row = 0; row < numRows; row++) {
+            memcpy(data, in->data.V[row], rowSize);
+            data += rowSize;
+        }
+    }
+
+    if (mask != NULL) {
+	// image not necessarily contiguous, generate a temp vector to hold the full image
+	int numRows = mask->numRows;
+	int numCols = mask->numCols;
+
+	junkMask = psVectorAlloc(numRows*numCols, PS_TYPE_VECTOR_MASK);
+
+	psVectorMaskType *data = junkMask->data.PS_TYPE_VECTOR_MASK_DATA;
+	for (int row = 0, nVect = 0; row < numRows; row++) {
+	    for (int col = 0; col < numCols; col++, nVect++) {
+		data[nVect] = (mask->data.PS_TYPE_IMAGE_MASK_DATA[row][col] & maskVal);
+	    }
+	}
+    }
+
+    psVectorStats(stats, junkData, NULL, junkMask, 0xff);
+
+    psFree(junkMask);
+    psFree(junkData);
+    return true;
+}
+
+/*****************************************************************************
+NOTE: We assume that the psHistogram structure out has already been allocated
+and initialized.
+ *****************************************************************************/
+bool psImageHistogram(psHistogram* out,
+                              const psImage* in,
+                              const psImage* mask,
+                              psImageMaskType maskVal)
+{
+    PS_ASSERT_PTR_NON_NULL(out, false);
+    PS_ASSERT_PTR_NON_NULL(in, false);
+    if (mask != NULL) {
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, false);
+        PS_ASSERT_IMAGES_SIZE_EQUAL(in, mask, false);
+    }
+    psVector* junkData = NULL;
+    psVector* junkMask = NULL;
 
     if (in->parent == NULL) {
@@ -89,96 +152,16 @@
 
     if (mask != NULL) {
-        if (mask->parent == NULL) {
-            // stuff the mask data into a psVector struct.
-            junkMask = psAlloc(sizeof(psVector));
-            junkMask->type = mask->type;
-            P_PSVECTOR_SET_NALLOC(junkMask,mask->numRows * mask->numCols);
-            junkMask->n = junkMask->nalloc;
-            junkMask->data.U8 = mask->data.V[0];
-        } else {
-            // image not necessarily contiguous
-            int numRows = mask->numRows;
-            int numCols = mask->numCols;
-            int rowSize = numCols * (PSELEMTYPE_SIZEOF(mask->type.type));
-
-            junkMask = psVectorAlloc(numRows*numCols, mask->type.type);
-
-            psU8* data = junkMask->data.U8;
-            for (int row = 0; row < numRows; row++) {
-                memcpy(data, mask->data.V[row], rowSize);
-                data += rowSize;
-            }
-        }
-    }
-
-    psVectorStats(stats, junkData, NULL, junkMask, maskVal);
-
-    psFree(junkMask);
-    psFree(junkData);
-    return true;
-}
-
-/*****************************************************************************
-NOTE: We assume that the psHistogram structure out has already been allocated
-and initialized.
- *****************************************************************************/
-bool psImageHistogram(psHistogram* out,
-                              const psImage* in,
-                              const psImage* mask,
-                              psMaskType maskVal)
-{
-    PS_ASSERT_PTR_NON_NULL(out, false);
-    PS_ASSERT_PTR_NON_NULL(in, false);
-    if (mask != NULL) {
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_U8, false);
-        PS_ASSERT_IMAGES_SIZE_EQUAL(in, mask, false);
-    }
-    psVector* junkData = NULL;
-    psVector* junkMask = NULL;
-
-    if (in->parent == NULL) {
-        // stuff the image data into a psVector struct.
-        junkData = (psVector *) psAlloc(sizeof(psVector));
-        junkData->type = in->type;
-        P_PSVECTOR_SET_NALLOC(junkData,in->numRows * in->numCols);
-        junkData->n = junkData->nalloc;
-        junkData->data.U8 = in->data.V[0];      // since psImage data is contiguous...
-    } else {
-        // image not necessarily contiguous
-        int numRows = in->numRows;
-        int numCols = in->numCols;
-        int rowSize = numCols * (PSELEMTYPE_SIZEOF(in->type.type));
-
-        junkData = psVectorAlloc(numRows*numCols, in->type.type);
-
-        psU8* data = junkData->data.U8;
-        for (int row = 0; row < numRows; row++) {
-            memcpy(data, in->data.V[row], rowSize);
-            data += rowSize;
-        }
-    }
-
-    if (mask != NULL) {
-        if (mask->parent == NULL) {
-            // stuff the mask data into a psVector struct.
-            junkMask = psAlloc(sizeof(psVector));
-            junkMask->type = mask->type;
-            P_PSVECTOR_SET_NALLOC(junkMask,mask->numRows * mask->numCols);
-            junkMask->n = junkMask->nalloc;
-            junkMask->data.U8 = mask->data.V[0];
-        } else {
-            // image not necessarily contiguous
-            int numRows = mask->numRows;
-            int numCols = mask->numCols;
-            int rowSize = numCols * (PSELEMTYPE_SIZEOF(mask->type.type));
-
-            junkMask = psVectorAlloc(numRows*numCols, mask->type.type);
-
-            psU8* data = junkMask->data.U8;
-            for (int row = 0; row < numRows; row++) {
-                memcpy(data, mask->data.V[row], rowSize);
-                data += rowSize;
-            }
-        }
+	// image not necessarily contiguous; vector & image mask types do not match
+	int numRows = mask->numRows;
+	int numCols = mask->numCols;
+
+	junkMask = psVectorAlloc(numRows*numCols, PS_TYPE_VECTOR_MASK);
+
+	psVectorMaskType *data = junkMask->data.PS_TYPE_VECTOR_MASK_DATA;
+	for (int row = 0, nVect = 0; row < numRows; row++) {
+	    for (int col = 0; col < numCols; col++, nVect++) {
+		data[nVect] = (mask->data.PS_TYPE_IMAGE_MASK_DATA[row][col] & maskVal);
+	    }
+	}
     }
 
@@ -472,5 +455,5 @@
 long psImageCountPixelMask (psImage *mask,
                             psRegion region,
-                            psMaskType value)
+                            psImageMaskType value)
 {
     long Npixels = 0;
@@ -479,5 +462,4 @@
     int x1 = 0;
     int y1 = 0;
-    psElemType type;
 
     // this is not a valid error: a psRegion with ranges outside the valid pixels
@@ -608,34 +590,30 @@
     y1 = row1;
 
-    type = mask->type.type;
-    if (type != PS_TYPE_MASK) {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                "psImage type does not match the specified psMaskType!\n");
-        return -1;
-    }
-
+# define PS_IMAGE_COUNT_PIXEL_MASK(NAME,TYPE) \
+    case PS_TYPE_##NAME: \
+        for (long j = y0; j < y1; j++) { \
+            for (long i = x0; i < x1; i++) { \
+                if (mask->data.TYPE[j][i] & value) { \
+                    Npixels ++; \
+                } \
+            } \
+        } \
+        break;
+
+    psElemType type = mask->type.type;
     switch (type) {
-    case PS_TYPE_U8:
-    case PS_TYPE_U16:
-        for (long j = y0; j < y1; j++) {
-            for (long i = x0; i < x1; i++) {
-                if (mask->data.PS_TYPE_MASK_DATA[j][i] & value) {
-                    Npixels ++;
-                }
-            }
-        }
-        break;
-    case PS_TYPE_S8:
-    case PS_TYPE_S16:
-    case PS_TYPE_S32:
-    case PS_TYPE_S64:
-    case PS_TYPE_U32:
-    case PS_TYPE_U64:
-    case PS_TYPE_F32:
-    case PS_TYPE_F64:
+	PS_IMAGE_COUNT_PIXEL_MASK(U8, U8);
+	PS_IMAGE_COUNT_PIXEL_MASK(U16,U16);
+	PS_IMAGE_COUNT_PIXEL_MASK(U32,U32);
+	PS_IMAGE_COUNT_PIXEL_MASK(U64,U64);
+	PS_IMAGE_COUNT_PIXEL_MASK(S8, S8);
+	PS_IMAGE_COUNT_PIXEL_MASK(S16,S16);
+	PS_IMAGE_COUNT_PIXEL_MASK(S32,S32);
+	PS_IMAGE_COUNT_PIXEL_MASK(S64,S64);
+
     default:
         // XXX this should include the mask type (as a string)
         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                _("Input psImage mask type is not a supported mask datatype"));
+                _("Input psImage is an unsupported datatype"));
 
         return -1;
Index: /trunk/psLib/src/imageops/psImageStats.h
===================================================================
--- /trunk/psLib/src/imageops/psImageStats.h	(revision 21182)
+++ /trunk/psLib/src/imageops/psImageStats.h	(revision 21183)
@@ -9,6 +9,6 @@
  * @author GLG, MHPCC
  *
- * @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-02-13 03:01:23 $
+ * @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -42,5 +42,5 @@
     const psImage* in,                 ///< image (or subimage) to calculate stats
     const psImage* mask,               ///< mask data for image (NULL ok)
-    psMaskType maskVal                 ///< mask value for mask
+    psImageMaskType maskVal		///< mask value for mask
 );
 
@@ -57,5 +57,5 @@
     const psImage* in,                 ///< Image data to be histogramed.
     const psImage* mask,               ///< mask data for image (NULL ok)
-    psMaskType maskVal                 ///< mask Mask for mask
+    psImageMaskType maskVal		///< mask Mask for mask
 );
 
@@ -97,5 +97,5 @@
     psImage *mask,                     ///< input image to count
     psRegion region,                   ///< input region of image
-    psMaskType value                   ///< the mask value to satisfy
+    psImageMaskType value		///< the mask value to satisfy
 );
 
Index: /trunk/psLib/src/mask.notes.txt
===================================================================
--- /trunk/psLib/src/mask.notes.txt	(revision 21183)
+++ /trunk/psLib/src/mask.notes.txt	(revision 21183)
@@ -0,0 +1,123 @@
+
+20081227 : upgrading masks
+
+  *** Additional notes ***
+
+  * psVectorCountPixelMask : fixed to use psU64 as input comparison value against any int-type input vector
+  * psImageBackground (and calling functions in psLib/src/fits) do not pass the image mask pixels to psStats, but instead pass a subset based on the mask: this is safe from psImageMaskType != psVectorMaskType
+
+  *** Conversion Plan ***
+
+  * start with the pure psVectorMaskType 
+  * do the psImageMaskType -> track places where the image values are converted to vectors
+
+  *** Initial Thoughts ***
+
+  We have decided to upgrade the image masks to 16bits.  This has a
+  variety of impacts and implications.  
+
+  * Currently, we have a single abstract mask type "psMaskType", which
+    is currently assigned to psU8.  Associated with this are the
+    PS_TYPE_MASK (== PS_TYPE_U8), PS_TYPE_MASK_DATA (== U8), and
+    PS_TYPE_MASK_NAME (== "psU8") macros.  
+
+  * The abstract names have not been used ubiquitously, so places with
+    U8 used explicitly need to be fixed.  Not all cases of U8 must be
+    changed: some places are simply referring to one of the types.
+
+  * In fact, we have several classes of masks, so we need to expand
+    the psMaskType to appropriate version for the different classes:
+    
+    ** There are mask images used to distinguish different types of
+    bad pixels or other reasons to include / exclude pixels from an
+    analysis.  We can call these psImageMaskType (and equiv).
+
+    ** There are mask vectors used to include or exclude elements of a
+       vector from operations.  We can call these psVectorMaskType
+       (etc).
+
+    ** There are various other random masks which are used (eg,
+       polynomial coeffs).  We will keep psMaskType for these cases.
+
+  The file U8.txt contains all of the psLib file with a U8 in them.
+  I am putting notes in that file as I fix the various files.  
+
+  Here are the related macros and types defined in psType.h:
+
+#define PS_TYPE_MASK PS_TYPE_U8        /**< the psElemType to use for mask image */
+#define PS_TYPE_MASK_DATA U8           /**< the data member to use for mask image */
+#define PS_TYPE_MASK_NAME "psU8"       /**< the data type for mask as a string */
+
+typedef psU8 psMaskType;               ///< the C datatype for a mask image
+
+#define PS_TYPE_IMAGE_MASK PS_TYPE_U8        /**< the psElemType to use for mask image */
+#define PS_TYPE_IMAGE_MASK_DATA U8           /**< the data member to use for mask image */
+#define PS_TYPE_IMAGE_MASK_NAME "psU8"       /**< the data type for mask as a string */
+
+typedef psU8 psImageMaskType;               ///< the C datatype for a mask image
+
+#define PS_TYPE_VECTOR_MASK PS_TYPE_U8        /**< the psElemType to use for mask image */
+#define PS_TYPE_VECTOR_MASK_DATA U8           /**< the data member to use for mask image */
+#define PS_TYPE_VECTOR_MASK_NAME "psU8"       /**< the data type for mask as a string */
+
+typedef psU8 psVectorMaskType;			  ///< the C datatype for a mask image
+
+
+---
+    #define PS_METADATA_ITEM_COPY_CASE(NAME,TYPE) \
+case PS_DATA_##NAME: \
+    newItem = p_psMetadataItemAlloc(file, lineno, func, in->name, PS_DATA_##NAME, in->comment, in->data.TYPE); \
+    break; \
+
+./mathtypes/psVector.c  -- DONE psVectorCountMaskPixels was modified to use any type
+./math/psHistogram.c -- DONE mask vectors need to be fixed (mostly explicit U8; double check)
+./math/psMinimizeLMM.c -- DONE param mask vectors need to be fixed (mostly explicit U8; double check)
+./math/psMinimizeLMM_ND.c -- DONE param mask vectors need to be fixed (mostly explicit U8; double check)
+./math/psMinimizePolyFit.c -- DONE mask vectors need to be fixed (mostly explicit U8; double check)
+./math/psMinimizePowell.c -- DONE mask vectors need to be fixed (mostly explicit U8; double check)
+./math/psPolynomialMD.c -- DONE mask vectors need to be fixed (mostly explicit U8; double check)
+./math/psPolynomialUtils.c --  DONE mask vectors need to be fixed (mostly explicit U8; double check)
+./math/psStats.c -- DONE mask vectors need to be fixed (mostly explicit U8; double check) -- XXX redefine MASK_MARK?
+./math/psClip.c -- DONE vector masks
+./imageops/psImageMapFit.c -- DONE vector masks need to use psVectorMaskType
+
+./fits/psFitsImage.c -- DONE various image masks need to be fixed
+./fits/psFitsScale.c -- DONE various image masks need to be fixed
+./imageops/psImageBackground.c -- DONE various image masks need to be fixed
+./imageops/psImageConvolve.c -- DONE various image masks need to be fixed
+./imageops/psImageGeomManip.c -- DONE various image masks need to be fixed
+./imageops/psImageInterpolate.c -- DONE image masks need to be updated.
+./imageops/psImageMap.c -- DONE image map mask is u8, should be psImageMaskType
+./imageops/psImagePixelExtract.c -- DONE : partially cleaned up psImageSlice to create vector mask; currently uses hackish coding to avoid allocating and assigning a vector
+./imageops/psImageStats.c -- DONE : some issues : image mask needs to be reconciled with fixes to psStats
+./fft/psImageFFT.c -- DONE image masks
+./imageops/psImageMaskOps.c -- DONE image masks
+./imageops/psImagePixelInterpolate.c -- DONE image masks
+./math/psPolynomial.c -- DONE psMaskType is used for coeffMask, OK?
+./types/psPixels.c -- DONE image masks
+
+# ./math/psPolynomialMetadata.c -- probably OK
+# ./types/psBitSet.c -- nothing needs to be changed
+# ./math/psMathUtils.c -- nothing needs to be changed
+# ./math/psUnaryOp.c  -- nothing needs to be changed
+# ./mathtypes/psImage.c  -- nothing needs to be changed
+# ./mathtypes/psScalar.c  -- nothing needs to be changed
+# ./types/psArguments.c  -- nothing needs to be changed
+# ./types/psLookupTable.c  -- nothing needs to be changed
+# ./types/psMetadata.c  -- nothing needs to be changed
+# ./types/psMetadataConfig.c  -- nothing needs to be changed
+# ./types/psMetadataItemCompare.c  -- nothing needs to be changed
+# ./types/psMetadataItemParse.c  -- nothing needs to be changed
+# ./types/psTree.c  -- nothing needs to be changed
+# ./db/psDB.c -- nothing needs to be changed
+# ./fits/psFits.c -- nothing needs to be changed
+# ./fits/psFitsHeader.c -- nothing needs to be changed
+# ./fits/psFitsTable.c -- nothing needs to be changed
+# ./imageops/psImagePixelManip.c  -- nothing needs to be changed
+# ./imageops/psImageStructManip.c  -- nothing needs to be changed
+# ./jpeg/psImageJpeg.c  -- nothing needs to be changed (U8 used for 24bit colors; required!)
+# ./math/psBinaryOp.c  -- nothing needs to be changed
+# ./math/psCompare.c  -- nothing needs to be changed
+# ./math/psMD5.c  -- nothing needs to be changed (U8 used for hash is OK)
+# ./math/psMathUtils.c  -- nothing needs to be changed
+# ./math/psMatrix.c  -- nothing needs to be changed
Index: /trunk/psLib/src/math/psClip.c
===================================================================
--- /trunk/psLib/src/math/psClip.c	(revision 21182)
+++ /trunk/psLib/src/math/psClip.c	(revision 21183)
@@ -22,5 +22,5 @@
 
 psClipParams *psClipParamsAlloc(psStatsOptions meanStat, psStatsOptions stdevStat,
-                                psMaskType masked, psMaskType clipped)
+                                psVectorMaskType masked, psVectorMaskType clipped)
 {
     psClipParams *params = psAlloc(sizeof(psClipParams)); // Clip parameters
@@ -48,5 +48,5 @@
     PS_ASSERT_VECTOR_NON_NULL(values, -1);
     PS_ASSERT_VECTOR_NON_NULL(mask, -1);
-    PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_MASK, -1);
+    PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, -1);
     PS_ASSERT_PTR(params, -1);
     PS_ASSERT_VECTORS_SIZE_EQUAL(values, mask, -1);
@@ -62,8 +62,8 @@
     }
 
-    psMaskType masked = params->masked; // Indicates masked values
-    psMaskType clipped = params->clipped; // Indicates clipped values
+    psVectorMaskType masked = params->masked; // Indicates masked values
+    psVectorMaskType clipped = params->clipped; // Indicates clipped values
     masked |= clipped;                  // Make sure we're also masking clipped values
-    psMaskType *maskData = mask->data.PS_TYPE_MASK_DATA; // Dereference mask
+    psVectorMaskType *maskData = mask->data.PS_TYPE_VECTOR_MASK_DATA; // Dereference mask
     long totalMasked = 0;               // Total number of pixels masked
 
@@ -120,5 +120,5 @@
     PS_ASSERT_VECTOR_NON_NULL(values, -1);
     PS_ASSERT_VECTOR_NON_NULL(mask, -1);
-    PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_MASK, -1);
+    PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, -1);
     PS_ASSERT_PTR(params, -1);
     PS_ASSERT_VECTORS_SIZE_EQUAL(values, mask, -1);
@@ -141,6 +141,6 @@
     }
 
-    psMaskType masked = params->masked; // Indicates masked values
-    psMaskType clipped = params->clipped; // Indicates clipped values
+    psVectorMaskType masked = params->masked; // Indicates masked values
+    psVectorMaskType clipped = params->clipped; // Indicates clipped values
     masked |= clipped;                  // Make sure we're also masking clipped values
 
@@ -158,5 +158,5 @@
 case PS_TYPE_##TYPE: { \
         ps##TYPE *valuesData = values->data.TYPE; /* Dereference for speed */ \
-        psMaskType *maskData = mask->data.PS_TYPE_MASK_DATA; /* Dereference mask for speed */ \
+        psVectorMaskType *maskData = mask->data.PS_TYPE_VECTOR_MASK_DATA; /* Dereference mask for speed */ \
         if (errors) { \
             ps##TYPE *errorsData = errors->data.TYPE; \
Index: /trunk/psLib/src/math/psClip.h
===================================================================
--- /trunk/psLib/src/math/psClip.h	(revision 21182)
+++ /trunk/psLib/src/math/psClip.h	(revision 21183)
@@ -4,6 +4,6 @@
  * @author Paul Price, IfA.
  *
- * $Revision: 1.5 $ $Name: not supported by cvs2svn $
- * $Date: 2007-08-09 01:40:07 $
+ * $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ * $Date: 2009-01-27 06:39:38 $
  * Copyright 2007 Institute for Astronomy, University of Hawaii
  */
@@ -25,6 +25,6 @@
     int iter;                           ///< Number of rejection iterations; unused by psClip functions
     float rej;                          ///< Rejection limit (standard deviations)
-    psMaskType masked;                  ///< Mask value for entries already masked
-    psMaskType clipped;                 ///< Mask value to give to clipped entries
+    psVectorMaskType masked;                  ///< Mask value for entries already masked
+    psVectorMaskType clipped;                 ///< Mask value to give to clipped entries
     double mean;                        ///< Resultant mean
     double stdev;                       ///< Resultant stdev
@@ -35,6 +35,6 @@
 psClipParams *psClipParamsAlloc(psStatsOptions meanStat, ///< Stats option to use for mean
                                 psStatsOptions stdevStat, ///< Stats option to use for standard deviation
-                                psMaskType masked, ///< Mask value for entries already masked
-                                psMaskType clipped ///< Mask value to give to clipped entries
+                                psVectorMaskType masked, ///< Mask value for entries already masked
+                                psVectorMaskType clipped ///< Mask value to give to clipped entries
     ) PS_ATTR_MALLOC;
 
Index: /trunk/psLib/src/math/psConstants.h
===================================================================
--- /trunk/psLib/src/math/psConstants.h	(revision 21182)
+++ /trunk/psLib/src/math/psConstants.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author GLG, MHPCC
  *
- * @version $Revision: 1.96 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-03-18 18:25:00 $
+ * @version $Revision: 1.97 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  *
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -67,6 +67,8 @@
 
 // These defines for bitwise opertaions are necessary to yield results of the proper size (use instead of ~)
-#define PS_NOT_U8(A)(UCHAR_MAX-(A)) // Perform bitwise NOT on A which is of type U8
-#define PS_NOT_U16(A)(USHORT_MAX-(A)) // Perform bitwaise NOT on A which is of type U16
+#define PS_NOT_U8(A)(UINT8_MAX-(A)) // Perform bitwise NOT on A which is of type U8
+#define PS_NOT_U16(A)(UINT16_MAX-(A)) // Perform bitwaise NOT on A which is of type U16
+#define PS_NOT_U32(A)(UINT32_MAX-(A)) // Perform bitwise NOT on A which is of type U8
+#define PS_NOT_U64(A)(UINT64_MAX-(A)) // Perform bitwaise NOT on A which is of type U16
 
 /// @}
Index: /trunk/psLib/src/math/psHistogram.c
===================================================================
--- /trunk/psLib/src/math/psHistogram.c	(revision 21182)
+++ /trunk/psLib/src/math/psHistogram.c	(revision 21183)
@@ -5,6 +5,6 @@
  *  @author GLG (MHPCC), EAM (IfA)
  *
- *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-05-07 23:11:30 $
+ *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -231,5 +231,5 @@
                                const psVector* errors,
                                const psVector* mask,
-                               psMaskType maskVal)
+                               psVectorMaskType maskVal)
 {
     psTrace("psLib.math", 3, "---- %s() begin  ----\n", __func__);
@@ -244,5 +244,5 @@
     if (mask) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(values, mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
     }
     if (errors) {
@@ -274,5 +274,5 @@
     for (long i = 0; i < inF32->n; i++) {
         // Check if this pixel is masked, and if so, skip it.
-        if (!mask || (mask && (!(mask->data.U8[i] & maskVal)))) {
+        if (!mask || (mask && (!(mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal)))) {
             if (inF32->data.F32[i] < out->bounds->data.F32[0]) {
                 // If this pixel is below minimum value, count it, then skip.
Index: /trunk/psLib/src/math/psHistogram.h
===================================================================
--- /trunk/psLib/src/math/psHistogram.h	(revision 21182)
+++ /trunk/psLib/src/math/psHistogram.h	(revision 21183)
@@ -7,6 +7,6 @@
  * @author GLG, MHPCC
  *
- * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-08-09 01:40:07 $
+ * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  *
  * Copyright 2004-2005 IfA, University of Hawaii
@@ -88,6 +88,6 @@
     const psVector* errors,            ///< Errors
     const psVector* mask,              ///< Mask dat for input vector
-    psMaskType maskVal                 ///< Mask value
-);
+    psVectorMaskType maskVal		///< Mask value
+    );
 
 /// @}
Index: /trunk/psLib/src/math/psMinimizeLMM.c
===================================================================
--- /trunk/psLib/src/math/psMinimizeLMM.c	(revision 21182)
+++ /trunk/psLib/src/math/psMinimizeLMM.c	(revision 21183)
@@ -10,6 +10,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-10-02 20:49:22 $
+ *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -74,5 +74,5 @@
     PS_ASSERT_VECTOR_TYPE(params,    PS_TYPE_F32,  false);
     if (paramMask) {
-        PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_MASK, false);
+        PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_VECTOR_MASK, false);
     }
 
@@ -113,5 +113,5 @@
     // set tmpBeta values which are not masked
     for (int j = 0, n = 0; j < params->n; j++) {
-	if (paramMask && (paramMask->data.U8[j])) continue;
+	if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) continue;
 	tmpBeta->data.F32[j] = Beta->data.F32[n];
 	n++;
@@ -120,5 +120,5 @@
     // apply Beta to get new Params values
     for (int j = 0; j < params->n; j++) {
-        if (paramMask && (paramMask->data.U8[j])) {
+        if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) {
             Params->data.F32[j] = params->data.F32[j];
             continue;
@@ -140,5 +140,5 @@
     // apply tmpBeta after limits have been checked
     for (int j = 0, n = 0; j < params->n; j++) {
-	if (paramMask && (paramMask->data.U8[j])) continue;
+	if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) continue;
 	Beta->data.F32[n] = tmpBeta->data.F32[j];
 	n++;
@@ -269,5 +269,5 @@
     PS_ASSERT_VECTOR_TYPE(params, PS_TYPE_F32, false);
     if (paramMask) {
-        PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_MASK, false);
+        PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_VECTOR_MASK, false);
     }
 
@@ -297,10 +297,10 @@
 	// we track alpha,beta and params,deriv separately
         for (int j = 0, J = 0; j < params->n; j++) {
-            if (paramMask && (paramMask->data.U8[j])) continue;
+            if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) continue;
 
             weight = deriv->data.F32[j] * dy->data.F32[i];
 
             for (int k = 0, K = 0; k <= j; k++) {
-                if (paramMask && (paramMask->data.U8[k])) continue;
+                if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[k])) continue;
                 alpha->data.F32[J][K] += weight * deriv->data.F32[k];
 		K++;
@@ -351,5 +351,5 @@
         paramMask = constraint->paramMask;
         if (paramMask != NULL) {
-            PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_U8, false);
+            PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_VECTOR_MASK, false);
             PS_ASSERT_VECTORS_SIZE_EQUAL(params, paramMask, false);
         }
@@ -493,10 +493,10 @@
 	psImageInit (covar, 0.0);
 	for (int j = 0, J = 0; j < params->n; j++) {
-	    if (paramMask && (paramMask->data.U8[j])) {
+	    if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) {
 		covar->data.F32[j][j] = 1.0;
 		continue;
 	    }
 	    for (int k = 0, K = 0; k < params->n; k++) {
-		if (paramMask && (paramMask->data.U8[k])) continue;
+		if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[k])) continue;
 		covar->data.F32[j][k] = Alpha->data.F32[J][K];
 		K++;
@@ -535,5 +535,5 @@
 	nParams = 0;
 	for (int i = 0; i < paramMask->n; i++) {
-	    if (paramMask->data.U8[i]) continue;
+	    if (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
 	    nParams ++;
 	}
Index: /trunk/psLib/src/math/psMinimizeLMM_ND.c
===================================================================
--- /trunk/psLib/src/math/psMinimizeLMM_ND.c	(revision 21182)
+++ /trunk/psLib/src/math/psMinimizeLMM_ND.c	(revision 21183)
@@ -8,6 +8,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-04-11 08:01:29 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -55,5 +55,5 @@
         paramMask = constraint->paramMask;
         if (paramMask != NULL) {
-            PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_U8, false);
+            PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_VECTOR_MASK, false);
             PS_ASSERT_VECTORS_SIZE_EQUAL(params, paramMask, false);
         }
@@ -201,10 +201,10 @@
 	psImageInit (covar, 0.0);
 	for (int j = 0, J = 0; j < params->n; j++) {
-	    if (paramMask && (paramMask->data.U8[j])) {
+	    if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) {
 		covar->data.F32[j][j] = 1.0;
 		continue;
 	    }
 	    for (int k = 0, K = 0; k < params->n; k++) {
-		if (paramMask && (paramMask->data.U8[k])) continue;
+		if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[k])) continue;
 		covar->data.F32[j][k] = Alpha->data.F32[J][K];
 		K++;
@@ -251,5 +251,5 @@
     PS_ASSERT_VECTOR_TYPE(params,    PS_TYPE_F32,  false);
     if (paramMask) {
-        PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_MASK, false);
+        PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_VECTOR_MASK, false);
     }
 
@@ -282,5 +282,5 @@
     // set tmpBeta values which are not masked
     for (int j = 0, n = 0; j < params->n; j++) {
-	if (paramMask && (paramMask->data.U8[j])) continue;
+	if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) continue;
 	tmpBeta->data.F32[j] = Beta->data.F32[n];
 	n++;
@@ -289,5 +289,5 @@
     // apply Beta to get new Params values
     for (int j = 0; j < params->n; j++) {
-        if (paramMask && (paramMask->data.U8[j])) {
+        if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) {
             Params->data.F32[j] = params->data.F32[j];
             continue;
@@ -309,5 +309,5 @@
     // apply tmpBeta after limits have been checked
     for (int j = 0, n = 0; j < params->n; j++) {
-	if (paramMask && (paramMask->data.U8[j])) continue;
+	if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) continue;
 	Beta->data.F32[n] = tmpBeta->data.F32[j];
 	n++;
@@ -438,5 +438,5 @@
     PS_ASSERT_VECTOR_TYPE(params, PS_TYPE_F32, false);
     if (paramMask) {
-        PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_MASK, false);
+        PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_VECTOR_MASK, false);
     }
 
@@ -474,10 +474,10 @@
 	// we track alpha,beta and params,deriv separately
         for (int j = 0, J = 0; j < params->n; j++) {
-            if (paramMask && (paramMask->data.U8[j])) continue;
+            if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) continue;
 
             weight = deriv->data.F32[j] * dy->data.F32[i];
 
             for (int k = 0, K = 0; k <= j; k++) {
-                if (paramMask && (paramMask->data.U8[k])) continue;
+                if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[k])) continue;
                 alpha->data.F32[J][K] += weight * deriv->data.F32[k];
 		K++;
@@ -512,5 +512,5 @@
 	nParams = 0;
 	for (int i = 0; i < paramMask->n; i++) {
-	    if (paramMask->data.U8[i]) continue;
+	    if (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
 	    nParams ++;
 	}
Index: /trunk/psLib/src/math/psMinimizePolyFit.c
===================================================================
--- /trunk/psLib/src/math/psMinimizePolyFit.c	(revision 21182)
+++ /trunk/psLib/src/math/psMinimizePolyFit.c	(revision 21183)
@@ -10,6 +10,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-09-02 19:03:38 $
+ *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -307,5 +307,5 @@
     psPolynomial1D* myPoly,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector* y,
     const psVector* yErr,
@@ -326,5 +326,5 @@
     if (mask != NULL) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(y, mask, NULL);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, NULL);
     }
 
@@ -354,9 +354,9 @@
     psF64 **matrix = A->data.F64;       // Least-squares matrix
     psF64 *vector = B->data.F64;        // Least-squares vector
-    psU8 *dataMask = NULL;              // Mask for data
+    psVectorMaskType *dataMask = NULL;              // Mask for data
     if (mask) {
-        dataMask = mask->data.U8;
-    }
-    psU8 *coeffMask = myPoly->coeffMask;      // Mask for polynomial terms
+        dataMask = mask->data.PS_TYPE_VECTOR_MASK_DATA;
+    }
+    psMaskType *coeffMask = myPoly->coeffMask;      // Mask for polynomial terms
     psF64 *yData = y->data.F64;         // Coordinate data
     psF64 *yErrData = NULL;             // Errors in the coordinate
@@ -473,5 +473,5 @@
     psPolynomial1D* myPoly,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -484,5 +484,5 @@
     if (mask) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
     }
     if (x) {
@@ -529,9 +529,9 @@
 
     // Dereference some pointers for speed in the loop
-    psU8 *dataMask = NULL;              // Dereferenced version of mask for data points
+    psVectorMaskType *dataMask = NULL;              // Dereferenced version of mask for data points
     if (mask) {
-        dataMask = mask->data.U8;
-    }
-    psU8 *coeffMask = myPoly->coeffMask;      // Dereferenced version of mask for polynomial terms
+        dataMask = mask->data.PS_TYPE_VECTOR_MASK_DATA;
+    }
+    psMaskType *coeffMask = myPoly->coeffMask;      // Dereferenced version of mask for polynomial terms
     psF64 *ordinates = NULL;            // Dereferenced version of ordinate data
     if (x) {
@@ -698,5 +698,5 @@
     psPolynomial1D *poly,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -711,5 +711,5 @@
     if (mask != NULL) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
     }
     if (fErr != NULL) {
@@ -782,5 +782,5 @@
     psStats *stats,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -794,5 +794,5 @@
     PS_ASSERT_VECTOR_NON_NULL(mask, false);
     PS_ASSERT_VECTORS_SIZE_EQUAL(mask, f, false);
-    PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+    PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
 
     if (fErr != NULL) {
@@ -862,5 +862,5 @@
             if (mask != NULL) {
                 for (psS32 i = 0 ; i < mask->n ; i++) {
-                    psTrace("psLib.math", 6,  "mask[%d] is %d\n", i, mask->data.U8[i]);
+                    psTrace("psLib.math", 6,  "mask[%d] is %d\n", i, mask->data.PS_TYPE_VECTOR_MASK_DATA[i]);
                 }
             }
@@ -895,5 +895,5 @@
             if (mask != NULL) {
                 for (psS32 i = 0 ; i < mask->n ; i++) {
-                    if (!((mask != NULL) && (mask->data.U8[i] & maskValue))) {
+                    if (!((mask != NULL) && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue))) {
                         psTrace("psLib.math", 6,  "(f, fit)[%d] is (%f, %f).  resid is (%f)\n",
                                 i, f->data.F32[i], fit->data.F32[i], resid->data.F64[i]);
@@ -922,5 +922,5 @@
         // recovery is not allowed with this scheme
         for (psS32 i = 0; i < resid->n; i++) {
-            if ((mask != NULL) && (mask->data.U8[i] & maskValue)) {
+            if ((mask != NULL) && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) {
                 continue;
             }
@@ -936,5 +936,5 @@
 
                 if (mask != NULL) {
-                    mask->data.U8[i] |= 0x01;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= 0x01;
                 }
                 continue;
@@ -979,5 +979,5 @@
     psPolynomial2D* myPoly,
     const psVector* mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -1003,5 +1003,5 @@
     if (mask != NULL) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(y, mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
     }
 
@@ -1026,8 +1026,8 @@
     psF64 **matrix = A->data.F64;       // Dereference the least-squares matrix
     psF64 *vector = B->data.F64;        // Dereference the least-squares vector
-    psU8 **coeffMask = myPoly->coeffMask;     // Dereference mask for polynomial terms
-    psU8 *dataMask = NULL;              // Dereference mask for data
+    psMaskType **coeffMask = myPoly->coeffMask;     // Dereference mask for polynomial terms
+    psVectorMaskType *dataMask = NULL;              // Dereference mask for data
     if (mask) {
-        dataMask = mask->data.U8;
+        dataMask = mask->data.PS_TYPE_VECTOR_MASK_DATA;
     }
     psF64 *xData = x->data.F64;         // Dereference x
@@ -1162,5 +1162,5 @@
     psPolynomial2D *poly,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -1179,5 +1179,5 @@
     if (mask != NULL) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
     }
     if (fErr != NULL) {
@@ -1231,5 +1231,5 @@
     psStats *stats,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -1254,5 +1254,5 @@
 
     PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false);
-    PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+    PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
 
     if (fErr != NULL) {
@@ -1300,5 +1300,5 @@
             if (mask != NULL) {
                 for (psS32 i = 0 ; i < mask->n ; i++) {
-                    psTrace("psLib.math", 7,  "mask[%d] is %d\n", i, mask->data.U8[i]);
+                    psTrace("psLib.math", 7,  "mask[%d] is %d\n", i, mask->data.PS_TYPE_VECTOR_MASK_DATA[i]);
                 }
             }
@@ -1329,5 +1329,5 @@
             if (mask != NULL) {
                 for (psS32 i = 0 ; i < mask->n ; i++) {
-                    if (!((mask != NULL) && (mask->data.U8[i] & maskValue))) {
+                    if (!((mask != NULL) && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue))) {
                         psTrace("psLib.math", 7,  "point %d at %f %f : value, fit : %f  %f resid: %f\n",
                                 i, x->data.F32[i], y->data.F32[i], f->data.F32[i], fit->data.F32[i], resid->data.F64[i]);
@@ -1356,5 +1356,5 @@
         // recovery is not allowed with this scheme
         for (psS32 i = 0; i < resid->n; i++) {
-            if ((mask != NULL) && (mask->data.U8[i] & maskValue)) {
+            if ((mask != NULL) && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) {
                 continue;
             }
@@ -1370,5 +1370,5 @@
 
                 if (mask != NULL) {
-                    mask->data.U8[i] |= 0x01;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= 0x01;
                 }
                 continue;
@@ -1403,5 +1403,5 @@
     psPolynomial3D* myPoly,
     const psVector* mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -1433,5 +1433,5 @@
     if (mask != NULL) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
     }
 
@@ -1464,9 +1464,9 @@
         fErrData = fErr->data.F64;
     }
-    psU8 *dataMask = NULL;              // Mask for data
+    psVectorMaskType *dataMask = NULL;              // Mask for data
     if (mask) {
-        dataMask = mask->data.U8;
-    }
-    psU8 ***coeffMask = myPoly->coeffMask;    // Mask for polynomial terms
+        dataMask = mask->data.PS_TYPE_VECTOR_MASK_DATA;
+    }
+    psMaskType ***coeffMask = myPoly->coeffMask;    // Mask for polynomial terms
     int nYZterm = nYterm * nZterm;      // Multiplication of the numbers, to calculate the index
 
@@ -1603,5 +1603,5 @@
     psPolynomial3D *poly,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -1623,5 +1623,5 @@
     if (mask != NULL) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
     }
     if (fErr != NULL) {
@@ -1677,5 +1677,5 @@
     psStats *stats,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -1705,5 +1705,5 @@
 
     PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false);
-    PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+    PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
 
     if (fErr != NULL) {
@@ -1751,5 +1751,5 @@
             if (mask != NULL) {
                 for (psS32 i = 0 ; i < mask->n ; i++) {
-                    psTrace("psLib.math", 6,  "mask[%d] is %d\n", i, mask->data.U8[i]);
+                    psTrace("psLib.math", 6,  "mask[%d] is %d\n", i, mask->data.PS_TYPE_VECTOR_MASK_DATA[i]);
                 }
             }
@@ -1778,5 +1778,5 @@
             if (mask != NULL) {
                 for (psS32 i = 0 ; i < mask->n ; i++) {
-                    if (!((mask != NULL) && (mask->data.U8[i] & maskValue))) {
+                    if (!((mask != NULL) && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue))) {
                         psTrace("psLib.math", 6,  "(f, fit)[%d] is (%f, %f).  resid is (%f)\n",
                                 i, f->data.F32[i], fit->data.F32[i], resid->data.F64[i]);
@@ -1805,5 +1805,5 @@
         // recovery is not allowed with this scheme
         for (psS32 i = 0; i < resid->n; i++) {
-            if ((mask != NULL) && (mask->data.U8[i] & maskValue)) {
+            if ((mask != NULL) && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) {
                 continue;
             }
@@ -1819,5 +1819,5 @@
 
                 if (mask != NULL) {
-                    mask->data.U8[i] |= 0x01;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= 0x01;
                 }
                 continue;
@@ -1850,5 +1850,5 @@
     psPolynomial4D* myPoly,
     const psVector* mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -1884,5 +1884,5 @@
     if (mask) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(y, mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
     }
 
@@ -1918,9 +1918,9 @@
         fErrData = fErr->data.F64;
     }
-    psU8 *dataMask = NULL;              // Mask for data
+    psVectorMaskType *dataMask = NULL;              // Mask for data
     if (mask) {
-        dataMask = mask->data.U8;
-    }
-    psU8 ****coeffMask = myPoly->coeffMask;    // Mask for polynomial terms
+        dataMask = mask->data.PS_TYPE_VECTOR_MASK_DATA;
+    }
+    psMaskType ****coeffMask = myPoly->coeffMask;    // Mask for polynomial terms
     int nYZTterm = nYterm * nZterm * nTterm; // Multiplication of the numbers, for calculating the index
     int nZTterm = nZterm * nTterm;      // Multiplication of the numbers, for calculating the index
@@ -2068,5 +2068,5 @@
     psPolynomial4D *poly,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -2091,5 +2091,5 @@
     if (mask) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
     }
     if (fErr != NULL) {
@@ -2148,5 +2148,5 @@
     psStats *stats,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -2181,5 +2181,5 @@
 
     PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false);
-    PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+    PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
 
     if (fErr != NULL) {
@@ -2227,5 +2227,5 @@
             if (mask != NULL) {
                 for (psS32 i = 0 ; i < mask->n ; i++) {
-                    psTrace("psLib.math", 6,  "mask[%d] is %d\n", i, mask->data.U8[i]);
+                    psTrace("psLib.math", 6,  "mask[%d] is %d\n", i, mask->data.PS_TYPE_VECTOR_MASK_DATA[i]);
                 }
             }
@@ -2255,5 +2255,5 @@
             if (mask != NULL) {
                 for (psS32 i = 0 ; i < mask->n ; i++) {
-                    if (!((mask != NULL) && (mask->data.U8[i] & maskValue))) {
+                    if (!((mask != NULL) && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue))) {
                         psTrace("psLib.math", 6,  "(f, fit)[%d] is (%f, %f).  resid is (%f)\n",
                                 i, f->data.F32[i], fit->data.F32[i], resid->data.F64[i]);
@@ -2282,5 +2282,5 @@
         // recovery is not allowed with this scheme
         for (psS32 i = 0; i < resid->n; i++) {
-            if ((mask != NULL) && (mask->data.U8[i] & maskValue)) {
+            if ((mask != NULL) && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) {
                 continue;
             }
@@ -2296,5 +2296,5 @@
 
                 if (mask != NULL) {
-                    mask->data.U8[i] |= 0x01;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= 0x01;
                 }
                 continue;
Index: /trunk/psLib/src/math/psMinimizePolyFit.h
===================================================================
--- /trunk/psLib/src/math/psMinimizePolyFit.h	(revision 21182)
+++ /trunk/psLib/src/math/psMinimizePolyFit.h	(revision 21183)
@@ -7,6 +7,6 @@
  * @author GLG, MHPCC
  *
- * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-23 22:47:23 $
+ * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  *
@@ -48,5 +48,5 @@
     psPolynomial1D *poly,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -57,5 +57,5 @@
     psPolynomial2D *poly,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -67,5 +67,5 @@
     psPolynomial3D *poly,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -78,5 +78,5 @@
     psPolynomial4D *poly,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -92,5 +92,5 @@
     psStats *stats,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -102,5 +102,5 @@
     psStats *stats,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -113,5 +113,5 @@
     psStats *stats,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -125,5 +125,5 @@
     psStats *stats,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
Index: /trunk/psLib/src/math/psMinimizePowell.c
===================================================================
--- /trunk/psLib/src/math/psMinimizePowell.c	(revision 21182)
+++ /trunk/psLib/src/math/psMinimizePowell.c	(revision 21183)
@@ -11,6 +11,6 @@
  *  NOTE: XXX: The SDR is silent about data types.  F32 is implemented here.
  *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-02-06 21:36:09 $
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -43,5 +43,5 @@
 #define PS_VECTOR_ADD_MULTIPLE(BASE, BASEMASK, LINE, OUT, MUL) \
 for (psS32 i=0;i<BASE->n;i++) { \
-    if (BASEMASK->data.U8[i] == 0) { \
+    if (BASEMASK->data.PS_TYPE_VECTOR_MASK_DATA[i] == 0) { \
         OUT->data.F32[i] = BASE->data.F32[i] + (MUL * LINE->data.F32[i]); \
     } else { \
@@ -62,5 +62,5 @@
 BOOL_VAR = true; \
 for (psS32 i=0;i<IN->n;i++) { \
-    if ((INMASK->data.U8[i] == 0) && (fabs(IN->data.F32[i]) >= FLT_EPSILON)) { \
+    if ((INMASK->data.PS_TYPE_VECTOR_MASK_DATA[i] == 0) && (fabs(IN->data.F32[i]) >= FLT_EPSILON)) { \
         BOOL_VAR = false; \
         break; \
@@ -359,5 +359,5 @@
     PS_ASSERT_VECTOR_NON_NULL(paramMask, NAN);
     PS_ASSERT_VECTOR_NON_EMPTY(paramMask, NAN);
-    PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_U8, NAN);
+    PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_VECTOR_MASK, NAN);
     PS_ASSERT_PTR_NON_NULL(coords, NAN);
     PS_ASSERT_PTR_NON_NULL(func, NAN);
@@ -388,5 +388,5 @@
         for (i=0;i<params->n;i++) {
             psTrace("psLib.math", 6, "(params, paramMask, line)[%d] is (%f %d %f)\n", i,
-                    params->data.F32[i], paramMask->data.U8[i], line->data.F32[i]);
+                    params->data.F32[i], paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i], line->data.F32[i]);
         }
     }
@@ -527,5 +527,5 @@
 
     if (paramMask == NULL) {
-        myParamMask = psVectorAlloc(params->n, PS_TYPE_U8);
+        myParamMask = psVectorAlloc(params->n, PS_TYPE_VECTOR_MASK);
         psVectorInit(myParamMask, 0);
     } else {
@@ -572,5 +572,5 @@
         biggestIter = 0;
         for (i=0;i<numDims;i++) {
-            if (myParamMask->data.U8[i] == 0) {
+            if (myParamMask->data.PS_TYPE_VECTOR_MASK_DATA[i] == 0) {
                 P_PSMINIMIZATION_SET_MAXITER((&dummyMin),PS_MINIMIZE_POWELL_LINEMIN_MAX_ITERATIONS);
                 *(float*)&dummyMin.tol = PS_MINIMIZE_POWELL_LINEMIN_ERROR_TOLERANCE;
@@ -603,5 +603,5 @@
         // 4: Set the vector u = Q - P
         for (i=0;i<numDims;i++) {
-            if (myParamMask->data.U8[i] == 0) {
+            if (myParamMask->data.PS_TYPE_VECTOR_MASK_DATA[i] == 0) {
                 u->data.F32[i] = Q->data.F32[i] - params->data.F32[i];
                 u->n++;
@@ -649,5 +649,5 @@
 
         for (i=0;i<numDims;i++) {
-            if (myParamMask->data.U8[i] == 0) {
+            if (myParamMask->data.PS_TYPE_VECTOR_MASK_DATA[i] == 0) {
                 pQP->data.F32[i] = (2 * Q->data.F32[i]) - params->data.F32[i];
             } else {
@@ -663,5 +663,5 @@
         if (term1 < term2) {
             for (i=0;i<numDims;i++) {
-                if (myParamMask->data.U8[i] == 0) {
+                if (myParamMask->data.PS_TYPE_VECTOR_MASK_DATA[i] == 0) {
                     ((psVector *) v->data[biggestIter])->data.F32[i] = u->data.F32[i];
                 }
@@ -671,5 +671,5 @@
         // 7: Set P to Q
         for (i=0;i<numDims;i++) {
-            if (myParamMask->data.U8[i] == 0) {
+            if (myParamMask->data.PS_TYPE_VECTOR_MASK_DATA[i] == 0) {
                 params->data.F32[i] = Q->data.F32[i];
             }
Index: /trunk/psLib/src/math/psPolynomialMD.c
===================================================================
--- /trunk/psLib/src/math/psPolynomialMD.c	(revision 21182)
+++ /trunk/psLib/src/math/psPolynomialMD.c	(revision 21183)
@@ -132,5 +132,5 @@
                               const psVector *values, // Measured values
                               const psVector *mask, // Mask for values
-			      psMaskType maskVal 
+			      psVectorMaskType maskVal 
                               )
 {
@@ -143,5 +143,5 @@
     int numGood = numValues;            // Number of good values
     for (int i = 0; i < numValues; i++) {
-        if (mask && (mask->data.U8[i] & maskVal)) {
+        if (mask && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal)) {
             numGood--;
             continue;
@@ -253,5 +253,5 @@
 
 bool psPolynomialMDFit(psPolynomialMD *poly, const psVector *values, const psVector *errors,
-                       const psVector *mask, psMaskType maskVal, const psArray *coordsArray)
+                       const psVector *mask, psVectorMaskType maskVal, const psArray *coordsArray)
 {
     PS_ASSERT_POLYNOMIALMD_NON_NULL(poly, false);
@@ -268,5 +268,5 @@
     if (mask) {
         PS_ASSERT_VECTOR_NON_NULL(mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_MASK, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
         PS_ASSERT_VECTORS_SIZE_EQUAL(values, mask, false);
     }
@@ -294,5 +294,5 @@
         PS_ASSERT_VECTOR_TYPE(coords, PS_TYPE_F32, false);
 
-        if (mask && (mask->data.PS_TYPE_MASK_DATA[i] & maskVal)) {
+        if (mask && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal)) {
             continue;
         }
@@ -321,7 +321,7 @@
 }
 
-// XXX this function should take a (psMaskType markVal) argument
+// XXX this function should take a (psVectorMaskType markVal) argument
 bool psPolynomialMDClipFit(psPolynomialMD *poly, const psVector *values, const psVector *errors,
-                           const psVector *mask, psMaskType maskVal, const psArray *coordsArray,
+                           const psVector *mask, psVectorMaskType maskVal, const psArray *coordsArray,
                            int numIter, float rej) 
 {
@@ -340,5 +340,5 @@
     if (mask) {
         PS_ASSERT_VECTOR_NON_NULL(mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_MASK, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
         PS_ASSERT_VECTORS_SIZE_EQUAL(values, mask, false);
     }
@@ -355,9 +355,9 @@
 
     // copy the input mask to a local temporary mask 
-    poly->ownMask = psVectorRecycle(poly->ownMask, numValues, PS_TYPE_U8); // Our own mask for input values
+    poly->ownMask = psVectorRecycle(poly->ownMask, numValues, PS_TYPE_VECTOR_MASK); // Our own mask for input values
     psVectorInit(poly->ownMask, 0);
     for (int i = 0; mask && (i < numValues); i++) {
-	if (mask->data.PS_TYPE_MASK_DATA[i] & maskVal) {
-	    poly->ownMask->data.U8[i] = 0xff;
+	if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal) {
+	    poly->ownMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff;
 	    numGood--;
 	}
@@ -392,5 +392,5 @@
 		    i, values->data.F32[i], values->data.F32[i] - poly->deviations->data.F32[i], poly->deviations->data.F32[i], limit);
 
-            if (poly->ownMask->data.U8[i]) continue;
+            if (poly->ownMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
 
             if (fabs(poly->deviations->data.F32[i]) > limit) {
@@ -398,5 +398,5 @@
                         i, values->data.F32[i], values->data.F32[i] + poly->deviations->data.F32[i], 
                         poly->deviations->data.F32[i], limit);
-                poly->ownMask->data.U8[i] = 0xff;
+                poly->ownMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff;
                 numClipped++;
                 numGood--;
@@ -435,5 +435,5 @@
     psVectorInit(vector, 0.0);
     for (int i = 0; i < numValues; i++) {
-        if (mask->data.U8[i]) {
+        if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
             continue;
         }
@@ -462,5 +462,5 @@
 
 bool psPolynomialMDClipFit(psPolynomialMD *poly, const psVector *values, const psVector *errors,
-                           const psVector *mask, psMaskType maskVal, const psArray *coordsArray,
+                           const psVector *mask, psVectorMaskType maskVal, const psArray *coordsArray,
                            int numIter, float rej)
 {
@@ -478,5 +478,5 @@
     if (mask) {
         PS_ASSERT_VECTOR_NON_NULL(mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_MASK, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
         PS_ASSERT_VECTORS_SIZE_EQUAL(values, mask, false);
     }
@@ -500,5 +500,5 @@
         PS_ASSERT_VECTOR_TYPE(coords, PS_TYPE_F32, false);
 
-        if (mask && (mask->data.PS_TYPE_MASK_DATA[i] & maskVal)) {
+        if (mask && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal)) {
             continue;
         }
@@ -516,10 +516,10 @@
     psImage *matrix = psImageAlloc(numTerms, numTerms, PS_TYPE_F64); // Least-squares matrix
     psVector *vector = psVectorAlloc(numTerms, PS_TYPE_F64); // Least-squares vector
-    psVector *ownMask = psVectorAlloc(numValues, PS_TYPE_U8); // Our own mask for input values
+    psVector *ownMask = psVectorAlloc(numValues, PS_TYPE_VECTOR_MASK); // Our own mask for input values
     psVectorInit(ownMask, 0);
     if (mask) {
         for (int i = 0; i < numValues; i++) {
-            if (mask->data.PS_TYPE_MASK_DATA[i] & maskVal) {
-                ownMask->data.U8[i] = 0xff;
+            if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal) {
+                ownMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff;
                 numGood--;
             }
@@ -551,5 +551,5 @@
         float limit = rej * poly->stdevFit; // Rejection limit
         for (int i = 0; i < numValues; i++) {
-            if (ownMask->data.U8[i]) {
+            if (ownMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
                 continue;
             }
@@ -558,5 +558,5 @@
                         i, values->data.F32[i], psPolynomialMDEval(poly, coordsArray->data[i]),
                         deviations->data.F32[i], limit);
-                ownMask->data.U8[i] = 0xff;
+                ownMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff;
                 numClipped++;
                 numGood--;
Index: /trunk/psLib/src/math/psPolynomialMD.h
===================================================================
--- /trunk/psLib/src/math/psPolynomialMD.h	(revision 21182)
+++ /trunk/psLib/src/math/psPolynomialMD.h	(revision 21183)
@@ -52,5 +52,5 @@
                        const psVector *errors, ///< Errors
                        const psVector *mask, ///< Mask
-                       psMaskType maskVal, ///< Value to mask
+                       psVectorMaskType maskVal, ///< Value to mask
                        const psArray *coordsArray ///< Array of coordinates
     );
@@ -61,5 +61,5 @@
                            const psVector *errors, ///< Errors
                            const psVector *mask, ///< Mask
-                           psMaskType maskVal, ///< Value to mask
+                           psVectorMaskType maskVal, ///< Value to mask
                            const psArray *coordsArray, ///< Array of coordinates
                            int numIter,    ///< Number of rejection iterations
Index: /trunk/psLib/src/math/psPolynomialUtils.c
===================================================================
--- /trunk/psLib/src/math/psPolynomialUtils.c	(revision 21182)
+++ /trunk/psLib/src/math/psPolynomialUtils.c	(revision 21183)
@@ -21,5 +21,5 @@
     psStats *stats,
     const psVector *mask,
-    psMaskType maskValue,
+    psVectorMaskType maskValue,
     const psVector *f,
     const psVector *fErr,
@@ -36,5 +36,5 @@
     if (mask != NULL) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, NULL);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, NULL);
     }
     PS_ASSERT_VECTOR_NON_NULL(x, NULL);
@@ -106,5 +106,5 @@
         // recovery is not allowed with this scheme
         for (int i = 0; i < resid->n; i++) {
-            if ((mask != NULL) && (mask->data.U8[i] & maskValue)) {
+            if ((mask != NULL) && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) {
                 continue;
             }
@@ -112,5 +112,5 @@
             if (resid->data.F64[i] - stats->sampleMedian > sigma*maxClipSigma) {
                 if (mask != NULL) {
-                    mask->data.U8[i] |= 0x01;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= 0x01;
                 }
                 continue;
@@ -118,5 +118,5 @@
             if (resid->data.F64[i] - stats->sampleMedian < sigma*minClipSigma) {
                 if (mask != NULL) {
-                    mask->data.U8[i] |= 0x01;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= 0x01;
                 }
                 continue;
Index: /trunk/psLib/src/math/psPolynomialUtils.h
===================================================================
--- /trunk/psLib/src/math/psPolynomialUtils.h	(revision 21182)
+++ /trunk/psLib/src/math/psPolynomialUtils.h	(revision 21183)
@@ -2,6 +2,6 @@
  * @brief extra psPolynomial-related functions
  *
- * $Revision: 1.5 $ $Name: not supported by cvs2svn $
- * $Date: 2007-01-23 22:47:23 $
+ * $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ * $Date: 2009-01-27 06:39:38 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -24,5 +24,5 @@
     psStats *stats,                     // Statistics to use in clipping
     const psVector *mask,               // Mask for input values
-    psMaskType maskValue,               // Mask value
+    psVectorMaskType maskValue,		// Mask value
     const psVector *f,                  // Value of the function, f(x,y,z,t)
     const psVector *fErr,               // Error in the value
Index: /trunk/psLib/src/math/psStats.c
===================================================================
--- /trunk/psLib/src/math/psStats.c	(revision 21182)
+++ /trunk/psLib/src/math/psStats.c	(revision 21183)
@@ -13,6 +13,6 @@
  * use ->min and ->max (PS_STAT_USE_RANGE)
  *
- *  @version $Revision: 1.230 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-11-04 00:55:14 $
+ *  @version $Revision: 1.231 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -68,5 +68,6 @@
 #define PS_CLIPPED_SIGMA_UB 10.0
 #define PS_POLY_MEDIAN_MAX_ITERATIONS 30
-#define MASK_MARK 0x80   // bit to use internally to mark data as bad
+
+#define MASK_MARK 0x80   // XXX : can we change this? bit to use internally to mark data as bad
 #define PS_ROBUST_MAX_ITERATIONS 20     // Maximum number of iterations for robust statistics
 
@@ -178,5 +179,5 @@
                                  const psVector* errors,
                                  const psVector* maskVector,
-                                 psMaskType maskVal,
+                                 psVectorMaskType maskVal,
                                  psStats* stats)
 {
@@ -190,5 +191,5 @@
     int numData = myVector->n;          // Number of data points
 
-    psU8 *maskData = (maskVector == NULL) ? NULL : maskVector->data.U8;
+    psVectorMaskType *maskData = (maskVector == NULL) ? NULL : maskVector->data.PS_TYPE_VECTOR_MASK_DATA;
     bool useRange = stats->options & PS_STAT_USE_RANGE;
 
@@ -245,5 +246,5 @@
     static long vectorMinMax(const psVector* myVector,
                              const psVector* maskVector,
-                             psMaskType maskVal,
+                             psVectorMaskType maskVal,
                              psStats* stats
         )
@@ -257,5 +258,5 @@
     int numValid = 0;                   // Number of valid values
 
-    psU8 *maskData = (maskVector == NULL) ? NULL : maskVector->data.U8;
+    psVectorMaskType *maskData = (maskVector == NULL) ? NULL : maskVector->data.PS_TYPE_VECTOR_MASK_DATA;
     bool useRange = stats->options & PS_STAT_USE_RANGE;
 
@@ -302,5 +303,5 @@
 static bool vectorSampleMedian(const psVector* inVector,
                                const psVector* maskVector,
-                               psMaskType maskVal,
+                               psVectorMaskType maskVal,
                                psStats* stats)
 {
@@ -308,5 +309,5 @@
 
     bool useRange = stats->options & PS_STAT_USE_RANGE;
-    psU8 *maskData = (maskVector == NULL) ? NULL : maskVector->data.U8; // Dereference the vector
+    psVectorMaskType *maskData = (maskVector == NULL) ? NULL : maskVector->data.PS_TYPE_VECTOR_MASK_DATA; // Dereference the vector
     psF32 *input = inVector->data.F32; // Dereference the vector
 
@@ -387,5 +388,5 @@
                               const psVector* errors,
                               const psVector* maskVector,
-                              psMaskType maskVal,
+                              psVectorMaskType maskVal,
                               psStats* stats)
 {
@@ -407,5 +408,5 @@
 
     psF32 *data = myVector->data.F32;   // Dereference
-    psU8 *maskData = (maskVector == NULL) ? NULL : maskVector->data.U8;
+    psVectorMaskType *maskData = (maskVector == NULL) ? NULL : maskVector->data.PS_TYPE_VECTOR_MASK_DATA;
     bool useRange = stats->options & PS_STAT_USE_RANGE;
     psF32 *errorsData = (errors == NULL) ? NULL : errors->data.F32;
@@ -468,5 +469,5 @@
 static bool vectorSampleMoments(const psVector* myVector,
                                 const psVector* maskVector,
-                                psMaskType maskVal,
+                                psVectorMaskType maskVal,
                                 psStats* stats)
 {
@@ -490,5 +491,5 @@
 
     psF32 *data = myVector->data.F32;   // Dereference
-    psU8 *maskData = (maskVector == NULL) ? NULL : maskVector->data.U8;
+    psVectorMaskType *maskData = (maskVector == NULL) ? NULL : maskVector->data.PS_TYPE_VECTOR_MASK_DATA;
     bool useRange = stats->options & PS_STAT_USE_RANGE;
 
@@ -557,5 +558,5 @@
                                const psVector* errors,
                                psVector* maskInput,
-                               psMaskType maskValInput,
+                               psVectorMaskType maskValInput,
                                psStats* stats
     )
@@ -580,14 +581,14 @@
 
     // We copy the mask vector, to preserve the original
-    psMaskType maskVal = MASK_MARK | maskValInput;
+    psVectorMaskType maskVal = MASK_MARK | maskValInput;
 
     // use the temporary vector for local temporary mask
-    stats->tmpMask = psVectorRecycle (stats->tmpMask, myVector->n, PS_TYPE_U8);
+    stats->tmpMask = psVectorRecycle (stats->tmpMask, myVector->n, PS_TYPE_VECTOR_MASK);
     psVector *tmpMask = stats->tmpMask;
     psVectorInit(tmpMask, 0);
     if (maskInput) {
         for (long i = 0; i < myVector->n; i++) {
-            if (maskInput->data.U8[i] & maskValInput) {
-                tmpMask->data.U8[i] = maskVal;
+            if (maskInput->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValInput) {
+                tmpMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = maskVal;
             }
         }
@@ -629,7 +630,7 @@
             // sqrt(A))
             for (long j = 0; j < myVector->n; j++) {
-                if (!tmpMask->data.U8[j] &&
+                if (!tmpMask->data.PS_TYPE_VECTOR_MASK_DATA[j] &&
                     fabsf(myVector->data.F32[j] - clippedMean) > stats->clipSigma * errors->data.F32[j]) {
-                    tmpMask->data.U8[j] = 0xff;
+                    tmpMask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xff;
                     psTrace(TRACE, 10, "Clipped %ld: %f +/- %f\n", j,
                             myVector->data.F32[j], errors->data.F32[j]);
@@ -640,7 +641,7 @@
         } else {
             for (long j = 0; j < myVector->n; j++) {
-                if (!tmpMask->data.U8[j] &&
+                if (!tmpMask->data.PS_TYPE_VECTOR_MASK_DATA[j] &&
                     fabsf(myVector->data.F32[j] - clippedMean) > (stats->clipSigma * clippedStdev)) {
-                    tmpMask->data.U8[j] = 0xff;
+                    tmpMask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xff;
                     psTrace(TRACE, 10, "Clipped %ld: %f\n", j, myVector->data.F32[j]);
                     numClipped++;
@@ -715,5 +716,5 @@
                               const psVector* errors,
                               psVector* maskInput,
-                              psMaskType maskValInput,
+                              psVectorMaskType maskValInput,
                               psStats* stats)
 {
@@ -726,11 +727,11 @@
     // and tested even if there is no supplied mask (and/or the maskVal is 0)
     // XXX this would be better if we had globally defined mask values
-    psMaskType maskVal = MASK_MARK | maskValInput;
-    psVector *mask = psVectorAlloc(myVector->n, PS_TYPE_MASK); // The actual mask we will use
+    psVectorMaskType maskVal = MASK_MARK | maskValInput;
+    psVector *mask = psVectorAlloc(myVector->n, PS_TYPE_VECTOR_MASK); // The actual mask we will use
     psVectorInit(mask, 0);
     if (maskInput) {
         for (long i = 0; i < myVector->n; i++) {
-            if (maskInput->data.U8[i] & maskValInput) {
-                mask->data.U8[i] = maskVal;
+            if (maskInput->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValInput) {
+                mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = maskVal;
             }
         }
@@ -934,5 +935,5 @@
                 if ((myVector->data.F32[i] < medianLo) || (myVector->data.F32[i] > medianHi)) {
                     // XXXX is this correct?  is MASK_MARK safe?
-                    mask->data.U8[i] |= MASK_MARK;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= MASK_MARK;
                     psTrace(TRACE, 6, "Masking element %ld is %f\n", i, myVector->data.F32[i]);
                 }
@@ -998,5 +999,5 @@
     long N50 = 0;
     for (long i = 0 ; i < myVector->n ; i++) {
-        if (!mask->data.U8[i] &&
+        if (!mask->data.PS_TYPE_VECTOR_MASK_DATA[i] &&
             (binLo25F32 <= myVector->data.F32[i]) && (binHi25F32 >= myVector->data.F32[i])) {
             N50++;
@@ -1046,5 +1047,5 @@
                                const psVector* errors,
                                psVector* mask,
-                               psMaskType maskVal,
+                               psVectorMaskType maskVal,
                                psStats* stats)
 {
@@ -1224,5 +1225,5 @@
                                   const psVector* errors,
                                   psVector* mask,
-                                  psMaskType maskVal,
+                                  psVectorMaskType maskVal,
                                   psStats* stats)
 {
@@ -1347,5 +1348,5 @@
         // fitStats->clipIter = 3.0;
         // fitStats->clipSigma = 3.0;
-        // psVector *fitMask = psVectorAlloc(y->n, PS_TYPE_U8);
+        // psVector *fitMask = psVectorAlloc(y->n, PS_TYPE_VECTOR_MASK);
         // psVectorInit (fitMask, 0);
 
@@ -1418,5 +1419,5 @@
                                   const psVector* errors,
                                   psVector* mask,
-                                  psMaskType maskVal,
+                                  psVectorMaskType maskVal,
                                   psStats* stats)
 {
@@ -1713,5 +1714,5 @@
                                   const psVector* errors,
                                   psVector* mask,
-                                  psMaskType maskVal,
+                                  psVectorMaskType maskVal,
                                   psStats* stats)
 {
@@ -2225,5 +2226,5 @@
                    const psVector* errors,
                    const psVector* mask,
-                   psMaskType maskVal)
+                   psVectorMaskType maskVal)
 {
     psTrace(TRACE, 3,"---- %s() begin  ----\n", __func__);
@@ -2233,5 +2234,5 @@
     if (mask) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(mask, in, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
     }
     if (errors) {
@@ -2255,10 +2256,10 @@
         }
     }
-    psVector *maskU8 = NULL;            // Input mask vector, U8 version
+    psVector *maskVector = NULL;            // Input mask vector, U8 version
     if (mask) {
-        if (mask->type.type == PS_TYPE_MASK) {
-            maskU8 = psMemIncrRefCounter((psPtr)mask);
+        if (mask->type.type == PS_TYPE_VECTOR_MASK) {
+            maskVector = psMemIncrRefCounter((psPtr)mask);
         } else {
-            maskU8 = psVectorCopy(NULL, mask, PS_TYPE_MASK);
+            maskVector = psVectorCopy(NULL, mask, PS_TYPE_VECTOR_MASK);
         }
     }
@@ -2279,5 +2280,5 @@
     // ************************************************************************
     if (stats->options & PS_STAT_SAMPLE_MEAN) {
-        if (!vectorSampleMean(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorSampleMean(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, "Failed to calculate vector sample mean");
             status &= false;
@@ -2287,5 +2288,5 @@
     // ************************************************************************
     if (stats->options & (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_QUARTILE)) {
-        if (!vectorSampleMedian(inF32, maskU8, maskVal, stats)) {
+        if (!vectorSampleMedian(inF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, "Failed to calculate sample median");
             status &= false;
@@ -2295,5 +2296,5 @@
     // ************************************************************************
     if (stats->options & PS_STAT_SAMPLE_STDEV) {
-        if (!vectorSampleStdev(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorSampleStdev(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, "Failed to calculate sample stdev");
             status &= false;
@@ -2302,5 +2303,5 @@
 
     if (stats->options & (PS_STAT_SAMPLE_SKEWNESS | PS_STAT_SAMPLE_KURTOSIS)) {
-        if (!vectorSampleMoments(inF32, maskU8, maskVal, stats)) {
+        if (!vectorSampleMoments(inF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, "Failed to calculate sample moments");
             status &= false;
@@ -2310,5 +2311,5 @@
     // ************************************************************************
     if (stats->options & (PS_STAT_MAX | PS_STAT_MIN)) {
-        if (vectorMinMax(inF32, maskU8, maskVal, stats) == 0) {
+        if (vectorMinMax(inF32, maskVector, maskVal, stats) == 0) {
             psError(PS_ERR_UNKNOWN, false, "Failed to calculate vector minimum and maximum");
             status &= false;
@@ -2318,5 +2319,5 @@
     // ************************************************************************
     if (stats->options & (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV | PS_STAT_ROBUST_QUARTILE)) {
-        if (!vectorRobustStats(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorRobustStats(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, _("Failed to calculate robust statistics"));
             status &= false;
@@ -2326,5 +2327,5 @@
     // ************************************************************************
     if (stats->options & (PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV)) {
-        if (!vectorFittedStats(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorFittedStats(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, _("Failed to calculate fitted statistics"));
             status &= false;
@@ -2337,5 +2338,5 @@
             psAbort("you may not specify both FITTED_MEAN and FITTED_MEAN_V2");
         }
-        if (!vectorFittedStats_v2(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorFittedStats_v2(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, _("Failed to calculate fitted statistics"));
             status &= false;
@@ -2348,5 +2349,5 @@
             psAbort("you may not specify both FITTED_MEAN and FITTED_MEAN_V3");
         }
-        if (!vectorFittedStats_v3(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorFittedStats_v3(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, _("Failed to calculate fitted statistics"));
             status &= false;
@@ -2359,5 +2360,5 @@
             psAbort("you may not specify both FITTED_MEAN and FITTED_MEAN_V4");
         }
-        if (!vectorFittedStats_v4(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorFittedStats_v4(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, _("Failed to calculate fitted statistics"));
             status &= false;
@@ -2367,5 +2368,5 @@
     // ************************************************************************
     if ((stats->options & PS_STAT_CLIPPED_MEAN) || (stats->options & PS_STAT_CLIPPED_STDEV)) {
-        if (!vectorClippedStats(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorClippedStats(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, "Failed to calculate clipped statistics\n");
             status &= false;
@@ -2375,5 +2376,5 @@
     psFree(inF32);
     psFree(errorsF32);
-    psFree(maskU8);
+    psFree(maskVector);
     psTrace(TRACE, 3,"---- %s() end  ----\n", __func__);
     return status;
Index: /trunk/psLib/src/math/psStats.h
===================================================================
--- /trunk/psLib/src/math/psStats.h	(revision 21182)
+++ /trunk/psLib/src/math/psStats.h	(revision 21183)
@@ -8,6 +8,6 @@
  * @author GLG, MHPCC
  *
- * @version $Revision: 1.65 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-08-03 20:55:09 $
+ * @version $Revision: 1.66 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -96,9 +96,9 @@
  */
 bool psVectorStats(
-    psStats* stats,                    ///< stats structure defines stats to be calculated and how
-    const psVector* in,                ///< Vector to be analysed.
-    const psVector* errors,            ///< Errors.
-    const psVector* mask,              ///< Ignore elements where (maskVector & maskVal) != 0: must be INT or NULL
-    psMaskType maskVal                 ///< Only mask elements with one of these bits set in maskVector
+    psStats* stats,	       ///< stats structure defines stats to be calculated and how
+    const psVector* in,			///< Vector to be analysed.
+    const psVector* errors,		///< Errors.
+    const psVector* mask, ///< Ignore elements where (maskVector & maskVal) != 0: must be INT or NULL
+    psVectorMaskType maskVal ///< Only mask elements with one of these bits set in maskVector
 );
 
Index: /trunk/psLib/src/mathtypes/psVector.c
===================================================================
--- /trunk/psLib/src/mathtypes/psVector.c	(revision 21182)
+++ /trunk/psLib/src/mathtypes/psVector.c	(revision 21183)
@@ -10,6 +10,6 @@
 *  @author Joshua Hoblitt, University of Hawaii
 *
-*  @version $Revision: 1.104 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2008-11-05 11:12:40 $
+*  @version $Revision: 1.105 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2009-01-27 06:39:38 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -987,7 +987,8 @@
 }
 
-// count number of pixels with given mask value
+// count number of pixels with given mask value.  the comparison is against a U64 type to
+// allow any int-type of vector.  all signed and unsigned int types are allowed
 long psVectorCountPixelMask (psVector *mask,
-                             psMaskType value)
+                             psU64 value)
 {
     long Npixels = 0;
@@ -998,30 +999,23 @@
     }
 
-    psElemType type;
-    type = mask->type.type;
-
-    if (type != PS_TYPE_MASK) {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                "psVector type does not match the specified psMaskType!\n");
-        return -1;
-    }
-
+# define PS_VECTOR_COUNT_PIXEL_MASK(NAME,TYPE) \
+    case PS_TYPE_##NAME: \
+        for (long i = 0; i < mask->n; i++) { \
+            if (mask->data.TYPE[i] & value) { \
+                Npixels ++; \
+            } \
+        } \
+        break;
+
+    psElemType type = mask->type.type;
     switch (type) {
-    case PS_TYPE_U8:
-    case PS_TYPE_U16:
-        for (long i = 0; i < mask->n; i++) {
-            if (mask->data.PS_TYPE_MASK_DATA[i] & value) {
-                Npixels ++;
-            }
-        }
-        break;
-    case PS_TYPE_S8:
-    case PS_TYPE_S16:
-    case PS_TYPE_S32:
-    case PS_TYPE_S64:
-    case PS_TYPE_U32:
-    case PS_TYPE_U64:
-    case PS_TYPE_F32:
-    case PS_TYPE_F64:
+	PS_VECTOR_COUNT_PIXEL_MASK(U8, U8);
+	PS_VECTOR_COUNT_PIXEL_MASK(U16,U16);
+	PS_VECTOR_COUNT_PIXEL_MASK(U32,U32);
+	PS_VECTOR_COUNT_PIXEL_MASK(U64,U64);
+	PS_VECTOR_COUNT_PIXEL_MASK(S8, S8);
+	PS_VECTOR_COUNT_PIXEL_MASK(S16,S16);
+	PS_VECTOR_COUNT_PIXEL_MASK(S32,S32);
+	PS_VECTOR_COUNT_PIXEL_MASK(S64,S64);
     default:
         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
Index: /trunk/psLib/src/mathtypes/psVector.h
===================================================================
--- /trunk/psLib/src/mathtypes/psVector.h	(revision 21182)
+++ /trunk/psLib/src/mathtypes/psVector.h	(revision 21183)
@@ -10,6 +10,6 @@
  * @author Joshua Hoblitt, University of Hawaii
  *
- * @version $Revision: 1.73 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-09-12 00:22:48 $
+ * @version $Revision: 1.74 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -379,6 +379,6 @@
  */
 long psVectorCountPixelMask(
-    psVector *mask,                    ///< input vector to count
-    psMaskType value                   ///< the mask value to satisfy
+    psVector *mask,			///< input vector to count
+    psU64 value				///< the mask value to satisfy
 );
 
Index: /trunk/psLib/src/sys/psType.h
===================================================================
--- /trunk/psLib/src/sys/psType.h	(revision 21182)
+++ /trunk/psLib/src/sys/psType.h	(revision 21183)
@@ -10,6 +10,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.62 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2007-08-09 03:30:47 $
+*  @version $Revision: 1.63 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2009-01-27 06:39:38 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -141,9 +141,35 @@
 } psDataType;
 
+// macros to abstract the generic mask type : these values must be consistent 
 #define PS_TYPE_MASK PS_TYPE_U8        /**< the psElemType to use for mask image */
 #define PS_TYPE_MASK_DATA U8           /**< the data member to use for mask image */
 #define PS_TYPE_MASK_NAME "psU8"       /**< the data type for mask as a string */
-
+#define PS_MIN_MASK_TYPE 0             /**< minimum valid Mask value */
+#define PS_MAX_MASK_TYPE UINT8_MAX     /**< maximum valid Mask value */
 typedef psU8 psMaskType;               ///< the C datatype for a mask image
+#define PS_NOT_MASK(A)(UINT8_MAX-(A))
+
+// alternate versions if needed
+// #define PS_NOT_MASK(A)(UINT16_MAX-(A))
+// #define PS_NOT_MASK(A)(UINT32_MAX-(A)) 
+// #define PS_NOT_MASK(A)(UINT64_MAX-(A))
+
+// macros to abstract the vector mask type : these values must be consistent 
+#define PS_TYPE_VECTOR_MASK PS_TYPE_U8        /**< the psElemType to use for mask image */
+#define PS_TYPE_VECTOR_MASK_DATA U8           /**< the data member to use for mask image */
+#define PS_TYPE_VECTOR_MASK_NAME "psU8"       /**< the data type for mask as a string */
+#define PS_MIN_VECTOR_MASK_TYPE 0             /**< minimum valid Vector Mask value */
+#define PS_MAX_VECTOR_MASK_TYPE UINT8_MAX     /**< maximum valid Vector Mask value */
+typedef psU8 psVectorMaskType;			  ///< the C datatype for a mask image
+#define PS_NOT_VECTOR_MASK(A)(UINT8_MAX-(A))
+
+// macros to abstract the image mask type : these values must be consistent 
+#define PS_TYPE_IMAGE_MASK PS_TYPE_U16	     /**< the psElemType to use for mask image */
+#define PS_TYPE_IMAGE_MASK_DATA U16	     /**< the data member to use for mask image */
+#define PS_TYPE_IMAGE_MASK_NAME "psU16"	     /**< the data type for mask as a string */
+#define PS_MIN_IMAGE_MASK_TYPE 0             /**< minimum valid Image Mask value */
+#define PS_MAX_IMAGE_MASK_TYPE UINT16_MAX    /**< maximum valid Image Mask value */
+typedef psU16 psImageMaskType;               ///< the C datatype for a mask image
+#define PS_NOT_IMAGE_MASK(A)(UINT16_MAX-(A))
 
 #define PS_MIN_S8        INT8_MIN      /**< minimum valid psS8 value */
Index: /trunk/psLib/src/types/psMetadata.c
===================================================================
--- /trunk/psLib/src/types/psMetadata.c	(revision 21182)
+++ /trunk/psLib/src/types/psMetadata.c	(revision 21183)
@@ -12,6 +12,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.174 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-10-28 00:13:19 $
+ *  @version $Revision: 1.175 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -866,4 +866,9 @@
 METADATA_ADD_TYPE(F32,psF32,PS_DATA_F32)
 METADATA_ADD_TYPE(F64,psF64,PS_DATA_F64)
+
+METADATA_ADD_TYPE(Mask,psMaskType,PS_TYPE_MASK)
+METADATA_ADD_TYPE(VectorMask,psVectorMaskType,PS_TYPE_VECTOR_MASK)
+METADATA_ADD_TYPE(ImageMask,psImageMaskType,PS_TYPE_IMAGE_MASK)
+
 METADATA_ADD_TYPE(List,psList*,PS_DATA_LIST)
 METADATA_ADD_TYPE(Str,const char*,PS_DATA_STRING)
@@ -1011,6 +1016,6 @@
 }
 
-#define psMetadataLookupNumTYPE(TYPE) \
-ps##TYPE psMetadataLookup##TYPE(bool *status, const psMetadata *md, const char *key) \
+#define psMetadataLookupNumTYPE(TYPE,NAME) \
+ps##TYPE psMetadataLookup##NAME(bool *status, const psMetadata *md, const char *key) \
 { \
     psMetadataItem *metadataItem = NULL; \
@@ -1081,15 +1086,19 @@
 }
 
-psMetadataLookupNumTYPE(F32)
-psMetadataLookupNumTYPE(F64)
-psMetadataLookupNumTYPE(S8)
-psMetadataLookupNumTYPE(S16)
-psMetadataLookupNumTYPE(S32)
-psMetadataLookupNumTYPE(S64)
-psMetadataLookupNumTYPE(U8)
-psMetadataLookupNumTYPE(U16)
-psMetadataLookupNumTYPE(U32)
-psMetadataLookupNumTYPE(U64)
-psMetadataLookupNumTYPE(Bool)
+psMetadataLookupNumTYPE(F32,F32)
+psMetadataLookupNumTYPE(F64,F64)
+psMetadataLookupNumTYPE(S8,S8)
+psMetadataLookupNumTYPE(S16,S16)
+psMetadataLookupNumTYPE(S32,S32)
+psMetadataLookupNumTYPE(S64,S64)
+psMetadataLookupNumTYPE(U8,U8)
+psMetadataLookupNumTYPE(U16,U16)
+psMetadataLookupNumTYPE(U32,U32)
+psMetadataLookupNumTYPE(U64,U64)
+psMetadataLookupNumTYPE(Bool,Bool)
+
+psMetadataLookupNumTYPE(MaskType,Mask)
+psMetadataLookupNumTYPE(VectorMaskType,VectorMask)
+psMetadataLookupNumTYPE(ImageMaskType,ImageMask)
 
 psMetadataItem* psMetadataGet(const psMetadata *md,
Index: /trunk/psLib/src/types/psMetadata.h
===================================================================
--- /trunk/psLib/src/types/psMetadata.h	(revision 21182)
+++ /trunk/psLib/src/types/psMetadata.h	(revision 21183)
@@ -9,6 +9,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.105 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2008-08-14 03:18:41 $
+*  @version $Revision: 1.106 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2009-01-27 06:39:38 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -763,4 +763,47 @@
 
 
+/** Add a psMaskType value to metadata collection.
+ *
+ *  @return bool:  True for success, False for failure.
+ */
+bool psMetadataAddMask(
+    psMetadata* md,                    ///< Metadata collection to insert metadata item
+    long location,                     ///< Index number, PS_LIST_HEAD, or PS_LIST_TAIL
+    const char* name,                  ///< Name of metadata item
+    int format,                        ///< psMetadataFlag options/flags
+    const char* comment,               ///< Comment for metadata item
+    psMaskType value			///< Value for metadata item data
+);
+
+
+/** Add a psVectorMaskType value to metadata collection.
+ *
+ *  @return bool:  True for success, False for failure.
+ */
+bool psMetadataAddVectorMask(
+    psMetadata* md,                    ///< Metadata collection to insert metadata item
+    long location,                     ///< Index number, PS_LIST_HEAD, or PS_LIST_TAIL
+    const char* name,                  ///< Name of metadata item
+    int format,                        ///< psMetadataFlag options/flags
+    const char* comment,               ///< Comment for metadata item
+    psVectorMaskType value			///< Value for metadata item data
+);
+
+
+/** Add a psImageMaskType value to metadata collection.
+ *
+ *  @return bool:  True for success, False for failure.
+ */
+bool psMetadataAddImageMask(
+    psMetadata* md,                    ///< Metadata collection to insert metadata item
+    long location,                     ///< Index number, PS_LIST_HEAD, or PS_LIST_TAIL
+    const char* name,                  ///< Name of metadata item
+    int format,                        ///< psMetadataFlag options/flags
+    const char* comment,               ///< Comment for metadata item
+    psImageMaskType value			///< Value for metadata item data
+);
+
+
+
 /** Add a psList to metadata collection.
  *
@@ -1095,4 +1138,49 @@
  */
 psU64 psMetadataLookupU64(
+    bool *status,                      ///< Status of lookup.
+    const psMetadata *md,              ///< Metadata collection to lookup metadata item.
+    const char *key                    ///< Name of metadata key.
+);
+
+
+/** Find an item in the metadata collection based on key name and return its integer value.
+ *
+ *  Items may be found in the metadata by providing a key. If the key is
+ *  non-unique, the value of the first item is returned. If the item is not
+ *  found, zero is returned.
+ *
+ * @return psMaskType : Value of metadata item.
+ */
+psMaskType psMetadataLookupMask(
+    bool *status,                      ///< Status of lookup.
+    const psMetadata *md,              ///< Metadata collection to lookup metadata item.
+    const char *key                    ///< Name of metadata key.
+);
+
+
+/** Find an item in the metadata collection based on key name and return its integer value.
+ *
+ *  Items may be found in the metadata by providing a key. If the key is
+ *  non-unique, the value of the first item is returned. If the item is not
+ *  found, zero is returned.
+ *
+ * @return psVectorMaskType : Value of metadata item.
+ */
+psVectorMaskType psMetadataLookupVectorMask(
+    bool *status,                      ///< Status of lookup.
+    const psMetadata *md,              ///< Metadata collection to lookup metadata item.
+    const char *key                    ///< Name of metadata key.
+);
+
+
+/** Find an item in the metadata collection based on key name and return its integer value.
+ *
+ *  Items may be found in the metadata by providing a key. If the key is
+ *  non-unique, the value of the first item is returned. If the item is not
+ *  found, zero is returned.
+ *
+ * @return psImageMaskType : Value of metadata item.
+ */
+psImageMaskType psMetadataLookupImageMask(
     bool *status,                      ///< Status of lookup.
     const psMetadata *md,              ///< Metadata collection to lookup metadata item.
Index: /trunk/psLib/src/types/psPixels.c
===================================================================
--- /trunk/psLib/src/types/psPixels.c	(revision 21182)
+++ /trunk/psLib/src/types/psPixels.c	(revision 21183)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-09-12 22:36:29 $
+ *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -150,5 +150,5 @@
                         const psPixels *pixels,
                         psRegion region,
-                        psMaskType maskVal)
+                        psImageMaskType maskVal)
 {
     PS_ASSERT_PIXELS_NON_NULL(pixels, NULL);
@@ -169,5 +169,5 @@
     int numRows = y1 - y0 + 1, numCols = x1 - x0 + 1; // Size of image
 
-    out = psImageRecycle(out, numCols, numRows, PS_TYPE_MASK);
+    out = psImageRecycle(out, numCols, numRows, PS_TYPE_IMAGE_MASK);
     if (!out) {
         psError(PS_ERR_UNKNOWN, false, _("Failed to create image of size %dx%d."), numCols, numRows);
@@ -181,5 +181,5 @@
     // cycle through the vector of pixels and insert pixels into image
     long length = pixels->n;            // Length of pixel array
-    psMaskType** outData = out->data.PS_TYPE_MASK_DATA;
+    psImageMaskType** outData = out->data.PS_TYPE_IMAGE_MASK_DATA;
     for (int p = 0; p < length; p++) {
         float x = pixels->data[p].x;
@@ -196,8 +196,8 @@
 psPixels* psPixelsFromMask(psPixels* out,
                            const psImage* mask,
-                           psMaskType maskVal)
+                           psImageMaskType maskVal)
 {
     PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
 
     int numRows = mask->numRows, numCols = mask->numCols; // Size of image
@@ -214,5 +214,5 @@
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) {
+            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
                 psPixelsAdd(out, out->nalloc, x, y);
             }
Index: /trunk/psLib/src/types/psPixels.h
===================================================================
--- /trunk/psLib/src/types/psPixels.h	(revision 21182)
+++ /trunk/psLib/src/types/psPixels.h	(revision 21183)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-09-12 22:36:29 $
+ *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -189,5 +189,5 @@
     const psPixels* pixels,            ///< list of pixels to use
     psRegion region,                   ///< region to define the output mask image
-    psMaskType maskVal                 ///< the mask bit-values to act upon
+    psImageMaskType maskVal		///< the mask bit-values to act upon
 );
 
@@ -205,5 +205,5 @@
     psPixels *out,                     ///< psPixels to recycle, or NULL
     const psImage *mask,               ///< the input mask psImage
-    psMaskType maskVal                 ///< the mask bit-values to act upon
+    psImageMaskType maskVal		///< the mask bit-values to act upon
 );
 
Index: /trunk/psModules/src/astrom/pmAstrometryDistortion.c
===================================================================
--- /trunk/psModules/src/astrom/pmAstrometryDistortion.c	(revision 21182)
+++ /trunk/psModules/src/astrom/pmAstrometryDistortion.c	(revision 21183)
@@ -7,6 +7,6 @@
 *  @author EAM, IfA
 *
-*  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2008-09-02 19:05:09 $
+*  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2009-01-27 06:39:38 $
 *
 *  Copyright 2006 Institute for Astronomy, University of Hawaii
@@ -121,5 +121,5 @@
             // this analysis has too few data points to use the robust median method
             stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
-            mask = psVectorAlloc (Npts, PS_TYPE_MASK);
+            mask = psVectorAlloc (Npts, PS_TYPE_VECTOR_MASK);
             psVectorInit (mask, 0);
 
@@ -206,5 +206,5 @@
     // this analysis has too few data points to use the robust median method
     psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
-    psVector *mask = psVectorAlloc (gradients->n, PS_TYPE_MASK);
+    psVector *mask = psVectorAlloc (gradients->n, PS_TYPE_VECTOR_MASK);
     psVectorInit (mask, 0);
 
Index: /trunk/psModules/src/astrom/pmAstrometryObjects.c
===================================================================
--- /trunk/psModules/src/astrom/pmAstrometryObjects.c	(revision 21182)
+++ /trunk/psModules/src/astrom/pmAstrometryObjects.c	(revision 21183)
@@ -8,6 +8,6 @@
 *  @author EAM, IfA
 *
-*  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2008-11-20 01:26:07 $
+*  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2009-01-27 06:39:38 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -227,5 +227,5 @@
 
     // constant errors
-    psVector *mask = psVectorAlloc (match->n, PS_TYPE_U8);
+    psVector *mask = psVectorAlloc (match->n, PS_TYPE_VECTOR_MASK);
     psVectorInit (mask, 0);
 
Index: /trunk/psModules/src/camera/pmCellSquish.c
===================================================================
--- /trunk/psModules/src/camera/pmCellSquish.c	(revision 21182)
+++ /trunk/psModules/src/camera/pmCellSquish.c	(revision 21183)
@@ -12,5 +12,5 @@
 
 
-bool pmCellSquish(pmCell *cell, psMaskType maskVal, bool useShifts)
+bool pmCellSquish(pmCell *cell, psImageMaskType maskVal, bool useShifts)
 {
     PS_ASSERT_PTR_NON_NULL(cell, false);
@@ -116,5 +116,5 @@
     psImage *squishImage = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Squished image
     psImageInit(squishImage, 0.0);
-    psImage *squishMask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); // Squished mask
+    psImage *squishMask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); // Squished mask
     psImageInit(squishMask, 0);
 
@@ -159,5 +159,5 @@
                 squishImage->data.F32[ySquish][xSquish] += image->data.F32[y][x];
                 if (mask) {
-                    squishMask->data.PS_TYPE_MASK_DATA[ySquish][xSquish] |= mask->data.U8[y][x] & maskVal;
+                    squishMask->data.PS_TYPE_IMAGE_MASK_DATA[ySquish][xSquish] |= mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal;
                 }
             }
Index: /trunk/psModules/src/camera/pmCellSquish.h
===================================================================
--- /trunk/psModules/src/camera/pmCellSquish.h	(revision 21182)
+++ /trunk/psModules/src/camera/pmCellSquish.h	(revision 21183)
@@ -7,5 +7,5 @@
 /// already have been read) and masks.
 bool pmCellSquish(pmCell *cell,         ///< Cell to have readouts combined
-                  psMaskType maskVal,   ///< Value to be masked
+                  psImageMaskType maskVal,   ///< Value to be masked
                   bool useShifts        ///< Use the shifts when squishing?
     );
Index: /trunk/psModules/src/camera/pmFPABin.c
===================================================================
--- /trunk/psModules/src/camera/pmFPABin.c	(revision 21182)
+++ /trunk/psModules/src/camera/pmFPABin.c	(revision 21183)
@@ -9,5 +9,5 @@
 #include "pmFPABin.h"
 
-bool pmReadoutRebin(pmReadout *out, const pmReadout *in, psMaskType maskVal, int xBin, int yBin)
+bool pmReadoutRebin(pmReadout *out, const pmReadout *in, psImageMaskType maskVal, int xBin, int yBin)
 {
     PM_ASSERT_READOUT_NON_NULL(out, false);
@@ -50,5 +50,5 @@
             for (int y = yStart; y < yStop; y++) {
                 for (int x = xStart; x < xStop; x++) {
-                    if (inMask && (inMask->data.PS_TYPE_MASK_DATA[y][x] & maskVal)) {
+                    if (inMask && (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal)) {
                         continue;
                     }
Index: /trunk/psModules/src/camera/pmFPABin.h
===================================================================
--- /trunk/psModules/src/camera/pmFPABin.h	(revision 21182)
+++ /trunk/psModules/src/camera/pmFPABin.h	(revision 21183)
@@ -9,5 +9,5 @@
 bool pmReadoutRebin(pmReadout *out,     ///< Output readout
                     const pmReadout *in,///< Input readout
-                    psMaskType maskVal, ///< Value to mask
+                    psImageMaskType maskVal, ///< Value to mask
                     int xBin, int yBin  ///< Binning factors in x and y
     );
Index: /trunk/psModules/src/camera/pmFPAMaskWeight.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAMaskWeight.c	(revision 21182)
+++ /trunk/psModules/src/camera/pmFPAMaskWeight.c	(revision 21183)
@@ -42,5 +42,5 @@
             continue;
         }
-        masks->data[i] = psImageAlloc(image->numCols, image->numRows, PS_TYPE_U8);
+        masks->data[i] = psImageAlloc(image->numCols, image->numRows, PS_TYPE_IMAGE_MASK);
         psImageInit(masks->data[i], 0);
     }
@@ -98,5 +98,5 @@
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-bool pmReadoutSetMask(pmReadout *readout, psMaskType satMask, psMaskType badMask)
+bool pmReadoutSetMask(pmReadout *readout, psImageMaskType satMask, psImageMaskType badMask)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -124,5 +124,5 @@
     if (!readout->mask) {
         // Generate a (throwaway) mask image, if required
-        readout->mask = psImageAlloc(image->numCols, image->numRows, PS_TYPE_U8);
+        readout->mask = psImageAlloc(image->numCols, image->numRows, PS_TYPE_IMAGE_MASK);
     }
     psImage *mask = readout->mask;      // The mask pixels
@@ -131,5 +131,5 @@
     // Dereference pointers for speed
     psF32 **imageData = image->data.F32;// The image
-    psU8  **maskData  = mask->data.U8;  // The mask
+    psImageMaskType **maskData = mask->data.PS_TYPE_IMAGE_MASK_DATA;  // The mask
 
     for (int i = 0; i < image->numRows; i++) {
@@ -153,5 +153,5 @@
 // pixels.  currently, it will set mask bits if (value <= BAD) or (value >= SATURATION)
 // should we optionally ignore these tests?
-bool pmReadoutGenerateMask(pmReadout *readout, psMaskType satMask, psMaskType badMask)
+bool pmReadoutGenerateMask(pmReadout *readout, psImageMaskType satMask, psImageMaskType badMask)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -294,5 +294,5 @@
 }
 
-bool pmReadoutGenerateMaskWeight(pmReadout *readout, psMaskType satMask, psMaskType badMask, bool poisson)
+bool pmReadoutGenerateMaskWeight(pmReadout *readout, psImageMaskType satMask, psImageMaskType badMask, bool poisson)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -306,5 +306,5 @@
 }
 
-bool pmCellGenerateMaskWeight(pmCell *cell, psMaskType satMask, psMaskType badMask, bool poisson)
+bool pmCellGenerateMaskWeight(pmCell *cell, psImageMaskType satMask, psImageMaskType badMask, bool poisson)
 {
     PS_ASSERT_PTR_NON_NULL(cell, false);
@@ -321,5 +321,5 @@
 
 
-bool pmReadoutWeightRenormPixels(const pmReadout *readout, psMaskType maskVal,
+bool pmReadoutWeightRenormPixels(const pmReadout *readout, psImageMaskType maskVal,
                                  psStatsOptions meanStat, psStatsOptions stdevStat, psRandom *rng)
 {
@@ -363,5 +363,5 @@
 
 
-bool pmReadoutWeightRenormPhot(const pmReadout *readout, psMaskType maskVal, int num, float width,
+bool pmReadoutWeightRenormPhot(const pmReadout *readout, psImageMaskType maskVal, int num, float width,
                                psStatsOptions meanStat, psStatsOptions stdevStat, psRandom *rng)
 {
@@ -411,5 +411,5 @@
     psVector *source = psVectorAlloc(num, PS_TYPE_F32); // Measurements of fake sources
     psVector *guess = psVectorAlloc(num, PS_TYPE_F32); // Guess at significance
-    psVector *photMask = psVectorAlloc(num, PS_TYPE_MASK); // Mask for fluxes
+    psVector *photMask = psVectorAlloc(num, PS_TYPE_VECTOR_MASK); // Mask for fluxes
     for (int i = 0; i < num; i++) {
         // Coordinates of interest
@@ -433,5 +433,5 @@
             float yGauss = gauss->data.F32[v]; // Value of Gaussian in y
             for (int u = 0, x = xPix - size; u < fullSize; u++, x++) {
-                if (mask && mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) {
+                if (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
                     continue;
                 }
@@ -453,5 +453,5 @@
         }
 
-        photMask->data.PS_TYPE_MASK_DATA[i] = ((isfinite(sumNoise) && isfinite(sumSource) &&
+        photMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = ((isfinite(sumNoise) && isfinite(sumSource) &&
                                                 isfinite(sumWeight) && sumGauss > 0 && sumGauss2 > 0) ?
                                                0 : 0xFF);
@@ -493,5 +493,5 @@
         ratio->data.F32[i] = measuredSig / guess->data.F32[i];
         if (guess->data.F32[i] <= 0.0 || source->data.F32[i] <= 0.0 || !isfinite(ratio->data.F32[i])) {
-            photMask->data.PS_TYPE_MASK_DATA[i] = 0xFF;
+            photMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xFF;
         }
         psTrace("psModules.camera", 9, "Ratio %d: %f, %f, %f\n",
@@ -523,5 +523,5 @@
 
 
-bool pmReadoutWeightRenorm(const pmReadout *readout, psMaskType maskVal, psStatsOptions meanStat,
+bool pmReadoutWeightRenorm(const pmReadout *readout, psImageMaskType maskVal, psStatsOptions meanStat,
                            psStatsOptions stdevStat, int width, psRandom *rng)
 {
@@ -591,5 +591,5 @@
 
 
-bool pmReadoutMaskNonfinite(pmReadout *readout, psMaskType maskVal)
+bool pmReadoutMaskNonfinite(pmReadout *readout, psImageMaskType maskVal)
 {
     PM_ASSERT_READOUT_NON_NULL(readout, false);
@@ -601,5 +601,5 @@
 
     if (!readout->mask) {
-        readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+        readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
     }
     psImage *mask = readout->mask;      // Readout's mask
@@ -608,5 +608,5 @@
         for (int x = 0; x < numCols; x++) {
             if (!isfinite(image->data.F32[y][x]) || (weight && !isfinite(weight->data.F32[y][x]))) {
-                mask->data.PS_TYPE_MASK_DATA[y][x] |= maskVal;
+                mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= maskVal;
             }
         }
@@ -618,5 +618,5 @@
 
 
-bool pmReadoutMaskApply(pmReadout *readout, psMaskType maskVal)
+bool pmReadoutMaskApply(pmReadout *readout, psImageMaskType maskVal)
 {
     PM_ASSERT_READOUT_NON_NULL(readout, false);
@@ -625,5 +625,5 @@
 
     int numCols = readout->image->numCols, numRows = readout->image->numRows; // Size of image
-    psMaskType **maskData = readout->mask->data.PS_TYPE_MASK_DATA; // Dereference mask
+    psImageMaskType **maskData = readout->mask->data.PS_TYPE_IMAGE_MASK_DATA; // Dereference mask
     psF32 **imageData = readout->image->data.F32;// Dereference image
     psF32 **weightData = readout->weight ? readout->weight->data.F32 : NULL; // Dereference weight map
@@ -644,6 +644,6 @@
 
 
-bool pmReadoutInterpolateBadPixels(pmReadout *readout, psMaskType maskVal, psImageInterpolateMode mode,
-                                   float poorFrac, psMaskType maskPoor, psMaskType maskBad)
+bool pmReadoutInterpolateBadPixels(pmReadout *readout, psImageMaskType maskVal, psImageInterpolateMode mode,
+                                   float poorFrac, psImageMaskType maskPoor, psImageMaskType maskBad)
 {
     PM_ASSERT_READOUT_NON_NULL(readout, false);
@@ -667,14 +667,15 @@
     psVector *imagePix = psVectorAllocEmpty(PIXELS_BUFFER, PS_TYPE_F32); // Corresponding values for image
     psVector *weightPix = psVectorAllocEmpty(PIXELS_BUFFER, PS_TYPE_F32); // Corresponding values for weight
-    psVector *maskPix = psVectorAllocEmpty(PIXELS_BUFFER, PS_TYPE_MASK); // Corresponding values for mask
+    psVector *maskPix = psVectorAllocEmpty(PIXELS_BUFFER, PS_TYPE_IMAGE_MASK); // Corresponding values for mask
+    // NOTE: maskPix carries the actual image mask values -- do NOT use
+    // PS_TYPE_VECTOR_MASK here; it is storage, and is not treated as a vector mask
 
     long numBad = 0;                    // Number of bad pixels interpolated
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) {
+            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
                 double imageValue, weightValue; // Image and weight value from interpolation
-                psMaskType maskValue = 0; // Mask value from interpolation
-                psImageInterpolateStatus status = psImageInterpolate(&imageValue, &weightValue, &maskValue,
-                                                                     x, y, interp);
+                psImageMaskType maskValue = 0; // Mask value from interpolation
+                psImageInterpolateStatus status = psImageInterpolate(&imageValue, &weightValue, &maskValue, x, y, interp);
                 if (status == PS_INTERPOLATE_STATUS_ERROR || status == PS_INTERPOLATE_STATUS_OFF) {
                     psError(PS_ERR_UNKNOWN, false, "Unable to interpolate readout at %d,%d", x, y);
@@ -697,5 +698,5 @@
                 imagePix->data.F32[numBad] = imageValue;
                 weightPix->data.F32[numBad] = weightValue;
-                maskPix->data.PS_TYPE_MASK_DATA[numBad] = maskValue;
+                maskPix->data.PS_TYPE_IMAGE_MASK_DATA[numBad] = maskValue;
                 numBad++;
             }
@@ -709,5 +710,5 @@
         image->data.F32[y][x] = imagePix->data.F32[i];
         weight->data.F32[y][x] = weightPix->data.F32[i];
-        mask->data.PS_TYPE_MASK_DATA[y][x] = maskPix->data.PS_TYPE_MASK_DATA[i];
+        mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = maskPix->data.PS_TYPE_IMAGE_MASK_DATA[i];
     }
 
Index: /trunk/psModules/src/camera/pmFPAMaskWeight.h
===================================================================
--- /trunk/psModules/src/camera/pmFPAMaskWeight.h	(revision 21182)
+++ /trunk/psModules/src/camera/pmFPAMaskWeight.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author Eugene Magnier, IfA
  *
- * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-10-31 21:50:16 $
+ * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
  */
@@ -42,6 +42,6 @@
 /// iterating using pmReadoutReadNext, in which case the HDU can't be generated.
 bool pmReadoutSetMask(pmReadout *readout, ///< Readout for which to set mask
-                      psMaskType satMask, ///< Mask value to give saturated pixels
-                      psMaskType badMask  ///< Mask value to give bad (low) pixels
+                      psImageMaskType satMask, ///< Mask value to give saturated pixels
+                      psImageMaskType badMask  ///< Mask value to give bad (low) pixels
     );
 
@@ -62,6 +62,6 @@
 /// is suitable for output (complete with HDU entry).  This is intended for most operations.
 bool pmReadoutGenerateMask(pmReadout *readout, ///< Readout for which to generate mask
-                           psMaskType sat, ///< Mask value to give saturated pixels
-                           psMaskType bad ///< Mask value to give bad (low) pixels
+                           psImageMaskType sat, ///< Mask value to give saturated pixels
+                           psImageMaskType bad ///< Mask value to give bad (low) pixels
     );
 
@@ -79,6 +79,6 @@
 /// Calls pmReadoutGenerateMask and pmReadoutGenerateWeight for the readout
 bool pmReadoutGenerateMaskWeight(pmReadout *readout, ///< Readout for which to generate mask and weights
-                                 psMaskType sat, ///< Mask value to give saturated pixels
-                                 psMaskType bad, ///< Mask value to give bad (low) pixels
+                                 psImageMaskType sat, ///< Mask value to give saturated pixels
+                                 psImageMaskType bad, ///< Mask value to give bad (low) pixels
                                  bool poisson ///< Use poisson weights (in addition to read noise)?
                                 );
@@ -88,6 +88,6 @@
 /// Calls pmReadoutGenerateMaskWeight for each readout within the cell.
 bool pmCellGenerateMaskWeight(pmCell *cell, ///< Cell for which to generate mask and weights
-                              psMaskType sat, ///< Mask value to give saturated pixels
-                              psMaskType bad, ///< Mask value to give bad (low) pixels
+                              psImageMaskType sat, ///< Mask value to give saturated pixels
+                              psImageMaskType bad, ///< Mask value to give bad (low) pixels
                               bool poisson ///< Use poisson weights (in addition to read noise)?
                              );
@@ -98,5 +98,5 @@
 bool pmReadoutWeightRenormPixels(
     const pmReadout *readout,           ///< Readout to normalise
-    psMaskType maskVal,                 ///< Value to mask
+    psImageMaskType maskVal,                 ///< Value to mask
     psStatsOptions meanStat,            ///< Statistic to measure the mean (of the variance map)
     psStatsOptions stdevStat,           ///< Statistic to measure the stdev (of the image)
@@ -110,5 +110,5 @@
 bool pmReadoutWeightRenormPhot(
     const pmReadout *readout,           ///< Readout to normalise
-    psMaskType maskVal,                 ///< Value to mask
+    psImageMaskType maskVal,                 ///< Value to mask
     int num,                            ///< Number of instances to measure over the image
     float width,                        ///< Photometry width
@@ -123,5 +123,5 @@
 /// that patch corresponds.
 bool pmReadoutWeightRenorm(const pmReadout *readout, // Readout to normalise
-                           psMaskType maskVal, // Value to mask
+                           psImageMaskType maskVal, // Value to mask
                            psStatsOptions meanStat, // Statistic to measure the mean (of the variance map)
                            psStatsOptions stdevStat, // Statistic to measure the stdev (of the image)
@@ -136,5 +136,5 @@
 /// the provided value.
 bool pmReadoutMaskNonfinite(pmReadout *readout, ///< Readout to mask
-                            psMaskType maskVal ///< Mask value to give non-finite pixels
+                            psImageMaskType maskVal ///< Mask value to give non-finite pixels
     );
 
@@ -145,5 +145,5 @@
 /// sets masked areas to NAN in the image and weight.
 bool pmReadoutMaskApply(pmReadout *readout, ///< Readout to mask
-                        psMaskType maskVal ///< Mask value for which to apply mask
+                        psImageMaskType maskVal ///< Mask value for which to apply mask
     );
 
@@ -152,9 +152,9 @@
 /// Scan the mask image for bad pixels, and interpolate over them using the nominated options
 bool pmReadoutInterpolateBadPixels(pmReadout *readout, ///< Readout to work on
-                                   psMaskType maskVal, ///< Value to mask
+                                   psImageMaskType maskVal, ///< Value to mask
                                    psImageInterpolateMode mode, ///< Interpolation mode
                                    float poorFrac, ///< Maximum bad fraction of kernel for "poor" status
-                                   psMaskType maskPoor, ///< Mask value to give poor pixels
-                                   psMaskType maskBad ///< Mask value to give bad pixels
+                                   psImageMaskType maskPoor, ///< Mask value to give poor pixels
+                                   psImageMaskType maskBad ///< Mask value to give bad pixels
     );
 
Index: /trunk/psModules/src/camera/pmFPAMosaic.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAMosaic.c	(revision 21182)
+++ /trunk/psModules/src/camera/pmFPAMosaic.c	(revision 21183)
@@ -471,6 +471,4 @@
         numImages++;
 
-        // Only implemented for F32 and U8 images so far.
-        assert(image->type.type == PS_TYPE_F32 || image->type.type == PS_TYPE_U8);
         // All input types must be the same
         if (type == 0) {
@@ -537,6 +535,14 @@
         if (xBinSource->data.S32[i] == xBinTarget && yBinSource->data.S32[i] == yBinTarget) {
             switch (type) {
+                COPY_WITH_PARITY_DIFFERENCE(U8);
+                COPY_WITH_PARITY_DIFFERENCE(U16);
+                COPY_WITH_PARITY_DIFFERENCE(U32);
+                COPY_WITH_PARITY_DIFFERENCE(U64);
+                COPY_WITH_PARITY_DIFFERENCE(S8);
+                COPY_WITH_PARITY_DIFFERENCE(S16);
+                COPY_WITH_PARITY_DIFFERENCE(S32);
+                COPY_WITH_PARITY_DIFFERENCE(S64);
                 COPY_WITH_PARITY_DIFFERENCE(F32);
-                COPY_WITH_PARITY_DIFFERENCE(U8);
+                COPY_WITH_PARITY_DIFFERENCE(F64);
               default:
                 psAbort("Should never get here.\n");
@@ -548,6 +554,14 @@
         // We have to do all of the hard work ourselves
         switch (type) {
-            FILL_IN(F32);
-            FILL_IN(U8);
+	    FILL_IN(U8);
+	    FILL_IN(U16);
+	    FILL_IN(U32);
+	    FILL_IN(U64);
+	    FILL_IN(S8);
+	    FILL_IN(S16);
+	    FILL_IN(S32);
+	    FILL_IN(S64);
+	    FILL_IN(F32);
+	    FILL_IN(F64);
           default:
             psAbort("Should never get here.\n");
@@ -730,5 +744,5 @@
                        const pmChip *chip, // Chip to mosaic
                        const pmCell *targetCell, // Cell to which to mosaic
-                       psMaskType blank // Mask value to give blank pixels
+                       psImageMaskType blank // Mask value to give blank pixels
                       )
 {
@@ -838,5 +852,5 @@
                       const pmChip *targetChip, // Chip to which to mosaic
                       const pmCell *targetCell, // Cell to which to mosaic
-                      psMaskType blank  // Mask value to give blank pixels
+                      psImageMaskType blank  // Mask value to give blank pixels
                      )
 {
@@ -994,5 +1008,5 @@
 // the mosaic image.
 
-bool pmChipMosaic(pmChip *target, const pmChip *source, bool deepCopy, psMaskType blank)
+bool pmChipMosaic(pmChip *target, const pmChip *source, bool deepCopy, psImageMaskType blank)
 {
     // Target exists, and has only a single cell
@@ -1225,5 +1239,5 @@
 
 
-bool pmFPAMosaic(pmFPA *target, const pmFPA *source, bool deepCopy, psMaskType blank)
+bool pmFPAMosaic(pmFPA *target, const pmFPA *source, bool deepCopy, psImageMaskType blank)
 {
     // Target exists, and has only a single chip with single cell
Index: /trunk/psModules/src/camera/pmFPAMosaic.h
===================================================================
--- /trunk/psModules/src/camera/pmFPAMosaic.h	(revision 21182)
+++ /trunk/psModules/src/camera/pmFPAMosaic.h	(revision 21183)
@@ -4,6 +4,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-06-20 02:22:26 $
+ * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
  */
@@ -24,5 +24,5 @@
                   const pmChip *source, ///< Source chip whose cells will be mosaicked
                   bool deepCopy,        ///< Require a deep copy (disregard 'nice' chip)
-                  psMaskType blank      ///< Mask value to give blank pixels
+                  psImageMaskType blank      ///< Mask value to give blank pixels
     );
 
@@ -36,5 +36,5 @@
                  const pmFPA *source,   ///< FPA whose chips and cells will be mosaicked
                  bool deepCopy,         ///< Require a deep copy (disregard 'nice' chip)
-                 psMaskType blank       ///< Mask value to give blank pixels
+                 psImageMaskType blank       ///< Mask value to give blank pixels
                 );
 /// @}
Index: /trunk/psModules/src/camera/pmFPARead.c
===================================================================
--- /trunk/psModules/src/camera/pmFPARead.c	(revision 21182)
+++ /trunk/psModules/src/camera/pmFPARead.c	(revision 21183)
@@ -35,5 +35,5 @@
 static psElemType pixelTypes[] = {
     PS_TYPE_F32,
-    PS_TYPE_MASK,
+    PS_TYPE_IMAGE_MASK,
     PS_TYPE_F32,
     0
Index: /trunk/psModules/src/camera/pmFPA_JPEG.c
===================================================================
--- /trunk/psModules/src/camera/pmFPA_JPEG.c	(revision 21182)
+++ /trunk/psModules/src/camera/pmFPA_JPEG.c	(revision 21183)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-09-23 02:00:36 $
+ *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -157,5 +157,5 @@
     psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN);
     stats->nSubsample = 10000;
-    psMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask
+    psImageMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask
     float mean = 0, delta = 0;          //
     if (!psImageBackground(stats, NULL, readout->image, readout->mask, maskVal, rng)) {
Index: /trunk/psModules/src/camera/pmHDU.c
===================================================================
--- /trunk/psModules/src/camera/pmHDU.c	(revision 21182)
+++ /trunk/psModules/src/camera/pmHDU.c	(revision 21183)
@@ -167,5 +167,5 @@
                      const psArray *images, // Images to write
                      const psArray *masks, // Masks to use when writing
-                     psMaskType maskVal,// Value to mask
+                     psImageMaskType maskVal,// Value to mask
                      psFits *fits       // FITS file to which to write
                     )
@@ -222,5 +222,5 @@
     PS_ASSERT_PTR_NON_NULL(fits, false);
 
-    psMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask
+    psImageMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask
     return hduWrite(hdu, hdu->images, hdu->masks, maskVal, fits);
 }
@@ -240,5 +240,5 @@
     PS_ASSERT_PTR_NON_NULL(fits, false);
 
-    psMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask
+    psImageMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask
     return hduWrite(hdu, hdu->weights, hdu->masks, maskVal, fits);
 }
Index: /trunk/psModules/src/camera/pmReadoutStack.c
===================================================================
--- /trunk/psModules/src/camera/pmReadoutStack.c	(revision 21182)
+++ /trunk/psModules/src/camera/pmReadoutStack.c	(revision 21183)
@@ -78,5 +78,5 @@
 
 // XXX for the moment, use col0, row0, numCols, numRows supplied from the outside
-bool pmReadoutStackDefineOutput(pmReadout *readout, int col0, int row0, int numCols, int numRows, bool mask, bool weight, psMaskType blank)
+bool pmReadoutStackDefineOutput(pmReadout *readout, int col0, int row0, int numCols, int numRows, bool mask, bool weight, psImageMaskType blank)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -94,5 +94,5 @@
 	// XXX is this an error?
         if (readout->mask) return false;
-	readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+	readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
 	psImageInit(readout->mask, blank);
     }
@@ -163,5 +163,5 @@
 bool pmReadoutUpdateSize(pmReadout *readout, int minCols, int minRows,
                          int numCols, int numRows, bool mask, bool weight,
-                         psMaskType blank)
+                         psImageMaskType blank)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -191,9 +191,9 @@
     if (mask) {
         if (!readout->mask) {
-            readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+            readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
             psImageInit(readout->mask, blank);
         }
         if (readout->mask->numCols < numCols || readout->mask->numRows < numRows) {
-            psImage *newMask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+            psImage *newMask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
             psImageInit(newMask, blank);
             psImageOverlaySection(newMask, readout->mask, readout->col0, readout->row0, "=");
Index: /trunk/psModules/src/camera/pmReadoutStack.h
===================================================================
--- /trunk/psModules/src/camera/pmReadoutStack.h	(revision 21182)
+++ /trunk/psModules/src/camera/pmReadoutStack.h	(revision 21183)
@@ -14,5 +14,5 @@
                          bool mask,     ///< Worry about the mask?
                          bool weight,   ///< Worry about the weight?
-                         psMaskType blank ///< Mask value to give to blank pixels
+                         psImageMaskType blank ///< Mask value to give to blank pixels
     );
 
@@ -47,5 +47,5 @@
 
 // XXX for the moment, use col0, row0, numCols, numRows supplied from the outside
-bool pmReadoutStackDefineOutput(pmReadout *readout, int col0, int row0, int numCols, int numRows, bool mask, bool weight, psMaskType blank);
+bool pmReadoutStackDefineOutput(pmReadout *readout, int col0, int row0, int numCols, int numRows, bool mask, bool weight, psImageMaskType blank);
 
 bool pmReadoutStackSetOutputSize(int *col0, int *row0, int *numCols, int *numRows, const psArray *inputs);
Index: /trunk/psModules/src/concepts/pmConceptsStandard.c
===================================================================
--- /trunk/psModules/src/concepts/pmConceptsStandard.c	(revision 21182)
+++ /trunk/psModules/src/concepts/pmConceptsStandard.c	(revision 21183)
@@ -16,4 +16,6 @@
 #include "pmConceptsWrite.h"
 #include "pmConceptsStandard.h"
+
+// XXX why are these functions not supporting all types (S64, U64 often missing)?
 
 // The functions in this file are intended to be called solely within the psModules concepts code.  For this
@@ -591,7 +593,9 @@
         TYPE_CASE(binning, concept, U16);
         TYPE_CASE(binning, concept, U32);
+        // TYPE_CASE(binning, concept, U64);
         TYPE_CASE(binning, concept, S8);
         TYPE_CASE(binning, concept, S16);
         TYPE_CASE(binning, concept, S32);
+        // TYPE_CASE(binning, concept, S64);
       default:
         psError(PS_ERR_UNKNOWN, true, "Note sure how to parse %s of type %x --- assuming 1.\n", pattern->name,
Index: /trunk/psModules/src/config/pmConfigMask.c
===================================================================
--- /trunk/psModules/src/config/pmConfigMask.c	(revision 21182)
+++ /trunk/psModules/src/config/pmConfigMask.c	(revision 21183)
@@ -9,103 +9,79 @@
 #include "pmConfigMask.h"
 
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Private functions
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-// maskSetValues examine named mask values and set the bits for maskValue and markValue.
-// Ensures that the below-named bad mask values are set, and calculates the mask value to catch them all
-// Ensure that the below-named other mask values are set (to 0x00 if necessary)
-
-// List of mask names for "bad" (i.e., mask me please) pixels
-static const char *badMaskNames[] = { "DETECTOR", // Something is wrong with the detector
-                                      "DARK", // Pixel doesn't dark-subtract properly
-                                      "FLAT", // Pixel doesn't flat-field properly
-                                      "BLANK", // Pixel doesn't contain valid data
-                                      "RANGE",// Pixel is out-of-range of linearity
-                                      "SAT",  // Pixel is saturated
-                                      // "LOW",  // Pixel is low
-                                      // "CONV", // Pixel is bad after convolution with a bad pixel
-                                      "BAD", // Pixel is low
-                                      "BAD.WARP", // Pixel is bad after convolution with a bad pixel
-                                      "CR",   // Pixel contains a cosmic ray
-                                      "GHOST",// Pixel contains an optical ghost
-                                      NULL // End marker
+static pmConfigMaskInfo masks[] = {
+    { "DETECTOR",  NULL,       0x00, true  },	// Something is wrong with the detector
+    { "DARK",      "DETECTOR", 0x00, true  },	// Pixel doesn't dark-subtract properly
+    { "FLAT",  	   "DETECTOR", 0x01, true  },	// Pixel doesn't flat-field properly
+    { "BLANK", 	   "DETECTOR", 0x01, true  },	// Pixel doesn't contain valid data
+    { "RANGE",     NULL,       0x00, true  },	// Pixel is out-of-range of linearity
+    { "SAT",       "RANGE",    0x01, true  },	// Pixel is saturated
+    { "BAD",       "RANGE",    0x01, true  },	// Pixel is low
+    { "BAD.WARP",  NULL,       0x01, true  },	// Pixel is bad after convolution with a bad pixel
+    { "CR",        NULL,       0x00, true  },	// Pixel contains a cosmic ray
+    { "GHOST",     NULL,       0x00, true  },	// Pixel contains an optical ghost
+    { "POOR.WARP", NULL,       0x00, false },	// Pixel is poor after convolution with a bad pixel
+    // "LOW"  Pixel is low
+    // "CONV" Pixel is bad after convolution with a bad pixel
 };
-// Fallback names in case a bad mask name is not defined
-static const char *fallbackMaskNames[] = { NULL, // DETECTOR
-                                           "DETECTOR", // DARK
-                                           "DETECTOR", // FLAT
-                                           "DETECTOR", // BLANK
-                                           NULL, // RANGE
-                                           "RANGE", // SAT
-                                           "RANGE", // LOW
-                                           NULL, // CONV
-                                           NULL, // CR
-                                           NULL, // GHOST
-};
-// Default values in case a bad mask name and its fallback is not defined
-static const psMaskType defaultMask[] = { 0x00, // DETECTOR
-                                          0x00, // DARK
-                                          0x01, // FLAT
-                                          0x01, // BLANK
-                                          0x00, // RANGE
-                                          0x01, // SAT
-                                          0x01, // LOW
-                                          0x01, // CONV
-                                          0x00, // CR
-                                          0x00  // GHOST
-};
-// Other mask names to ensure exist; these shouldn't be combined in the MASK.VALUE
-static const char *otherMaskNames[] = { // "POOR", // Pixel is poor after convolution with a bad pixel
-                                        "POOR.WARP", // Pixel is poor after convolution with a bad pixel
-                                        NULL // End marker
-};
-
-static bool maskSetValues(psMaskType *outMaskValue, // Value of MASK.VALUE, returned
-                          psMaskType *outMarkValue, // Value of MARK.VALUE, returned
-                          psMetadata *source  // Source of mask bits
-                          )
+
+// The functions in this file do not force the recipe or header values to be stored as the same
+// type as psImageMaskType : they only check that the given values will fit in the space
+// provided by psImageMaskType.  This should allow some backwards compatibility (old 8-bit
+// masks will work with a 16-bit system), but will catch unhandled conflicts (trying to fit 16
+// bits in 8-bits of space).
+
+// XXX this file does not have psError vs psWarning worked out correctly.  some of the 
+// failure modes should result in errors, not just warnings.
+
+// pmConfigMaskSetInMetadata examines named mask values and set the bits for maskValue and
+// markValue.  Ensures that the below-named mask values are set, and calculates the mask value
+// to catch all of the mask values marked as 'bad'.  Supplies the fallback name if the primary
+// name is not found, or the default values if the fallback name is not found.
+
+bool pmConfigMaskSetInMetadata(psImageMaskType *outMaskValue, // Value of MASK.VALUE, returned
+			       psImageMaskType *outMarkValue, // Value of MARK.VALUE, returned
+			       psMetadata *source  // Source of mask bits
+    )
 {
     PS_ASSERT_METADATA_NON_NULL(source, false);
-
+    
     // Ensure all the bad mask names exist, and set the value to catch all bad pixels
-    psMaskType maskValue = 0;           // Value to mask to catch all the bad pixels
-    for (int i = 0; badMaskNames[i]; i++) {
-        const char *name = badMaskNames[i]; // Name for mask
-        const char *fallback = fallbackMaskNames[i]; // Fallback for mask
-
+    psImageMaskType maskValue = 0;           // Value to mask to catch all the bad pixels
+    psImageMaskType allMasks = 0;	     // Value to mask to catch all masked bits (to set MARK)
+
+    int nMasks = sizeof (masks) / sizeof (pmConfigMaskInfo);
+
+    for (int i = 0; i < nMasks; i++) {
         bool mdok;                      // Status of MD lookup
-        psMaskType value = psMetadataLookupU8(&mdok, source, name); // Value of mask
+        psImageMaskType value = psMetadataLookupImageMaskFromGeneric(&mdok, source, masks[i].badMaskName); // Value of mask
+	if (!mdok) {
+	    psWarning ("problem with mask value %s\n", masks[i].badMaskName);
+	}
+
         if (!value) {
-            if (fallback) {
-                value = psMetadataLookupU8(&mdok, source, fallback);
-            }
-            if (!value) {
-                value = defaultMask[i];
-            }
-            psMetadataAddU8(source, PS_LIST_TAIL, name, PS_META_REPLACE, NULL, value);
-        }
-        maskValue |= value;
-    }
-
-    // Ensure all the other mask names exist
-    for (int i = 0; otherMaskNames[i]; i++) {
-        const char *name = otherMaskNames[i]; // Name for mask
-        bool mdok;                      // Status of MD lookup
-        psMaskType value = psMetadataLookupU8(&mdok, source, name); // Value of mask
-        if (!value) {
-            psMetadataAddU8(source, PS_LIST_TAIL, name, PS_META_REPLACE, NULL, 0x00);
-        }
+	    if (masks[i].fallbackName) {
+		value = psMetadataLookupImageMaskFromGeneric(&mdok, source, masks[i].fallbackName);
+	    }
+	    if (!value) {
+		value = masks[i].defaultMaskValue;
+	    }
+	    psMetadataAddImageMask(source, PS_LIST_TAIL, masks[i].badMaskName, PS_META_REPLACE, NULL, value);
+        }
+	if (masks[i].isBad) {
+	    maskValue |= value;
+	}
+	allMasks |= value;
     }
 
     // search for an unset bit to use for MARK:
-    psMaskType markValue = 0x80;
-
-    int nBits = sizeof(psMaskType) * 8;
+    psImageMaskType markValue = 0x00;
+    psImageMaskType markTrial = 0x01;
+
+    int nBits = sizeof(psImageMaskType) * 8;
     for (int i = 0; !markValue && (i < nBits); i++) {
-        if (maskValue & markValue) {
-            markValue >>= 1;
+        if (allMasks & markTrial) {
+            markTrial <<= 1;
         } else {
-            markValue = markValue;
+            markValue = markTrial;
         }
     }
@@ -116,6 +92,6 @@
 
     // update the list with the results
-    psMetadataAddU8(source, PS_LIST_TAIL, "MASK.VALUE", PS_META_REPLACE, NULL, maskValue);
-    psMetadataAddU8(source, PS_LIST_TAIL, "MARK.VALUE", PS_META_REPLACE, NULL, markValue);
+    psMetadataAddImageMask(source, PS_LIST_TAIL, "MASK.VALUE", PS_META_REPLACE, NULL, maskValue);
+    psMetadataAddImageMask(source, PS_LIST_TAIL, "MARK.VALUE", PS_META_REPLACE, NULL, markValue);
 
     if (outMaskValue) {
@@ -130,9 +106,9 @@
 
 // Get a mask value by name(s)
-static psMaskType maskGet(psMetadata *source, // Source of masks
-                          const char *masks // Mask values to get
-                          )
-{
-    psMaskType mask = 0;                // Mask value, to return
+psImageMaskType pmConfigMaskGetFromMetadata(psMetadata *source, // Source of masks
+					    const char *masks // Mask values to get
+    )
+{
+    psImageMaskType mask = 0;                // Mask value, to return
 
     psArray *names = psStringSplitArray(masks, " ,;", false); // Array of symbolic names
@@ -140,13 +116,13 @@
         const char *name = names->data[i]; // Symbolic name of interest
         bool mdok;                      // Status of MD lookup
-        psMaskType value = psMetadataLookupU8(&mdok, source, name);
+        psImageMaskType value = psMetadataLookupImageMaskFromGeneric(&mdok, source, name);
         if (!mdok) {
             // Try and generate the value if we can
             if (strcmp(name, "MASK.VALUE") == 0 || strcmp(name, "MARK.VALUE") == 0) {
-                if (!maskSetValues(NULL, NULL, source)) {
+                if (!pmConfigMaskSetInMetadata(NULL, NULL, source)) {
                     psError(PS_ERR_UNKNOWN, false, "Unable to set mask bits.");
                     return 0;
                 }
-                value = psMetadataLookupU8(&mdok, source, name);
+                value = psMetadataLookupImageMaskFromGeneric(&mdok, source, name);
                 psAssert(mdok, "Should have generated mask value");
             } else {
@@ -163,8 +139,67 @@
 }
 
+// lookup an image mask value by name from a psMetadata, without requiring the entry to 
+// be of type psImageMaskType, but verifying that it will fit in psImageMaskType
+psImageMaskType psMetadataLookupImageMaskFromGeneric (bool *status, const psMetadata *md, const char *name) {
+
+    *status = true;
+
+	// select the mask bit name from the header
+	psMetadataItem *item = psMetadataLookup (md, name);
+        if (!item) {
+            psWarning("Unable to find header keyword %s when parsing mask", name);
+	    *status = false;
+	    return 0;
+        }
+
+	// the value may be any of the U8, U16, U32, U64 types : accept the value regardless of type size
+	psU64 fullValue = 0;
+	switch (item->type) {
+	  case PS_DATA_U8:
+	    fullValue = item->data.U8;
+	    break;
+	  case PS_DATA_U16:
+	    fullValue = item->data.U16;
+	    break;
+	  case PS_DATA_U32:
+	    fullValue = item->data.U32;
+	    break;
+	  case PS_DATA_U64:
+	    fullValue = item->data.U64;
+	    break;
+	  case PS_DATA_S8:
+	    fullValue = item->data.S8;
+	    break;
+	  case PS_DATA_S16:
+	    fullValue = item->data.S16;
+	    break;
+	  case PS_DATA_S32:
+	    fullValue = item->data.S32;
+	    break;
+	  case PS_DATA_S64:
+	    fullValue = item->data.S64;
+	    break;
+	  default:
+            psWarning("Mask entry %s in metadata is not of a mask type", name);
+	    *status = false;
+	    return 0;
+	}
+
+	// will the incoming value fit within the current image mask type?
+	if (fullValue > PS_MAX_IMAGE_MASK_TYPE) {
+            psWarning("Mask entry %s in metadata is larger than allowed by the psImageMaskType", name);
+	    *status = false;
+	    return 0;
+        }
+	psImageMaskType value = fullValue;
+        // XXX validate that value is a 2^n value?
+
+	return value;
+}
+
 // Remove from the header keywords starting with the provided string
-static int maskRemoveHeader(psMetadata *header, // Header from which to remove keywords
-                            const char *start // Remove keywords that start with this string
-                            )
+int pmConfigMaskRemoveHeaderKeywords(psMetadata *header, // Header from which to remove keywords
+				     const char *start // Remove keywords that start with this string
+    )
 {
     psString regex = NULL;              // Regular expression for keywords
@@ -182,4 +217,208 @@
 }
 
+// look up the named mask value(s) from the MASKS recipe in the config system
+psImageMaskType pmConfigMaskGet(const char *masks, const pmConfig *config)
+{
+    psAssert(config, "Require configuration");
+    PS_ASSERT_STRING_NON_EMPTY(masks, 0);
+
+    bool mdok;                          // Status of MD lookup
+    psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, "MASKS"); // The recipe
+    if (!recipe) {
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
+        return 0;
+    }
+    
+    psImageMaskType mask = pmConfigMaskGetFromMetadata (recipe, masks);
+    return mask;
+}
+
+bool pmConfigMaskSet(const pmConfig *config, const char *maskName, psImageMaskType maskValue)
+{
+    psAssert(config, "Require configuration");
+    PS_ASSERT_STRING_NON_EMPTY(maskName, false);
+
+    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
+    if (!recipe) {
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
+        return false;
+    }
+
+    bool status = psMetadataAddImageMask(recipe, PS_LIST_TAIL, maskName, PS_META_REPLACE, NULL, maskValue);
+    return status;
+}
+
+
+// replace the named masks in the recipe with values in the header:
+// replace only the names in the header in the recipe
+bool pmConfigMaskReadHeader(pmConfig *config, const psMetadata *header)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_METADATA_NON_NULL(header, false);
+
+    bool status = false;
+
+    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
+    if (!recipe) {
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
+        return false;
+    }
+
+    // MASK.VALUE and MARK.VALUE aren't usually set in the recipe, but may be set in the header: create fake
+    // versions so that it won't complain later
+    if (!psMetadataLookup(recipe, "MASK.VALUE")) {
+        psMetadataAddImageMask(recipe, PS_LIST_TAIL, "MASK.VALUE", 0, "Bits to mask", 0);
+    }
+    if (!psMetadataLookup(recipe, "MARK.VALUE")) {
+        psMetadataAddImageMask(recipe, PS_LIST_TAIL, "MARK.VALUE", 0, "Bits for marking", 0);
+    }
+
+    // How many mask values do we need to read?  We raise an error if this is not found, 
+    // unless the MASK.FORCE is set to true in the camera config
+    int nMask = psMetadataLookupS32(&status, header, "MSKNUM");
+    if (!status) {
+        if (psMetadataLookupBool(&status, config->camera, "MASK.FORCE")) {
+            psWarning("No mask values in header.  Assuming MASKS recipe is accurate because of MASK.FORCE");
+            return true;
+        }
+        psError(PS_ERR_UNKNOWN, true, "Unable to find MSKNUM in header.");
+        return false;
+    }
+
+    // Loop over the expected number of header mask names.  For each named mask value, there
+    // should be a pair of header keywords, one for the name and one for the value
+    char namekey[80];                   // Keyword name for symbolic name of mask entry
+    char valuekey[80];                  // Keyword name for value of mask entry
+    for (int i = 0; i < nMask; i++) {
+        snprintf(namekey,  64, "MSKNAM%02d", i);
+        snprintf(valuekey, 64, "MSKVAL%02d", i);
+
+        char *name = psMetadataLookupStr(&status, header, namekey);
+        if (!status || !name) {
+            psWarning("Unable to find header keyword %s when parsing mask", namekey);
+            continue;
+        }
+
+	psImageMaskType headerValue = psMetadataLookupImageMaskFromGeneric (&status, header, valuekey);
+	if (!status) {
+            psWarning("Failed to get mask value %s from header, skipping", valuekey);
+	    continue;
+	}	    
+
+	// since we may read multiple mask files, we need to warn (or error?) if any of the
+	// header mask values conflict with other header mask values; However, the original
+	// mask values from the recipe do not need to match the header values.
+
+	// when we add a header mask value, we will also add the NAME.ALREADY entry; check for
+	// the NAME.ALREADY entry to see if we have previously added this mask value from a
+	// header.
+
+        psString nameAlready = NULL;    // Name of key with ".ALREADY" added
+        psStringAppend(&nameAlready, "%s.ALREADY", name);
+        bool already = psMetadataLookupBool(&status, recipe, nameAlready); // Already read this one?
+
+	bool inRecipe = false;
+	psImageMaskType recipeValue = psMetadataLookupImageMaskFromGeneric (&inRecipe, recipe, name);
+	if (!inRecipe) {
+            psWarning("Mask value %s is not defined in the recipe", name);
+	}	    
+
+        if (already) {
+	    assert (inRecipe); // XXX makes no sense for NAME.ALREADY to be in without NAME
+            if (recipeValue != headerValue) {
+                psWarning("New mask header value does not match previously loaded entry: %x vs %x", headerValue, recipeValue);
+		psMetadataAddImageMask(recipe, PS_LIST_TAIL, name, PS_META_REPLACE, "Bitmask bit value", headerValue);
+		// XXX alternatively, error here
+            }
+        } else {
+            psMetadataAddBool(recipe, PS_LIST_TAIL, nameAlready, 0, "Already read this mask value", true);
+            psMetadataAddImageMask(recipe, PS_LIST_TAIL, name, PS_META_REPLACE, "Bitmask bit value", headerValue);
+        }
+
+        psFree(nameAlready);
+    }
+
+    return true;
+}
+
+// write the named mask bits to the header
+bool pmConfigMaskWriteHeader(const pmConfig *config, psMetadata *header)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_METADATA_NON_NULL(header, false);
+
+    pmConfigMaskRemoveHeaderKeywords(header, "MSKNAM");
+    pmConfigMaskRemoveHeaderKeywords(header, "MSKVAL");
+    if (psMetadataLookup(header, "MSKNUM")) {
+        psMetadataRemoveKey(header, "MSKNUM");
+    }
+
+    char namekey[80];
+    char valuekey[80];
+
+    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
+    if (!recipe) {
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
+        return false;
+    }
+
+    int nMask = 0;
+
+    psMetadataIterator *iter = psMetadataIteratorAlloc(recipe, PS_LIST_HEAD, NULL); // Iterator
+    psMetadataItem *item;               // Item from iteration
+    while ((item = psMetadataGetAndIncrement(iter))) {
+
+	// XXX this would give a false positive for mask which include '.ALREADY' in their names
+	char *ptr = strstr (item->name, ".ALREADY");
+	if (ptr) continue;
+
+	psU64 fullValue = 0;
+        switch (item->type) {
+	  case PS_DATA_U8:
+	    fullValue = item->data.U8;
+	    break;
+	  case PS_DATA_U16:
+	    fullValue = item->data.U16;
+	    break;
+	  case PS_DATA_U32:
+	    fullValue = item->data.U32;
+	    break;
+	  case PS_DATA_U64:
+	    fullValue = item->data.U64;
+	    break;
+	  default:
+            psWarning("mask recipe entry %s is not a bit value\n", item->name);
+            continue;
+        }
+	assert (fullValue <= PS_MAX_IMAGE_MASK_TYPE); // this should have been asserted on read...
+
+        snprintf(namekey,  64, "MSKNAM%02d", nMask);
+        snprintf(valuekey, 64, "MSKVAL%02d", nMask);
+
+        psMetadataAddStr(header, PS_LIST_TAIL, namekey, 0, "Bitmask bit name", item->name);
+        psMetadataAddImageMask(header, PS_LIST_TAIL, valuekey, 0, "Bitmask bit value", fullValue);
+        nMask++;
+    }
+    psFree(iter);
+
+    psMetadataAddS32(header, PS_LIST_TAIL, "MSKNUM", 0, "Bitmask bit count", nMask);
+    return true;
+}
+
+
+bool pmConfigMaskSetBits(psImageMaskType *outMaskValue, psImageMaskType *outMarkValue, const pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
+    if (!recipe) {
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
+        return false;
+    }
+
+    bool status = pmConfigMaskSetInMetadata(outMaskValue, outMarkValue, recipe);
+    return status;
+}
+
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // FPA version of mask functions.  These are not ready to go yet.
@@ -187,12 +426,48 @@
 
 #if 0
-bool pmFPAMaskSetValues(psMaskType *outMaskValue, psMaskType *outMarkValue, pmFPA *fpa)
-{
+
+bool pmFPAMaskWriteHeader(psMetadata *header, const pmFPA *fpa)
+{
+    PS_ASSERT_METADATA_NON_NULL(header, false);
     PS_ASSERT_PTR_NON_NULL(fpa, false);
 
+    // clear out the header of the associated keywords:
+    pmConfigMaskRemoveHeaderKeywords(header, "MSKNAM");
+    pmConfigMaskRemoveHeaderKeywords(header, "MSKVAL");
+    if (psMetadataLookup(header, "MSKNUM")) {
+        psMetadataRemoveKey(header, "MSKNUM");
+    }
+
+    char namekey[80], valuekey[80];     // Mask name and mask value header keywords
+    int numMask = 0;                    // Number of mask entries
+
+    psMetadataIterator *iter = psMetadataIteratorAlloc(fpa->masks, PS_LIST_HEAD, NULL); // Iterator
+    psMetadataItem *item;               // Item from iteration
+    while ((item = psMetadataGetAndIncrement(iter))) {
+        if (item->type != PS_TYPE_IMAGE_MASK) {
+            psWarning("mask recipe entry %s is not of a mask type (%x)", item->name, item->type);
+            continue;
+        }
+
+        snprintf(namekey,  64, "MSKNAM%02d", numMask);
+        snprintf(valuekey, 64, "MSKVAL%02d", numMask);
+
+        psMetadataAddStr(header, PS_LIST_TAIL, namekey, 0, "Bitmask bit name", item->name);
+        psMetadataAddImageMask(header, PS_LIST_TAIL, valuekey, 0, "Bitmask bit value", item->data.PS_TYPE_IMAGE_MASK_DATA);
+        numMask++;
+    }
+    psFree(iter);
+
+    return psMetadataAddS32(header, PS_LIST_TAIL, "MSKNUM", 0, "Number of named mask entries", numMask);
+}
+
+bool pmFPAMaskSetValues(psImageMaskType *outMaskValue, psImageMaskType *outMarkValue, pmFPA *fpa)
+{
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+
     return maskSetValues(outMaskValue, outMarkValue, fpa->masks);
 }
 
-psMaskType pmFPAMaskGet(const pmFPA *fpa, const char *masks, const pmConfig *config)
+psImageMaskType pmFPAMaskGet(const pmFPA *fpa, const char *masks, const pmConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(fpa, 0);
@@ -201,10 +476,10 @@
 
     if (fpa->masks) {
-        return maskGet(fpa->masks, masks);
+        return pmConfigMaskGetFromMetadata(fpa->masks, masks);
     }
     return pmConfigMaskGet(masks, config);
 }
 
-bool pmFPAMaskSet(pmFPA *fpa, const char *maskName, psMaskType maskValue)
+bool pmFPAMaskSet(pmFPA *fpa, const char *maskName, psImageMaskType maskValue)
 {
     PS_ASSERT_PTR_NON_NULL(fpa, 0);
@@ -214,5 +489,5 @@
         fpa->masks = psMetadataAlloc();
     }
-    return psMetadataAddU8(fpa->masks, PS_LIST_TAIL, maskName, PS_META_REPLACE, NULL, maskValue);
+    return psMetadataAddImageMask(fpa->masks, PS_LIST_TAIL, maskName, PS_META_REPLACE, NULL, maskValue);
 }
 
@@ -250,5 +525,5 @@
             continue;
         }
-        psU8 bit = psMetadataLookupU8(&mdok, header, valuekey);
+        psImageMaskType bit = psMetadataLookupImageMask(&mdok, header, valuekey);
         if (!mdok) {
             psWarning("Unable to find header keyword %s when parsing mask", namekey);
@@ -260,12 +535,12 @@
         psMetadataItem *item = psMetadataLookup(fpa->masks, name); // Item in recipe with current value
         if (item) {
-            psAssert(item->type == PS_TYPE_MASK, "Mask entry %s is not of a mask type (%x)",
+            psAssert(item->type == PS_TYPE_IMAGE_MASK, "Mask entry %s is not of a mask type (%x)",
                      name, item->type);
-            if (item->data.PS_TYPE_MASK_DATA != bit) {
+            if (item->data.PS_TYPE_IMAGE_MASK_DATA != bit) {
                 psWarning("New mask entry %s doesn't match previously loaded entry: %x vs %x",
-                          name, bit, item->data.PS_TYPE_MASK_DATA);
+                          name, bit, item->data.PS_TYPE_IMAGE_MASK_DATA);
             }
         } else {
-            psMetadataAddU8(fpa->masks, PS_LIST_TAIL, name, 0, NULL, bit);
+            psMetadataAddImageMask(fpa->masks, PS_LIST_TAIL, name, 0, NULL, bit);
         }
     }
@@ -281,11 +556,11 @@
     psMetadataItem *item;               // Item from iteration
     while ((item = psMetadataGetAndIncrement(iter))) {
-        if (item->type != PS_TYPE_MASK) {
+        if (item->type != PS_TYPE_IMAGE_MASK) {
             psWarning("Recipe mask entry %s is not of a mask type (%x)", item->name, item->type);
             continue;
         }
         if (!psMetadataLookup(fpa->masks, item->name)) {
-            psMetadataAddU8(fpa->masks, PS_LIST_TAIL, item->name, 0, item->comment,
-                            item->data.PS_TYPE_MASK_DATA);
+            psMetadataAddImageMask(fpa->masks, PS_LIST_TAIL, item->name, 0, item->comment,
+                            item->data.PS_TYPE_IMAGE_MASK_DATA);
         }
     }
@@ -294,220 +569,3 @@
     return true;
 }
-
-
-bool pmFPAMaskWriteHeader(psMetadata *header, const pmFPA *fpa)
-{
-    PS_ASSERT_METADATA_NON_NULL(header, false);
-    PS_ASSERT_PTR_NON_NULL(fpa, false);
-
-    maskRemoveHeader(header, "MSKNAM");
-    maskRemoveHeader(header, "MSKVAL");
-    if (psMetadataLookup(header, "MSKNUM")) {
-        psMetadataRemoveKey(header, "MSKNUM");
-    }
-
-    char namekey[80], valuekey[80];     // Mask name and mask value header keywords
-    int numMask = 0;                    // Number of mask entries
-
-    psMetadataIterator *iter = psMetadataIteratorAlloc(fpa->masks, PS_LIST_HEAD, NULL); // Iterator
-    psMetadataItem *item;               // Item from iteration
-    while ((item = psMetadataGetAndIncrement(iter))) {
-        if (item->type != PS_TYPE_MASK) {
-            psWarning("mask recipe entry %s is not of a mask type (%x)", item->name, item->type);
-            continue;
-        }
-
-        snprintf(namekey,  64, "MSKNAM%02d", numMask);
-        snprintf(valuekey, 64, "MSKVAL%02d", numMask);
-
-        psMetadataAddStr(header, PS_LIST_TAIL, namekey, 0, "Bitmask bit name", item->name);
-        psMetadataAddU8(header, PS_LIST_TAIL, valuekey, 0, "Bitmask bit value", item->data.PS_TYPE_MASK_DATA);
-        numMask++;
-    }
-    psFree(iter);
-
-    return psMetadataAddS32(header, PS_LIST_TAIL, "MSKNUM", 0, "Number of named mask entries", numMask);
-}
-
 #endif
-
-
-psMaskType pmConfigMaskGet(const char *masks, const pmConfig *config)
-{
-    psAssert(config, "Require configuration");
-    PS_ASSERT_STRING_NON_EMPTY(masks, 0);
-
-    bool mdok;                          // Status of MD lookup
-    psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, "MASKS"); // The recipe
-    if (!recipe) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
-        return 0;
-    }
-    return maskGet(recipe, masks);
-}
-
-
-bool pmConfigMaskSet(const pmConfig *config, const char *maskName, psMaskType maskValue)
-{
-    psAssert(config, "Require configuration");
-    PS_ASSERT_STRING_NON_EMPTY(maskName, false);
-
-    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
-    if (!recipe) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
-        return false;
-    }
-
-    return psMetadataAddU8(recipe, PS_LIST_TAIL, maskName, PS_META_REPLACE, NULL, maskValue);
-}
-
-
-// replace the named masks in the recipe with values in the header:
-// replace only the names in the header in the recipe
-bool pmConfigMaskReadHeader(pmConfig *config, const psMetadata *header)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-    PS_ASSERT_METADATA_NON_NULL(header, false);
-
-    bool status = false;
-
-    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
-    if (!recipe) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
-        return false;
-    }
-
-    // MASK.VALUE and MARK.VALUE aren't usually set in the recipe, but may be set in the header: create fake
-    // versions so that it won't complain later
-    if (!psMetadataLookup(recipe, "MASK.VALUE")) {
-        psMetadataAddU8(recipe, PS_LIST_TAIL, "MASK.VALUE", 0, "Bits to mask", 0);
-    }
-    if (!psMetadataLookup(recipe, "MARK.VALUE")) {
-        psMetadataAddU8(recipe, PS_LIST_TAIL, "MARK.VALUE", 0, "Bits for marking", 0);
-    }
-
-    int nMask = psMetadataLookupS32(&status, header, "MSKNUM");
-    if (!status) {
-        if (psMetadataLookupBool(&status, config->camera, "MASK.FORCE")) {
-            psWarning("No mask values in header.  Assuming MASKS recipe is accurate because of MASK.FORCE");
-            return true;
-        }
-        psError(PS_ERR_UNKNOWN, true, "Unable to find MSKNUM in header.");
-        return false;
-    }
-
-    char namekey[80];                   // Keyword name for symbolic name of mask entry
-    char valuekey[80];                  // Keyword name for value of mask entry
-    for (int i = 0; i < nMask; i++) {
-        snprintf(namekey,  64, "MSKNAM%02d", i);
-        snprintf(valuekey, 64, "MSKVAL%02d", i);
-
-        char *name = psMetadataLookupStr(&status, header, namekey);
-        if (!status || !name) {
-            psWarning("Unable to find header keyword %s when parsing mask", namekey);
-            continue;
-        }
-        psU8 bit = psMetadataLookupU8(&status, header, valuekey);
-        if (!status) {
-            psWarning("Unable to find header keyword %s when parsing mask", namekey);
-            continue;
-        }
-
-        // XXX validate that bit is a 2^n value?
-
-        psString nameAlready = NULL;    // Name of key with ".ALREADY" added
-        psStringAppend(&nameAlready, "%s.ALREADY", name);
-        bool already = psMetadataLookupBool(&status, recipe, nameAlready); // Already read this one?
-
-        psMetadataItem *item = psMetadataLookup(recipe, name); // Item in recipe with current value
-        if (item && item->type != PS_TYPE_MASK) {
-            psWarning("Mask recipe entry is not of a mask type (%x)", item->type);
-            item->type = PS_TYPE_MASK;
-        }
-
-        if (already) {
-            if (item && item->data.U8 != bit) {
-                psWarning("New mask recipe entry doesn't match previously loaded entry: %x vs %x",
-                          bit, item->data.U8);
-            }
-        } else {
-            psMetadataAddBool(recipe, PS_LIST_TAIL, nameAlready, 0, "Already read this mask value", true);
-        }
-
-        if (!item) {
-            psWarning("Mask recipe entry %s not in recipe\n", name);
-            psMetadataAddU8(recipe, PS_LIST_TAIL, name, 0, "Bitmask bit value", bit);
-        } else {
-            item->data.U8 = bit;
-        }
-
-        psFree(nameAlready);
-    }
-
-
-    return true;
-}
-
-
-
-// write the named mask bits to the header
-bool pmConfigMaskWriteHeader(const pmConfig *config, psMetadata *header)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-    PS_ASSERT_METADATA_NON_NULL(header, false);
-
-    maskRemoveHeader(header, "MSKNAM");
-    maskRemoveHeader(header, "MSKVAL");
-    if (psMetadataLookup(header, "MSKNUM")) {
-        psMetadataRemoveKey(header, "MSKNUM");
-    }
-
-    char namekey[80];
-    char valuekey[80];
-
-    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
-    if (!recipe) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
-        return false;
-    }
-
-    int nMask = 0;
-
-    psMetadataIterator *iter = psMetadataIteratorAlloc(recipe, PS_LIST_HEAD, NULL); // Iterator
-    psMetadataItem *item;               // Item from iteration
-    while ((item = psMetadataGetAndIncrement(iter))) {
-        if (strcmp(item->name + strlen(item->name) - strlen(".ALREADY"), ".ALREADY") == 0) {
-            continue;
-        }
-
-        if (item->type != PS_DATA_U8) {
-            psWarning("mask recipe entry %s is not a bit value\n", item->name);
-            continue;
-        }
-
-        snprintf(namekey,  64, "MSKNAM%02d", nMask);
-        snprintf(valuekey, 64, "MSKVAL%02d", nMask);
-
-        psMetadataAddStr(header, PS_LIST_TAIL, namekey, 0, "Bitmask bit name", item->name);
-        psMetadataAddU8(header, PS_LIST_TAIL, valuekey, 0, "Bitmask bit value", item->data.U8);
-        nMask++;
-    }
-    psFree(iter);
-
-    psMetadataAddS32(header, PS_LIST_TAIL, "MSKNUM", 0, "Bitmask bit count", nMask);
-    return true;
-}
-
-
-bool pmConfigMaskSetBits(psMaskType *outMaskValue, psMaskType *outMarkValue, const pmConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
-    if (!recipe) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
-        return false;
-    }
-
-    return maskSetValues(outMaskValue, outMarkValue, recipe);
-}
Index: /trunk/psModules/src/config/pmConfigMask.h
===================================================================
--- /trunk/psModules/src/config/pmConfigMask.h	(revision 21182)
+++ /trunk/psModules/src/config/pmConfigMask.h	(revision 21183)
@@ -4,6 +4,6 @@
  *  @author Paul Price, IfA
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-07-17 20:37:20 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
  */
@@ -20,12 +20,45 @@
 /// @{
 
+// structure to hold the properties of a mask value
+typedef struct {
+    char *badMaskName;			// name for "bad" (i.e., mask me please) pixels
+    char *fallbackName;			// Fallback name in case a bad mask name is not defined
+    psImageMaskType defaultMaskValue;	// Default value in case a bad mask name and its fallback are not defined
+    bool isBad;	// include this value as part of the MASK.VALUE entry (generically bad)
+} pmConfigMaskInfo;
+
+// pmConfigMaskSetInMetadata examines named mask values and set the bits for maskValue and
+// markValue.  Ensures that the below-named mask values are set, and calculates the mask value
+// to catch all of the mask values marked as 'bad'.  Supplies the fallback name if the primary
+// name is not found, or the default values if the fallback name is not found.
+bool pmConfigMaskSetInMetadata(psImageMaskType *outMaskValue, // Value of MASK.VALUE, returned
+			       psImageMaskType *outMarkValue, // Value of MARK.VALUE, returned
+			       psMetadata *source  // Source of mask bits
+  );
+
+
+// Get a mask value by name(s)
+psImageMaskType pmConfigMaskGetFromMetadata(psMetadata *source, // Source of masks
+					    const char *masks // Mask values to get
+  );
+
+
+// lookup an image mask value by name from a psMetadata, without requiring the entry to 
+// be of type psImageMaskType, but verifying that it will fit in psImageMaskType
+psImageMaskType psMetadataLookupImageMaskFromGeneric (bool *status, const psMetadata *md, const char *name);
+
+// Remove from the header keywords starting with the provided string
+int pmConfigMaskRemoveHeaderKeywords(psMetadata *header, // Header from which to remove keywords
+				     const char *start // Remove keywords that start with this string
+  );
+
 /// Return a mask value given a list of symbolic names
 ///
 /// The mask values are derived from the MASKS recipe
-psMaskType pmConfigMaskGet(const char *masks, ///< List of symbolic names, space/comma delimited
+psImageMaskType pmConfigMaskGet(const char *masks, ///< List of symbolic names, space/comma delimited
                            const pmConfig *config ///< Configuration
     );
 
-bool pmConfigMaskSet(const pmConfig *config, const char *maskName, psMaskType maskValue);
+bool pmConfigMaskSet(const pmConfig *config, const char *maskName, psImageMaskType maskValue);
 
 // replace the named masks in the recipe with values in the header:
@@ -36,5 +69,5 @@
 bool pmConfigMaskWriteHeader(const pmConfig *config, psMetadata *header);
 
-bool pmConfigMaskSetBits(psMaskType *outMaskValue, psMaskType *outMarkValue, const pmConfig *config);
+bool pmConfigMaskSetBits(psImageMaskType *outMaskValue, psImageMaskType *outMarkValue, const pmConfig *config);
 
 #endif
Index: /trunk/psModules/src/detrend/pmBias.c
===================================================================
--- /trunk/psModules/src/detrend/pmBias.c	(revision 21182)
+++ /trunk/psModules/src/detrend/pmBias.c	(revision 21183)
@@ -45,5 +45,5 @@
                 inImage->data.F32[i][j] -= subImage->data.F32[i+yOffset][j+xOffset];
                 if (inMask && subMask) {
-                    inMask->data.U8[i][j] |= subMask->data.U8[i+yOffset][j+xOffset];
+                    inMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] |= subMask->data.PS_TYPE_IMAGE_MASK_DATA[i+yOffset][j+xOffset];
                 }
             }
@@ -54,5 +54,5 @@
                 inImage->data.F32[i][j] -= subImage->data.F32[i+yOffset][j+xOffset] * scale;
                 if (inMask && subMask) {
-                    inMask->data.U8[i][j] |= subMask->data.U8[i+yOffset][j+xOffset];
+                    inMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] |= subMask->data.PS_TYPE_IMAGE_MASK_DATA[i+yOffset][j+xOffset];
                 }
             }
Index: /trunk/psModules/src/detrend/pmDark.c
===================================================================
--- /trunk/psModules/src/detrend/pmDark.c	(revision 21182)
+++ /trunk/psModules/src/detrend/pmDark.c	(revision 21183)
@@ -103,5 +103,5 @@
 {
     psArray *values = psArrayAlloc(inputs->n);
-    psVector *roMask = psVectorAlloc(inputs->n, PS_TYPE_U8); // Mask for bad readouts
+    psVector *roMask = psVectorAlloc(inputs->n, PS_TYPE_VECTOR_MASK); // Mask for bad readouts
     psVector *norm = normConcept ? psVectorAlloc(inputs->n, PS_TYPE_F32) : NULL; // Normalizations for each
     psVector *orders = psVectorAlloc(ordinates->n, PS_TYPE_U8); // Orders for each concept
@@ -121,5 +121,5 @@
         if (!ordinateLookup(&normValue, &inRange, normConcept, false, NAN, NAN, readout)) {
             psWarning("Unable to find value of %s for readout %d", normConcept, i);
-            roMask->data.U8[i] = 0xff;
+            roMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff;
             norm->data.F32[i] = NAN;
             numBadInputs++;
@@ -128,5 +128,5 @@
         if (normValue == 0.0) {
             psWarning("Normalisation value (%s) for readout %d is zero", normConcept, i);
-            roMask->data.U8[i] = 0xff;
+            roMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff;
             norm->data.F32[i] = NAN;
             numBadInputs++;
@@ -151,5 +151,5 @@
         for (int j = 0; j < inputs->n; j++) {
             psVector *val = values->data[j]; // Value vector for readout
-            if (roMask->data.U8[j]) {
+            if (roMask->data.PS_TYPE_VECTOR_MASK_DATA[j]) {
                 val->data.F32[i] = NAN;
                 continue;
@@ -159,5 +159,5 @@
             float value = NAN;          // Value of ordinate
             if (!ordinateLookup(&value, &inRange, ord->name, ord->scale, ord->min, ord->max, readout)) {
-                roMask->data.U8[j] = 0xff;
+                roMask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xff;
                 val->data.F32[i] = NAN;
                 numBadInputs++;
@@ -165,5 +165,5 @@
             }
             if (!inRange) {
-                roMask->data.U8[j] = 0xff;
+                roMask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xff;
                 val->data.F32[i] = NAN;
                 numBadInputs++;
@@ -263,5 +263,5 @@
 
 // do the combine work for this portion of the output (range is set by input data)
-bool pmDarkCombine(pmCell *output, const psArray *inputs, int iter, float rej, psMaskType maskVal)
+bool pmDarkCombine(pmCell *output, const psArray *inputs, int iter, float rej, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(output, false);
@@ -314,5 +314,5 @@
     // Iterate over pixels, fitting polynomial
     psVector *pixels = psVectorAlloc(inputs->n, PS_TYPE_F32); // Stack of pixels
-    psVector *mask   = psVectorAlloc(inputs->n, PS_TYPE_MASK); // Mask for stack
+    psVector *mask   = psVectorAlloc(inputs->n, PS_TYPE_VECTOR_MASK); // Mask for stack
     for (int i = minInputRows; i < maxInputRows; i++) {
         int yOut = i - outReadout->row0; // y position on output readout
@@ -330,6 +330,6 @@
             psVectorInit(mask, 0);
             for (int r = 0; r < inputs->n; r++) {
-                if (roMask->data.U8[r]) {
-                    mask->data.PS_TYPE_MASK_DATA[r] = 0xff;
+                if (roMask->data.PS_TYPE_VECTOR_MASK_DATA[r]) {
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[r] = 0xff;
                     continue;
                 }
@@ -343,10 +343,10 @@
                 }
                 if (readout->mask) {
-                    mask->data.PS_TYPE_MASK_DATA[r] = readout->mask->data.PS_TYPE_MASK_DATA[yIn][xIn];
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[r] = (readout->mask->data.PS_TYPE_IMAGE_MASK_DATA[yIn][xIn] & maskVal);
                 }
 
             }
 
-            if (!psPolynomialMDClipFit(poly, pixels, NULL, mask, maskVal, values, iter, rej)) {
+            if (!psPolynomialMDClipFit(poly, pixels, NULL, mask, 0xff, values, iter, rej)) {
                 psErrorClear();         // Nothing we can do about it
                 psVectorInit(poly->coeff, NAN);
@@ -376,5 +376,5 @@
     const psVector *values = job->args->data[3]; // Values for each ordinate
 
-    psMaskType bad = PS_SCALAR_VALUE(job->args->data[4], U8); // Mask value to give bad pixels
+    psImageMaskType bad = PS_SCALAR_VALUE(job->args->data[4], PS_TYPE_IMAGE_MASK_DATA); // Mask value to give bad pixels
     bool doNorm    = PS_SCALAR_VALUE(job->args->data[5], U8); // Normalise values?
     float norm     = PS_SCALAR_VALUE(job->args->data[6], F32); // Value by which to normalise
@@ -386,5 +386,5 @@
 
 bool pmDarkApplyScan(pmReadout *readout, const pmCell *dark, const psVector *orders, const psVector *values,
-                     psMaskType bad, bool doNorm, float norm, int rowStart, int rowStop)
+                     psImageMaskType bad, bool doNorm, float norm, int rowStart, int rowStop)
 {
     int numCols = readout->image->numCols;
@@ -405,5 +405,5 @@
             readout->image->data.F32[y][x] -= value;
             if (readout->mask && !isfinite(value)) {
-                readout->mask->data.PS_TYPE_MASK_DATA[y][x] = bad;
+                readout->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = bad;
             }
         }
@@ -414,5 +414,5 @@
 }
 
-bool pmDarkApply(pmReadout *readout, pmCell *dark, psMaskType bad)
+bool pmDarkApply(pmReadout *readout, pmCell *dark, psImageMaskType bad)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -424,5 +424,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);
     }
     int numTerms = dark->readouts->n;   // Number of polynomial terms
@@ -496,5 +496,5 @@
             psArrayAdd(job->args, 1, orders);
             psArrayAdd(job->args, 1, values);
-            PS_ARRAY_ADD_SCALAR(job->args, bad, PS_TYPE_MASK);
+            PS_ARRAY_ADD_SCALAR(job->args, bad, PS_TYPE_IMAGE_MASK);
             PS_ARRAY_ADD_SCALAR(job->args, doNorm, PS_TYPE_U8);
             PS_ARRAY_ADD_SCALAR(job->args, norm, PS_TYPE_F32);
Index: /trunk/psModules/src/detrend/pmDark.h
===================================================================
--- /trunk/psModules/src/detrend/pmDark.h	(revision 21182)
+++ /trunk/psModules/src/detrend/pmDark.h	(revision 21183)
@@ -37,5 +37,5 @@
                    int iter,            // Number of rejection iterations
                    float rej,           // Rejection threshold (standard deviations)
-                   psMaskType maskVal   // Value to mask
+                   psImageMaskType maskVal   // Value to mask
     );
 
@@ -49,5 +49,5 @@
                      const psVector *orders, // Polynomial orders for each ordinate
                      const psVector *values, // Values for each ordinate
-                     psMaskType bad,    // Value to give bad pixels
+                     psImageMaskType bad,    // Value to give bad pixels
                      bool doNorm,       // Normalise values?
                      float norm,        // Value by which to normalise
@@ -58,5 +58,5 @@
 bool pmDarkApply(pmReadout *readout,    // Readout to which to apply dark
                  pmCell *dark,    // Dark to apply
-                 psMaskType bad         // Mask value to give bad pixels
+                 psImageMaskType bad         // Mask value to give bad pixels
     );
 
Index: /trunk/psModules/src/detrend/pmFlatField.c
===================================================================
--- /trunk/psModules/src/detrend/pmFlatField.c	(revision 21182)
+++ /trunk/psModules/src/detrend/pmFlatField.c	(revision 21183)
@@ -22,5 +22,5 @@
     const psImage *flatMask  = job->args->data[3]; // Flat-field mask
 
-    psMaskType badFlat = PS_SCALAR_VALUE(job->args->data[4],U8);
+    psImageMaskType badFlat = PS_SCALAR_VALUE(job->args->data[4],PS_TYPE_IMAGE_MASK_DATA);
     int xOffset        = PS_SCALAR_VALUE(job->args->data[5],S32);
     int yOffset        = PS_SCALAR_VALUE(job->args->data[6],S32);
@@ -38,7 +38,7 @@
             ps##TYPE flatValue = flatImage->data.TYPE[j + yOffset][i + xOffset]; \
             if (!isfinite(flatValue) || flatValue <= 0.0 || \
-                (flatMask && flatMask->data.U8[j + yOffset][i + xOffset])) { \
+                (flatMask && flatMask->data.PS_TYPE_IMAGE_MASK_DATA[j + yOffset][i + xOffset])) { \
                 if (inMask) { \
-                    inMask->data.PS_TYPE_MASK_DATA[j][i] |= badFlat; \
+                    inMask->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= badFlat; \
                 } \
                 inImage->data.TYPE[j][i] = SPECIAL; \
@@ -51,5 +51,5 @@
 
 bool pmFlatFieldScan(psImage *inImage, psImage *inMask, const psImage *flatImage, const psImage *flatMask,
-                     psMaskType badFlat, int xOffset, int yOffset, int rowStart, int rowStop)
+                     psImageMaskType badFlat, int xOffset, int yOffset, int rowStart, int rowStop)
 {
     switch (inImage->type.type) {
@@ -72,5 +72,5 @@
 }
 
-bool pmFlatField(pmReadout *in, const pmReadout *flat, psMaskType badFlat)
+bool pmFlatField(pmReadout *in, const pmReadout *flat, psImageMaskType badFlat)
 {
     PS_ASSERT_PTR_NON_NULL(in, false);
@@ -81,10 +81,10 @@
     PS_ASSERT_IMAGE_NON_EMPTY(flat->image, false);
     if (in->mask) {
-        PS_ASSERT_IMAGE_TYPE(in->mask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(in->mask, PS_TYPE_IMAGE_MASK, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(in->mask, in->image, false);
     }
     PS_ASSERT_IMAGE_TYPE(flat->image, in->image->type.type, false);
     if (flat->mask) {
-        PS_ASSERT_IMAGE_TYPE(flat->mask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(flat->mask, PS_TYPE_IMAGE_MASK, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(flat->mask, flat->image, false);
     }
@@ -148,5 +148,5 @@
           psArrayAdd(job->args, 1, flatImage);
           psArrayAdd(job->args, 1, flatMask);
-          PS_ARRAY_ADD_SCALAR(job->args, badFlat, PS_TYPE_U8);
+          PS_ARRAY_ADD_SCALAR(job->args, badFlat, PS_TYPE_IMAGE_MASK);
           PS_ARRAY_ADD_SCALAR(job->args, xOffset, PS_TYPE_S32);
           PS_ARRAY_ADD_SCALAR(job->args, yOffset, PS_TYPE_S32);
Index: /trunk/psModules/src/detrend/pmFlatField.h
===================================================================
--- /trunk/psModules/src/detrend/pmFlatField.h	(revision 21182)
+++ /trunk/psModules/src/detrend/pmFlatField.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-09-09 04:10:14 $
+ * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004-2006 Institute for Astronomy, University of Hawaii
  */
@@ -25,5 +25,5 @@
 bool pmFlatField(pmReadout *in,         ///< Readout with input image
                  const pmReadout *flat,  ///< Readout with flat image
-                 psMaskType badFlat     ///< Mask value to give bad flat pixels
+                 psImageMaskType badFlat     ///< Mask value to give bad flat pixels
                 );
 
@@ -38,5 +38,5 @@
     const psImage *flatImage,           ///< Flat-field image
     const psImage *flatMask,            ///< Flat-field mask
-    psMaskType badFlag,                 ///< Mask value to give bad pixels
+    psImageMaskType badFlag,                 ///< Mask value to give bad pixels
     int xOffset, int yOffset,           ///< Offset between input and flat-field
     int rowStart, int rowStop           ///< Scan range
Index: /trunk/psModules/src/detrend/pmFlatNormalize.c
===================================================================
--- /trunk/psModules/src/detrend/pmFlatNormalize.c	(revision 21182)
+++ /trunk/psModules/src/detrend/pmFlatNormalize.c	(revision 21183)
@@ -9,4 +9,6 @@
 
 #include "pmFlatNormalize.h"
+
+// XXX this function should take the abstract mask names and set bad values in a more precise way
 
 // I'm not sure that many many iterations are required, but rather suspect that the system converges within a
@@ -55,9 +57,9 @@
     // Take the logarithms
     psImage *flux = psImageCopy(NULL, bgMatrix, PS_TYPE_F32); // Copy of the input flux levels matrix
-    psImage *fluxMask = psImageAlloc(numChips, numExps, PS_TYPE_U8); // Mask for bad measurements
+    psImage *fluxMask = psImageAlloc(numChips, numExps, PS_TYPE_IMAGE_MASK); // Mask for bad measurements
     psImageInit(fluxMask, 0);
-    psVector *gainMask = psVectorAlloc(numChips, PS_TYPE_U8); // Mask for bad gains
+    psVector *gainMask = psVectorAlloc(numChips, PS_TYPE_VECTOR_MASK); // Mask for bad gains
     psVectorInit(gainMask, 0);
-    psVector *expMask = psVectorAlloc(numExps, PS_TYPE_U8); // Mask for bad exposures
+    psVector *expMask = psVectorAlloc(numExps, PS_TYPE_VECTOR_MASK); // Mask for bad exposures
     psVectorInit(expMask, 0);
     for (int i = 0; i < numChips; i++) {
@@ -75,5 +77,5 @@
             } else {
                 // Blank out this measurement
-                fluxMask->data.U8[j][i] = 1;
+                fluxMask->data.PS_TYPE_IMAGE_MASK_DATA[j][i] = 1;
                 flux->data.F32[j][i] = NAN;
             }
@@ -90,5 +92,5 @@
         int numFluxes = 0;              // Number of fluxes
         for (int i = 0; i < numExps; i++) {
-            if (expMask->data.U8[i]) {
+            if (expMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
                 psTrace("psModules.detrend", 7, "Flux for exposure %d is masked.\n", i);
                 continue;
@@ -98,5 +100,5 @@
             int number = 0;             // Number of chips contributing
             for (int j = 0; j < numChips; j++) {
-                if (!gainMask->data.U8[j] && !fluxMask->data.U8[i][j]) {
+                if (!gainMask->data.PS_TYPE_VECTOR_MASK_DATA[j] && !fluxMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j]) {
                     sum += flux->data.F32[i][j] - chipGains->data.F32[j];
                     number++;
@@ -106,5 +108,5 @@
                 expFluxes->data.F32[i] = sum / (float)number;
             } else {
-                expMask->data.U8[i] = 1;
+                expMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 1;
                 expFluxes->data.F32[i] = NAN;
             }
@@ -116,5 +118,5 @@
         int numGains = 0;               // Number of gains
         for (int i = 0; i < numChips; i++) {
-            if (gainMask->data.U8[i]) {
+            if (gainMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
                 continue;
             }
@@ -122,5 +124,5 @@
             int number = 0;             // Numer of sources contributing
             for (int j = 0; j < numExps; j++) {
-                if (!fluxMask->data.U8[j][i]) {
+                if (!fluxMask->data.PS_TYPE_IMAGE_MASK_DATA[j][i]) {
                     sum += flux->data.F32[j][i] - expFluxes->data.F32[j];
                     number++;
@@ -130,5 +132,5 @@
                 chipGains->data.F32[i] = sum / (float)number;
             } else {
-                gainMask->data.U8[i] = 1;
+                gainMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 1;
                 chipGains->data.F32[i] = NAN;
             }
@@ -144,5 +146,5 @@
             diff = 0.0;
             for (int i = 0; i < numChips; i++) {
-                if (gainMask->data.U8[i]) {
+                if (gainMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
                     continue;
                 }
@@ -151,5 +153,5 @@
             }
             for (int i = 0; i < numExps; i++) {
-                if (expMask->data.U8[i]) {
+                if (expMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
                     continue;
                 }
@@ -171,10 +173,10 @@
     // Un-log the vectors
     for (int i = 0; i < numChips; i++) {
-        if (!gainMask->data.U8[i]) {
+        if (!gainMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
             chipGains->data.F32[i] = expf(chipGains->data.F32[i]);
         }
     }
     for (int i = 0; i < numExps; i++) {
-        if (!expMask->data.U8[i]) {
+        if (!expMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
             expFluxes->data.F32[i] = expf(expFluxes->data.F32[i]);
         }
Index: /trunk/psModules/src/detrend/pmFringeStats.c
===================================================================
--- /trunk/psModules/src/detrend/pmFringeStats.c	(revision 21182)
+++ /trunk/psModules/src/detrend/pmFringeStats.c	(revision 21183)
@@ -70,5 +70,5 @@
     fringe->x = psVectorRecycle(fringe->x, fringe->nRequested, PS_TYPE_F32);
     fringe->y = psVectorRecycle(fringe->y, fringe->nRequested, PS_TYPE_F32);
-    fringe->mask = psVectorRecycle(fringe->mask, fringe->nRequested, PS_TYPE_U8);
+    fringe->mask = psVectorRecycle(fringe->mask, fringe->nRequested, PS_TYPE_VECTOR_MASK);
     fringe->x->n = fringe->y->n = fringe->mask->n = fringe->nRequested;
     psVectorInit(fringe->mask, 0);
@@ -115,5 +115,5 @@
     if (mask) {
         PS_ASSERT_VECTOR_NON_NULL(mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
         PS_ASSERT_VECTOR_SIZE(mask, (long)numRows, false);
     }
@@ -142,9 +142,9 @@
         psMetadataAddF32(row, PS_LIST_TAIL, "x", PS_META_REPLACE, "Fringe position in x", x->data.F32[i]);
         psMetadataAddF32(row, PS_LIST_TAIL, "y", PS_META_REPLACE, "Fringe position in y", y->data.F32[i]);
-        psU8 maskValue = 0;
-        if (mask && mask->data.U8[i]) {
+        psVectorMaskType maskValue = 0;
+        if (mask && mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
             maskValue = 0xff;
         }
-        psMetadataAddU8(row, PS_LIST_TAIL, "mask", PS_META_REPLACE, "Mask", maskValue);
+        psMetadataAddVectorMask(row, PS_LIST_TAIL, "mask", PS_META_REPLACE, "Mask", maskValue);
         table->data[i] = row;
     }
@@ -207,11 +207,11 @@
     psVector *x = psVectorAlloc(numRows, PS_TYPE_F32); // x position
     psVector *y = psVectorAlloc(numRows, PS_TYPE_F32); // y position
-    psVector *mask = psVectorAlloc(numRows, PS_TYPE_U8); // mask
+    psVector *mask = psVectorAlloc(numRows, PS_TYPE_VECTOR_MASK); // mask
     regions->x = x;
     regions->y = y;
     regions->mask = mask;
 
-    #define READ_REGIONS_ROW(VECTOR, TYPE, NAME, DESCRIPTION) \
-    VECTOR->data.TYPE[i] = psMetadataLookup##TYPE(&mdok, row, NAME); \
+    #define READ_REGIONS_ROW(VECTOR, TYPE, DATATYPE, NAME, DESCRIPTION) \
+    VECTOR->data.DATATYPE[i] = psMetadataLookup##TYPE(&mdok, row, NAME); \
     if (!mdok) { \
         psError(PS_ERR_IO, true, "Unable to find " #DESCRIPTION " .\n"); \
@@ -224,7 +224,7 @@
     for (long i = 0; i < numRows; i++) {
         psMetadata *row = table->data[i]; // Table row
-        READ_REGIONS_ROW(x, F32, "x", "x position");
-        READ_REGIONS_ROW(y, F32, "y", "y position");
-        READ_REGIONS_ROW(mask, U8, "mask", "mask");
+        READ_REGIONS_ROW(x, F32, F32, "x", "x position");
+        READ_REGIONS_ROW(y, F32, F32, "y", "y position");
+        READ_REGIONS_ROW(mask, VectorMask, PS_TYPE_VECTOR_MASK_DATA, "mask", "mask");
     }
     psFree(table);
@@ -259,5 +259,5 @@
 }
 
-pmFringeStats *pmFringeStatsMeasure(pmFringeRegions *fringe, const pmReadout *readout, psMaskType maskVal)
+pmFringeStats *pmFringeStatsMeasure(pmFringeRegions *fringe, const pmReadout *readout, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(fringe, NULL);
@@ -490,5 +490,5 @@
     newRegions->x = psVectorAlloc(numPoints, PS_TYPE_F32);
     newRegions->y = psVectorAlloc(numPoints, PS_TYPE_F32);
-    newRegions->mask = psVectorAlloc(numPoints, PS_TYPE_U8);
+    newRegions->mask = psVectorAlloc(numPoints, PS_TYPE_VECTOR_MASK);
     pmFringeStats *newStats = pmFringeStatsAlloc(newRegions); // The new list of statistics
 
@@ -500,5 +500,5 @@
         memcpy(&newRegions->x->data.F32[offset], regions->x->data.F32, regions->x->n * sizeof(psF32));
         memcpy(&newRegions->y->data.F32[offset], regions->y->data.F32, regions->y->n * sizeof(psF32));
-        memcpy(&newRegions->mask->data.U8[offset], regions->mask->data.U8, regions->mask->n * sizeof(psU8));
+        memcpy(&newRegions->mask->data.PS_TYPE_VECTOR_MASK_DATA[offset], regions->mask->data.PS_TYPE_VECTOR_MASK_DATA, regions->mask->n * sizeof(psVectorMaskType));
         memcpy(&newStats->f->data.F32[offset], fringe->f->data.F32, fringe->f->n * sizeof(psF32));
         memcpy(&newStats->df->data.F32[offset], fringe->df->data.F32, fringe->df->n * sizeof(psF32));
@@ -549,5 +549,5 @@
     if (mask) {
         PS_ASSERT_VECTOR_NON_NULL(mask, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
         PS_ASSERT_VECTOR_SIZE(mask, (long)numRows, false);
     }
@@ -580,6 +580,6 @@
         psMetadataAddF32(row, PS_LIST_TAIL, "x", PS_META_REPLACE, "Fringe position in x", x->data.F32[i]);
         psMetadataAddF32(row, PS_LIST_TAIL, "y", PS_META_REPLACE, "Fringe position in y", y->data.F32[i]);
-        psU8 maskValue = 0;             // Mask value
-        if (mask && mask->data.U8[i]) {
+        psVectorMaskType maskValue = 0;             // Mask value
+        if (mask && mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
             maskValue = 0xff;
         }
@@ -601,5 +601,5 @@
         psFree(df);
 
-        psMetadataAddU8(row, PS_LIST_TAIL, "mask", PS_META_REPLACE, "Mask", maskValue);
+        psMetadataAddVectorMask(row, PS_LIST_TAIL, "mask", PS_META_REPLACE, "Mask", maskValue);
         table->data[i] = row;
     }
@@ -648,5 +648,5 @@
     psVector *x = psVectorAlloc(numRows, PS_TYPE_F32); // x position
     psVector *y = psVectorAlloc(numRows, PS_TYPE_F32); // y position
-    psVector *mask = psVectorAlloc(numRows, PS_TYPE_U8); // mask
+    psVector *mask = psVectorAlloc(numRows, PS_TYPE_VECTOR_MASK); // mask
     regions->x = x;
     regions->y = y;
@@ -656,7 +656,7 @@
     psArray *fringes = NULL; // Array of fringes, to return
 
-    #define READ_FRINGES_VECTOR_ROW(VECTOR, TYPE, NAME, DESCRIPTION) \
+    #define READ_FRINGES_VECTOR_ROW(VECTOR, TYPE, DATATYPE, NAME, DESCRIPTION) \
     { \
-        VECTOR->data.TYPE[i] = psMetadataLookup##TYPE(&mdok, row, NAME); \
+        VECTOR->data.DATATYPE[i] = psMetadataLookup##TYPE(&mdok, row, NAME); \
         if (!mdok) { \
             psError(PS_ERR_IO, true, "Unable to find " #DESCRIPTION " for row %ld.\n", i); \
@@ -686,10 +686,11 @@
     }
 
+    // XXX : need to extend this to support arbitrary types for the vectors on disk
     // Translate the table into vectors
     for (long i = 0; i < numRows; i++) {
         psMetadata *row = table->data[i]; // Table row
-        READ_FRINGES_VECTOR_ROW(x, F32, "x", "x position");
-        READ_FRINGES_VECTOR_ROW(y, F32, "y", "y position");
-        READ_FRINGES_VECTOR_ROW(mask, U8, "mask", "mask");
+        READ_FRINGES_VECTOR_ROW(x, F32, F32, "x", "x position");
+        READ_FRINGES_VECTOR_ROW(y, F32, F32, "y", "y position");
+        READ_FRINGES_VECTOR_ROW(mask, VectorMask, PS_TYPE_VECTOR_MASK_DATA, "mask", "mask");
         READ_FRINGES_ARRAY_ROW(f, F32, "f", "fringe measurement");
         READ_FRINGES_ARRAY_ROW(df, F32, "df", "fringe error");
@@ -782,5 +783,5 @@
             double matrix = 0.0;        // The matrix sum
             for (int k = 0; k < numPoints; k++) {
-                if (!mask->data.U8[k]) {
+                if (!mask->data.PS_TYPE_VECTOR_MASK_DATA[k]) {
                     psF32 f1 = (fringe1) ? fringe1->data.F32[k] : 1.0; // Contribution from i fringe
                     psF32 f2 = (fringe2) ? fringe2->data.F32[k] : 1.0; // Contribution from j fringe
@@ -799,5 +800,5 @@
         double vector = 0.0;            // The vector sum
         for (int k = 0; k < numPoints; k++) {
-            if (!mask->data.U8[k]) {
+            if (!mask->data.PS_TYPE_VECTOR_MASK_DATA[k]) {
                 psF32 f1 = (fringe1) ? fringe1->data.F32[k] : 1.0; // Contribution from fringe 1
                 psF32 s = science->f->data.F32[k]; // Contribution from science measurement
@@ -855,5 +856,5 @@
 
     for (int i = 0; i < diff->n; i++) {
-        if (!mask->data.U8[i]) {
+        if (!mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
             float difference = science->f->data.F32[i] - scale->coeff->data.F32[0];
             for (int j = 0; j < fringes->n; j++) {
@@ -877,5 +878,5 @@
     assert(diffs->type.type == PS_TYPE_F32);
     assert(mask);
-    assert(mask->type.type == PS_TYPE_U8);
+    assert(mask->type.type == PS_TYPE_VECTOR_MASK);
     assert(diffs->n == mask->n);
 
@@ -888,8 +889,8 @@
     int numClipped = 0;                 // Number clipped
     for (int i = 0; i < diffs->n; i++) {
-        psTrace("psModules.detrend", 10, "Region %d (%d): %f\n", i, mask->data.U8[i], diffs->data.F32[i]);
-        if (!mask->data.U8[i] && fabs(diffs->data.F32[i]) > middle + thresh) {
+        psTrace("psModules.detrend", 10, "Region %d (%d): %f\n", i, mask->data.PS_TYPE_VECTOR_MASK_DATA[i], diffs->data.F32[i]);
+        if (!mask->data.PS_TYPE_VECTOR_MASK_DATA[i] && fabs(diffs->data.F32[i]) > middle + thresh) {
             psTrace("psModules.detrend", 5, "Masking %d: %f\n", i, diffs->data.F32[i]);
-            mask->data.U8[i] = 1;
+            mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 1;
             numClipped++;
         }
@@ -931,5 +932,5 @@
     // Set up the mask
     if (!regions->mask) {
-        regions->mask = psVectorAlloc(numRegions, PS_TYPE_U8);
+        regions->mask = psVectorAlloc(numRegions, PS_TYPE_VECTOR_MASK);
         psVectorInit(regions->mask, 0);
     }
@@ -946,5 +947,5 @@
         for (int j = 0; j < numRegions; j++) {
             if (!isfinite(fringe->f->data.F32[j])) {
-                mask->data.U8[j] = 1;
+                mask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 1;
                 psTrace("psModules.detrend", 9, "Masking region %d because not finite in fringe %d.\n", j, i);
             }
@@ -956,5 +957,5 @@
     FILE *f = fopen ("fringe.dat", "w");
     for (int j = 0; j < numRegions; j++) {
-	if (mask->data.U8[j]) continue;
+	if (mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) continue;
 	fprintf (f, "%d %f %f ", j, science->f->data.F32[j], science->df->data.F32[j]);
 	for (int i = 0; i < fringes->n; i++) {
@@ -1014,5 +1015,5 @@
 // XXX note that this modifies the input fringe images
 psImage *pmFringeCorrect(pmReadout *readout, pmFringeRegions *fringes, psArray *fringeImages,
-                         psArray *fringeStats, psMaskType maskVal, float rej,
+                         psArray *fringeStats, psImageMaskType maskVal, float rej,
                          unsigned int nIter, float keepFrac)
 {
Index: /trunk/psModules/src/detrend/pmFringeStats.h
===================================================================
--- /trunk/psModules/src/detrend/pmFringeStats.h	(revision 21182)
+++ /trunk/psModules/src/detrend/pmFringeStats.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-24 02:54:15 $
+ * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004-2006 Institute for Astronomy, University of Hawaii
  */
@@ -102,5 +102,5 @@
 pmFringeStats *pmFringeStatsMeasure(pmFringeRegions *fringe, ///< Fringe regions at which to measure
                                     const pmReadout *readout, ///< Readout for which to measure
-                                    psMaskType maskVal ///< Mask value for image
+                                    psImageMaskType maskVal ///< Mask value for image
                                    );
 
@@ -206,5 +206,5 @@
                          psArray *fringeImages, ///< Fringe template images to use in correction
                          psArray *fringeStats, ///< Fringe stats (for templates) to use in correction
-                         psMaskType maskVal, ///< Value to mask for science image
+                         psImageMaskType maskVal, ///< Value to mask for science image
                          float rej,     ///< Rejection threshold, for pmFringeScaleMeasure
                          unsigned int nIter, ///< Maximum number of iterations, for pmFringeScaleMeasure
Index: /trunk/psModules/src/detrend/pmMaskBadPixels.c
===================================================================
--- /trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 21182)
+++ /trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 21183)
@@ -14,13 +14,13 @@
 #include "pmMaskBadPixels.h"
 
-bool pmMaskBadPixels(pmReadout *input, const pmReadout *mask, psMaskType maskVal)
+bool pmMaskBadPixels(pmReadout *input, const pmReadout *mask, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(input, false);
     PS_ASSERT_PTR_NON_NULL(input->mask, false);
-    PS_ASSERT_IMAGE_TYPE(input->mask, PS_TYPE_MASK, false);
+    PS_ASSERT_IMAGE_TYPE(input->mask, PS_TYPE_IMAGE_MASK, false);
 
     PS_ASSERT_PTR_NON_NULL(mask, false);
     PS_ASSERT_PTR_NON_NULL(mask->mask, false);
-    PS_ASSERT_IMAGE_TYPE(mask->mask, PS_TYPE_MASK, false);
+    PS_ASSERT_IMAGE_TYPE(mask->mask, PS_TYPE_IMAGE_MASK, false);
 
     psImage *inMask = input->mask;
@@ -53,7 +53,7 @@
     int offRow = input->row0 - mask->row0;
 
-    // masks are both of type PS_TYPE_MASK
-    psMaskType **exVal = exMask->data.U8;
-    psMaskType **inVal = inMask->data.U8;
+    // masks are both of type PS_TYPE_IMAGE_MASK
+    psImageMaskType **exVal = exMask->data.PS_TYPE_IMAGE_MASK_DATA;
+    psImageMaskType **inVal = inMask->data.PS_TYPE_IMAGE_MASK_DATA;
 
     // apply exMask values
@@ -82,5 +82,5 @@
 
 bool pmMaskFlagSuspectPixels(pmReadout *output, const pmReadout *readout, float median, float stdev,
-                             float rej, psMaskType maskVal)
+                             float rej, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -92,5 +92,5 @@
         PS_ASSERT_IMAGE_NON_EMPTY(readout->mask, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(readout->image, readout->mask, false);
-        PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_IMAGE_MASK, false);
     }
     PS_ASSERT_PTR_NON_NULL(output, false);
@@ -128,5 +128,5 @@
         for (int x = 0; x < image->numCols; x++) {
             if (fabs((image->data.F32[y][x] - median) / stdev) < rej) continue;
-	    if (mask && (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal)) continue;
+	    if (mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal)) continue;
 	    suspect->data.F32[y][x] += 1.0;
         }
@@ -142,5 +142,5 @@
 
 // the maskVal supplied here is the value SET for this mask (ie, it is not used to avoid pixels)
-bool pmMaskIdentifyBadPixels(pmReadout *output, psMaskType maskVal, float thresh, pmMaskIdentifyMode mode)
+bool pmMaskIdentifyBadPixels(pmReadout *output, psImageMaskType maskVal, float thresh, pmMaskIdentifyMode mode)
 {
     PS_ASSERT_PTR_NON_NULL(output, false);
@@ -155,7 +155,7 @@
         PS_ASSERT_IMAGE_NON_EMPTY(output->mask, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(output->mask, suspects, false);
-        PS_ASSERT_IMAGE_TYPE(output->mask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(output->mask, PS_TYPE_IMAGE_MASK, false);
     } else {
-        output->mask = psImageAlloc(suspects->numCols, suspects->numRows, PS_TYPE_MASK);
+        output->mask = psImageAlloc(suspects->numCols, suspects->numRows, PS_TYPE_IMAGE_MASK);
     }
     int num = psMetadataLookupS32(NULL, output->analysis, PM_MASK_ANALYSIS_NUM); // Number of inputs
@@ -246,5 +246,5 @@
         for (int x = 0; x < suspects->numCols; x++) {
             if (suspects->data.F32[y][x] >= limit) {
-                badpix->data.PS_TYPE_MASK_DATA[y][x] = maskVal;
+                badpix->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = maskVal;
             }
         }
Index: /trunk/psModules/src/detrend/pmMaskBadPixels.h
===================================================================
--- /trunk/psModules/src/detrend/pmMaskBadPixels.h	(revision 21182)
+++ /trunk/psModules/src/detrend/pmMaskBadPixels.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author Eugene Magnier, IfA
  *
- * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-03-29 03:10:17 $
+ * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004 Institute for Astronomy, University of Hawaii
  */
@@ -40,5 +40,5 @@
 bool pmMaskBadPixels(pmReadout *input,  ///< Input science image
                      const pmReadout *mask, ///< Mask image to apply
-                     psMaskType maskVal ///< Mask value to apply
+                     psImageMaskType maskVal ///< Mask value to apply
                     );
 
@@ -56,5 +56,5 @@
                              float stdev, ///< Image standard deviation
                              float rej, ///< Rejection threshold (standard deviations)
-                             psMaskType maskVal ///< Mask value for statistics
+                             psImageMaskType maskVal ///< Mask value for statistics
     );
 
@@ -64,5 +64,5 @@
 /// according to the chosen mode.
 bool pmMaskIdentifyBadPixels(pmReadout *output, ///< Output readout, with suspect pixels imageOut
-                             psMaskType maskVal, ///< Value to set for bad pixels
+                             psImageMaskType maskVal, ///< Value to set for bad pixels
                              float thresh, ///< Threshold for bad pixel
                              pmMaskIdentifyMode mode ///< Mode for identifying bad pixels
Index: /trunk/psModules/src/detrend/pmOverscan.c
===================================================================
--- /trunk/psModules/src/detrend/pmOverscan.c	(revision 21182)
+++ /trunk/psModules/src/detrend/pmOverscan.c	(revision 21183)
@@ -67,10 +67,10 @@
     psVector *reduced = psVectorAlloc(pixels->n, PS_TYPE_F32); // Overscan for each row
     psVector *ordinate = psVectorAlloc(pixels->n, PS_TYPE_F32); // Ordinate
-    psVector *mask = psVectorAlloc(pixels->n, PS_TYPE_U8); // Mask for fitting
+    psVector *mask = psVectorAlloc(pixels->n, PS_TYPE_VECTOR_MASK); // Mask for fitting
 
     for (int i = 0; i < pixels->n; i++) {
         psVector *values = pixels->data[i]; // Vector with overscan values
         if (values->n > 0) {
-            mask->data.U8[i] = 0;
+            mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0;
             ordinate->data.F32[i] = 2.0*(float)i/(float)pixels->n - 1.0; // Scale to [-1,1]
             psVectorStats(myStats, values, NULL, NULL, 0);
@@ -82,5 +82,5 @@
         } else {
             // We'll fit this one out
-            mask->data.U8[i] = 1;
+            mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 1;
         }
     }
Index: /trunk/psModules/src/detrend/pmRemnance.c
===================================================================
--- /trunk/psModules/src/detrend/pmRemnance.c	(revision 21182)
+++ /trunk/psModules/src/detrend/pmRemnance.c	(revision 21183)
@@ -13,6 +13,6 @@
 
 bool pmRemnance(pmReadout *ro,           ///< Readout with input image
-                psMaskType maskVal,      ///< Value of mask
-                psMaskType maskRem,       ///< Value to give remance
+                psImageMaskType maskVal,      ///< Value of mask
+                psImageMaskType maskRem,       ///< Value to give remance
                 int size,               ///< Size of accumulation patches
                 float threshold         ///< Threshold for masking
@@ -23,5 +23,7 @@
     PM_ASSERT_READOUT_MASK(ro, false);
 
-    psImage *image = ro->image, *mask = ro->mask; // Mask and image from readout
+    psImage *image = ro->image;
+    psImage *mask = ro->mask; // Mask and image from readout
+
     int numCols = image->numCols, numRows = image->numRows; // Size of image
 
@@ -33,5 +35,5 @@
         psErrorClear();
         psWarning("Unable to calculate image statistics: masking entire readout.");
-        psBinaryOp(mask, mask, "|", psScalarAlloc(maskRem, PS_TYPE_MASK));
+        psBinaryOp(mask, mask, "|", psScalarAlloc(maskRem, PS_TYPE_IMAGE_MASK));
         psFree(stats);
         psFree(rng);
@@ -57,5 +59,5 @@
             }
             for (int y = min; y < max; y++) {
-                if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) {
+                if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
                     continue;
                 }
@@ -84,5 +86,5 @@
             }
             for (int y = 0; y < maxMask; y++) {
-                mask->data.PS_TYPE_MASK_DATA[y][x] |= maskRem;
+                mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= maskRem;
             }
             numMasked += maxMask;
Index: /trunk/psModules/src/detrend/pmRemnance.h
===================================================================
--- /trunk/psModules/src/detrend/pmRemnance.h	(revision 21182)
+++ /trunk/psModules/src/detrend/pmRemnance.h	(revision 21183)
@@ -13,6 +13,6 @@
 // GPC1 leaves remnance that flows down from where the annoyed pixels are.
 bool pmRemnance(pmReadout *ro,           ///< Readout with input image
-                psMaskType maskVal,      ///< Value of mask
-                psMaskType maskRem,       ///< Value to give remance
+                psImageMaskType maskVal,      ///< Value of mask
+                psImageMaskType maskRem,       ///< Value to give remance
                 int size,               ///< Size of accumulation patches
                 float threshold         ///< Threshold for masking
Index: /trunk/psModules/src/detrend/pmShifts.c
===================================================================
--- /trunk/psModules/src/detrend/pmShifts.c	(revision 21182)
+++ /trunk/psModules/src/detrend/pmShifts.c	(revision 21183)
@@ -412,5 +412,5 @@
 }
 
-bool pmShiftsConvolve(pmReadout *detrend, const pmCell *source, psMaskType maskVal)
+bool pmShiftsConvolve(pmReadout *detrend, const pmCell *source, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR(detrend, false);
Index: /trunk/psModules/src/detrend/pmShifts.h
===================================================================
--- /trunk/psModules/src/detrend/pmShifts.h	(revision 21182)
+++ /trunk/psModules/src/detrend/pmShifts.h	(revision 21183)
@@ -46,5 +46,5 @@
 bool pmShiftsConvolve(pmReadout *detrend, ///< Detrend readout to convolve
                       const pmCell *source, ///< Science exposure, containing a shifts kernel
-                      psMaskType maskVal ///< Mask value to smear
+                      psImageMaskType maskVal ///< Mask value to smear
                       );
 
Index: /trunk/psModules/src/detrend/pmShutterCorrection.c
===================================================================
--- /trunk/psModules/src/detrend/pmShutterCorrection.c	(revision 21182)
+++ /trunk/psModules/src/detrend/pmShutterCorrection.c	(revision 21183)
@@ -198,5 +198,5 @@
 pmShutterCorrection *pmShutterCorrectionLinFit(const psVector *exptime, const psVector *counts,
                                                const psVector *cntError, const psVector *mask, float offref,
-                                               int nIter, float rej, psMaskType maskVal)
+                                               int nIter, float rej)
 {
     PS_ASSERT_VECTOR_NON_NULL(exptime, NULL);
@@ -241,5 +241,5 @@
     stats->clipIter = nIter;
 
-    if (!psVectorClipFitPolynomial2D(line, stats, mask, maskVal, counts, cntError, x, y)) {
+    if (!psVectorClipFitPolynomial2D(line, stats, mask, 0xff, counts, cntError, x, y)) {
         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to fit shutter correction.\n");
         psFree(stats);
@@ -371,5 +371,5 @@
 
 bool pmShutterCorrectionMeasure(pmReadout *output, const psArray *readouts, int size, psStatsOptions meanStat,
-                                psStatsOptions stdevStat, int nIter, float rej, psMaskType maskVal)
+                                psStatsOptions stdevStat, int nIter, float rej, psImageMaskType maskVal)
 {
     PS_ASSERT_ARRAY_NON_NULL(readouts, NULL);
@@ -457,5 +457,5 @@
             masks->data[i] = psMemIncrRefCounter(mask);
 
-            if (mask->type.type != PS_TYPE_U8) {
+            if (mask->type.type != PS_TYPE_IMAGE_MASK) {
                 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Bad type for mask: %x\n", mask->type.type);
                 goto MEASURE_ERROR;
@@ -582,5 +582,5 @@
     psImage *shutter = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Shutter correction image
     psImage *pattern = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Illumination pattern
-    psVector *mask = psVectorAlloc(num, PS_TYPE_U8); // Mask for each image
+    psVector *mask = psVectorAlloc(num, PS_TYPE_VECTOR_MASK); // Mask for each image
     psVectorInit(mask, 0);
     psTrace("psModules.detrend", 2, "Performing linear fit on individual pixels...\n");
@@ -592,5 +592,5 @@
                 psImage *maskImage;     // Mask image
                 if (masks && (maskImage = masks->data[i])) {
-                    mask->data.U8[i] = maskImage->data.U8[y][x];
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = (maskImage->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal);
                 }
                 psImage *weight;        // Weight image
@@ -602,6 +602,5 @@
             }
 
-            pmShutterCorrection *corr = pmShutterCorrectionLinFit(exptimes, counts, errors, mask, meanRef,
-                                        nIter, rej, maskVal);
+            pmShutterCorrection *corr = pmShutterCorrectionLinFit(exptimes, counts, errors, mask, meanRef, nIter, rej);
             shutter->data.F32[y][x] = corr->offset;
             pattern->data.F32[y][x] = corr->scale;
@@ -665,5 +664,5 @@
 
     float exptime    = PS_SCALAR_VALUE(job->args->data[3],F32);
-    psMaskType blank = PS_SCALAR_VALUE(job->args->data[4],U8);
+    psImageMaskType blank = PS_SCALAR_VALUE(job->args->data[4],PS_TYPE_IMAGE_MASK_DATA);
     int rowStart     = PS_SCALAR_VALUE(job->args->data[5],S32);
     int rowStop      = PS_SCALAR_VALUE(job->args->data[6],S32);
@@ -672,10 +671,10 @@
 
 bool pmShutterCorrectionApplyScan(psImage *image, const psImage *shutterImage, psImage *mask, float exptime,
-                                  psMaskType blank, int rowStart, int rowStop)
+                                  psImageMaskType blank, int rowStart, int rowStop)
 {
     for (int y = rowStart; y < rowStop; y++) {
         for (int x = 0; x < image->numCols; x++) {
             if (mask && !isfinite(shutterImage->data.F32[y][x])) {
-                mask->data.PS_TYPE_MASK_DATA[y][x] |= blank;
+                mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= blank;
                 image->data.F32[y][x] = NAN;
                 continue;
@@ -687,5 +686,5 @@
 }
 
-bool pmShutterCorrectionApply(pmReadout *readout, const pmReadout *shutter, psMaskType blank)
+bool pmShutterCorrectionApply(pmReadout *readout, const pmReadout *shutter, psImageMaskType blank)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -746,5 +745,5 @@
             for (int x = 0; x < image->numCols; x++) {
                 if (mask && !isfinite(shutterImage->data.F32[y][x])) {
-                    mask->data.PS_TYPE_MASK_DATA[y][x] |= blank;
+                    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= blank;
                     image->data.F32[y][x] = NAN;
                     continue;
@@ -770,5 +769,5 @@
                 psArrayAdd(job->args, 1, mask);
                 PS_ARRAY_ADD_SCALAR(job->args, exptime, PS_TYPE_F32);
-                PS_ARRAY_ADD_SCALAR(job->args, blank, PS_TYPE_MASK);
+                PS_ARRAY_ADD_SCALAR(job->args, blank, PS_TYPE_IMAGE_MASK);
                 PS_ARRAY_ADD_SCALAR(job->args, rowStart, PS_TYPE_S32);
                 PS_ARRAY_ADD_SCALAR(job->args, rowStop, PS_TYPE_S32);
@@ -860,5 +859,5 @@
                                    psStatsOptions meanStat, ///< Statistic to use for mean
                                    psStatsOptions stdevStat, ///< Statistic to use for stdev
-                                   psMaskType maskVal, ///< Mask value
+                                   psImageMaskType maskVal, ///< Mask value
                                    psRandom *rng ///< Random number generator
     )
@@ -876,5 +875,5 @@
     if (readout->mask) {
         PS_ASSERT_IMAGE_NON_NULL(readout->mask, NULL);
-        PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_MASK, NULL);
+        PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_IMAGE_MASK, NULL);
         PS_ASSERT_IMAGE_SIZE(readout->mask, data->numCols, data->numRows, NULL);
     }
@@ -1022,5 +1021,5 @@
 
 bool pmShutterCorrectionGeneratePrepare(pmReadout *shutter, pmReadout *pattern, const psArray *inputs,
-                                        psMaskType maskVal)
+                                        psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(shutter, false);
@@ -1084,5 +1083,5 @@
 bool pmShutterCorrectionGenerate(pmReadout *shutter, pmReadout *pattern, const psArray *inputs,
                                  float reference, const pmShutterCorrectionData *data,
-                                 int nIter, float rej, psMaskType maskVal)
+                                 int nIter, float rej, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(shutter, false);
@@ -1116,5 +1115,5 @@
     psVector *counts = psVectorAlloc(num, PS_TYPE_F32); // Counts in each image
     psVector *errors = psVectorAlloc(num, PS_TYPE_F32); // Counts in each image
-    psVector *mask = psVectorAlloc(num, PS_TYPE_MASK); // Mask for each image
+    psVector *mask = psVectorAlloc(num, PS_TYPE_VECTOR_MASK); // Mask for each image
     psTrace("psModules.detrend", 2, "Performing linear fit on individual pixels...\n");
     for (int i = minInputRows; i < maxInputRows; i++) {
@@ -1132,5 +1131,5 @@
                 counts->data.F32[r] = image->data.F32[yIn][xIn] * ref;
                 if (readout->mask) {
-                    mask->data.PS_TYPE_MASK_DATA[r] = readout->mask->data.PS_TYPE_MASK_DATA[yIn][xIn];
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[r] = (readout->mask->data.PS_TYPE_IMAGE_MASK_DATA[yIn][xIn] & maskVal);
                 }
                 if (readout->weight) {
@@ -1142,6 +1141,5 @@
             }
 
-            pmShutterCorrection *corr = pmShutterCorrectionLinFit(data->exptimes, counts, errors, mask,
-                                                                  reference, nIter, rej, maskVal);
+            pmShutterCorrection *corr = pmShutterCorrectionLinFit(data->exptimes, counts, errors, mask, reference, nIter, rej);
             if (!corr) {
                 // Nothing we can do about it
Index: /trunk/psModules/src/detrend/pmShutterCorrection.h
===================================================================
--- /trunk/psModules/src/detrend/pmShutterCorrection.h	(revision 21182)
+++ /trunk/psModules/src/detrend/pmShutterCorrection.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-09-09 04:10:14 $
+ * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2006 Institute for Astronomy, University of Hawaii
  */
@@ -91,6 +91,5 @@
     float offref,                       ///< Reference time offset
     int nIter,                          ///< Number of iterations
-    float rej,                          ///< Rejection threshold (sigma)
-    psMaskType maskVal                  ///< Mask value
+    float rej				///< Rejection threshold (sigma)
     );
 
@@ -121,5 +120,5 @@
     int nIter,                          ///< Number of iterations
     float rej,                          ///< Rejection threshold (sigma)
-    psMaskType maskVal                  ///< Mask value
+    psImageMaskType maskVal                  ///< Mask value
     );
 
@@ -135,5 +134,5 @@
     psImage *mask,                      ///< Input mask image
     float exptime,                      ///< Exposure time to which to correct
-    psMaskType blank,                   ///< Mask value to give blank pixels
+    psImageMaskType blank,                   ///< Mask value to give blank pixels
     int rowStart, int rowStop           ///< Range of scan
     );
@@ -145,5 +144,5 @@
     pmReadout *readout,                 ///< Readout to which to apply shutter correction
     const pmReadout *shutter,           ///< Shutter correction readout, with dT for each pixel
-    psMaskType blank                    ///< Value to give blank pixels
+    psImageMaskType blank                    ///< Value to give blank pixels
     );
 
@@ -181,5 +180,5 @@
     psStatsOptions meanStat,            ///< Statistic to use for mean
     psStatsOptions stdevStat,           ///< Statistic to use for stdev
-    psMaskType maskVal,                 ///< Mask value
+    psImageMaskType maskVal,                 ///< Mask value
     psRandom *rng                       ///< Random number generator
     );
@@ -201,10 +200,10 @@
     int nIter,                          ///< Number of iterations
     float rej,                          ///< Rejection threshold (sigma)
-    psMaskType maskVal                  ///< Mask value
+    psImageMaskType maskVal                  ///< Mask value
     );
 
 // prepare outputs for shutter correction
 bool pmShutterCorrectionGeneratePrepare(pmReadout *shutter, pmReadout *pattern, const psArray *inputs,
-                                        psMaskType maskVal);
+                                        psImageMaskType maskVal);
 
 /// @}
Index: /trunk/psModules/src/detrend/pmSkySubtract.c
===================================================================
--- /trunk/psModules/src/detrend/pmSkySubtract.c	(revision 21182)
+++ /trunk/psModules/src/detrend/pmSkySubtract.c	(revision 21183)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-04-04 22:42:48 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -114,5 +114,5 @@
 
     psVector *binVector = psVectorAlloc(binFactor * binFactor, PS_TYPE_F32);
-    psVector *binMask = psVectorAlloc(binFactor * binFactor, PS_TYPE_U8);
+    psVector *binMask = psVectorAlloc(binFactor * binFactor, PS_TYPE_VECTOR_MASK);
     psStats *myStats = psStatsAlloc(statOptions);
 
@@ -126,8 +126,8 @@
                         binVector->data.F32[count] =
                             origImage->data.F32[row + binRow][col + binCol];
-                        binMask->data.U8[count] = 0;
+                        binMask->data.PS_TYPE_VECTOR_MASK_DATA[count] = 0;
                     } else {
                         binVector->data.F32[count] = 0.0;
-                        binMask->data.U8[count] = 1;
+                        binMask->data.PS_TYPE_VECTOR_MASK_DATA[count] = 1;
                     }
                     count++;
@@ -313,5 +313,5 @@
     PS_ASSERT_IMAGE_NON_NULL(maskImage, NULL);
     PS_ASSERT_IMAGE_NON_EMPTY(maskImage, NULL);
-    PS_ASSERT_IMAGE_TYPE(maskImage, PS_TYPE_U8, NULL);
+    PS_ASSERT_IMAGE_TYPE(maskImage, PS_TYPE_IMAGE_MASK, NULL);
     PS_ASSERT_IMAGES_SIZE_EQUAL(dataImage, maskImage, NULL);
     psS32 oldPolyX = -1;
@@ -361,5 +361,5 @@
     for (x=0;x<dataImage->numRows;x++) {
         for (y=0;y<dataImage->numCols;y++) {
-            if (maskImage->data.U8[x][y] == 0) {
+            if (maskImage->data.PS_TYPE_IMAGE_MASK_DATA[x][y] == 0) {
                 buildSums((psF64) x, (psF64) y, myPoly->nX, myPoly->nY);
 
@@ -572,5 +572,5 @@
 
         if (in->mask != NULL) {
-            binnedMaskImage = psImageCopy(binnedMaskImage, in->mask, PS_TYPE_U8);
+            binnedMaskImage = psImageCopy(binnedMaskImage, in->mask, PS_TYPE_IMAGE_MASK);
             if (binnedMaskImage == NULL) {
                 psError(PS_ERR_UNKNOWN, false, "psImageCopy() returned NULL.  Returning in image.\n");
@@ -581,5 +581,5 @@
             binnedMaskImage = psImageAlloc(binnedImage->numCols,
                                            binnedImage->numRows,
-                                           PS_TYPE_U8);
+                                           PS_TYPE_IMAGE_MASK);
             psImageInit(binnedMaskImage, 0);
         }
@@ -592,5 +592,5 @@
         binnedMaskImage = psImageAlloc(binnedImage->numCols,
                                        binnedImage->numRows,
-                                       PS_TYPE_U8);
+                                       PS_TYPE_IMAGE_MASK);
         psImageInit(binnedMaskImage, 0);
     }
@@ -625,5 +625,5 @@
                 if (fabs(binnedImage->data.F32[row][col] - binnedMean) >
                         (clipSD * binnedStdev)) {
-                    binnedMaskImage->data.U8[row][col] = 1;
+                    binnedMaskImage->data.PS_TYPE_IMAGE_MASK_DATA[row][col] = 1;
                 }
             }
Index: /trunk/psModules/src/imcombine/pmImageCombine.c
===================================================================
--- /trunk/psModules/src/imcombine/pmImageCombine.c	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmImageCombine.c	(revision 21183)
@@ -8,6 +8,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-04-04 22:42:48 $
+ *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  XXX: pmRejectPixels() has a known bug with the pmImageTransform() call.
@@ -17,4 +17,6 @@
  */
 
+// XXX this is somewhat messy and unclear on the masking.
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -53,5 +55,5 @@
 
     buffer->pixels = psVectorAlloc(numImages, PS_TYPE_F32);
-    buffer->masks = psVectorAlloc(numImages, PS_TYPE_MASK);
+    buffer->masks = psVectorAlloc(numImages, PS_TYPE_VECTOR_MASK);
     buffer->errors = psVectorAlloc(numImages, PS_TYPE_F32);
     buffer->stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
@@ -67,5 +69,5 @@
                           const psArray *errors, // Array of input error images
                           const psArray *masks, // Array of input masks
-                          psU32 maskVal, // Mask value
+                          psImageMaskType maskVal, // Mask value
                           psS32 numIter, // Number of rejection iterations
                           psF32 sigmaClip, // Number of standard deviations at which to reject
@@ -115,6 +117,7 @@
         if (masks) {
             psImage *mask = masks->data[i]; // Mask of interest
-            pixelMasks->data.U8[i] = mask->data.U8[y][x];
-        }        // Set the pixel error data, if necessary
+            pixelMasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal);
+        }        
+	// Set the pixel error data, if necessary
         if (errors) {
             psImage *error = errors->data[i]; // Error image of interest
@@ -128,5 +131,5 @@
     for (int iter = 0; iter < numIter; iter++) {
         // Combine all the pixels, using the specified stat.
-        if (!psVectorStats(stats, pixelData, pixelErrors, pixelMasks, maskVal)) {
+        if (!psVectorStats(stats, pixelData, pixelErrors, pixelMasks, 0xff)) {
             combine->data.F32[y][x] = NAN;
             psFree(buffer);
@@ -148,9 +151,9 @@
         float stdev = stats->sampleStdev;
         for (int i = 0; i < numImages; i++) {
-            if (!(pixelMasks->data.U8[i] & maskVal) &&
+            if (!(pixelMasks->data.PS_TYPE_VECTOR_MASK_DATA[i] & 0xff) &&
                     fabs(pixelData->data.F32[i] - combinedPixel) > sigmaClip * stdev) {
                 // Reject pixel as questionable
                 numRejects++;
-                pixelMasks->data.U8[i] = maskVal;
+                pixelMasks->data.PS_TYPE_IMAGE_MASK_DATA[i] = 0xff;
                 if (questionablePixels) {
                     // Mark the pixel as questionable
@@ -191,5 +194,5 @@
     const psArray *errors,              ///< Array of input error images
     const psArray *masks,               ///< Array of input masks
-    psU32 maskVal,                      ///< Mask value
+    psImageMaskType maskVal,                      ///< Mask value
     const psPixels *pixels,             ///< Pixels to combine
     psS32 numIter,                      ///< Number of rejection iterations
@@ -231,5 +234,5 @@
             psImage *mask  = masks->data[i];
             PS_ASSERT_IMAGE_SIZE(mask, numCols, numRows, NULL);
-            PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+            PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
         }
     }
@@ -319,5 +322,5 @@
     int num = 0;
     psVector *pixels = psVectorAlloc(8, PS_TYPE_F32); // Array of pixels
-    psVector *mask = psVectorAlloc(8, PS_TYPE_U8); // Corresponding mask
+    psVector *mask = psVectorAlloc(8, PS_TYPE_VECTOR_MASK); // Corresponding mask
 
     // Get limits
@@ -329,10 +332,10 @@
         for (int j = yMin; j <= yMax; j++) {
             for (int i = xMin; i <= xMax; i++) {
-                if ((i != x) && (j != y) && (0 == imageMask->data.U8[j][i])) {
+                if ((i != x) && (j != y) && (0 == imageMask->data.PS_TYPE_IMAGE_MASK_DATA[j][i])) {
                     pixels->data.F32[num] = image->data.F32[j][i];
-                    mask->data.U8[num] = 0;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[num] = 0;
                     num++;
                 } else {
-                    mask->data.U8[num] = 1;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[num] = 1;
                 }
             }
@@ -347,8 +350,8 @@
                 if ((i != x) && (j != y)) {
                     pixels->data.F32[num] = image->data.F32[j][i];
-                    mask->data.U8[num] = 0;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[num] = 0;
                     num++;
                 } else {
-                    mask->data.U8[num] = 1;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[num] = 1;
                 }
             }
@@ -473,5 +476,5 @@
     for (psS32 i = 0 ; i < image->numRows ; i++) {
         for (psS32 j = 0 ; j < image->numCols ; j++) {
-            imgF32->data.F32[i][j] = (psF32) image->data.U8[i][j];
+            imgF32->data.F32[i][j] = (psF32) image->data.PS_TYPE_IMAGE_MASK_DATA[i][j];
         }
     }
@@ -518,5 +521,5 @@
             PS_ASSERT_IMAGE_NON_NULL(tmpMask, NULL);
             PS_ASSERT_IMAGE_NON_EMPTY(tmpMask, NULL);
-            PS_ASSERT_IMAGE_TYPE(tmpMask, PS_TYPE_F32, NULL);
+            PS_ASSERT_IMAGE_TYPE(tmpMask, PS_TYPE_F32, NULL); // XXX really F32??
             PS_ASSERT_IMAGES_SIZE_EQUAL(tmpImage, tmpMask, NULL);
         }
@@ -571,5 +574,5 @@
 
         //
-        // Create a psU8 mask image from the list of cosmic pixels.
+        // Create a psImageMaskType mask image from the list of cosmic pixels.
         //
         psImage *maskImage = NULL;
Index: /trunk/psModules/src/imcombine/pmPSFEnvelope.c
===================================================================
--- /trunk/psModules/src/imcombine/pmPSFEnvelope.c	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmPSFEnvelope.c	(revision 21183)
@@ -223,5 +223,5 @@
     // *** readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "*", psScalarAlloc(WEIGHT_FACTOR, PS_TYPE_F32));
     readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "+", psScalarAlloc(WEIGHT_VAL, PS_TYPE_F32));
-    readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+    readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
     psImageInit(readout->mask, 0);
 
Index: /trunk/psModules/src/imcombine/pmReadoutCombine.c
===================================================================
--- /trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 21183)
@@ -105,5 +105,5 @@
 
     // note the mask value actually used
-    psMaskType maskVal = params->maskVal; // The mask value
+    psImageMaskType maskVal = params->maskVal; // The mask value
     if (maskVal) {
         psString comment = NULL;        // Comment to add to header
@@ -247,6 +247,6 @@
     psF32 *pixelsData = pixels->data.F32; // Dereference pixels
 
-    psVector *mask   = psVectorAlloc(inputs->n, PS_TYPE_U8); // Mask for stack
-    psU8 *maskData = mask->data.U8;     // Dereference mask
+    psVector *mask   = psVectorAlloc(inputs->n, PS_TYPE_VECTOR_MASK); // Mask for stack
+    psVectorMaskType *maskData = mask->data.PS_TYPE_VECTOR_MASK_DATA;     // Dereference mask
 
     psVector *weights = NULL;           // Stack of weights
@@ -260,5 +260,5 @@
 
     float keepFrac = 1.0 - params->fracLow - params->fracHigh; // Fraction of pixels to keep
-    psMaskType maskVal = params->maskVal; // The mask value
+    psImageMaskType maskVal = params->maskVal; // The mask value
 
     #ifndef PS_NO_TRACE
@@ -278,5 +278,5 @@
     // Dereference output products
     psF32 **outputImage  = output->image->data.F32; // Output image
-    psU8  **outputMask   = output->mask->data.U8; // Output mask
+    psImageMaskType **outputMask   = output->mask->data.PS_TYPE_IMAGE_MASK_DATA; // Output mask
     psF32 **outputWeight = NULL; // Output weight map
     if (output->weight) {
@@ -303,5 +303,5 @@
 
             int numValid = 0;           // Number of valid pixels in the stack
-            memset(maskData, 0, mask->n * sizeof(psU8)); // Reset the mask
+            memset(maskData, 0, mask->n * sizeof(psVectorMaskType)); // Reset the mask
             for (int r = 0; r < inputs->n; r++) {
                 pmReadout *readout = inputs->data[r]; // Input readout
@@ -318,5 +318,5 @@
                 // Check mask
                 psImage *roMask = readout->mask; // The mask image
-                if (roMask && roMask->data.U8[yIn][xIn] & maskVal) {
+                if (roMask && roMask->data.PS_TYPE_IMAGE_MASK_DATA[yIn][xIn] & maskVal) {
                     maskData[r] = 1;
                     continue;
Index: /trunk/psModules/src/imcombine/pmReadoutCombine.h
===================================================================
--- /trunk/psModules/src/imcombine/pmReadoutCombine.h	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmReadoutCombine.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-08-01 00:01:26 $
+ * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004-2006 Institute for Astronomy, University of Hawaii
  */
@@ -22,6 +22,6 @@
 typedef struct {
     psStatsOptions combine;             ///< Statistic to use when performing the combination
-    psMaskType maskVal;                 ///< Mask value
-    psMaskType blank;                   ///< Mask value to give blank (i.e., no data) pixels
+    psImageMaskType maskVal;		///< Mask value
+    psImageMaskType blank;	      ///< Mask value to give blank (i.e., no data) pixels
     int nKeep;                          ///< Mimimum number of pixels to keep
     float fracHigh;                     ///< Fraction of high pixels to immediately throw
Index: /trunk/psModules/src/imcombine/pmStack.c
===================================================================
--- /trunk/psModules/src/imcombine/pmStack.c	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmStack.c	(revision 21183)
@@ -8,6 +8,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-11-13 03:50:30 $
+ *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
  *
@@ -63,5 +63,5 @@
 
     buffer->pixels = psVectorAlloc(numImages, PS_TYPE_F32);
-    buffer->masks = psVectorAlloc(numImages, PS_TYPE_MASK);
+    buffer->masks = psVectorAlloc(numImages, PS_TYPE_VECTOR_MASK);
     buffer->variances = psVectorAlloc(numImages, PS_TYPE_F32);
     buffer->weights = psVectorAlloc(numImages, PS_TYPE_F32);
@@ -143,5 +143,5 @@
     assert(!masks || values->n == masks->n);
     assert(values->type.type == PS_TYPE_F32);
-    assert(!masks || masks->type.type == PS_TYPE_MASK);
+    assert(!masks || masks->type.type == PS_TYPE_VECTOR_MASK);
     assert(sortBuffer && sortBuffer->nalloc >= values->n && sortBuffer->type.type == PS_TYPE_F32);
 
@@ -149,5 +149,5 @@
     int num = 0;            // Number of valid values
     for (int i = 0; i < values->n; i++) {
-        if (!masks || !masks->data.PS_TYPE_MASK_DATA[i]) {
+        if (!masks || !masks->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
             sortBuffer->data.F32[num++] = values->data.F32[i];
         }
@@ -215,6 +215,6 @@
                           const psVector *reject, // Indices of pixels to reject, or NULL
                           int x, int y, // Coordinates of interest; frame of output image
-                          psMaskType maskVal, // Value to mask
-                          psMaskType bad, // Value to give bad pixels
+                          psImageMaskType maskVal, // Value to mask
+                          psImageMaskType bad, // Value to give bad pixels
                           int numIter, // Number of rejection iterations
                           float rej, // Number of standard deviations at which to reject
@@ -258,5 +258,5 @@
         int xIn = x - data->readout->col0, yIn = y - data->readout->row0; // Coordinates on input readout
         psImage *mask = data->readout->mask; // Mask of interest
-        if (mask->data.PS_TYPE_MASK_DATA[yIn][xIn] & maskVal) {
+        if (mask->data.PS_TYPE_IMAGE_MASK_DATA[yIn][xIn] & maskVal) {
             continue;
         }
@@ -283,5 +283,5 @@
     // Default option is that the pixel is bad
     float imageValue = NAN, varianceValue = NAN; // Value for combined image and variance map
-    psMaskType maskValue = bad;         // Value for combined mask
+    psImageMaskType maskValue = bad;         // Value for combined mask
     switch (num) {
       case 0:
@@ -382,5 +382,5 @@
 // Mask a pixel for inspection
 #define MASK_PIXEL_FOR_INSPECTION() \
-    pixelMasks->data.PS_TYPE_MASK_DATA[j] = 0xff; \
+    pixelMasks->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xff; \
     combineInspect(inputs, x, y, pixelSources->data.U16[j]); \
     numClipped++; \
@@ -388,5 +388,5 @@
 
               for (int j = 0; j < num; j++) {
-                  if (pixelMasks->data.PS_TYPE_MASK_DATA[j]) {
+                  if (pixelMasks->data.PS_TYPE_VECTOR_MASK_DATA[j]) {
                       continue;
                   }
@@ -408,5 +408,5 @@
 
     image->data.F32[y][x] = imageValue;
-    mask->data.PS_TYPE_MASK_DATA[y][x] = maskValue;
+    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = maskValue;
     if (variance) {
         variance->data.F32[y][x] = varianceValue;
@@ -438,5 +438,5 @@
     PS_ASSERT_IMAGE_TYPE(data->readout->image, PS_TYPE_F32, false);
     PS_ASSERT_IMAGE_NON_NULL(data->readout->mask, false);
-    PS_ASSERT_IMAGE_TYPE(data->readout->mask, PS_TYPE_MASK, false);
+    PS_ASSERT_IMAGE_TYPE(data->readout->mask, PS_TYPE_IMAGE_MASK, false);
     PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->mask, false);
     *numCols = data->readout->image->numCols;
@@ -469,5 +469,5 @@
         PS_ASSERT_IMAGE_NON_NULL(data->readout->mask, false);
         PS_ASSERT_IMAGE_TYPE(data->readout->image, PS_TYPE_F32, false);
-        PS_ASSERT_IMAGE_TYPE(data->readout->mask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(data->readout->mask, PS_TYPE_IMAGE_MASK, false);
         PS_ASSERT_IMAGE_SIZE(data->readout->image, *numCols, *numRows, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->mask, false);
@@ -562,5 +562,5 @@
 
 /// Stack input images
-bool pmStackCombine(pmReadout *combined, psArray *input, psMaskType maskVal, psMaskType bad,
+bool pmStackCombine(pmReadout *combined, psArray *input, psImageMaskType maskVal, psImageMaskType bad,
                     int kernelSize, int numIter, float rej, float sys,
                     bool entire, bool useVariance, bool safe)
@@ -587,5 +587,5 @@
         PS_ASSERT_IMAGE_TYPE(combined->image, PS_TYPE_F32, false);
         PS_ASSERT_IMAGE_NON_NULL(combined->mask, false);
-        PS_ASSERT_IMAGE_TYPE(combined->mask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(combined->mask, PS_TYPE_IMAGE_MASK, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(combined->image, combined->mask, false);
     }
@@ -698,5 +698,5 @@
         psImage *combinedMask = combined->mask; // Combined mask
         if (!combinedMask) {
-            combined->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+            combined->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
             combinedMask = combined->mask;
         }
Index: /trunk/psModules/src/imcombine/pmStack.h
===================================================================
--- /trunk/psModules/src/imcombine/pmStack.h	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmStack.h	(revision 21183)
@@ -8,6 +8,6 @@
  * @author GLG, MHPCC
  *
- * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-11-01 02:59:33 $
+ * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  *
  * Copyright 2004-2007 Institute for Astronomy, University of Hawaii
@@ -43,6 +43,6 @@
 bool pmStackCombine(pmReadout *combined,///< Combined readout (output)
                     psArray *input,     ///< Input array of pmStackData
-                    psMaskType maskVal, ///< Mask value of bad pixels
-                    psMaskType bad,     ///< Mask value to give rejected pixels
+                    psImageMaskType maskVal, ///< Mask value of bad pixels
+                    psImageMaskType bad,     ///< Mask value to give rejected pixels
                     int kernelSize,     ///< Half-size of the convolution kernel
                     int numIter,        ///< Number of iterations
Index: /trunk/psModules/src/imcombine/pmStackReject.c
===================================================================
--- /trunk/psModules/src/imcombine/pmStackReject.c	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmStackReject.c	(revision 21183)
@@ -61,19 +61,19 @@
         }
 
-        int numBytes = (xMax - xMin) * PSELEMTYPE_SIZEOF(PS_TYPE_MASK); // Number of bytes to copy
+        int numBytes = (xMax - xMin) * PSELEMTYPE_SIZEOF(PS_TYPE_IMAGE_MASK); // Number of bytes to copy
         psAssert(convolved->numCols - 2 * box == xMax - xMin, "Bad number of columns");
         psAssert(convolved->numRows - 2 * box == yMax - yMin, "Bad number of rows");
 
         for (int yTarget = yMin, ySource = box; yTarget < yMax; yTarget++, ySource++) {
-            memcpy(&target->data.PS_TYPE_MASK_DATA[yTarget][xMin],
-                   &convolved->data.PS_TYPE_MASK_DATA[ySource][box], numBytes);
+            memcpy(&target->data.PS_TYPE_IMAGE_MASK_DATA[yTarget][xMin],
+                   &convolved->data.PS_TYPE_IMAGE_MASK_DATA[ySource][box], numBytes);
         }
         psFree(convolved);
     } else {
         // Just copy over
-        int numBytes = (xMax - xMin) * PSELEMTYPE_SIZEOF(PS_TYPE_MASK); // Number of bytes to copy
+        int numBytes = (xMax - xMin) * PSELEMTYPE_SIZEOF(PS_TYPE_IMAGE_MASK); // Number of bytes to copy
         for (int yTarget = yMin; yTarget < yMax; yTarget++) {
-            memcpy(&target->data.PS_TYPE_MASK_DATA[yTarget][xMin],
-                   &source->data.PS_TYPE_MASK_DATA[yTarget][xMin], numBytes);
+            memcpy(&target->data.PS_TYPE_IMAGE_MASK_DATA[yTarget][xMin],
+                   &source->data.PS_TYPE_IMAGE_MASK_DATA[yTarget][xMin], numBytes);
         }
     }
@@ -262,5 +262,5 @@
     bool oldThreads = psImageConvolveSetThreads(false); // Old value of threading for psImageColvolve
 
-    psImage *target = psImageRecycle(convolved, numCols, numRows, PS_TYPE_MASK); // Grown image
+    psImage *target = psImageRecycle(convolved, numCols, numRows, PS_TYPE_IMAGE_MASK); // Grown image
     psImageInit(target, 0);
     if (threaded) {
Index: /trunk/psModules/src/imcombine/pmSubtraction.c
===================================================================
--- /trunk/psModules/src/imcombine/pmSubtraction.c	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmSubtraction.c	(revision 21183)
@@ -246,5 +246,5 @@
                         psImage *image, // Image to convolve
                         psImage *mask, // Mask image
-                        psMaskType maskVal, // Value to mask
+                        psImageMaskType maskVal, // Value to mask
                         const psKernel *kernel, // Kernel by which to convolve
                         psRegion region,// Region of interest
@@ -291,5 +291,5 @@
                               psImage *sys, // Systematic error image
                               psImage *mask, // Mask image
-                              psMaskType maskVal, // Value to mask
+                              psImageMaskType maskVal, // Value to mask
                               const psKernel *kernel, // Kernel by which to convolve
                               psRegion region,// Region of interest
@@ -373,6 +373,6 @@
                                   float background, // Background value to apply
                                   psRegion region, // Region to convolve
-                                  psMaskType maskBad, // Value to give bad pixels
-                                  psMaskType maskPoor, // Value to give poor pixels
+                                  psImageMaskType maskBad, // Value to give bad pixels
+                                  psImageMaskType maskPoor, // Value to give poor pixels
                                   float poorFrac, // Fraction for "poor"
                                   bool useFFT,  // Use FFT to convolve?
@@ -385,7 +385,7 @@
     }
 
-    psMaskType subBad;                  // Bad pixels in subtraction mask
-    psMaskType subConvBad;              // Bad pixels in subtraction mask when convolving
-    psMaskType subConvPoor;             // Poor pixels in subtraction mask when convolving
+    psImageMaskType subBad;                  // Bad pixels in subtraction mask
+    psImageMaskType subConvBad;              // Bad pixels in subtraction mask when convolving
+    psImageMaskType subConvPoor;             // Poor pixels in subtraction mask when convolving
     if (kernels->mode == PM_SUBTRACTION_MODE_1 || (kernels->mode == PM_SUBTRACTION_MODE_DUAL && !wantDual)) {
         subBad = PM_SUBTRACTION_MASK_BAD_1;
@@ -437,6 +437,6 @@
             for (int yTarget = rowMin, ySource = box; yTarget < rowMax; yTarget++, ySource++) {
                 // Dereference images
-                psMaskType *target = &convMask->data.PS_TYPE_MASK_DATA[yTarget][colMin]; // Target values
-                psMaskType *source = &convolved->data.PS_TYPE_MASK_DATA[ySource][box]; // Source values
+                psImageMaskType *target = &convMask->data.PS_TYPE_IMAGE_MASK_DATA[yTarget][colMin]; // Target values
+                psImageMaskType *source = &convolved->data.PS_TYPE_IMAGE_MASK_DATA[ySource][box]; // Source values
                 for (int xTarget = colMin; xTarget < colMax; xTarget++, target++, source++) {
                     if (*source & subConvBad) {
@@ -783,5 +783,5 @@
     PS_ASSERT_VECTOR_TYPE(deviations, PS_TYPE_F32, -1);
     PS_ASSERT_IMAGE_NON_EMPTY(subMask, -1);
-    PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_MASK, -1);
+    PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_IMAGE_MASK, -1);
 
     // I used to measure the rms deviation about zero, and use that as the sigma against which to clip, but
@@ -794,10 +794,10 @@
 
     int numStamps = 0;                  // Number of used stamps
-    psVector *mask = psVectorAlloc(stamps->num, PS_TYPE_MASK); // Mask, for statistics
+    psVector *mask = psVectorAlloc(stamps->num, PS_TYPE_VECTOR_MASK); // Mask, for statistics
     psVectorInit(mask, 0);
     for (int i = 0; i < stamps->num; i++) {
         pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
         if (stamp->status != PM_SUBTRACTION_STAMP_USED) {
-            mask->data.PS_TYPE_MASK_DATA[i] = 0xff;
+            mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff;
             continue;
         }
@@ -869,5 +869,5 @@
                 for (int y = stamp->y - footprint; y <= stamp->y + footprint; y++) {
                     for (int x = stamp->x - footprint; x <= stamp->x + footprint; x++) {
-                        subMask->data.PS_TYPE_MASK_DATA[y][x] |= PM_SUBTRACTION_MASK_REJ;
+                        subMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= PM_SUBTRACTION_MASK_REJ;
                     }
                 }
@@ -997,6 +997,6 @@
                                      psImage *sys1, psImage *sys2, // Systematic error images
                                      psImage *subMask, // Input subtraction mask
-                                     psMaskType maskBad, // Mask value to give bad pixels
-                                     psMaskType maskPoor, // Mask value to give poor pixels
+                                     psImageMaskType maskBad, // Mask value to give bad pixels
+                                     psImageMaskType maskPoor, // Mask value to give poor pixels
                                      float poorFrac, // Fraction for "poor"
                                      const psRegion *region, // Patch to convolve
@@ -1035,6 +1035,6 @@
 
     if ((kernels->mode == PM_SUBTRACTION_MODE_1 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) && ro1->mask) {
-        psMaskType **target = convMask->data.PS_TYPE_MASK_DATA; // Target mask
-        psMaskType **source = ro1->mask->data.PS_TYPE_MASK_DATA; // Source mask
+        psImageMaskType **target = convMask->data.PS_TYPE_IMAGE_MASK_DATA; // Target mask
+        psImageMaskType **source = ro1->mask->data.PS_TYPE_IMAGE_MASK_DATA; // Source mask
 
         for (int y = yMin; y < yMax; y++) {
@@ -1045,6 +1045,6 @@
     }
     if ((kernels->mode == PM_SUBTRACTION_MODE_2 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) && ro2->mask) {
-        psMaskType **target = convMask->data.PS_TYPE_MASK_DATA; // Target mask
-        psMaskType **source = ro2->mask->data.PS_TYPE_MASK_DATA; // Source mask
+        psImageMaskType **target = convMask->data.PS_TYPE_IMAGE_MASK_DATA; // Target mask
+        psImageMaskType **source = ro2->mask->data.PS_TYPE_IMAGE_MASK_DATA; // Source mask
 
         for (int y = yMin; y < yMax; y++) {
@@ -1075,11 +1075,11 @@
     psImage *sys2 = args->data[10]; // Systematic error image 2
     psImage *subMask = args->data[11]; // Subtraction mask
-    psMaskType maskBad = PS_SCALAR_VALUE(args->data[12], U8); // Output mask value for bad pixels
-    psMaskType maskPoor = PS_SCALAR_VALUE(args->data[13], U8); // Output mask value for poor pixels
+    psImageMaskType maskBad = PS_SCALAR_VALUE(args->data[12], PS_TYPE_IMAGE_MASK_DATA); // Output mask value for bad pixels
+    psImageMaskType maskPoor = PS_SCALAR_VALUE(args->data[13], PS_TYPE_IMAGE_MASK_DATA); // Output mask value for poor pixels
     float poorFrac = PS_SCALAR_VALUE(args->data[14], F32); // Fraction for "poor"
     const psRegion *region = args->data[15]; // Region to convolve
     const pmSubtractionKernels *kernels = args->data[16]; // Kernels
-    bool doBG = PS_SCALAR_VALUE(args->data[17], U8); // Do background subtraction?
-    bool useFFT = PS_SCALAR_VALUE(args->data[18], U8); // Use FFT for convolution?
+    bool doBG = PS_SCALAR_VALUE(args->data[17], PS_TYPE_IMAGE_MASK_DATA); // Do background subtraction?
+    bool useFFT = PS_SCALAR_VALUE(args->data[18], PS_TYPE_IMAGE_MASK_DATA); // Use FFT for convolution?
 
     return subtractionConvolvePatch(numCols, numRows, x0, y0, out1, out2, convMask, ro1, ro2, sys1, sys2,
@@ -1088,5 +1088,5 @@
 
 bool pmSubtractionConvolve(pmReadout *out1, pmReadout *out2, const pmReadout *ro1, const pmReadout *ro2,
-                           psImage *subMask, int stride, psMaskType maskBad, psMaskType maskPoor,
+                           psImage *subMask, int stride, psImageMaskType maskBad, psImageMaskType maskPoor,
                            float poorFrac, float sysError, const psRegion *region,
                            const pmSubtractionKernels *kernels, bool doBG, bool useFFT)
@@ -1121,5 +1121,5 @@
     if (subMask) {
         PS_ASSERT_IMAGE_NON_NULL(subMask, false);
-        PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_IMAGE_MASK, false);
         PS_ASSERT_IMAGE_SIZE(subMask, numCols, numRows, false);
     }
@@ -1182,5 +1182,5 @@
         if (kernels->mode == PM_SUBTRACTION_MODE_1 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) {
             if (!out1->mask) {
-                out1->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+                out1->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
             }
             convMask = out1->mask;
@@ -1194,5 +1194,5 @@
             } else {
                 if (!out2->mask) {
-                    out2->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+                    out2->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
                 }
                 convMask = out2->mask;
@@ -1285,6 +1285,6 @@
                     psMutexUnlock(subMask);
                 }
-                PS_ARRAY_ADD_SCALAR(args, maskBad, PS_TYPE_U8);
-                PS_ARRAY_ADD_SCALAR(args, maskPoor, PS_TYPE_U8);
+                PS_ARRAY_ADD_SCALAR(args, maskBad, PS_TYPE_IMAGE_MASK);
+                PS_ARRAY_ADD_SCALAR(args, maskPoor, PS_TYPE_IMAGE_MASK);
                 PS_ARRAY_ADD_SCALAR(args, poorFrac, PS_TYPE_F32);
                 psArrayAdd(args, 1, subRegion);
Index: /trunk/psModules/src/imcombine/pmSubtraction.h
===================================================================
--- /trunk/psModules/src/imcombine/pmSubtraction.h	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmSubtraction.h	(revision 21183)
@@ -6,6 +6,6 @@
  * @author GLG, MHPCC
  *
- * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-11-07 00:03:18 $
+ * @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004-207 Institute for Astronomy, University of Hawaii
  */
@@ -104,6 +104,6 @@
                            psImage *subMask, ///< Subtraction mask (or NULL)
                            int stride,  ///< Size of convolution patches
-                           psMaskType maskBad, ///< Mask value to give bad pixels
-                           psMaskType maskPoor, ///< Mask value to give poor pixels
+                           psImageMaskType maskBad, ///< Mask value to give bad pixels
+                           psImageMaskType maskPoor, ///< Mask value to give poor pixels
                            float poorFrac, ///< Fraction for "poor"
                            float sysError, ///< Relative systematic error
Index: /trunk/psModules/src/imcombine/pmSubtractionMask.c
===================================================================
--- /trunk/psModules/src/imcombine/pmSubtractionMask.c	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmSubtractionMask.c	(revision 21183)
@@ -20,10 +20,10 @@
                              psImage *weight, // Weight map to mark as blank (or NULL)
                              int x, int y, // Coordinates to mark blank
-                             psMaskType blank // Blank mask value
+                             psImageMaskType blank // Blank mask value
     )
 {
     image->data.F32[y][x] = NAN;
     if (mask) {
-        mask->data.PS_TYPE_MASK_DATA[y][x] |= blank;
+        mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= blank;
     }
     if (weight) {
@@ -37,12 +37,12 @@
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-psImage *pmSubtractionMask(const psImage *mask1, const psImage *mask2, psMaskType maskVal,
+psImage *pmSubtractionMask(const psImage *mask1, const psImage *mask2, psImageMaskType maskVal,
                            int size, int footprint, float badFrac, bool useFFT)
 {
     PS_ASSERT_IMAGE_NON_NULL(mask1, NULL);
-    PS_ASSERT_IMAGE_TYPE(mask1, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask1, PS_TYPE_IMAGE_MASK, NULL);
     if (mask2) {
         PS_ASSERT_IMAGE_NON_NULL(mask2, NULL);
-        PS_ASSERT_IMAGE_TYPE(mask2, PS_TYPE_MASK, NULL);
+        PS_ASSERT_IMAGE_TYPE(mask2, PS_TYPE_IMAGE_MASK, NULL);
         PS_ASSERT_IMAGES_SIZE_EQUAL(mask2, mask1, NULL);
     }
@@ -57,8 +57,8 @@
 
     // Dereference inputs for convenience
-    psMaskType **data1 = mask1->data.PS_TYPE_MASK_DATA;
-    psMaskType **data2 = NULL;
+    psImageMaskType **data1 = mask1->data.PS_TYPE_IMAGE_MASK_DATA;
+    psImageMaskType **data2 = NULL;
     if (mask2) {
-        data2 = mask2->data.PS_TYPE_MASK_DATA;
+        data2 = mask2->data.PS_TYPE_IMAGE_MASK_DATA;
     }
 
@@ -86,7 +86,7 @@
 
     // Worried about the masks for bad pixels and bad stamps colliding, so make our own mask
-    psImage *mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); // The global mask
+    psImage *mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); // The global mask
     psImageInit(mask, 0);
-    psMaskType **maskData = mask->data.PS_TYPE_MASK_DATA; // Dereference for convenience
+    psImageMaskType **maskData = mask->data.PS_TYPE_IMAGE_MASK_DATA; // Dereference for convenience
 
     // Block out a border around the edge of the image
@@ -161,5 +161,5 @@
 
 bool pmSubtractionBorder(psImage *image, psImage *weight, psImage *mask,
-                         int size, psMaskType blank)
+                         int size, psImageMaskType blank)
 {
     PS_ASSERT_IMAGE_NON_NULL(image, false);
@@ -168,5 +168,5 @@
         PS_ASSERT_IMAGE_NON_NULL(mask, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(mask, image, false);
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, false);
     }
     if (weight) {
@@ -211,5 +211,5 @@
     }
     PS_ASSERT_IMAGE_NON_NULL(mask, false);
-    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, false);
+    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, false);
     PS_ASSERT_IMAGES_SIZE_EQUAL(mask, image, false);
 
@@ -233,5 +233,5 @@
 
     int numCols = image->numCols, numRows = image->numRows; // Size of image
-    psMaskType **maskData = mask->data.PS_TYPE_MASK_DATA; // Dereference mask
+    psImageMaskType **maskData = mask->data.PS_TYPE_IMAGE_MASK_DATA; // Dereference mask
 
     for (int y = 0; y < numRows; y++) {
Index: /trunk/psModules/src/imcombine/pmSubtractionMask.h
===================================================================
--- /trunk/psModules/src/imcombine/pmSubtractionMask.h	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmSubtractionMask.h	(revision 21183)
@@ -7,5 +7,5 @@
 psImage *pmSubtractionMask(const psImage *refMask, ///< Mask for the reference image (will be convolved)
                            const psImage *inMask, ///< Mask for the input image, or NULL
-                           psMaskType maskVal, ///< Value to mask out
+                           psImageMaskType maskVal, ///< Value to mask out
                            int size, ///< Half-size of the kernel (pmSubtractionKernels.size)
                            int footprint, ///< Half-size of the kernel footprint
@@ -19,5 +19,5 @@
                          psImage *mask, ///< Mask (or NULL)
                          int size,      ///< Kernel half-size
-                         psMaskType blank ///< Mask value for blank regions
+                         psImageMaskType blank ///< Mask value for blank regions
     );
 
Index: /trunk/psModules/src/imcombine/pmSubtractionMatch.c
===================================================================
--- /trunk/psModules/src/imcombine/pmSubtractionMatch.c	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmSubtractionMatch.c	(revision 21183)
@@ -98,6 +98,6 @@
                         int inner, int ringsOrder, int binning, float penalty,
                         bool optimum, const psVector *optFWHMs, int optOrder, float optThreshold,
-                        int iter, float rej, float sysError, psMaskType maskVal, psMaskType maskBad,
-                        psMaskType maskPoor, float poorFrac, float badFrac, pmSubtractionMode subMode)
+                        int iter, float rej, float sysError, psImageMaskType maskVal, psImageMaskType maskBad,
+                        psImageMaskType maskPoor, float poorFrac, float badFrac, pmSubtractionMode subMode)
 {
     if (subMode != PM_SUBTRACTION_MODE_2) {
@@ -565,8 +565,8 @@
     if (width1 == 0 || width2 == 0) {
         ratios->data.F32[index] = NAN;
-        mask->data.PS_TYPE_MASK_DATA[index] = 0xff;
+        mask->data.PS_TYPE_IMAGE_MASK_DATA[index] = 0xff;
     } else {
         ratios->data.F32[index] = (float)width1 / (float)width2;
-        mask->data.PS_TYPE_MASK_DATA[index] = 0;
+        mask->data.PS_TYPE_IMAGE_MASK_DATA[index] = 0;
         psTrace("psModules.imcombine", 3, "Stamp %d (%.1f,%.1f) widths: %d, %d --> %f\n",
                 index, stamp->x, stamp->y, width1, width2, ratios->data.F32[index]);
@@ -596,5 +596,5 @@
     PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, PM_SUBTRACTION_MODE_ERR);
 
-    psVector *mask = psVectorAlloc(stamps->num, PS_TYPE_MASK); // Mask for stamps
+    psVector *mask = psVectorAlloc(stamps->num, PS_TYPE_VECTOR_MASK); // Mask for stamps
     psVector *ratios = psVectorAlloc(stamps->num, PS_TYPE_F32); // Ratios of widths
 
@@ -624,5 +624,5 @@
         pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
         if (stamp->status != PM_SUBTRACTION_STAMP_CALCULATE && stamp->status != PM_SUBTRACTION_STAMP_USED) {
-            mask->data.PS_TYPE_MASK_DATA[i] = 0xff;
+            mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff;
             continue;
         }
Index: /trunk/psModules/src/imcombine/pmSubtractionMatch.h
===================================================================
--- /trunk/psModules/src/imcombine/pmSubtractionMatch.h	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmSubtractionMatch.h	(revision 21183)
@@ -40,7 +40,7 @@
                         float rej,      ///< Rejection threshold
                         float sysError, ///< Relative systematic error
-                        psMaskType maskVal, ///< Value to mask for input
-                        psMaskType maskBad, ///< Mask for output bad pixels
-                        psMaskType maskPoor, ///< Mask for output poor pixels
+                        psImageMaskType maskVal, ///< Value to mask for input
+                        psImageMaskType maskBad, ///< Mask for output bad pixels
+                        psImageMaskType maskPoor, ///< Mask for output poor pixels
                         float poorFrac, ///< Fraction for "poor"
                         float badFrac,   ///< Maximum fraction of bad input pixels to accept
Index: /trunk/psModules/src/imcombine/pmSubtractionStamps.c
===================================================================
--- /trunk/psModules/src/imcombine/pmSubtractionStamps.c	(revision 21182)
+++ /trunk/psModules/src/imcombine/pmSubtractionStamps.c	(revision 21183)
@@ -98,5 +98,5 @@
 
     // Determine mask value
-    psMaskType maskVal = PM_SUBTRACTION_MASK_BORDER | PM_SUBTRACTION_MASK_BAD_1 | PM_SUBTRACTION_MASK_BAD_2;
+    psImageMaskType maskVal = PM_SUBTRACTION_MASK_BORDER | PM_SUBTRACTION_MASK_BAD_1 | PM_SUBTRACTION_MASK_BAD_2;
     switch (mode) {
       case PM_SUBTRACTION_MODE_1:
@@ -115,5 +115,5 @@
 
     // Check the immediate pixel
-    if (clean && (mask->data.PS_TYPE_MASK_DATA[y][x] & (maskVal | PM_SUBTRACTION_MASK_REJ))) {
+    if (clean && (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & (maskVal | PM_SUBTRACTION_MASK_REJ))) {
         clean = false;
     }
@@ -126,5 +126,5 @@
         for (int j = yMin; j <= yMax; j++) {
             for (int i = xMin; i <= xMax; i++) {
-                if (mask->data.PS_TYPE_MASK_DATA[j][i] & maskVal) {
+                if (mask->data.PS_TYPE_IMAGE_MASK_DATA[j][i] & maskVal) {
                     clean = false;
                     goto CHECK_STAMP_MASK_DONE;
@@ -139,5 +139,5 @@
         for (int j = yMin; j <= yMax; j++) {
             for (int i = xMin; i <= xMax; i++) {
-                mask->data.PS_TYPE_MASK_DATA[j][i] |= PM_SUBTRACTION_MASK_REJ;
+                mask->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= PM_SUBTRACTION_MASK_REJ;
             }
         }
@@ -235,5 +235,5 @@
         PS_ASSERT_IMAGE_NON_NULL(subMask, NULL);
         PS_ASSERT_IMAGES_SIZE_EQUAL(image, subMask, NULL);
-        PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_MASK, NULL);
+        PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_IMAGE_MASK, NULL);
     }
     PS_ASSERT_INT_NONNEGATIVE(footprint, NULL);
@@ -377,5 +377,5 @@
     if (subMask) {
         PS_ASSERT_IMAGE_NON_NULL(subMask, NULL);
-        PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_MASK, NULL);
+        PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_IMAGE_MASK, NULL);
         if (image) {
             PS_ASSERT_IMAGE_NON_NULL(image, NULL);
Index: /trunk/psModules/src/objects/pmFootprintArrayGrow.c
===================================================================
--- /trunk/psModules/src/objects/pmFootprintArrayGrow.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmFootprintArrayGrow.c	(revision 21183)
@@ -3,6 +3,6 @@
  * @author RHL, Princeton & IfA; EAM, IfA
  *
- * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-12-08 02:51:14 $
+ * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2006 Institute for Astronomy, University of Hawaii
  */
@@ -45,5 +45,5 @@
     // Use a separable convolution: should be faster
     idImage = (psImage*)psBinaryOp(idImage, idImage, "MIN", psScalarAlloc(1, PS_TYPE_S32));
-    psImage *idImageMask = psImageCopy(NULL, idImage, PS_TYPE_MASK); // Image with 1 = object
+    psImage *idImageMask = psImageCopy(NULL, idImage, PS_TYPE_IMAGE_MASK); // Image with 1 = object
     psImage *grownIdImage = psImageConvolveMask(NULL, idImageMask, 0x01, 0x01, -r, r, -r, r); // Grown mask
     if (!grownIdImage) {
Index: /trunk/psModules/src/objects/pmFootprintFindAtPoint.c
===================================================================
--- /trunk/psModules/src/objects/pmFootprintFindAtPoint.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmFootprintFindAtPoint.c	(revision 21183)
@@ -4,6 +4,6 @@
  * @author RHL, Princeton & IfA; EAM, IfA
  *
- * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-12-08 02:51:14 $
+ * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2006 Institute for Astronomy, University of Hawaii
  */
@@ -77,5 +77,5 @@
     
     if (mask != NULL) {			// remember that we've detected these pixels
-	psMaskType *mpix = &mask->data.PS_TYPE_MASK_DATA[span->y - mask->row0][span->x0 - mask->col0];
+	psImageMaskType *mpix = &mask->data.PS_TYPE_IMAGE_MASK_DATA[span->y - mask->row0][span->x0 - mask->col0];
 
 	for (int i = 0; i <= span->x1 - span->x0; i++) {
@@ -143,5 +143,5 @@
     psF32 *imgRowF32 = NULL;		// row pointer if F32
     psS32 *imgRowS32 = NULL;		//  "   "   "  "  !F32
-    psMaskType *maskRow = NULL;		//  masks's row pointer
+    psImageMaskType *maskRow = NULL;		//  masks's row pointer
     
     const int row0 = img->row0;
@@ -186,5 +186,5 @@
 	imgRowF32 = img->data.F32[i];	// only one of
 	imgRowS32 = img->data.S32[i];	//      these is valid!
-	maskRow = mask->data.PS_TYPE_MASK_DATA[i];
+	maskRow = mask->data.PS_TYPE_IMAGE_MASK_DATA[i];
 	//
 	// Search left from the pixel diagonally to the left of (i - di, x0). If there's
@@ -354,5 +354,5 @@
  * looking for the rest of the pmFootprint.  These are generally set from peaks.
  */
-   psImage *mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+   psImage *mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
    P_PSIMAGE_SET_ROW0(mask, row0);
    P_PSIMAGE_SET_COL0(mask, col0);
@@ -365,5 +365,5 @@
        for (int i = 0; i < peaks->n; i++) {
 	   pmPeak *peak = peaks->data[i];
-	   mask->data.PS_TYPE_MASK_DATA[peak->y - mask->row0][peak->x - mask->col0] |= PM_SSPAN_STOP;
+	   mask->data.PS_TYPE_IMAGE_MASK_DATA[peak->y - mask->row0][peak->x - mask->col0] |= PM_SSPAN_STOP;
        }
    }
@@ -375,5 +375,5 @@
    imgRowF32 = img->data.F32[row];	// only one of
    imgRowS32 = img->data.S32[row];	//      these is valid!
-   psMaskType *maskRow = mask->data.PS_TYPE_MASK_DATA[row];
+   psImageMaskType *maskRow = mask->data.PS_TYPE_IMAGE_MASK_DATA[row];
    {
        int i;
Index: /trunk/psModules/src/objects/pmGrowthCurveGenerate.c
===================================================================
--- /trunk/psModules/src/objects/pmGrowthCurveGenerate.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmGrowthCurveGenerate.c	(revision 21183)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-12-08 02:51:14 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004 Institute for Astronomy, University of Hawaii
@@ -41,5 +41,5 @@
 #include "pmErrorCodes.h"
 
-pmGrowthCurve *pmGrowthCurveForPosition (psImage *image, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType markVal, float xc, float yc);
+pmGrowthCurve *pmGrowthCurveForPosition (psImage *image, pmPSF *psf, bool ignore, psImageMaskType maskVal, psImageMaskType markVal, float xc, float yc);
 
 /*****************************************************************************/
@@ -48,5 +48,5 @@
 
 // we generate the growth curve for the center of the image with the specified psf model
-bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType markVal)
+bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore, psImageMaskType maskVal, psImageMaskType markVal)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -119,5 +119,5 @@
 }
 
-pmGrowthCurve *pmGrowthCurveForPosition (psImage *image, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType markVal, float xc, float yc) {
+pmGrowthCurve *pmGrowthCurveForPosition (psImage *image, pmPSF *psf, bool ignore, psImageMaskType maskVal, psImageMaskType markVal, float xc, float yc) {
 
     float fitMag, apMag;
@@ -162,5 +162,5 @@
     psImage *view = psImageSubset (image, region);
     psImage *pixels = psImageCopy (NULL, view, PS_TYPE_F32);
-    psImage *mask = psImageCopy (NULL, view, PS_TYPE_U8);
+    psImage *mask = psImageCopy (NULL, view, PS_TYPE_IMAGE_MASK);
 
     psImageInit (pixels, 0.0);
@@ -189,5 +189,5 @@
 	    return NULL;
         }
-        psImageKeepCircle (mask, xc, yc, radius, "AND", PS_NOT_U8(markVal));
+        psImageKeepCircle (mask, xc, yc, radius, "AND", PS_NOT_IMAGE_MASK(markVal));
 
         // the 'ignore' mode is for testing
Index: /trunk/psModules/src/objects/pmModel.c
===================================================================
--- /trunk/psModules/src/objects/pmModel.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmModel.c	(revision 21183)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-11-09 00:28:18 $
+ *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -172,5 +172,5 @@
                           pmModelOpMode mode,
                           bool add,
-                          psMaskType maskVal,
+                          psImageMaskType maskVal,
                           int dx,
                           int dy
@@ -229,5 +229,5 @@
     psF32 **Rx = NULL;
     psF32 **Ry = NULL;
-    psU8  **Rm = NULL;
+    psImageMaskType **Rm = NULL;
 
     if (model->residuals) {
@@ -237,5 +237,5 @@
 	Rx = (model->residuals->Rx)   ? model->residuals->Rx->data.F32 : NULL;
 	Ry = (model->residuals->Ry)   ? model->residuals->Ry->data.F32 : NULL;
-	Rm = (model->residuals->mask) ? model->residuals->mask->data.U8 : NULL;
+	Rm = (model->residuals->mask) ? model->residuals->mask->data.PS_TYPE_IMAGE_MASK_DATA : NULL;
 	if (Ro) {
 	    NX = model->residuals->Ro->numCols;
@@ -249,5 +249,5 @@
     for (psS32 iy = 0; iy < image->numRows; iy++) {
         for (psS32 ix = 0; ix < image->numCols; ix++) {
-            if ((mask != NULL) && (mask->data.U8[iy][ix] & maskVal))
+            if ((mask != NULL) && (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal))
                 continue;
 
@@ -351,5 +351,5 @@
                 pmModel *model,
                 pmModelOpMode mode,
-                psMaskType maskVal)
+                psImageMaskType maskVal)
 {
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
@@ -365,5 +365,5 @@
                 pmModel *model,
                 pmModelOpMode mode,
-                psMaskType maskVal)
+                psImageMaskType maskVal)
 {
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
@@ -379,5 +379,5 @@
                           pmModel *model,
                           pmModelOpMode mode,
-                          psMaskType maskVal,
+                          psImageMaskType maskVal,
                           int dx,
                           int dy)
@@ -395,5 +395,5 @@
                           pmModel *model,
                           pmModelOpMode mode,
-                          psMaskType maskVal,
+                          psImageMaskType maskVal,
                           int dx,
                           int dy)
Index: /trunk/psModules/src/objects/pmModel.h
===================================================================
--- /trunk/psModules/src/objects/pmModel.h	(revision 21182)
+++ /trunk/psModules/src/objects/pmModel.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-12-09 21:16:09 $
+ * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  *
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -150,5 +150,5 @@
     pmModel *model,                     ///< The input pmModel
     pmModelOpMode mode,                 ///< mode to control how the model is added into the image
-    psMaskType maskVal                  ///< Value to mask
+    psImageMaskType maskVal		///< Value to mask
 );
 
@@ -168,5 +168,5 @@
     pmModel *model,                     ///< The input pmModel
     pmModelOpMode mode,                 ///< mode to control how the model is added into the image
-    psMaskType maskVal                  ///< Value to mask
+    psImageMaskType maskVal		///< Value to mask
 );
 
@@ -175,5 +175,5 @@
                           pmModel *model,
                           pmModelOpMode mode,
-                          psMaskType maskVal,
+                          psImageMaskType maskVal,
                           int dx,
                           int dy);
@@ -183,5 +183,5 @@
                           pmModel *model,
                           pmModelOpMode mode,
-                          psMaskType maskVal,
+                          psImageMaskType maskVal,
                           int dx,
                           int dy);
Index: /trunk/psModules/src/objects/pmPSF.h
===================================================================
--- /trunk/psModules/src/objects/pmPSF.h	(revision 21182)
+++ /trunk/psModules/src/objects/pmPSF.h	(revision 21183)
@@ -6,6 +6,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-12-09 21:16:09 $
+ * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -102,5 +102,5 @@
 double pmPSF_SXYtoModel (psF32 *fittedPar);
 
-bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType mark);
+bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore, psImageMaskType maskVal, psImageMaskType mark);
 pmPSF *pmPSFBuildSimple (char *typeName, float sxx, float syy, float sxy, ...);
 
Index: /trunk/psModules/src/objects/pmPSF_IO.c
===================================================================
--- /trunk/psModules/src/objects/pmPSF_IO.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmPSF_IO.c	(revision 21183)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-12-08 02:51:14 $
+ *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -871,4 +871,5 @@
             psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2); // Desired pixels
         }
+	// XXX notice that we are not saving the resid->mask
     }
 
Index: /trunk/psModules/src/objects/pmPSFtry.c
===================================================================
--- /trunk/psModules/src/objects/pmPSFtry.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmPSFtry.c	(revision 21183)
@@ -5,7 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.68 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-01-27 00:01:33 $
- *
+ *  @version $Revision: 1.69 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  *
@@ -115,5 +114,5 @@
     test->metricErr = psVectorAlloc (sources->n, PS_TYPE_F32);
     test->fitMag    = psVectorAlloc (sources->n, PS_TYPE_F32);
-    test->mask      = psVectorAlloc (sources->n, PS_TYPE_U8);
+    test->mask      = psVectorAlloc (sources->n, PS_TYPE_VECTOR_MASK);
 
     psVectorInit (test->mask,        0);
@@ -148,5 +147,5 @@
 
 // generate a pmPSFtry with a copy of the test PSF sources
-pmPSFtry *pmPSFtryModel (const psArray *sources, const char *modelName, pmPSFOptions *options, psMaskType maskVal, psMaskType markVal)
+pmPSFtry *pmPSFtryModel (const psArray *sources, const char *modelName, pmPSFOptions *options, psImageMaskType maskVal, psImageMaskType markVal)
 {
     bool status;
@@ -176,9 +175,9 @@
         pmSource *source = psfTry->sources->data[i];
 	if (!source->moments) {
-            psfTry->mask->data.U8[i] = PSFTRY_MASK_EXT_FAIL;
+            psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_EXT_FAIL;
 	    continue;
 	}
 	if (!source->moments->nPixels) {
-            psfTry->mask->data.U8[i] = PSFTRY_MASK_EXT_FAIL;
+            psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_EXT_FAIL;
 	    continue;
 	}
@@ -186,5 +185,5 @@
         source->modelEXT = pmSourceModelGuess (source, psfTry->psf->type);
         if (source->modelEXT == NULL) {
-            psfTry->mask->data.U8[i] = PSFTRY_MASK_EXT_FAIL;
+            psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_EXT_FAIL;
             psTrace ("psModules.objects", 4, "masking %d (%d,%d) : failed to generate model guess\n", i, source->peak->x, source->peak->y);
             continue;
@@ -198,9 +197,9 @@
 
         // clear object mask to define valid pixels
-        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "AND", PS_NOT_U8(markVal));
+        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "AND", PS_NOT_IMAGE_MASK(markVal));
 
         // exclude the poor fits
         if (!status) {
-            psfTry->mask->data.U8[i] = PSFTRY_MASK_EXT_FAIL;
+            psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_EXT_FAIL;
             psTrace ("psModules.objects", 4, "masking %d (%d,%d) : status is poor\n", i, source->peak->x, source->peak->y);
             continue;
@@ -231,5 +230,5 @@
 
         // masked for: bad model fit, outlier in parameters
-        if (psfTry->mask->data.U8[i] & PSFTRY_MASK_ALL) {
+        if (psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL) {
             psTrace ("psModules.objects", 4, "dropping %d (%d,%d) : source is masked\n", i, source->peak->x, source->peak->y);
             continue;
@@ -239,5 +238,5 @@
         source->modelPSF = pmModelFromPSF (source->modelEXT, psfTry->psf);
         if (source->modelPSF == NULL) {
-            psfTry->mask->data.U8[i] = PSFTRY_MASK_BAD_MODEL;
+            psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_BAD_MODEL;
             abort();
             continue;
@@ -253,6 +252,6 @@
         // skip poor fits
         if (!status) {
-            psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "AND", PS_NOT_U8(markVal));
-            psfTry->mask->data.U8[i] = PSFTRY_MASK_PSF_FAIL;
+            psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "AND", PS_NOT_IMAGE_MASK(markVal));
+            psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_PSF_FAIL;
             psTrace ("psModules.objects", 4, "dropping %d (%d,%d) : failed PSF fit\n", i, source->peak->x, source->peak->y);
             continue;
@@ -261,6 +260,6 @@
         status = pmSourceMagnitudes (source, psfTry->psf, PM_SOURCE_PHOT_INTERP, maskVal);
         if (!status || isnan(source->apMag)) {
-            psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "AND", PS_NOT_U8(markVal));
-            psfTry->mask->data.U8[i] = PSFTRY_MASK_BAD_PHOT;
+            psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "AND", PS_NOT_IMAGE_MASK(markVal));
+            psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_BAD_PHOT;
             psTrace ("psModules.objects", 4, "dropping %d (%d,%d) : poor photometry\n", i, source->peak->x, source->peak->y);
             continue;
@@ -268,5 +267,5 @@
 
         // clear object mask to define valid pixels
-        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "AND", PS_NOT_U8(markVal));
+        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, options->radius, "AND", PS_NOT_IMAGE_MASK(markVal));
 
         psfTry->fitMag->data.F32[i] = source->psfMag;
@@ -292,5 +291,5 @@
     psVector *flux  = psVectorAlloc (psfTry->sources->n, PS_TYPE_F32);
     psVector *chisq = psVectorAlloc (psfTry->sources->n, PS_TYPE_F32);
-    psVector *mask  = psVectorAlloc (psfTry->sources->n, PS_TYPE_MASK);
+    psVector *mask  = psVectorAlloc (psfTry->sources->n, PS_TYPE_VECTOR_MASK);
 
     // generate the x and y vectors, and mask missing models
@@ -300,9 +299,9 @@
             flux->data.F32[i] = 0.0;
             chisq->data.F32[i] = 0.0;
-            mask->data.U8[i] = 0xff;
+            mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff;
         } else {
             flux->data.F32[i] = source->modelPSF->params->data.F32[PM_PAR_I0];
             chisq->data.F32[i] = source->modelPSF->chisq / source->modelPSF->nDOF;
-            mask->data.U8[i] = 0;
+            mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0;
         }
     }
@@ -312,6 +311,5 @@
 
     // linear clipped fit of chisq trend vs flux
-    bool result = psVectorClipFitPolynomial1D(psfTry->psf->ChiTrend, options->stats, mask,
-                                              0xff, chisq, NULL, flux);
+    bool result = psVectorClipFitPolynomial1D(psfTry->psf->ChiTrend, options->stats, mask, 0xff, chisq, NULL, flux);
     psStatsOptions meanStat = psStatsMeanOption(options->stats->options); // Statistic for mean
     psStatsOptions stdevStat = psStatsStdevOption(options->stats->options); // Statistic for stdev
@@ -370,5 +368,5 @@
 
     for (int i = 0; i < psfTry->sources->n; i++) {
-        if (psfTry->mask->data.U8[i] & PSFTRY_MASK_ALL)
+        if (psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL)
             continue;
         r2rflux->data.F32[i] = PS_SQR(RADIUS) * pow(10.0, 0.4*psfTry->fitMag->data.F32[i]);
@@ -379,5 +377,5 @@
         FILE *f = fopen ("apresid.dat", "w");
         for (int i = 0; i < psfTry->sources->n; i++) {
-            int keep = (psfTry->mask->data.U8[i] & PSFTRY_MASK_ALL);
+            int keep = (psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL);
 
             pmSource *source = psfTry->sources->data[i];
@@ -427,5 +425,5 @@
         psVector *apfit = psPolynomial1DEvalVector (poly, r2rflux);
         for (int i = 0; i < psfTry->sources->n; i++) {
-            int keep = (psfTry->mask->data.U8[i] & PSFTRY_MASK_ALL);
+            int keep = (psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL);
 
             pmSource *source = psfTry->sources->data[i];
@@ -603,5 +601,5 @@
     for (int i = 0; i < sources->n; i++) {
 	// skip any masked sources (failed to fit one of the model steps or get a magnitude)
-	if (srcMask->data.U8[i]) continue;
+	if (srcMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
 	
         pmSource *source = sources->data[i];
@@ -624,5 +622,5 @@
 
         psVector *dz = NULL;
-        psVector *mask = psVectorAlloc (sources->n, PS_TYPE_U8);
+        psVector *mask = psVectorAlloc (sources->n, PS_TYPE_VECTOR_MASK);
 
         // check the fit residuals and increase Nx,Ny until the error is minimized
@@ -632,5 +630,5 @@
 	    // copy srcMask to mask (we do not want the mask values set in pmPSFFitShapeParamsMap to be sticky)
 	    for (int i = 0; i < mask->n; i++) {
-		mask->data.U8[i] = srcMask->data.U8[i];
+		mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = srcMask->data.PS_TYPE_VECTOR_MASK_DATA[i];
 	    }
             if (!pmPSFFitShapeParamsMap (psf, i, &scatterTotal, mask, x, y, mag, e0, e1, e2, dz)) {
@@ -651,5 +649,5 @@
 	// copy srcMask to mask (we do not want the mask values set in pmPSFFitShapeParamsMap to be sticky)
 	for (int i = 0; i < mask->n; i++) {
-	    mask->data.U8[i] = srcMask->data.U8[i];
+	    mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = srcMask->data.PS_TYPE_VECTOR_MASK_DATA[i];
 	}
         if (!pmPSFFitShapeParamsMap (psf, entryMin, &scatterTotal, mask, x, y, mag, e0, e1, e2, dz)) {
@@ -663,5 +661,5 @@
 	// copy mask back to srcMask
 	for (int i = 0; i < mask->n; i++) {
-	    srcMask->data.U8[i] = mask->data.U8[i];
+	    srcMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = mask->data.PS_TYPE_VECTOR_MASK_DATA[i];
 	}
 
@@ -736,5 +734,5 @@
                      pmTrend2DEval (psf->params->data[PM_PAR_E1], x->data.F32[i], y->data.F32[i]),
                      pmTrend2DEval (psf->params->data[PM_PAR_E2], x->data.F32[i], y->data.F32[i]),
-                     srcMask->data.U8[i]);
+                     srcMask->data.PS_TYPE_VECTOR_MASK_DATA[i]);
         }
         fclose (f);
@@ -851,8 +849,8 @@
 
     // the mask marks the values not used to calculate the ApTrend
-    psVector *fitMask = psVectorAlloc (x_fit->n, PS_TYPE_U8);
+    psVector *fitMask = psVectorAlloc (x_fit->n, PS_TYPE_VECTOR_MASK);
     // copy mask values to fitMask as a starting point
     for (int i = 0; i < fitMask->n; i++) {
-	fitMask->data.U8[i] = mask->data.U8[i];
+	fitMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = mask->data.PS_TYPE_VECTOR_MASK_DATA[i];
     }
 
@@ -943,5 +941,5 @@
     // XXX copy fitMask values back to mask
     for (int i = 0; i < fitMask->n; i++) {
-	mask->data.U8[i] = fitMask->data.U8[i];
+	mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = fitMask->data.PS_TYPE_VECTOR_MASK_DATA[i];
     }
     psFree (fitMask);
@@ -951,5 +949,5 @@
 
 // calculate the scatter of the parameters
-bool pmPSFShapeParamsScatter(float *scatterTotal, psVector *e0res, psVector *e1res, psVector *e2res, psVector *mask, psMaskType maskValue, psStatsOptions stdevOpt)
+bool pmPSFShapeParamsScatter(float *scatterTotal, psVector *e0res, psVector *e1res, psVector *e2res, psVector *mask, psVectorMaskType maskValue, psStatsOptions stdevOpt)
 {
 
@@ -994,5 +992,5 @@
     psVector *dE1subset = psVectorAllocEmpty (nGroup, PS_TYPE_F32);
     psVector *dE2subset = psVectorAllocEmpty (nGroup, PS_TYPE_F32);
-    psVector *mkSubset  = psVectorAllocEmpty (nGroup, PS_TYPE_U8);
+    psVector *mkSubset  = psVectorAllocEmpty (nGroup, PS_TYPE_VECTOR_MASK);
 
     int n = 0;
@@ -1007,6 +1005,6 @@
             dE2subset->data.F32[j] = e2res->data.F32[N];
 
-            mkSubset->data.U8[j]   = mask->data.U8[N];
-	    if (!mask->data.U8[N]) nValid ++;
+            mkSubset->data.PS_TYPE_VECTOR_MASK_DATA[j]   = mask->data.PS_TYPE_VECTOR_MASK_DATA[N];
+	    if (!mask->data.PS_TYPE_VECTOR_MASK_DATA[N]) nValid ++;
         }
 	if (nValid < 3) continue;
Index: /trunk/psModules/src/objects/pmPSFtry.h
===================================================================
--- /trunk/psModules/src/objects/pmPSFtry.h	(revision 21182)
+++ /trunk/psModules/src/objects/pmPSFtry.h	(revision 21183)
@@ -6,6 +6,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
- * @date $Date: 2009-01-27 00:02:16 $
+ * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -48,5 +48,5 @@
     pmPSF      *psf;                    ///< Add comment.
     psArray    *sources;                ///< pointers to the original sources
-    psVector   *mask;                   ///< Add comment.
+    psVector   *mask;                   ///< PS_TYPE_VECTOR_MASK to flag good and bad sources 
     psVector   *metric;                 ///< Add comment.
     psVector   *metricErr;              ///< Add comment.
@@ -89,5 +89,5 @@
  *
  */
-pmPSFtry *pmPSFtryModel (const psArray *sources, const char *modelName, pmPSFOptions *options, psMaskType maskVal, psMaskType mark);
+pmPSFtry *pmPSFtryModel (const psArray *sources, const char *modelName, pmPSFOptions *options, psImageMaskType maskVal, psImageMaskType mark);
 
 /** pmPSFtryMetric()
@@ -129,5 +129,5 @@
 bool pmPSFFitShapeParams (pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask);
 bool pmPSFFitShapeParamsMap (pmPSF *psf, int scale, float *scatterTotal, psVector *mask, psVector *x, psVector *y, psVector *mag, psVector *e0obs, psVector *e1obs, psVector *e2obs, psVector *dz);
-bool pmPSFShapeParamsScatter(float *scatterTotal, psVector *e0res, psVector *e1res, psVector *e2res, psVector *mask, psMaskType maskValue, psStatsOptions stdevOpt);
+bool pmPSFShapeParamsScatter(float *scatterTotal, psVector *e0res, psVector *e1res, psVector *e2res, psVector *mask, psVectorMaskType maskValue, psStatsOptions stdevOpt);
 bool pmPSFShapeParamsErrors (float *errorFloor, psVector *mag, psVector *e0res, psVector *e1res, psVector *e2res, psVector *mask, int nGroup, psStatsOptions stdevOpt);
 
Index: /trunk/psModules/src/objects/pmResiduals.c
===================================================================
--- /trunk/psModules/src/objects/pmResiduals.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmResiduals.c	(revision 21183)
@@ -4,6 +4,6 @@
  *
  * @author EAM, IfA
- * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-11-10 01:09:20 $
+ * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004 IfA, University of Hawaii
  */
@@ -43,5 +43,7 @@
     resid->Ry  = psImageAlloc (nX, nY, PS_TYPE_F32);
     resid->weight = psImageAlloc (nX, nY, PS_TYPE_F32);
-    resid->mask   = psImageAlloc (nX, nY, PS_TYPE_U8);
+    resid->mask   = psImageAlloc (nX, nY, PM_TYPE_RESID_MASK);
+
+    // NOTE : the residual mask is internal only : 1 byte is sufficient
 
     resid->xBin = xBin;
Index: /trunk/psModules/src/objects/pmResiduals.h
===================================================================
--- /trunk/psModules/src/objects/pmResiduals.h	(revision 21182)
+++ /trunk/psModules/src/objects/pmResiduals.h	(revision 21183)
@@ -4,6 +4,6 @@
  *
  * @author EAM, IfA
- * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-11-10 01:09:20 $
+ * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004 IfA, University of Hawaii
  */
@@ -31,4 +31,11 @@
 bool psMemCheckResiduals(psPtr ptr);
 
+// macros to abstract the resid mask type : these values must be consistent 
+#define PM_TYPE_RESID_MASK PS_TYPE_U8        /**< the psElemType to use for mask image */
+#define PM_TYPE_RESID_MASK_DATA U8           /**< the data member to use for mask image */
+#define PM_TYPE_RESID_MASK_NAME "psU8"       /**< the data type for mask as a string */
+typedef psU8 pmResidMaskType;               ///< the C datatype for a mask image
+#define PM_NOT_RESID_MASK(A)(UINT8_MAX-(A))
+
 /// @}
 # endif
Index: /trunk/psModules/src/objects/pmSource.c
===================================================================
--- /trunk/psModules/src/objects/pmSource.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmSource.c	(revision 21183)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.66 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-12-08 02:51:14 $
+ *  @version $Revision: 1.67 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -171,5 +171,5 @@
 
     // the maskObj is a unique mask array; create a new mask image
-    source->maskObj = in->maskObj ? psImageCopy (NULL, in->maskObj, PS_TYPE_MASK) : NULL;
+    source->maskObj = in->maskObj ? psImageCopy (NULL, in->maskObj, PS_TYPE_IMAGE_MASK) : NULL;
 
     source->type = in->type;
@@ -205,5 +205,5 @@
         mySource->maskView = psImageSubset(readout->mask,  srcRegion);
         // the object mask is a copy, and used to define the source pixels
-        mySource->maskObj = psImageCopy(NULL, mySource->maskView, PS_TYPE_MASK);
+        mySource->maskObj = psImageCopy(NULL, mySource->maskView, PS_TYPE_IMAGE_MASK);
     }
     mySource->region   = srcRegion;
@@ -255,5 +255,5 @@
         // re-copy the main mask pixels.  NOTE: the user will need to reset the object mask
         // pixels (eg, with psImageKeepCircle)
-        mySource->maskObj = psImageCopy (mySource->maskObj, mySource->maskView, PS_TYPE_MASK);
+        mySource->maskObj = psImageCopy (mySource->maskObj, mySource->maskView, PS_TYPE_IMAGE_MASK);
 
         // drop the old modelFlux pixels and force the user to re-create
@@ -505,5 +505,5 @@
 *****************************************************************************/
 
-bool pmSourceRoughClass(psRegion *region, psArray *sources, psMetadata *recipe, pmPSFClump clump, psMaskType maskSat)
+bool pmSourceRoughClass(psRegion *region, psArray *sources, psMetadata *recipe, pmPSFClump clump, psImageMaskType maskSat)
 {
     psTrace("psModules.objects", 5, "---- begin ----");
@@ -738,5 +738,5 @@
         psF32 *vPix = source->pixels->data.F32[row];
         psF32 *vWgt = source->weight->data.F32[row];
-        psU8  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.U8[row];
+        psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
 
         for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
@@ -848,5 +848,5 @@
 # endif
 // construct a realization of the source model
-bool pmSourceCacheModel (pmSource *source, psMaskType maskVal) {
+bool pmSourceCacheModel (pmSource *source, psImageMaskType maskVal) {
     PS_ASSERT_PTR_NON_NULL(source, false);
     // select appropriate model
@@ -867,5 +867,5 @@
 // construct a realization of the source model
 // XXX this function should optionally save an existing psf image from modelFlux
-bool pmSourceCachePSF (pmSource *source, psMaskType maskVal) {
+bool pmSourceCachePSF (pmSource *source, psImageMaskType maskVal) {
     PS_ASSERT_PTR_NON_NULL(source, false);
 
@@ -885,5 +885,5 @@
 
 // should we call pmSourceCacheModel if it does not exist?
-bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal, int dx, int dy)
+bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psImageMaskType maskVal, int dx, int dy)
 {
     PS_ASSERT_PTR_NON_NULL(source, false);
@@ -915,7 +915,7 @@
         }
 
-        psU8 **mask = NULL;
+        psImageMaskType **mask = NULL;
         if (source->maskObj) {
-            mask = source->maskObj->data.U8;
+            mask = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
         }
 
@@ -957,17 +957,17 @@
 }
 
-bool pmSourceAdd (pmSource *source, pmModelOpMode mode, psMaskType maskVal) {
+bool pmSourceAdd (pmSource *source, pmModelOpMode mode, psImageMaskType maskVal) {
     return pmSourceOp (source, mode, true, maskVal, 0, 0);
 }
 
-bool pmSourceSub (pmSource *source, pmModelOpMode mode, psMaskType maskVal) {
+bool pmSourceSub (pmSource *source, pmModelOpMode mode, psImageMaskType maskVal) {
     return pmSourceOp (source, mode, false, maskVal, 0, 0);
 }
 
-bool pmSourceAddWithOffset (pmSource *source, pmModelOpMode mode, psMaskType maskVal, int dx, int dy) {
+bool pmSourceAddWithOffset (pmSource *source, pmModelOpMode mode, psImageMaskType maskVal, int dx, int dy) {
     return pmSourceOp (source, mode, true, maskVal, dx, dy);
 }
 
-bool pmSourceSubWithOffset (pmSource *source, pmModelOpMode mode, psMaskType maskVal, int dx, int dy) {
+bool pmSourceSubWithOffset (pmSource *source, pmModelOpMode mode, psImageMaskType maskVal, int dx, int dy) {
     return pmSourceOp (source, mode, false, maskVal, dx, dy);
 }
Index: /trunk/psModules/src/objects/pmSource.h
===================================================================
--- /trunk/psModules/src/objects/pmSource.h	(revision 21182)
+++ /trunk/psModules/src/objects/pmSource.h	(revision 21183)
@@ -3,6 +3,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-12-09 21:16:09 $
+ * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -210,5 +210,5 @@
     psMetadata *metadata,               ///< Contains classification parameters
     pmPSFClump clump,                   ///< Statistics about the PSF clump
-    psMaskType maskSat                  ///< Mask value for saturated pixels
+    psImageMaskType maskSat		///< Mask value for saturated pixels
 );
 
@@ -231,12 +231,12 @@
 pmModel *pmSourceGetModel (bool *isPSF, const pmSource *source);
 
-bool pmSourceAdd (pmSource *source, pmModelOpMode mode, psMaskType maskVal);
-bool pmSourceSub (pmSource *source, pmModelOpMode mode, psMaskType maskVal);
-bool pmSourceAddWithOffset (pmSource *source, pmModelOpMode mode, psMaskType maskVal, int dx, int dy);
-bool pmSourceSubWithOffset (pmSource *source, pmModelOpMode mode, psMaskType maskVal, int dx, int dy);
-
-bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal, int dx, int dy);
-bool pmSourceCacheModel (pmSource *source, psMaskType maskVal);
-bool pmSourceCachePSF (pmSource *source, psMaskType maskVal);
+bool pmSourceAdd (pmSource *source, pmModelOpMode mode, psImageMaskType maskVal);
+bool pmSourceSub (pmSource *source, pmModelOpMode mode, psImageMaskType maskVal);
+bool pmSourceAddWithOffset (pmSource *source, pmModelOpMode mode, psImageMaskType maskVal, int dx, int dy);
+bool pmSourceSubWithOffset (pmSource *source, pmModelOpMode mode, psImageMaskType maskVal, int dx, int dy);
+
+bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psImageMaskType maskVal, int dx, int dy);
+bool pmSourceCacheModel (pmSource *source, psImageMaskType maskVal);
+bool pmSourceCachePSF (pmSource *source, psImageMaskType maskVal);
 
 int             pmSourceSortBySN (const void **a, const void **b);
Index: /trunk/psModules/src/objects/pmSourceFitModel.c
===================================================================
--- /trunk/psModules/src/objects/pmSourceFitModel.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmSourceFitModel.c	(revision 21183)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-12-08 02:51:14 $
+ *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -56,5 +56,5 @@
                        pmModel *model,
                        pmSourceFitMode mode,
-                       psMaskType maskVal)
+                       psImageMaskType maskVal)
 {
     psTrace("psModules.objects", 5, "---- %s begin ----\n", __func__);
@@ -81,5 +81,5 @@
         for (psS32 j = 0; j < source->pixels->numCols; j++) {
             // skip masked points
-            if (source->maskObj->data.U8[i][j] & maskVal) {
+            if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j] & maskVal) {
                 continue;
             }
@@ -121,5 +121,5 @@
     // create the minimization constraints
     psMinConstraint *constraint = psMinConstraintAlloc();
-    constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_U8);
+    constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK);
     constraint->checkLimits = model->modelLimits;
 
@@ -131,5 +131,5 @@
         nParams = 1;
         psVectorInit (constraint->paramMask, 1);
-        constraint->paramMask->data.U8[PM_PAR_I0] = 0;
+        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
         break;
     case PM_SOURCE_FIT_PSF:
@@ -137,7 +137,7 @@
         nParams = 3;
         psVectorInit (constraint->paramMask, 1);
-        constraint->paramMask->data.U8[PM_PAR_I0] = 0;
-        constraint->paramMask->data.U8[PM_PAR_XPOS] = 0;
-        constraint->paramMask->data.U8[PM_PAR_YPOS] = 0;
+        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
+        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_XPOS] = 0;
+        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_YPOS] = 0;
         break;
     case PM_SOURCE_FIT_EXT:
@@ -145,5 +145,5 @@
         nParams = params->n - 1;
         psVectorInit (constraint->paramMask, 0);
-        constraint->paramMask->data.U8[PM_PAR_SKY] = 1;
+        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1;
         break;
     default:
@@ -175,5 +175,5 @@
             fprintf (stderr, "%f ", params->data.F32[i]);
         }
-        if ((constraint->paramMask != NULL) && constraint->paramMask->data.U8[i])
+        if ((constraint->paramMask != NULL) && constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i])
             continue;
         dparams->data.F32[i] = sqrt(covar->data.F32[i][i]);
@@ -192,13 +192,13 @@
     if (constraint->paramMask != NULL) {
         psVector *delta = psVectorAlloc (params->n, PS_TYPE_F32);
-        psVector *altmask = psVectorAlloc (params->n, PS_TYPE_U8);
-        altmask->data.U8[0] = 1;
+        psVector *altmask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK);
+        altmask->data.PS_TYPE_VECTOR_MASK_DATA[0] = 1;
         for (int i = 1; i < dparams->n; i++) {
-            altmask->data.U8[i] = (constraint->paramMask->data.U8[i]) ? 0 : 1;
+            altmask->data.PS_TYPE_VECTOR_MASK_DATA[i] = (constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) ? 0 : 1;
         }
         psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, model->modelFunc);
 
         for (int i = 0; i < dparams->n; i++) {
-            if (!constraint->paramMask->data.U8[i])
+            if (!constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i])
                 continue;
             // note that delta is the value *subtracted* from the parameter
Index: /trunk/psModules/src/objects/pmSourceFitModel.h
===================================================================
--- /trunk/psModules/src/objects/pmSourceFitModel.h	(revision 21182)
+++ /trunk/psModules/src/objects/pmSourceFitModel.h	(revision 21183)
@@ -3,6 +3,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-06-20 02:22:26 $
+ * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -41,5 +41,5 @@
     pmModel *model,   ///< model to be fitted
     pmSourceFitMode mode,  ///< define parameters to be fitted
-    psMaskType maskVal                  ///< Value to mask
+    psImageMaskType maskVal		///< Value to mask
 );
 
@@ -71,5 +71,5 @@
     psArray *modelSet,   ///< model to be fitted
     pmSourceFitMode mode,  ///< define parameters to be fitted
-    psMaskType maskVal                  ///< Vale to mask
+    psImageMaskType maskVal		///< Vale to mask
 
 );
Index: /trunk/psModules/src/objects/pmSourceFitSet.c
===================================================================
--- /trunk/psModules/src/objects/pmSourceFitSet.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmSourceFitSet.c	(revision 21183)
@@ -6,7 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-01-24 20:52:26 $
- *
+ *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  *
@@ -394,5 +393,5 @@
             for (int j = 0; j < paramOne->n; j++) {
                 if (j == PM_PAR_I0) continue;
-                constraint->paramMask->data.U8[n + j] = 1;
+                constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n + j] = 1;
             }
             break;
@@ -403,10 +402,10 @@
                 if (j == PM_PAR_YPOS) continue;
                 if (j == PM_PAR_I0) continue;
-                constraint->paramMask->data.U8[n + j] = 1;
+                constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n + j] = 1;
             }
             break;
           case PM_SOURCE_FIT_EXT:
             // EXT model fits all params (except sky)
-            constraint->paramMask->data.U8[n + PM_PAR_SKY] = 1;
+            constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n + PM_PAR_SKY] = 1;
             break;
           default:
@@ -445,5 +444,5 @@
                      psArray *modelSet,
                      pmSourceFitMode mode,
-                     psMaskType maskVal)
+                     psImageMaskType maskVal)
 {
     psTrace("psModules.objects", 3, "---- %s begin ----\n", __func__);
@@ -469,5 +468,5 @@
         for (psS32 j = 0; j < source->pixels->numCols; j++) {
             // skip masked points
-            if (source->maskObj->data.U8[i][j] & maskVal) {
+            if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j] & maskVal) {
                 continue;
             }
@@ -515,5 +514,5 @@
     // create the minimization constraints
     psMinConstraint *constraint = psMinConstraintAlloc();
-    constraint->paramMask = psVectorAlloc (thisSet->nParamSet, PS_TYPE_U8);
+    constraint->paramMask = psVectorAlloc (thisSet->nParamSet, PS_TYPE_VECTOR_MASK);
     constraint->checkLimits = pmSourceFitSetCheckLimits;
 
@@ -528,5 +527,5 @@
     if (psTraceGetLevel("psModules.objects") >= 5) {
         for (int i = 0; i < params->n; i++) {
-            fprintf (stderr, "%d %f %d\n", i, params->data.F32[i], constraint->paramMask->data.U8[i]);
+            fprintf (stderr, "%d %f %d\n", i, params->data.F32[i], constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]);
         }
     }
@@ -560,5 +559,5 @@
     psVector *dparams = psVectorAlloc (thisSet->nParamSet, PS_TYPE_F32);
     for (int i = 0; i < dparams->n; i++) {
-        if ((constraint->paramMask != NULL) && constraint->paramMask->data.U8[i])
+        if ((constraint->paramMask != NULL) && constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i])
             continue;
         dparams->data.F32[i] = sqrt(covar->data.F32[i][i]);
@@ -568,13 +567,13 @@
     if (constraint->paramMask != NULL) {
         psVector *delta = psVectorAlloc (params->n, PS_TYPE_F32);
-        psVector *altmask = psVectorAlloc (params->n, PS_TYPE_U8);
-        altmask->data.U8[0] = 1;
+        psVector *altmask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK);
+        altmask->data.PS_TYPE_VECTOR_MASK_DATA[0] = 1;
         for (int i = 1; i < dparams->n; i++) {
-            altmask->data.U8[i] = (constraint->paramMask->data.U8[i]) ? 0 : 1;
+            altmask->data.PS_TYPE_VECTOR_MASK_DATA[i] = (constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) ? 0 : 1;
         }
         psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, pmSourceFitSetFunction);
 
         for (int i = 0; i < dparams->n; i++) {
-            if (!constraint->paramMask->data.U8[i])
+            if (!constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i])
                 continue;
             // note that delta is the value *subtracted* from the parameter
Index: /trunk/psModules/src/objects/pmSourceFitSet.h
===================================================================
--- /trunk/psModules/src/objects/pmSourceFitSet.h	(revision 21182)
+++ /trunk/psModules/src/objects/pmSourceFitSet.h	(revision 21183)
@@ -3,6 +3,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- * @date $Date: 2009-01-24 20:52:26 $
+ * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -54,8 +54,8 @@
  */
 bool pmSourceFitSet(
-    pmSource *source,   ///< The input pmSource
-    psArray *modelSet,   ///< model to be fitted
-    pmSourceFitMode mode,  ///< define parameters to be fitted
-    psMaskType maskVal                  ///< Vale to mask
+    pmSource *source,			///< The input pmSource
+    psArray *modelSet,			///< model to be fitted
+    pmSourceFitMode mode,		///< define parameters to be fitted
+    psImageMaskType maskVal		///< Vale to mask
 
 );
Index: /trunk/psModules/src/objects/pmSourceMatch.c
===================================================================
--- /trunk/psModules/src/objects/pmSourceMatch.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmSourceMatch.c	(revision 21183)
@@ -122,5 +122,5 @@
     match->image = psVectorAllocEmpty(num, PS_TYPE_U32);
     match->index = psVectorAllocEmpty(num, PS_TYPE_U32);
-    match->mask = psVectorAllocEmpty(num, PS_TYPE_MASK);
+    match->mask = psVectorAllocEmpty(num, PS_TYPE_VECTOR_MASK);
 
     return match;
@@ -143,5 +143,5 @@
     match->image->data.S32[num] = image;
     match->index->data.S32[num] = index;
-    match->mask->data.PS_TYPE_MASK_DATA[num] = 0;
+    match->mask->data.PS_TYPE_VECTOR_MASK_DATA[num] = 0;
     match->num++;
 
@@ -316,5 +316,5 @@
         double star = 0.0, starErr = 0.0; // Accumulators for star
         for (int j = 0; j < match->num; j++) {
-            if (match->mask->data.PS_TYPE_MASK_DATA[j]) {
+            if (match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) {
                 continue;
             }
@@ -347,5 +347,5 @@
         pmSourceMatch *match = matches->data[i]; // Matched stars
         for (int j = 0; j < match->num; j++) {
-            if (match->mask->data.PS_TYPE_MASK_DATA[j]) {
+            if (match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) {
                 continue;
             }
@@ -373,5 +373,5 @@
         pmSourceMatch *match = matches->data[i]; // Matched stars
         for (int j = 0; j < match->num; j++) {
-            if (match->mask->data.PS_TYPE_MASK_DATA[j]) {
+            if (match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) {
                 continue;
             }
@@ -474,5 +474,5 @@
         pmSourceMatch *match = matches->data[i]; // Matched stars
         for (int j = 0; j < match->num; j++) {
-            if (match->mask->data.PS_TYPE_MASK_DATA[j]) {
+            if (match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) {
                 continue;
             }
@@ -488,5 +488,5 @@
             if (PS_SQR(dev) > starClip * (PS_SQR(magErr) + sysErr2)) {
                 numRejected++;
-                match->mask->data.PS_TYPE_MASK_DATA[j] = 0xFF;
+                match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xFF;
             }
         }
Index: /trunk/psModules/src/objects/pmSourceMoments.c
===================================================================
--- /trunk/psModules/src/objects/pmSourceMoments.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmSourceMoments.c	(revision 21183)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-12-08 02:51:14 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -100,5 +100,5 @@
         psF32 *vPix = source->pixels->data.F32[row];
         psF32 *vWgt = source->weight->data.F32[row];
-        psU8  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.U8[row];
+        psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
 
         for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
@@ -190,5 +190,5 @@
         psF32 *vPix = source->pixels->data.F32[row];
         psF32 *vWgt = source->weight->data.F32[row];
-        psU8  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.U8[row];
+        psImageMaskType  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
 
         for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
@@ -342,5 +342,5 @@
         psF32 *vPix = source->pixels->data.F32[row];
         psF32 *vWgt = source->weight->data.F32[row];
-        psU8  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.U8[row];
+        psImageMaskType  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
 
         for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
Index: /trunk/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /trunk/psModules/src/objects/pmSourcePhotometry.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmSourcePhotometry.c	(revision 21183)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-12-08 02:51:14 $
+ *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -66,5 +66,5 @@
 
 // XXX masked region should be (optionally) elliptical
-bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psMaskType maskVal)
+bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(source, false);
@@ -306,5 +306,5 @@
 
 // return source aperture magnitude
-bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask, psMaskType maskVal)
+bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(apMag, false);
@@ -324,5 +324,5 @@
 
     psF32 **imData = image->data.F32;
-    psU8 **mkData = mask->data.U8;
+    psImageMaskType **mkData = mask->data.PS_TYPE_IMAGE_MASK_DATA;
 
     // measure apMag
@@ -344,5 +344,5 @@
 
 // return source aperture magnitude
-bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask, psMaskType maskVal)
+bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(pixWeight, false);
@@ -412,5 +412,5 @@
             if (my >= NY)
                 continue;
-            if (mask->data.U8[my][mx] & maskVal)
+            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)
                 continue;
 
@@ -475,7 +475,7 @@
     for (yi = yIs, yj = yJs; yi < yIe; yi++, yj++) {
         for (xi = xIs, xj = xJs; xi < xIe; xi++, xj++) {
-            if (Ti->data.U8[yi][xi])
-                continue;
-            if (Tj->data.U8[yj][xj])
+            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi])
+                continue;
+            if (Tj->data.PS_TYPE_IMAGE_MASK_DATA[yj][xj])
                 continue;
 
@@ -540,7 +540,7 @@
     for (yi = yIs, yj = yJs; yi < yIe; yi++, yj++) {
         for (xi = xIs, xj = xJs; xi < xIe; xi++, xj++) {
-            if (Ti->data.U8[yi][xi])
-                continue;
-            if (Tj->data.U8[yj][xj])
+            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi])
+                continue;
+            if (Tj->data.PS_TYPE_IMAGE_MASK_DATA[yj][xj])
                 continue;
 
@@ -578,5 +578,5 @@
     for (int yi = 0; yi < Pi->numRows; yi++) {
         for (int xi = 0; xi < Pi->numCols; xi++) {
-            if (Ti->data.U8[yi][xi])
+            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi])
                 continue;
             if (!unweighted_sum) {
@@ -613,5 +613,5 @@
 
 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight,
-                    psMaskType maskVal)
+                    psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(model, false);
@@ -624,5 +624,5 @@
     for (int j = 0; j < image->numRows; j++) {
         for (int i = 0; i < image->numCols; i++) {
-            if (mask->data.U8[j][i] & maskVal)
+            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[j][i] & maskVal)
                 continue;
             if (weight->data.F32[j][i] <= 0)
@@ -657,5 +657,5 @@
     for (int yi = 0; yi < Pi->numRows; yi++) {
         for (int xi = 0; xi < Pi->numCols; xi++) {
-            if (Ti->data.U8[yi][xi])
+            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi])
                 continue;
             if (!unweighted_sum) {
@@ -734,7 +734,7 @@
     for (yi = yIs, yj = yJs; yi < yIe; yi++, yj++) {
         for (xi = xIs, xj = xJs; xi < xIe; xi++, xj++) {
-            if (Ti->data.U8[yi][xi])
-                continue;
-            if (Tj->data.U8[yj][xj])
+            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi])
+                continue;
+            if (Tj->data.PS_TYPE_IMAGE_MASK_DATA[yj][xj])
                 continue;
 
@@ -798,7 +798,7 @@
     for (yi = yIs, yj = yJs; yi < yIe; yi++, yj++) {
         for (xi = xIs, xj = xJs; xi < xIe; xi++, xj++) {
-            if (Ti->data.U8[yi][xi])
-                continue;
-            if (Tj->data.U8[yj][xj])
+            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi])
+                continue;
+            if (Tj->data.PS_TYPE_IMAGE_MASK_DATA[yj][xj])
                 continue;
 
Index: /trunk/psModules/src/objects/pmSourcePhotometry.h
===================================================================
--- /trunk/psModules/src/objects/pmSourcePhotometry.h	(revision 21182)
+++ /trunk/psModules/src/objects/pmSourcePhotometry.h	(revision 21183)
@@ -4,6 +4,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-07-15 20:25:00 $
+ * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -46,11 +46,11 @@
     psImage *image,                     ///< image pixels to be used
     psImage *mask,                      ///< mask of pixels to ignore
-    psMaskType maskVal                  ///< Value to mask
+    psImageMaskType maskVal		///< Value to mask
 );
 
 bool pmSourceMagnitudesInit (psMetadata *config);
-bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psMaskType maskVal);
-bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask, psMaskType maskVal);
-bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psMaskType maskVal);
+bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal);
+bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask, psImageMaskType maskVal);
+bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psImageMaskType maskVal);
 
 
Index: /trunk/psModules/src/objects/pmSourceSky.c
===================================================================
--- /trunk/psModules/src/objects/pmSourceSky.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmSourceSky.c	(revision 21183)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-12-08 02:51:14 $
+ *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -52,6 +52,6 @@
     psStatsOptions statsOptions,
     psF32 Radius,
-    psMaskType maskVal,
-    psMaskType markVal)
+    psImageMaskType maskVal,
+    psImageMaskType markVal)
 {
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
@@ -86,5 +86,5 @@
         return false;
     }
-    psImageMaskRegion(mask, srcRegion, "AND", PS_NOT_U8(markVal));
+    psImageMaskRegion(mask, srcRegion, "AND", PS_NOT_IMAGE_MASK(markVal));
     double value = psStatsGetValue(myStats, statistic);
     psFree(myStats);
@@ -107,6 +107,6 @@
     psStatsOptions statsOptions,
     psF32 Radius,
-    psMaskType maskVal,
-    psMaskType markVal
+    psImageMaskType maskVal,
+    psImageMaskType markVal
 )
 {
@@ -142,5 +142,5 @@
         return false;
     }
-    psImageMaskRegion(mask, srcRegion, "AND", PS_NOT_U8(markVal));
+    psImageMaskRegion(mask, srcRegion, "AND", PS_NOT_IMAGE_MASK(markVal));
     double value = psStatsGetValue(myStats, statistic);
     psFree(myStats);
Index: /trunk/psModules/src/objects/pmSourceSky.h
===================================================================
--- /trunk/psModules/src/objects/pmSourceSky.h	(revision 21182)
+++ /trunk/psModules/src/objects/pmSourceSky.h	(revision 21183)
@@ -2,6 +2,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-06-20 02:22:26 $
+ * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -30,6 +30,6 @@
     psStatsOptions statsOptions, ///< The statistic used in calculating the background sky
     float Radius,   ///< The inner radius of the square annulus to exclude
-    psMaskType maskVal,                 ///< Value to mask
-    psMaskType mark                     ///< Mask value for marking
+    psImageMaskType maskVal,                 ///< Value to mask
+    psImageMaskType mark                     ///< Mask value for marking
 );
 
@@ -40,6 +40,6 @@
     psStatsOptions statsOptions, ///< The statistic used in calculating the background sky
     float Radius,   ///< The inner radius of the square annulus to exclude
-    psMaskType maskVal,                 ///< Value to mask
-    psMaskType mark                     ///< Mask value for marking
+    psImageMaskType maskVal,                 ///< Value to mask
+    psImageMaskType mark                     ///< Mask value for marking
 );
 
Index: /trunk/psModules/src/objects/pmSourceVisual.c
===================================================================
--- /trunk/psModules/src/objects/pmSourceVisual.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmSourceVisual.c	(revision 21183)
@@ -57,5 +57,5 @@
 	model->data.F32[i] = pmTrend2DEval (trend, x->data.F32[i], y->data.F32[i]);
 	resid->data.F32[i] = param->data.F32[i] - model->data.F32[i];
-	if (mask->data.U8[i]) continue;
+	if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
 	min = PS_MIN (min, resid->data.F32[i]);
 	max = PS_MAX (max, resid->data.F32[i]);
Index: /trunk/psModules/src/objects/pmTrend2D.c
===================================================================
--- /trunk/psModules/src/objects/pmTrend2D.c	(revision 21182)
+++ /trunk/psModules/src/objects/pmTrend2D.c	(revision 21183)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-01-27 00:00:44 $
+ *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *  Copyright 2004 Institute for Astronomy, University of Hawaii
  *
@@ -179,5 +179,5 @@
 }
 
-bool pmTrend2DFit(pmTrend2D *trend, psVector *mask, psMaskType maskVal, const psVector *x,
+bool pmTrend2DFit(pmTrend2D *trend, psVector *mask, psVectorMaskType maskVal, const psVector *x,
                   const psVector *y, const psVector *f, const psVector *df)
 {
@@ -234,5 +234,5 @@
 }
 
-psVector *pmTrend2DEvalVector(const pmTrend2D *trend, psVector *mask, psMaskType maskValue, const psVector *x, const psVector *y)
+psVector *pmTrend2DEvalVector(const pmTrend2D *trend, psVector *mask, psVectorMaskType maskValue, const psVector *x, const psVector *y)
 {
     PM_ASSERT_TREND2D_NON_NULL(trend, NULL);
Index: /trunk/psModules/src/objects/pmTrend2D.h
===================================================================
--- /trunk/psModules/src/objects/pmTrend2D.h	(revision 21182)
+++ /trunk/psModules/src/objects/pmTrend2D.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- * @date $Date: 2009-01-27 00:00:45 $
+ * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:38 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -80,5 +80,5 @@
 bool pmTrend2DFit(pmTrend2D *trend,
                   psVector *mask,       // Warning: mask is modified!
-                  psMaskType maskVal,
+                  psVectorMaskType maskVal,
                   const psVector *x,
                   const psVector *y,
@@ -90,5 +90,5 @@
                      float x, float y
     );
-psVector *pmTrend2DEvalVector(const pmTrend2D *trend, psVector *mask, psMaskType maskValue, 
+psVector *pmTrend2DEvalVector(const pmTrend2D *trend, psVector *mask, psVectorMaskType maskValue, 
                               const psVector *x, const psVector *y
     );
Index: /trunk/psastro/src/psastroAstromGuess.c
===================================================================
--- /trunk/psastro/src/psastroAstromGuess.c	(revision 21182)
+++ /trunk/psastro/src/psastroAstromGuess.c	(revision 21183)
@@ -267,5 +267,5 @@
     psVector *cornerDn = psVectorAllocEmpty (100, PS_TYPE_F32);
 
-    psVector *cornerMK = psVectorAllocEmpty (100, PS_TYPE_U8);
+    psVector *cornerMK = psVectorAllocEmpty (100, PS_TYPE_VECTOR_MASK);
 
     if (DEBUG) psastroDumpCorners ("corners.up.guess3.dat", "corners.dn.guess3.dat", fpa);
Index: /trunk/psastro/src/psastroFixChips.c
===================================================================
--- /trunk/psastro/src/psastroFixChips.c	(revision 21182)
+++ /trunk/psastro/src/psastroFixChips.c	(revision 21183)
@@ -160,5 +160,5 @@
     psPlaneTransform *map = psPlaneTransformAlloc (1, 1);
   
-    psVector *mask = psVectorAlloc (nPts, PS_TYPE_U8);
+    psVector *mask = psVectorAlloc (nPts, PS_TYPE_VECTOR_MASK);
     psVectorInit (mask, 0);
 
Index: /trunk/psastro/src/psastroLuminosityFunction.c
===================================================================
--- /trunk/psastro/src/psastroLuminosityFunction.c	(revision 21182)
+++ /trunk/psastro/src/psastroLuminosityFunction.c	(revision 21183)
@@ -91,5 +91,5 @@
     psLogMsg ("psastro", 4, "fitting %d points to luminosity function\n", n);
 
-    psVector *mask = psVectorAlloc (Mag->n, PS_TYPE_MASK);
+    psVector *mask = psVectorAlloc (Mag->n, PS_TYPE_VECTOR_MASK);
     psVectorInit (mask, 0);
 
@@ -108,5 +108,5 @@
     double mMaxValid = NAN;
     for (int i = 0; i < Mag->n; i++) {
-        if (mask->data.U8[i]) continue;
+        if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
         if (isnan(mMinValid) || (Mag->data.F32[i] < mMinValid)) {
             mMinValid = Mag->data.F32[i];
Index: /trunk/psastro/src/psastroMaskUpdates.Mosaic.c
===================================================================
--- /trunk/psastro/src/psastroMaskUpdates.Mosaic.c	(revision 21182)
+++ /trunk/psastro/src/psastroMaskUpdates.Mosaic.c	(revision 21183)
@@ -9,9 +9,9 @@
 pmCell *pmCellInChip (pmChip *chip, float x, float y);
 bool pmCellCoordsForChip (float *xCell, float *yCell, pmCell *cell, float xChip, float yChip);
-bool psastroMaskCircle (psImage *mask, char value, float x0, float y0, float dX, float dY);
-bool psastroMaskBox (psImage *mask, char value, float x0, float y0, float dL, float dW, float theta);
-void psastroMaskLine (psImage *mask, char value, double x1, double y1, double x2, double y2, int dW);
-void psastroMaskLineBresen (psImage *mask, char value, int X1, int Y1, int X2, int Y2, int dW, int swapcoords);
-void psastroMaskRectangle (psImage *mask, char value, int x0, int y0, int x1, int y1);
+bool psastroMaskCircle (psImage *mask, psImageMaskType value, float x0, float y0, float dX, float dY);
+bool psastroMaskBox (psImage *mask, psImageMaskType value, float x0, float y0, float dL, float dW, float theta);
+void psastroMaskLine (psImage *mask, psImageMaskType value, double x1, double y1, double x2, double y2, int dW);
+void psastroMaskLineBresen (psImage *mask, psImageMaskType value, int X1, int Y1, int X2, int Y2, int dW, int swapcoords);
+void psastroMaskRectangle (psImage *mask, psImageMaskType value, int x0, int y0, int x1, int y1);
 
 // create a mask or mask regions based on the collection of reference stars that are 
@@ -25,6 +25,6 @@
     float zeropt, exptime;
 
-    psMaskType maskValue  = pmConfigMaskGet("GHOST", config); // Mask value for ghost pixels
-    psMaskType maskBlank  = pmConfigMaskGet("BLANK", config); // Mask value for blank pixels
+    psImageMaskType maskValue  = pmConfigMaskGet("GHOST", config); // Mask value for ghost pixels
+    psImageMaskType maskBlank  = pmConfigMaskGet("BLANK", config); // Mask value for blank pixels
 
     // select the current recipe
@@ -342,5 +342,5 @@
 
 // XXX should be doing an OR
-bool psastroMaskCircle (psImage *mask, char value, float x0, float y0, float dX, float dY) {
+bool psastroMaskCircle (psImage *mask, psImageMaskType value, float x0, float y0, float dX, float dY) {
 
     // XXX need to worry about row0, col0
@@ -357,5 +357,5 @@
 	    if (r2 > 1.0) continue;
 	    
-	    mask->data.U8[jy][jx] |= value;
+	    mask->data.PS_TYPE_IMAGE_MASK_DATA[jy][jx] |= value;
 	}
     }
@@ -364,5 +364,5 @@
 
 // XXX should be doing an OR
-bool psastroMaskBox (psImage *mask, char value, float x0, float y0, float dL, float dW, float theta) {
+bool psastroMaskBox (psImage *mask, psImageMaskType value, float x0, float y0, float dL, float dW, float theta) {
 
     // draw a series of lines (from -0.5*dW to +0.5*dW) of length dL, starting at x0, y0, angle theta
@@ -379,5 +379,5 @@
 
 // identify the quadrant and draw the correct line
-void psastroMaskLine (psImage *mask, char value, double x1, double y1, double x2, double y2, int dW) {
+void psastroMaskLine (psImage *mask, psImageMaskType value, double x1, double y1, double x2, double y2, int dW) {
 
   int FlipDirect, FlipCoords;
@@ -408,5 +408,5 @@
 // use the Bresenham line drawing technique
 // integer-only Bresenham line-draw version which is fast
-void psastroMaskLineBresen (psImage *mask, char value, int X1, int Y1, int X2, int Y2, int dW, int swapcoords) {
+void psastroMaskLineBresen (psImage *mask, psImageMaskType value, int X1, int Y1, int X2, int Y2, int dW, int swapcoords) {
 
     int X, Y, dX, dY;
@@ -425,5 +425,5 @@
 		    if (y < 0) continue;
 		    if (y >= mask->numCols) continue;
-		    mask->data.U8[X][y] |= value;
+		    mask->data.PS_TYPE_IMAGE_MASK_DATA[X][y] |= value;
 		}
 	    } else {
@@ -432,5 +432,5 @@
 		    if (y < 0) continue;
 		    if (y >= mask->numRows) continue;
-		    mask->data.U8[y][X] |= value;
+		    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][X] |= value;
 		}
 	    }
@@ -450,10 +450,10 @@
 }
 
-void psastroMaskRectangle (psImage *mask, char value, int x0, int y0, int x1, int y1) {
+void psastroMaskRectangle (psImage *mask, psImageMaskType value, int x0, int y0, int x1, int y1) {
     for (int iy = PS_MAX(0,y0); iy < PS_MIN(y1,mask->numRows); iy++) {
 	for (int ix = PS_MAX(0,x0); ix < PS_MIN(x1,mask->numCols); ix++) {
-	    mask->data.U8[iy][ix] |= value;
-	}
-    }
-}
-
+	    mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= value;
+	}
+    }
+}
+
Index: /trunk/psastro/src/psastroMaskUpdates.c
===================================================================
--- /trunk/psastro/src/psastroMaskUpdates.c	(revision 21182)
+++ /trunk/psastro/src/psastroMaskUpdates.c	(revision 21183)
@@ -11,9 +11,9 @@
 bool pmChipCoordsForCell (float *xChip, float *yChip, pmCell *cell, float xCell, float yCell);
 
-bool psastroMaskCircle (psImage *mask, char value, float x0, float y0, float dX, float dY);
-bool psastroMaskBox (psImage *mask, char value, float x0, float y0, float dL, float dW, float theta);
-void psastroMaskLine (psImage *mask, char value, double x1, double y1, double x2, double y2, int dW);
-void psastroMaskLineBresen (psImage *mask, char value, int X1, int Y1, int X2, int Y2, int dW, int swapcoords);
-void psastroMaskRectangle (psImage *mask, char value, int x0, int y0, int x1, int y1);
+bool psastroMaskCircle (psImage *mask, psImageMaskType value, float x0, float y0, float dX, float dY);
+bool psastroMaskBox (psImage *mask, psImageMaskType value, float x0, float y0, float dL, float dW, float theta);
+void psastroMaskLine (psImage *mask, psImageMaskType value, double x1, double y1, double x2, double y2, int dW);
+void psastroMaskLineBresen (psImage *mask, psImageMaskType value, int X1, int Y1, int X2, int Y2, int dW, int swapcoords);
+void psastroMaskRectangle (psImage *mask, psImageMaskType value, int x0, int y0, int x1, int y1);
 
 // create a mask or mask regions based on the collection of reference stars that are
@@ -27,7 +27,7 @@
     float zeropt, exptime;
 
-    psMaskType maskValue  = pmConfigMaskGet("GHOST", config); // Mask value for ghost pixels
-
-    // psMaskType maskBlank  = pmConfigMaskGet("BLANK", config); // Mask value for blank pixels
+    psImageMaskType maskValue  = pmConfigMaskGet("GHOST", config); // Mask value for ghost pixels
+
+    // psImageMaskType maskBlank  = pmConfigMaskGet("BLANK", config); // Mask value for blank pixels
 
     // select the current recipe
@@ -376,5 +376,5 @@
 
 // XXX should be doing an OR
-bool psastroMaskCircle (psImage *mask, char value, float x0, float y0, float dX, float dY) {
+bool psastroMaskCircle (psImage *mask, psImageMaskType value, float x0, float y0, float dX, float dY) {
 
     // XXX need to worry about row0, col0
@@ -391,5 +391,5 @@
             if (r2 > 1.0) continue;
 
-            mask->data.U8[jy][jx] |= value;
+            mask->data.PS_TYPE_IMAGE_MASK_DATA[jy][jx] |= value;
         }
     }
@@ -398,5 +398,5 @@
 
 // XXX should be doing an OR
-bool psastroMaskBox (psImage *mask, char value, float x0, float y0, float dL, float dW, float theta) {
+bool psastroMaskBox (psImage *mask, psImageMaskType value, float x0, float y0, float dL, float dW, float theta) {
 
     // draw a series of lines (from -0.5*dW to +0.5*dW) of length dL, starting at x0, y0, angle theta
@@ -413,5 +413,5 @@
 
 // identify the quadrant and draw the correct line
-void psastroMaskLine (psImage *mask, char value, double x1, double y1, double x2, double y2, int dW) {
+void psastroMaskLine (psImage *mask, psImageMaskType value, double x1, double y1, double x2, double y2, int dW) {
 
   int FlipDirect, FlipCoords;
@@ -442,5 +442,5 @@
 // use the Bresenham line drawing technique
 // integer-only Bresenham line-draw version which is fast
-void psastroMaskLineBresen (psImage *mask, char value, int X1, int Y1, int X2, int Y2, int dW, int swapcoords) {
+void psastroMaskLineBresen (psImage *mask, psImageMaskType value, int X1, int Y1, int X2, int Y2, int dW, int swapcoords) {
 
     int X, Y, dX, dY;
@@ -459,5 +459,5 @@
                     if (y < 0) continue;
                     if (y >= mask->numCols) continue;
-                    mask->data.U8[X][y] |= value;
+                    mask->data.PS_TYPE_IMAGE_MASK_DATA[X][y] |= value;
                 }
             } else {
@@ -466,5 +466,5 @@
                     if (y < 0) continue;
                     if (y >= mask->numRows) continue;
-                    mask->data.U8[y][X] |= value;
+                    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][X] |= value;
                 }
             }
@@ -484,5 +484,5 @@
 }
 
-void psastroMaskRectangle (psImage *mask, char value, int x0, int y0, int x1, int y1) {
+void psastroMaskRectangle (psImage *mask, psImageMaskType value, int x0, int y0, int x1, int y1) {
 
     int xs = PS_MAX (0, PS_MIN (mask->numCols, PS_MIN (x0, x1)));
@@ -493,7 +493,7 @@
     for (int iy = ys; iy < ye; iy++) {
         for (int ix = xs; ix < xe; ix++) {
-            mask->data.U8[iy][ix] |= value;
-        }
-    }
-}
-
+            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= value;
+        }
+    }
+}
+
Index: /trunk/psastro/src/psastroMosaicFPtoTP.c
===================================================================
--- /trunk/psastro/src/psastroMosaicFPtoTP.c	(revision 21182)
+++ /trunk/psastro/src/psastroMosaicFPtoTP.c	(revision 21183)
@@ -74,5 +74,5 @@
 
     // constant errors
-    psVector *mask = psVectorAlloc (X->n, PS_TYPE_U8);
+    psVector *mask = psVectorAlloc (X->n, PS_TYPE_VECTOR_MASK);
     psVectorInit (mask, 0);
 
Index: /trunk/psphot/src/psphot.h
===================================================================
--- /trunk/psphot/src/psphot.h	(revision 21182)
+++ /trunk/psphot/src/psphot.h	(revision 21183)
@@ -40,5 +40,6 @@
 bool            psphotMomentsStats (pmReadout *readout, psMetadata *recipe, psArray *sources);
 bool            psphotFitSourcesLinear (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf, bool final);
-bool            psphotReplaceUnfitSources (psArray *sources, psMaskType maskVal);
+bool            psphotReplaceUnfitSources (psArray *sources, psImageMaskType maskVal);
+
 bool            psphotReplaceAllSources (psArray *sources, psMetadata *recipe);
 bool            psphotRemoveAllSources (psArray *sources, psMetadata *recipe);
@@ -70,7 +71,7 @@
 
 // used by psphotFindDetections
-psImage        *psphotSignificanceImage (pmReadout *readout, psMetadata *recipe, const int pass, psMaskType maskVal);
+psImage        *psphotSignificanceImage (pmReadout *readout, psMetadata *recipe, const int pass, psImageMaskType maskVal);
 psArray        *psphotFindPeaks (psImage *significance, pmReadout *readout, psMetadata *recipe, const float threshold, const int nMax);
-bool            psphotFindFootprints (pmDetections *detections, psImage *significance, pmReadout *readout, psMetadata *recipe, const int pass, psMaskType maskVal);
+bool            psphotFindFootprints (pmDetections *detections, psImage *significance, pmReadout *readout, psMetadata *recipe, const int pass, psImageMaskType maskVal);
 psErrorCode     psphotCullPeaks(const psImage *img, const psImage *weight, const psMetadata *recipe, psArray *footprints);
 
@@ -81,5 +82,5 @@
 // basic support functions
 void            psphotModelClassInit (void);
-bool            psphotGrowthCurve (pmReadout *readout, pmPSF *psf, bool ignore, psMaskType maskVal);
+bool            psphotGrowthCurve (pmReadout *readout, pmPSF *psf, bool ignore, psImageMaskType maskVal);
 bool            psphotSetMaskAndWeight (pmConfig *config, pmReadout *readout, psMetadata *recipe);
 void            psphotSourceFreePixels (psArray *sources);
@@ -87,8 +88,8 @@
 // functions to set the correct source pixels
 bool            psphotInitRadiusPSF (const psMetadata *recipe, const pmModelType type);
-bool            psphotCheckRadiusPSF (pmReadout *readout, pmSource *source, pmModel *model, psMaskType markVal);
-bool            psphotCheckRadiusPSFBlend (pmReadout *readout, pmSource *source, pmModel *model, psMaskType markVal, float dR);
+bool            psphotCheckRadiusPSF (pmReadout *readout, pmSource *source, pmModel *model, psImageMaskType markVal);
+bool            psphotCheckRadiusPSFBlend (pmReadout *readout, pmSource *source, pmModel *model, psImageMaskType markVal, float dR);
 bool            psphotInitRadiusEXT (psMetadata *recipe, pmModelType type);
-bool            psphotCheckRadiusEXT (pmReadout *readout, pmSource *source, pmModel *model, psMaskType markVal);
+bool            psphotCheckRadiusEXT (pmReadout *readout, pmSource *source, pmModel *model, psImageMaskType markVal);
 
 // output functions
@@ -109,12 +110,12 @@
 bool            psphotInitLimitsPSF (psMetadata *recipe, pmReadout *readout);
 bool            psphotInitLimitsEXT (psMetadata *recipe);
-bool            psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf, psMaskType maskVal, psMaskType markVal);
-bool            psphotFitBlob (pmReadout *readout, pmSource *source, psArray *sources, pmPSF *psf, psMaskType maskVal, psMaskType markVal);
-bool            psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf, psMaskType maskVal, psMaskType markVal);
-pmModel        *psphotFitEXT (pmReadout *readout, pmSource *source, pmModelType modelType, psMaskType maskVal, psMaskType markVal);
-psArray        *psphotFitDBL (pmReadout *readout, pmSource *source, psMaskType maskVal, psMaskType markVal);
+bool            psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal);
+bool            psphotFitBlob (pmReadout *readout, pmSource *source, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal);
+bool            psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal);
+pmModel        *psphotFitEXT (pmReadout *readout, pmSource *source, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal);
+psArray        *psphotFitDBL (pmReadout *readout, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
 
 // functions to support simultaneous multi-source fitting
-bool            psphotFitSet (pmSource *oneSrc, pmModel *oneModel, char *fitset, pmSourceFitMode mode, psMaskType maskVal);
+bool            psphotFitSet (pmSource *oneSrc, pmModel *oneModel, char *fitset, pmSourceFitMode mode, psImageMaskType maskVal);
 
 // plotting functions (available if libkapa is installed)
@@ -137,21 +138,21 @@
 bool            psphotMosaicSubimage (psImage *outImage, pmSource *source, int Xo, int Yo, int DX, int DY, bool normalize);
 
-bool            psphotAddWithTest (pmSource *source, bool useState, psMaskType maskVal);
-bool            psphotSubWithTest (pmSource *source, bool useState, psMaskType maskVal);
-bool            psphotSetState (pmSource *source, bool curState, psMaskType maskVal);
+bool            psphotAddWithTest (pmSource *source, bool useState, psImageMaskType maskVal);
+bool            psphotSubWithTest (pmSource *source, bool useState, psImageMaskType maskVal);
+bool            psphotSetState (pmSource *source, bool curState, psImageMaskType maskVal);
 bool            psphotDeblendSatstars (psArray *sources, psMetadata *recipe);
 bool            psphotSourceSize (pmConfig *config, pmReadout *readout, psArray *sources, psMetadata *recipe, long first);
 
-bool            psphotMakeResiduals (psArray *sources, psMetadata *recipe, pmPSF *psf, psMaskType maskVal);
-
-pmModel        *psphotPSFConvModel (pmReadout *readout, pmSource *source, pmModelType modelType, psMaskType maskVal, psMaskType markVal, int psfSize);
+bool            psphotMakeResiduals (psArray *sources, psMetadata *recipe, pmPSF *psf, psImageMaskType maskVal);
+
+pmModel        *psphotPSFConvModel (pmReadout *readout, pmSource *source, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize);
 
 psKernel       *psphotKernelFromPSF (pmSource *source, int nPix);
 
-bool            psphotRadialProfile (pmSource *source, psMetadata *recipe, psMaskType maskVal);
-bool            psphotPetrosian (pmSource *source, psMetadata *recipe, psMaskType maskVal);
-bool            psphotIsophotal (pmSource *source, psMetadata *recipe, psMaskType maskVal);
-bool            psphotAnnuli (pmSource *source, psMetadata *recipe, psMaskType maskVal);
-bool            psphotKron (pmSource *source, psMetadata *recipe, psMaskType maskVal);
+bool            psphotRadialProfile (pmSource *source, psMetadata *recipe, psImageMaskType maskVal);
+bool            psphotPetrosian (pmSource *source, psMetadata *recipe, psImageMaskType maskVal);
+bool            psphotIsophotal (pmSource *source, psMetadata *recipe, psImageMaskType maskVal);
+bool            psphotAnnuli (pmSource *source, psMetadata *recipe, psImageMaskType maskVal);
+bool            psphotKron (pmSource *source, psMetadata *recipe, psImageMaskType maskVal);
 
 // psphotVisual functions
@@ -168,5 +169,5 @@
 bool psphotVisualShowSatStars (psMetadata *recipe, pmPSF *psf, psArray *sources);
 bool psphotVisualShowPSFModel (pmReadout *readout, pmPSF *psf);
-bool psphotVisualPlotRadialProfile (int myKapa, pmSource *source, psMaskType maskVal);
+bool psphotVisualPlotRadialProfile (int myKapa, pmSource *source, psImageMaskType maskVal);
 bool psphotVisualPlotRadialProfiles (psMetadata *recipe, psArray *sources);
 bool psphotVisualShowFlags (psArray *sources);
@@ -223,5 +224,5 @@
 bool psphotMakeFluxScale (psImage *image, psMetadata *recipe, pmPSF *psf);
 bool psphotMakeGrowthCurve (pmReadout *readout, psMetadata *recipe, pmPSF *psf);
-bool psphotDumpPSFStars (pmReadout *readout, pmPSFtry *try, float radius, psMaskType maskVal, psMaskType markVal);
+bool psphotDumpPSFStars (pmReadout *readout, pmPSFtry *try, float radius, psImageMaskType maskVal, psImageMaskType markVal);
 
 bool psphotCheckStarDistribution (psArray *sources, psArray *stars, pmPSFOptions *options);
Index: /trunk/psphot/src/psphotAddNoise.c
===================================================================
--- /trunk/psphot/src/psphotAddNoise.c	(revision 21182)
+++ /trunk/psphot/src/psphotAddNoise.c	(revision 21183)
@@ -23,5 +23,5 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
Index: /trunk/psphot/src/psphotAnnuli.c
===================================================================
--- /trunk/psphot/src/psphotAnnuli.c	(revision 21182)
+++ /trunk/psphot/src/psphotAnnuli.c	(revision 21183)
@@ -1,5 +1,5 @@
 # include "psphotInternal.h"
 
-bool psphotAnnuli (pmSource *source, psMetadata *recipe, psMaskType maskVal) {
+bool psphotAnnuli (pmSource *source, psMetadata *recipe, psImageMaskType maskVal) {
 
   assert (source->extpars);
Index: /trunk/psphot/src/psphotApResid.c
===================================================================
--- /trunk/psphot/src/psphotApResid.c	(revision 21182)
+++ /trunk/psphot/src/psphotApResid.c	(revision 21183)
@@ -44,9 +44,9 @@
 
     // bit-masks to test for good/bad pixels
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT");
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     assert (maskVal);
 
     // bit-mask to mark pixels not used in analysis
-    psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT");
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     assert (markVal);
 
@@ -100,5 +100,5 @@
 	    psArrayAdd(job->args, 1, psf);
 	    PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32);
-	    PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_U8); // XXX change this to use abstract mask type info
+	    PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
 
 	    PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nskip
@@ -139,5 +139,5 @@
 
     // gather the stats to assess the aperture residuals
-    psVector *mask    = psVectorAllocEmpty (300, PS_TYPE_U8);
+    psVector *mask    = psVectorAllocEmpty (300, PS_TYPE_VECTOR_MASK);
     psVector *mag     = psVectorAllocEmpty (300, PS_TYPE_F32);
     psVector *xPos    = psVectorAllocEmpty (300, PS_TYPE_F32);
@@ -176,5 +176,5 @@
         yPos->data.F32[Npsf]    = model->params->data.F32[PM_PAR_YPOS];
 
-        mask->data.U8[Npsf] = 0;
+        mask->data.PS_TYPE_VECTOR_MASK_DATA[Npsf] = 0;
 
         dMag->data.F32[Npsf] = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
@@ -242,5 +242,5 @@
                      mag->data.F32[i], dMag->data.F32[i], dMagSys->data.F32[i],
                      apResid->data.F32[i], apResidRes->data.F32[i],
-                     mask->data.U8[i]);
+                     mask->data.PS_TYPE_VECTOR_MASK_DATA[i]);
         }
         fclose (dumpFile);
@@ -325,5 +325,5 @@
     psVector *dMSubset = psVectorAllocEmpty (nGroup, PS_TYPE_F32);
     psVector *dASubset = psVectorAllocEmpty (nGroup, PS_TYPE_F32);
-    psVector *mkSubset = psVectorAllocEmpty (nGroup, PS_TYPE_U8);
+    psVector *mkSubset = psVectorAllocEmpty (nGroup, PS_TYPE_VECTOR_MASK);
 
     int n = 0;
@@ -334,5 +334,5 @@
             dMSubset->data.F32[j] = dMag->data.F32[N];
             dASubset->data.F32[j] = dap->data.F32[N];
-            mkSubset->data.U8[j]  = mask->data.U8[N];
+            mkSubset->data.PS_TYPE_VECTOR_MASK_DATA[j] = mask->data.PS_TYPE_VECTOR_MASK_DATA[N];
         }
         dMSubset->n = j;
@@ -460,5 +460,5 @@
     pmPSF *psf                      = job->args->data[1];
     pmSourcePhotometryMode photMode = PS_SCALAR_VALUE(job->args->data[2],S32);
-    psMaskType maskVal              = PS_SCALAR_VALUE(job->args->data[3],U8);
+    psImageMaskType maskVal         = PS_SCALAR_VALUE(job->args->data[3],PS_TYPE_IMAGE_MASK_DATA);
 
     for (int i = 0; i < sources->n; i++) {
Index: /trunk/psphot/src/psphotBlendFit.c
===================================================================
--- /trunk/psphot/src/psphotBlendFit.c	(revision 21182)
+++ /trunk/psphot/src/psphotBlendFit.c	(revision 21183)
@@ -133,9 +133,9 @@
 
     // bit-masks to test for good/bad pixels
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT");
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     assert (maskVal);
 
     // bit-mask to mark pixels not used in analysis
-    psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT");
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     assert (markVal);
 
Index: /trunk/psphot/src/psphotChoosePSF.c
===================================================================
--- /trunk/psphot/src/psphotChoosePSF.c	(revision 21182)
+++ /trunk/psphot/src/psphotChoosePSF.c	(revision 21183)
@@ -24,9 +24,9 @@
 
     // bit-masks to test for good/bad pixels
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT");
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     assert (maskVal);
 
     // bit-mask to mark pixels not used in analysis
-    psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT");
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     assert (markVal);
 
@@ -258,5 +258,5 @@
     for (int i = 0; i < try->sources->n; i++) {
         pmSource *source = try->sources->data[i];
-        if (try->mask->data.U8[i]) {
+        if (try->mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
             source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
         }
Index: /trunk/psphot/src/psphotExtendedSourceAnalysis.c
===================================================================
--- /trunk/psphot/src/psphotExtendedSourceAnalysis.c	(revision 21182)
+++ /trunk/psphot/src/psphotExtendedSourceAnalysis.c	(revision 21183)
@@ -12,5 +12,5 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
Index: /trunk/psphot/src/psphotExtendedSourceFits.c
===================================================================
--- /trunk/psphot/src/psphotExtendedSourceFits.c	(revision 21182)
+++ /trunk/psphot/src/psphotExtendedSourceFits.c	(revision 21183)
@@ -13,8 +13,8 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
-    psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); // Mask value for bad pixels
     assert (markVal);
 
Index: /trunk/psphot/src/psphotExtendedSources.c
===================================================================
--- /trunk/psphot/src/psphotExtendedSources.c	(revision 21182)
+++ /trunk/psphot/src/psphotExtendedSources.c	(revision 21183)
@@ -12,5 +12,5 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
Index: /trunk/psphot/src/psphotFindDetections.c
===================================================================
--- /trunk/psphot/src/psphotFindDetections.c	(revision 21182)
+++ /trunk/psphot/src/psphotFindDetections.c	(revision 21183)
@@ -10,5 +10,5 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
Index: /trunk/psphot/src/psphotFindFootprints.c
===================================================================
--- /trunk/psphot/src/psphotFindFootprints.c	(revision 21182)
+++ /trunk/psphot/src/psphotFindFootprints.c	(revision 21183)
@@ -1,5 +1,5 @@
 # include "psphotInternal.h"
 
-bool psphotFindFootprints (pmDetections *detections, psImage *significance, pmReadout *readout, psMetadata *recipe, const int pass, psMaskType maskVal) {
+bool psphotFindFootprints (pmDetections *detections, psImage *significance, pmReadout *readout, psMetadata *recipe, const int pass, psImageMaskType maskVal) {
 
     bool status;
Index: /trunk/psphot/src/psphotFitSet.c
===================================================================
--- /trunk/psphot/src/psphotFitSet.c	(revision 21182)
+++ /trunk/psphot/src/psphotFitSet.c	(revision 21183)
@@ -2,5 +2,5 @@
 
 // This is only used by psphotModelTest.c
-bool psphotFitSet (pmSource *source, pmModel *oneModel, char *fitset, pmSourceFitMode mode, psMaskType maskVal) {
+bool psphotFitSet (pmSource *source, pmModel *oneModel, char *fitset, pmSourceFitMode mode, psImageMaskType maskVal) {
 
     double x, y, Io;
Index: /trunk/psphot/src/psphotFitSourcesLinear.c
===================================================================
--- /trunk/psphot/src/psphotFitSourcesLinear.c	(revision 21182)
+++ /trunk/psphot/src/psphotFitSourcesLinear.c	(revision 21183)
@@ -10,5 +10,5 @@
 // the analysis is performed wrt the simulated pixel values
 
-static bool SetBorderMatrixElements (psSparseBorder *border, pmReadout *readout, psArray *sources, bool constant_weights, int SKY_FIT_ORDER, psMaskType markVal);
+static bool SetBorderMatrixElements (psSparseBorder *border, pmReadout *readout, psArray *sources, bool constant_weights, int SKY_FIT_ORDER, psImageMaskType markVal);
 
 bool psphotFitSourcesLinear (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf, bool final) {
@@ -23,9 +23,9 @@
 
     // bit-masks to test for good/bad pixels
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT");
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     assert (maskVal);
 
     // bit-mask to mark pixels not used in analysis
-    psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT");
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     assert (markVal);
 
@@ -233,5 +233,5 @@
 // on the pixels which correspond to all of the sources of interest.  These elements fill in
 // the border matrix components in the sparse matrix equation.
-static bool SetBorderMatrixElements (psSparseBorder *border, pmReadout *readout, psArray *sources, bool constant_weights, int SKY_FIT_ORDER, psMaskType markVal) {
+static bool SetBorderMatrixElements (psSparseBorder *border, pmReadout *readout, psArray *sources, bool constant_weights, int SKY_FIT_ORDER, psImageMaskType markVal) {
 
     // generate the image-wide weight terms
@@ -248,5 +248,5 @@
         float x = model->params->data.F32[PM_PAR_XPOS];
         float y = model->params->data.F32[PM_PAR_YPOS];
-        psImageMaskCircle (source->maskView, x, y, model->radiusFit, "AND", PS_NOT_U8(markVal));
+        psImageMaskCircle (source->maskView, x, y, model->radiusFit, "AND", PS_NOT_IMAGE_MASK(markVal));
     }
 
@@ -254,5 +254,5 @@
     psF32 **image  = readout->image->data.F32;
     psF32 **weight = readout->weight->data.F32;
-    psU8  **mask   = readout->mask->data.U8;
+    psImageMaskType  **mask   = readout->mask->data.PS_TYPE_IMAGE_MASK_DATA;
 
     double w, x, y, x2, xy, y2, xc, yc, wt, f, fo, fx, fy;
@@ -288,5 +288,5 @@
 
     // turn off MARK for all image pixels
-    psImageMaskRegion (readout->mask, fullArray, "AND", PS_NOT_U8(markVal));
+    psImageMaskRegion (readout->mask, fullArray, "AND", PS_NOT_IMAGE_MASK(markVal));
 
     // set the Border T elements
Index: /trunk/psphot/src/psphotGuessModels.c
===================================================================
--- /trunk/psphot/src/psphotGuessModels.c	(revision 21182)
+++ /trunk/psphot/src/psphotGuessModels.c	(revision 21183)
@@ -41,9 +41,9 @@
 
     // bit-masks to test for good/bad pixels
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT");
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     assert (maskVal);
 
     // bit-mask to mark pixels not used in analysis
-    psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT");
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     assert (markVal);
 
@@ -73,6 +73,6 @@
 
 	    // XXX change these to use abstract mask type info
-	    PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_U8);
-	    PS_ARRAY_ADD_SCALAR(job->args, markVal,  PS_TYPE_U8);
+	    PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
+	    PS_ARRAY_ADD_SCALAR(job->args, markVal,  PS_TYPE_IMAGE_MASK);
 
 	    if (!psThreadJobAddPending(job)) {
@@ -130,6 +130,6 @@
     pmPSF *psf         = job->args->data[2];
     
-    psMaskType maskVal = PS_SCALAR_VALUE(job->args->data[3],U8);
-    psMaskType markVal = PS_SCALAR_VALUE(job->args->data[4],U8);
+    psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[3],PS_TYPE_IMAGE_MASK_DATA);
+    psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[4],PS_TYPE_IMAGE_MASK_DATA);
 
     int nSrc = 0;
Index: /trunk/psphot/src/psphotIsophotal.c
===================================================================
--- /trunk/psphot/src/psphotIsophotal.c	(revision 21182)
+++ /trunk/psphot/src/psphotIsophotal.c	(revision 21183)
@@ -1,5 +1,5 @@
 # include "psphotInternal.h"
 
-bool psphotIsophotal (pmSource *source, psMetadata *recipe, psMaskType maskVal) {
+bool psphotIsophotal (pmSource *source, psMetadata *recipe, psImageMaskType maskVal) {
 
   assert (source->extpars);
Index: /trunk/psphot/src/psphotKron.c
===================================================================
--- /trunk/psphot/src/psphotKron.c	(revision 21182)
+++ /trunk/psphot/src/psphotKron.c	(revision 21183)
@@ -1,5 +1,5 @@
 # include "psphotInternal.h"
 
-bool psphotKron (pmSource *source, psMetadata *recipe, psMaskType maskVal) {
+bool psphotKron (pmSource *source, psMetadata *recipe, psImageMaskType maskVal) {
 
   psLogMsg ("psphot", PS_LOG_INFO, "not implemented\n");
Index: /trunk/psphot/src/psphotMagnitudes.c
===================================================================
--- /trunk/psphot/src/psphotMagnitudes.c	(revision 21182)
+++ /trunk/psphot/src/psphotMagnitudes.c	(revision 21183)
@@ -28,9 +28,9 @@
 
     // bit-masks to test for good/bad pixels
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT");
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     assert (maskVal);
 
     // bit-mask to mark pixels not used in analysis
-    psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT");
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     assert (markVal);
 
Index: /trunk/psphot/src/psphotMakeGrowthCurve.c
===================================================================
--- /trunk/psphot/src/psphotMakeGrowthCurve.c	(revision 21182)
+++ /trunk/psphot/src/psphotMakeGrowthCurve.c	(revision 21183)
@@ -11,9 +11,9 @@
 
     // bit-masks to test for good/bad pixels
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT");
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     assert (maskVal);
 
     // bit-mask to mark pixels not used in analysis
-    psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT");
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     assert (markVal);
 
Index: /trunk/psphot/src/psphotMakeResiduals.c
===================================================================
--- /trunk/psphot/src/psphotMakeResiduals.c	(revision 21182)
+++ /trunk/psphot/src/psphotMakeResiduals.c	(revision 21183)
@@ -1,9 +1,9 @@
 # include "psphotInternal.h"
 
-bool psphotMakeResiduals (psArray *sources, psMetadata *recipe, pmPSF *psf, psMaskType maskVal) {
+bool psphotMakeResiduals (psArray *sources, psMetadata *recipe, pmPSF *psf, psImageMaskType maskVal) {
 
     bool status, isPSF;
     double flux, dflux;
-    psU8 mflux;
+    psImageMaskType mflux;
 
     psTimerStart ("psphot.residuals");
@@ -69,8 +69,15 @@
     // - set output pixel, weight, and mask
 
-    // XXX need to set these correctly!!
-    const int badMask = 1;              // mask bits
-    const int poorMask = 2;             //       from psImageInterpolate
-    const int clippedMask = 4;          // mask bit set for clipped values
+    // these mask values do not correspond to the recipe values: they
+    // are not propagated to images: they just need to fit in an 8-bit
+    // value.  they are supplied to psImageInterpolate, which takes a
+    // psImageMaskType; the mask portion of the result from
+    // psImageInterpolate is supplied to fmasks, which is then used by
+    // psVectorStats
+
+    const psImageMaskType badMask     = 0x01;	// mask bits
+    const psImageMaskType poorMask    = 0x02;	// from psImageInterpolate
+    const psImageMaskType clippedMask = 0x04;	// mask bit set for clipped values
+    const psVectorMaskType fmaskVal = badMask | poorMask | clippedMask;
 
     // determine the maximum image size from the input sources
@@ -95,5 +102,5 @@
         psImage *image  = psImageCopy (NULL, source->pixels,   PS_TYPE_F32);
         psImage *weight = psImageCopy (NULL, source->weight,   PS_TYPE_F32);
-        psImage *mask   = psImageCopy (NULL, source->maskView, PS_TYPE_U8);
+        psImage *mask   = psImageCopy (NULL, source->maskView, PS_TYPE_IMAGE_MASK);
         pmModelSub (image, mask, model, PM_MODEL_OP_FUNC, maskVal);
 
@@ -103,9 +110,9 @@
         psBinaryOp (weight, weight, "/", psScalarAlloc(Io*Io, PS_TYPE_F32));
 
-        // we will interpolate the image and weight - include the mask or not?
-        // XXX consider better values for the mask bits
-        psImageInterpolation *interp =
-            psImageInterpolationAlloc(mode, image, weight, NULL, 0xff, 0.0, 0.0, badMask, poorMask, 0.0, 0);
-        psArrayAdd (input,  100, interp);
+        // we interpolate the image and weight - include the mask or not?
+	// XXX why not the mask?
+        // psImageInterpolation *interp = psImageInterpolationAlloc(mode, image, weight, mask, maskVal, 0.0, 0.0, badMask, poorMask, 0.0, 0);
+        psImageInterpolation *interp = psImageInterpolationAlloc(mode, image, weight, NULL, 0xff, 0.0, 0.0, badMask, poorMask, 0.0, 0);
+        psArrayAdd (input, 100, interp);
 
         // save the X,Y position for future reference
@@ -131,5 +138,5 @@
     psVector *fluxes  = psVectorAlloc (input->n, PS_TYPE_F32);
     psVector *dfluxes = psVectorAlloc (input->n, PS_TYPE_F32);
-    psVector *fmasks  = psVectorAlloc (input->n, PS_TYPE_U8);
+    psVector *fmasks  = psVectorAlloc (input->n, PS_TYPE_VECTOR_MASK);
 
     // statistic to use to determine baseline for clipping
@@ -164,21 +171,22 @@
                 bool offImage = false;
                 if (psImageInterpolate (&flux, &dflux, &mflux, ix, iy, interp) == PS_INTERPOLATE_STATUS_OFF) {
+                    // fprintf (stderr, "off image: %f %f : %f %f\n", ix, iy, flux, dflux);
                     // This pixel is off the image
                     offImage = true;
-                    fmasks->data.U8[i] = 1;
-                    // fprintf (stderr, "off image: %f %f : %f %f\n", ix, iy, flux, dflux);
-                }
-                fluxes->data.F32[i] = flux;
-                dfluxes->data.F32[i] = dflux;
-                fmasks->data.U8[i] = mflux;
+                    fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = badMask;
+                } else {
+		  fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = mflux; // XXX is mflux IMAGE or VECTOR type?
+		}
+		fluxes->data.F32[i] = flux;
+		dfluxes->data.F32[i] = dflux;
                 if (isnan(flux)) {
-                    fmasks->data.U8[i] = 1;
-                }
-                if (fmasks->data.U8[i] == 0) {
+                    fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = badMask;
+                }
+                if (fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] == 0) {
                     nGoodPixel ++;
                 }
             }
 
-            // skip pixels which are off the image...
+            // skip pixels with insufficient data
             bool validPixel = (SPATIAL_ORDER == 0) ? (nGoodPixel > 1) : (nGoodPixel > 3);
             if (!validPixel) {
@@ -186,5 +194,5 @@
                 resid->Rx->data.F32[oy][ox] = 0.0;
                 resid->Ry->data.F32[oy][ox] = 0.0;
-                resid->mask->data.U8[oy][ox] = 1;
+                resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox] = badMask;
                 continue;
             }
@@ -192,5 +200,5 @@
             // measure the robust median to determine a baseline reference value
             *fluxClip = *fluxClipDef;
-            psVectorStats (fluxClip, fluxes, NULL, fmasks, 0xff);
+            psVectorStats (fluxClip, fluxes, NULL, fmasks, fmaskVal);
             psErrorClear();             // clear (ignore) any outstanding errors
 
@@ -202,9 +210,9 @@
                 float swing = fabs(delta) / sigma;
 
-                // make this a user option
+		// mask pixels which are out of range
                 if (swing > nSigma) {
-                    fmasks->data.U8[i] = clippedMask;
-                }
-		if (!fmasks->data.U8[i]) nKeep++;
+                    fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = clippedMask;
+                }
+		if (!fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i]) nKeep++;
             }
 
@@ -212,5 +220,5 @@
                 // measure the desired statistic on the unclipped pixels
                 *fluxStats = *fluxStatsDef;
-                psVectorStats (fluxStats, fluxes, NULL, fmasks, 0xff);
+                psVectorStats (fluxStats, fluxes, NULL, fmasks, fmaskVal);
                 psErrorClear();         // clear (ignore) any outstanding errors
 
@@ -220,8 +228,8 @@
 
                 if (fabs(resid->Ro->data.F32[oy][ox]) < pixelSN*fluxStats->sampleStdev/sqrt(nKeep)) {
-                  resid->mask->data.U8[oy][ox] = 1;
-                }
-
-		// fprintf (stderr, "res: %2d %2d : %6.4f  %6.4f  %6.4f   %3d  %1d\n", ox, oy, resid->Ro->data.F32[oy][ox], fluxStats->sampleStdev, fluxStats->sampleStdev/sqrt(nKeep), nKeep, resid->mask->data.U8[oy][ox]);
+                  resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox] = 1;
+                }
+
+		// fprintf (stderr, "res: %2d %2d : %6.4f  %6.4f  %6.4f   %3d  %1d\n", ox, oy, resid->Ro->data.F32[oy][ox], fluxStats->sampleStdev, fluxStats->sampleStdev/sqrt(nKeep), nKeep, resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox]);
 
             } else {
@@ -230,5 +238,5 @@
                 psVectorInit(B, 0.0);
                 for (int i = 0; i < fluxes->n; i++) {
-                    if (fmasks->data.U8[i]) continue;
+                    if (fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
                     B->data.F64[0] += fluxes->data.F32[i]/dfluxes->data.F32[i];
                     B->data.F64[1] += fluxes->data.F32[i]*xC->data.F32[i]/dfluxes->data.F32[i];
@@ -260,8 +268,9 @@
 
                 float dRo = sqrt(A->data.F32[0][0]);
-		// fprintf (stderr, "res: %2d %2d : %6.4f  %6.4f  %6.4f   %3d  %1d\n", ox, oy, resid->Ro->data.F32[oy][ox], dRo, dRo/sqrt(nKeep), nKeep, resid->mask->data.U8[oy][ox]);
+		// fprintf (stderr, "res: %2d %2d : %6.4f  %6.4f  %6.4f   %3d  %1d\n", 
+		// ox, oy, resid->Ro->data.F32[oy][ox], dRo, dRo/sqrt(nKeep), nKeep, resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox]);
 
                 if (fabs(resid->Ro->data.F32[oy][ox]) < pixelSN*dRo/sqrt(nKeep)) {
-                  resid->mask->data.U8[oy][ox] = 1;
+                  resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox] = 1;
                 }
                 //resid->weight->data.F32[oy][ox] = XXX;
Index: /trunk/psphot/src/psphotMaskReadout.c
===================================================================
--- /trunk/psphot/src/psphotMaskReadout.c	(revision 21182)
+++ /trunk/psphot/src/psphotMaskReadout.c	(revision 21183)
@@ -9,9 +9,9 @@
     // XXX drop the write to recipe and move config into psphotRoughClass?
     // XXX alternatively, define a function to set the psphot recipe masks
-    psMaskType maskSat  = pmConfigMaskGet("SAT", config); // Mask value for saturated pixels
-    psMetadataAddU8 (recipe, PS_LIST_TAIL, "MASK.SAT", PS_META_REPLACE, "user-defined mask", maskSat);
+    psImageMaskType maskSat  = pmConfigMaskGet("SAT", config); // Mask value for saturated pixels
+    psMetadataAddImageMask (recipe, PS_LIST_TAIL, "MASK.SAT", PS_META_REPLACE, "user-defined mask", maskSat);
 
-    psMaskType maskBad  = pmConfigMaskGet("BAD", config); // Mask value for bad pixels
-    psMetadataAddU8 (recipe, PS_LIST_TAIL, "MASK.BAD", PS_META_REPLACE, "user-defined mask", maskBad);
+    psImageMaskType maskBad  = pmConfigMaskGet("BAD", config); // Mask value for bad pixels
+    psMetadataAddImageMask (recipe, PS_LIST_TAIL, "MASK.BAD", PS_META_REPLACE, "user-defined mask", maskBad);
 
     // generate mask & weight images if they don't already exit
Index: /trunk/psphot/src/psphotModelBackground.c
===================================================================
--- /trunk/psphot/src/psphotModelBackground.c	(revision 21182)
+++ /trunk/psphot/src/psphotModelBackground.c	(revision 21183)
@@ -46,5 +46,5 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
Index: /trunk/psphot/src/psphotModelTest.c
===================================================================
--- /trunk/psphot/src/psphotModelTest.c	(revision 21182)
+++ /trunk/psphot/src/psphotModelTest.c	(revision 21183)
@@ -13,9 +13,9 @@
 
     // bit-masks to test for good/bad pixels
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT");
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     assert (maskVal);
 
     // bit-mask to mark pixels not used in analysis
-    psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT");
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     assert (markVal);
 
Index: /trunk/psphot/src/psphotModelWithPSF.c
===================================================================
--- /trunk/psphot/src/psphotModelWithPSF.c	(revision 21182)
+++ /trunk/psphot/src/psphotModelWithPSF.c	(revision 21183)
@@ -20,5 +20,5 @@
         paramMask = constraint->paramMask;
         if (paramMask != NULL) {
-            PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_U8, false);
+	  PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_VECTOR_MASK, false);
             PS_ASSERT_VECTORS_SIZE_EQUAL(params, paramMask, false);
         }
@@ -145,10 +145,10 @@
 	psImageInit (covar, 0.0);
 	for (int j = 0, J = 0; j < params->n; j++) {
-	    if (paramMask && (paramMask->data.U8[j])) {
+	    if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) {
 		covar->data.F32[j][j] = 1.0;
 		continue;
 	    }
 	    for (int k = 0, K = 0; k < params->n; k++) {
-		if (paramMask && (paramMask->data.U8[k])) continue;
+		if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[k])) continue;
 		covar->data.F32[j][k] = Alpha->data.F32[J][K];
 		K++;
@@ -197,5 +197,5 @@
     PS_ASSERT_VECTOR_TYPE(params, PS_TYPE_F32, false);
     if (paramMask) {
-        PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_MASK, false);
+        PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_VECTOR_MASK, false);
     }
 
@@ -224,5 +224,5 @@
 	    // XXX probably should not skipped masked points: 
 	    // XXX skip if convolution of unmasked pixels will not see this pixel
-            // if (source->maskObj->data.U8[i][j]) {
+            // if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j]) {
 	    // continue;
 	    // }
@@ -246,5 +246,5 @@
 
 	    for (int n = 0; n < params->n; n++) {
-		if ((paramMask != NULL) && (paramMask->data.U8[n])) { continue; }
+		if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; }
 		psImage *dmodel = pcm->dmodels->data[n];
 		dmodel->data.F32[i][j] = deriv->data.F32[n];
@@ -285,5 +285,5 @@
 	    // XXX are we doing the right thing with the mask?
             // skip masked points
-            if (source->maskObj->data.U8[i][j]) {
+            if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j]) {
                 continue;
             }
@@ -308,9 +308,9 @@
 	    // alpha & beta only contain unmasked elements 
 	    for (int n1 = 0, N1 = 0; n1 < params->n; n1++) {
-		if ((paramMask != NULL) && (paramMask->data.U8[n1])) continue;
+		if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n1])) continue;
 		psImage *dmodel = pcm->dmodelsConv->data[n1];
 		float weight = dmodel->data.F32[i][j] * yweight;
 		for (int n2 = 0, N2 = 0; n2 <= n1; n2++) {
-		    if ((paramMask != NULL) && (paramMask->data.U8[n2])) continue;
+		    if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n2])) continue;
 		    dmodel = pcm->dmodelsConv->data[n2];
 		    alpha->data.F32[N1][N2] += weight * dmodel->data.F32[i][j];
@@ -357,5 +357,5 @@
     for (psS32 n = 0; n < params->n; n++) {
 	pcm->dmodels->data[n] = NULL;
-	if ((paramMask != NULL) && (paramMask->data.U8[n])) { continue; }
+	if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; }
 	pcm->dmodels->data[n] = psImageCopy (NULL, source->pixels, PS_TYPE_F32);
     }
@@ -366,5 +366,5 @@
     for (psS32 n = 0; n < params->n; n++) {
 	pcm->dmodelsConv->data[n] = NULL;
-	if ((paramMask != NULL) && (paramMask->data.U8[n])) { continue; }
+	if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; }
 	pcm->dmodelsConv->data[n] = psImageCopy (NULL, source->pixels, PS_TYPE_F32);
     }
Index: /trunk/psphot/src/psphotMosaicChip.c
===================================================================
--- /trunk/psphot/src/psphotMosaicChip.c	(revision 21182)
+++ /trunk/psphot/src/psphotMosaicChip.c	(revision 21183)
@@ -25,5 +25,5 @@
     }
 
-    psMaskType blankMask = pmConfigMaskGet("BLANK", config);
+    psImageMaskType blankMask = pmConfigMaskGet("BLANK", config);
 
     // mosaic the chip, forcing a deep copy (resulting images are not subimages)
Index: /trunk/psphot/src/psphotOutput.c
===================================================================
--- /trunk/psphot/src/psphotOutput.c	(revision 21182)
+++ /trunk/psphot/src/psphotOutput.c	(revision 21183)
@@ -74,5 +74,5 @@
         for (int j = 0; j < source->pixels->numCols; j++) {
             // skip masked points
-            if (source->maskObj->data.U8[i][j]) {
+            if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j]) {
                 continue;
             }
@@ -87,5 +87,5 @@
                      source->pixels->data.F32[i][j],
                      1.0 / source->weight->data.F32[i][j],
-                     source->maskObj->data.U8[i][j]);
+                     source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j]);
         }
     }
@@ -237,5 +237,5 @@
 
 // XXX add args as needed
-bool psphotDumpPSFStars (pmReadout *readout, pmPSFtry *try, float radius, psMaskType maskVal, psMaskType markVal) {
+bool psphotDumpPSFStars (pmReadout *readout, pmPSFtry *try, float radius, psImageMaskType maskVal, psImageMaskType markVal) {
 
     psphotSaveImage (NULL, readout->image,  "rawstars.fits");
@@ -243,5 +243,5 @@
     for (int i = 0; i < try->sources->n; i++) {
 	// masked for: bad model fit, outlier in parameters
-	if (try->mask->data.U8[i] & PSFTRY_MASK_ALL)
+	if (try->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL)
 	    continue;
 
@@ -256,5 +256,5 @@
 	psImageKeepCircle (source->maskObj, x, y, radius, "OR", markVal);
 	pmModelSub (source->pixels, source->maskObj, source->modelPSF, PM_MODEL_OP_FULL, maskVal);
-	psImageKeepCircle (source->maskObj, x, y, radius, "AND", PS_NOT_U8(markVal));
+	psImageKeepCircle (source->maskObj, x, y, radius, "AND", PS_NOT_IMAGE_MASK(markVal));
     }
 
@@ -264,5 +264,5 @@
 
 	// masked for: bad model fit, outlier in parameters
-	if (try->mask->data.U8[i] & PSFTRY_MASK_ALL) continue;
+	if (try->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL) continue;
 
 	pmSource *source = try->sources->data[i];
Index: /trunk/psphot/src/psphotPSFConvModel.c
===================================================================
--- /trunk/psphot/src/psphotPSFConvModel.c	(revision 21182)
+++ /trunk/psphot/src/psphotPSFConvModel.c	(revision 21183)
@@ -9,5 +9,5 @@
 // modelConv to contain the fitted parameters, and the modelFlux to contain the 
 // convolved model image.
-pmModel *psphotPSFConvModel (pmReadout *readout, pmSource *source, pmModelType modelType, psMaskType maskVal, psMaskType markVal, int psfSize) {
+pmModel *psphotPSFConvModel (pmReadout *readout, pmSource *source, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) {
     
     // maskVal is used to test for rejected pixels, and must include markVal
@@ -72,5 +72,5 @@
     // create the minimization constraints
     psMinConstraint *constraint = psMinConstraintAlloc();
-    constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_U8);
+    constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK);
     constraint->checkLimits = modelConv->modelLimits;
 
@@ -79,5 +79,5 @@
     int nParams = params->n - 1;
     psVectorInit (constraint->paramMask, 0);
-    constraint->paramMask->data.U8[PM_PAR_SKY] = 1;
+    constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1;
 
     // force the floating parameters to fall within the contraint ranges
@@ -97,5 +97,5 @@
             fprintf (stderr, "%f ", params->data.F32[i]);
         }
-        if ((constraint->paramMask != NULL) && constraint->paramMask->data.U8[i])
+        if ((constraint->paramMask != NULL) && constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i])
             continue;
         dparams->data.F32[i] = sqrt(covar->data.F32[i][i]);
Index: /trunk/psphot/src/psphotPetrosian.c
===================================================================
--- /trunk/psphot/src/psphotPetrosian.c	(revision 21182)
+++ /trunk/psphot/src/psphotPetrosian.c	(revision 21183)
@@ -1,5 +1,5 @@
 # include "psphotInternal.h"
 
-bool psphotPetrosian (pmSource *source, psMetadata *recipe, psMaskType maskVal) {
+bool psphotPetrosian (pmSource *source, psMetadata *recipe, psImageMaskType maskVal) {
 
   bool status;
Index: /trunk/psphot/src/psphotRadialPlot.c
===================================================================
--- /trunk/psphot/src/psphotRadialPlot.c	(revision 21182)
+++ /trunk/psphot/src/psphotRadialPlot.c	(revision 21183)
@@ -60,5 +60,5 @@
     for (int iy = 0; iy < source->pixels->numRows; iy++) {
 	for (int ix = 0; ix < source->pixels->numCols; ix++) {
-	    if (source->maskObj->data.U8[iy][ix]) {
+	    if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) {
 		rb->data.F32[nb] = hypot (ix - Xo, iy - Yo) ;
 		fb->data.F32[nb] = log10(source->pixels->data.F32[iy][ix]);
Index: /trunk/psphot/src/psphotRadialProfile.c
===================================================================
--- /trunk/psphot/src/psphotRadialProfile.c	(revision 21182)
+++ /trunk/psphot/src/psphotRadialProfile.c	(revision 21183)
@@ -17,5 +17,5 @@
 }
 
-bool psphotRadialProfile (pmSource *source, psMetadata *recipe, psMaskType maskVal) {
+bool psphotRadialProfile (pmSource *source, psMetadata *recipe, psImageMaskType maskVal) {
 
     // allocate pmSourceExtendedParameters, if not already defined
@@ -54,5 +54,5 @@
     for (int iy = 0; iy < source->pixels->numRows; iy++) {
         for (int ix = 0; ix < source->pixels->numCols; ix++) {
-            if (source->maskObj->data.U8[iy][ix]) continue;
+            if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) continue;
             radius->data.F32[n] = hypot (ix - Xo, iy - Yo) ;
             flux->data.F32[n]   = source->pixels->data.F32[iy][ix];
Index: /trunk/psphot/src/psphotRadiusChecks.c
===================================================================
--- /trunk/psphot/src/psphotRadiusChecks.c	(revision 21182)
+++ /trunk/psphot/src/psphotRadiusChecks.c	(revision 21183)
@@ -19,5 +19,5 @@
 
 // call this function whenever you (re)-define the PSF model
-bool psphotCheckRadiusPSF (pmReadout *readout, pmSource *source, pmModel *model, psMaskType markVal)
+bool psphotCheckRadiusPSF (pmReadout *readout, pmSource *source, pmModel *model, psImageMaskType markVal)
 {
     psF32 *PAR = model->params->data.F32;
@@ -50,5 +50,5 @@
 }
 
-bool psphotCheckRadiusPSFBlend (pmReadout *readout, pmSource *source, pmModel *model, psMaskType markVal, float dR) {
+bool psphotCheckRadiusPSFBlend (pmReadout *readout, pmSource *source, pmModel *model, psImageMaskType markVal, float dR) {
 
     psF32 *PAR = model->params->data.F32;
@@ -86,5 +86,5 @@
 
 // call this function whenever you (re)-define the EXT model
-bool psphotCheckRadiusEXT (pmReadout *readout, pmSource *source, pmModel *model, psMaskType markVal) {
+bool psphotCheckRadiusEXT (pmReadout *readout, pmSource *source, pmModel *model, psImageMaskType markVal) {
 
     psF32 *PAR = model->params->data.F32;
Index: /trunk/psphot/src/psphotReplaceUnfit.c
===================================================================
--- /trunk/psphot/src/psphotReplaceUnfit.c	(revision 21182)
+++ /trunk/psphot/src/psphotReplaceUnfit.c	(revision 21183)
@@ -2,5 +2,5 @@
 
 // replace the flux for sources which failed
-bool psphotReplaceUnfitSources (psArray *sources, psMaskType maskVal) {
+bool psphotReplaceUnfitSources (psArray *sources, psImageMaskType maskVal) {
 
     pmSource *source;
@@ -31,5 +31,5 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
@@ -55,5 +55,5 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
@@ -72,5 +72,5 @@
 
 // add source, if the source has been subtracted; do not modify state
-bool psphotAddWithTest (pmSource *source, bool useState, psMaskType maskVal) {
+bool psphotAddWithTest (pmSource *source, bool useState, psImageMaskType maskVal) {
 
     // what is current state? (true : add; false : sub)
@@ -83,5 +83,5 @@
 
 // sub source, if the source has been added; do not modify state
-bool psphotSubWithTest (pmSource *source, bool useState, psMaskType maskVal) {
+bool psphotSubWithTest (pmSource *source, bool useState, psImageMaskType maskVal) {
 
     // what is current state? (true : sub; false : add)
@@ -94,5 +94,5 @@
 
 // add or sub source to match recorded state: supply current state as true (add) or false (sub)
-bool psphotSetState (pmSource *source, bool curState, psMaskType maskVal) {
+bool psphotSetState (pmSource *source, bool curState, psImageMaskType maskVal) {
 
     // what is desired state? (true : add; false : sub)
Index: /trunk/psphot/src/psphotRoughClass.c
===================================================================
--- /trunk/psphot/src/psphotRoughClass.c	(revision 21182)
+++ /trunk/psphot/src/psphotRoughClass.c	(revision 21183)
@@ -57,5 +57,5 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskSat = psMetadataLookupU8(&status, recipe, "MASK.SAT"); // Mask value for bad pixels
+    psImageMaskType maskSat = psMetadataLookupImageMask(&status, recipe, "MASK.SAT"); // Mask value for bad pixels
     assert (maskSat);
 
Index: /trunk/psphot/src/psphotSetMaskBits.c
===================================================================
--- /trunk/psphot/src/psphotSetMaskBits.c	(revision 21182)
+++ /trunk/psphot/src/psphotSetMaskBits.c	(revision 21183)
@@ -10,6 +10,6 @@
 bool psphotSetMaskBits (pmConfig *config) {
 
-    psMaskType maskValue;
-    psMaskType markValue;
+    psImageMaskType maskValue;
+    psImageMaskType markValue;
 
     if (!pmConfigMaskSetBits (&maskValue, &markValue, config)) {
@@ -26,6 +26,6 @@
 
     // set maskValue and markValue in the psphot recipe
-    psMetadataAddU8 (recipe, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "user-defined mask", markValue);
-    psMetadataAddU8 (recipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskValue);
+    psMetadataAddImageMask (recipe, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "user-defined mask", markValue);
+    psMetadataAddImageMask (recipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskValue);
 
     return true;
Index: /trunk/psphot/src/psphotSignificanceImage.c
===================================================================
--- /trunk/psphot/src/psphotSignificanceImage.c	(revision 21182)
+++ /trunk/psphot/src/psphotSignificanceImage.c	(revision 21183)
@@ -4,5 +4,5 @@
 // (S/N)^2.  If FWMH_X,Y have been recorded, use them, otherwise use PEAKS_SMOOTH_SIGMA for the
 // smoothing kernel.
-psImage *psphotSignificanceImage (pmReadout *readout, psMetadata *recipe, const int pass, psMaskType maskVal) {
+psImage *psphotSignificanceImage (pmReadout *readout, psMetadata *recipe, const int pass, psImageMaskType maskVal) {
 
     float SIGMA_SMTH, NSIGMA_SMTH;
@@ -110,5 +110,5 @@
         for (int i = 0; i < smooth_im->numCols; i++) {
             float value = smooth_im->data.F32[j][i];
-            if (value < 0 || smooth_wt->data.F32[j][i] <= 0 || (mask->data.U8[j][i] & maskVal)) {
+            if (value < 0 || smooth_wt->data.F32[j][i] <= 0 || (mask->data.PS_TYPE_IMAGE_MASK_DATA[j][i] & maskVal)) {
                 smooth_im->data.F32[j][i] = 0.0;
             } else {
Index: /trunk/psphot/src/psphotSkyReplace.c
===================================================================
--- /trunk/psphot/src/psphotSkyReplace.c	(revision 21182)
+++ /trunk/psphot/src/psphotSkyReplace.c	(revision 21183)
@@ -17,5 +17,5 @@
     // select the corresponding images
     psF32 **image = readout->image->data.F32;
-    psU8  **mask  = readout->mask->data.U8;
+    psImageMaskType  **mask  = readout->mask->data.PS_TYPE_IMAGE_MASK_DATA;
     psF32 **back  = background->image->data.F32;
 
Index: /trunk/psphot/src/psphotSourceFits.c
===================================================================
--- /trunk/psphot/src/psphotSourceFits.c	(revision 21182)
+++ /trunk/psphot/src/psphotSourceFits.c	(revision 21183)
@@ -22,5 +22,5 @@
 }
 
-bool psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf, psMaskType maskVal, psMaskType markVal) {
+bool psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) {
 
     float x, y, dR;
@@ -147,5 +147,5 @@
 }
 
-bool psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf, psMaskType maskVal, psMaskType markVal) {
+bool psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) {
 
     double chiTrend;
@@ -208,5 +208,5 @@
 }
 
-bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *newSources, pmPSF *psf, psMaskType maskVal, psMaskType markVal) {
+bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *newSources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) {
 
     bool okEXT, okDBL;
@@ -318,5 +318,5 @@
 
 // fit a double PSF source to an extended blob
-psArray *psphotFitDBL (pmReadout *readout, pmSource *source, psMaskType maskVal, psMaskType markVal) {
+psArray *psphotFitDBL (pmReadout *readout, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal) {
 
     float dx, dy;
@@ -370,5 +370,5 @@
 }
 
-pmModel *psphotFitEXT (pmReadout *readout, pmSource *source, pmModelType modelType, psMaskType maskVal, psMaskType markVal) {
+pmModel *psphotFitEXT (pmReadout *readout, pmSource *source, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal) {
 
     NfitEXT ++;
Index: /trunk/psphot/src/psphotSourcePlots.c
===================================================================
--- /trunk/psphot/src/psphotSourcePlots.c	(revision 21182)
+++ /trunk/psphot/src/psphotSourcePlots.c	(revision 21183)
@@ -7,5 +7,5 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
Index: /trunk/psphot/src/psphotSourceSize.c
===================================================================
--- /trunk/psphot/src/psphotSourceSize.c	(revision 21182)
+++ /trunk/psphot/src/psphotSourceSize.c	(revision 21183)
@@ -3,8 +3,8 @@
 
 static float psphotModelContour(const psImage *image, const psImage *weight, const psImage *mask,
-                                psMaskType maskVal, const pmModel *model, float Ro);
-
-bool psphotMaskCosmicRay_Old (pmSource *source, psMaskType maskVal, psMaskType crMask);
-bool psphotMaskCosmicRay_New (psImage *mask, pmSource *source, psMaskType maskVal, psMaskType crMask);
+                                psImageMaskType maskVal, const pmModel *model, float Ro);
+
+bool psphotMaskCosmicRay_Old (pmSource *source, psImageMaskType maskVal, psImageMaskType crMask);
+bool psphotMaskCosmicRay_New (psImage *mask, pmSource *source, psImageMaskType maskVal, psImageMaskType crMask);
 
 // we need to call this function after sources have been fitted to the PSF model and
@@ -21,9 +21,9 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
     // bit to mask the cosmic-ray pixels
-    psMaskType crMask  = pmConfigMaskGet("CR", config); // Mask value for cosmic rays
+    psImageMaskType crMask  = pmConfigMaskGet("CR", config); // Mask value for cosmic rays
 
     float CR_NSIGMA_LIMIT = psMetadataLookupF32 (&status, recipe, "PSPHOT.CR.NSIGMA.LIMIT");
@@ -63,5 +63,5 @@
         psF32 **resid  = source->pixels->data.F32;
         psF32 **weight = source->weight->data.F32;
-        psU8 **mask    = source->maskObj->data.U8;
+        psImageMaskType **mask    = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
 
         // check for extendedness: measure the delta flux significance at the 1 sigma contour
@@ -191,5 +191,5 @@
 // deviations?
 static float psphotModelContour(const psImage *image, const psImage *weight, const psImage *mask,
-                                psMaskType maskVal, const pmModel *model, float Ro)
+                                psImageMaskType maskVal, const pmModel *model, float Ro)
 {
     psF32 *PAR = model->params->data.F32; // Model parameters
@@ -239,5 +239,5 @@
 
         if (yPixM >= 0 && yPixM < image->numRows &&
-            !(mask && (mask->data.PS_TYPE_MASK_DATA[yPixM][xPix] & maskVal))) {
+            !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixM][xPix] & maskVal))) {
             float dSigma = image->data.F32[yPixM][xPix] / sqrtf(weight->data.F32[yPixM][xPix]);
             nSigma += dSigma;
@@ -250,5 +250,5 @@
 
         if (yPixP >= 0 && yPixP < image->numRows &&
-            !(mask && (mask->data.PS_TYPE_MASK_DATA[yPixP][xPix] & maskVal))) {
+            !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixP][xPix] & maskVal))) {
             float dSigma = image->data.F32[yPixP][xPix] / sqrtf(weight->data.F32[yPixP][xPix]);
             nSigma += dSigma;
@@ -260,5 +260,5 @@
 }
 
-bool psphotMaskCosmicRay_New (psImage *mask, pmSource *source, psMaskType maskVal, psMaskType crMask) {
+bool psphotMaskCosmicRay_New (psImage *mask, pmSource *source, psImageMaskType maskVal, psImageMaskType crMask) {
 
     // replace the source flux
@@ -294,5 +294,5 @@
 	
 	for (int ix = xs; ix < xe; ix++) {
-	    mask->data.U8[iy][ix] |= crMask;
+	    mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
 	}
     }
@@ -300,5 +300,5 @@
 }
 
-bool psphotMaskCosmicRay_Old (pmSource *source, psMaskType maskVal, psMaskType crMask) {
+bool psphotMaskCosmicRay_Old (pmSource *source, psImageMaskType maskVal, psImageMaskType crMask) {
 
     source->mode |= PM_SOURCE_MODE_CR_LIMIT;
@@ -320,5 +320,5 @@
 	float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]);
 	if (SN > SN_LIMIT) {
-	    mask->data.U8[yo][ix] |= crMask;
+	    mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
 	}
     }
@@ -326,5 +326,5 @@
 	float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]);
 	if (SN > SN_LIMIT) {
-	    mask->data.U8[yo][ix] |= crMask;
+	    mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
 	}
     }
@@ -339,10 +339,10 @@
 
 	    bool valid = false;
-	    valid |= (mask->data.U8[iy+1][ix] & crMask);
-	    valid |= (ix > 0) ? (mask->data.U8[iy+1][ix-1] & crMask) : 0;
-	    valid |= (ix <= mask->numCols) ? (mask->data.U8[iy+1][ix+1] & crMask) : 0;
+	    valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask);
+	    valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0;
+	    valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0;
 
 	    if (!valid) continue;
-	    mask->data.U8[iy][ix] |= crMask;
+	    mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
 	}
     }
@@ -355,10 +355,10 @@
 
 	    bool valid = false;
-	    valid |= (mask->data.U8[iy-1][ix] & crMask);
-	    valid |= (ix > 0) ? (mask->data.U8[iy-1][ix-1] & crMask) : 0;
-	    valid |= (ix <= mask->numCols) ? (mask->data.U8[iy-1][ix+1] & crMask) : 0;
+	    valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask);
+	    valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0;
+	    valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0;
 
 	    if (!valid) continue;
-	    mask->data.U8[iy][ix] |= crMask;
+	    mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
 	}
     }
Index: /trunk/psphot/src/psphotSourceStats.c
===================================================================
--- /trunk/psphot/src/psphotSourceStats.c	(revision 21182)
+++ /trunk/psphot/src/psphotSourceStats.c	(revision 21183)
@@ -17,5 +17,4 @@
 	nThreads = 0;
     }
-    // nThreads = 0; // XXX until testing is complete, do not thread this function
 
     // determine properties (sky, moments) of initial sources
@@ -144,9 +143,9 @@
 
     // bit-masks to test for good/bad pixels
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT");
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     assert (maskVal);
 
     // bit-mask to mark pixels not used in analysis
-    psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT");
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     assert (markVal);
 
Index: /trunk/psphot/src/psphotSubtractBackground.c
===================================================================
--- /trunk/psphot/src/psphotSubtractBackground.c	(revision 21182)
+++ /trunk/psphot/src/psphotSubtractBackground.c	(revision 21183)
@@ -28,5 +28,5 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
Index: /trunk/psphot/src/psphotTestPSF.c
===================================================================
--- /trunk/psphot/src/psphotTestPSF.c	(revision 21182)
+++ /trunk/psphot/src/psphotTestPSF.c	(revision 21183)
@@ -111,5 +111,5 @@
         psImageKeepCircle (source->mask, x, y, RADIUS, "OR", markVal);
         status = pmSourceFitModel (source, model, PM_SOURCE_FIT_EXT);
-        psImageKeepCircle (source->mask, x, y, RADIUS, "AND", PS_NOT_U8(markVal));
+        psImageKeepCircle (source->mask, x, y, RADIUS, "AND", PS_NOT_IMAGE_MASK(markVal));
 
 	// write fitted parameters to file
Index: /trunk/psphot/src/psphotTestSourceOutput.c
===================================================================
--- /trunk/psphot/src/psphotTestSourceOutput.c	(revision 21182)
+++ /trunk/psphot/src/psphotTestSourceOutput.c	(revision 21183)
@@ -80,5 +80,5 @@
 		float oy = yBin*(iy + 0.5 + image->row0 - yCenter) + yResidCenter;
 
-		psU8 mflux = 0;
+		psImageMaskType mflux = 0;
 		double Fo = 0.0;
 		double Fx = 0.0;
Index: /trunk/psphot/src/psphotVisual.c
===================================================================
--- /trunk/psphot/src/psphotVisual.c	(revision 21182)
+++ /trunk/psphot/src/psphotVisual.c	(revision 21183)
@@ -51,5 +51,5 @@
 	ALLOCATE (image.data2d[iy], float, image.Nx);
 	for (int ix = 0; ix < image.Nx; ix++) {
-	    image.data2d[iy][ix] = inImage->data.U8[iy][ix];
+	    image.data2d[iy][ix] = inImage->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix];
 	}
     }
@@ -813,5 +813,5 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
@@ -973,5 +973,5 @@
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
@@ -1097,5 +1097,5 @@
 }
 
-bool psphotVisualPlotRadialProfile (int myKapa, pmSource *source, psMaskType maskVal) {
+bool psphotVisualPlotRadialProfile (int myKapa, pmSource *source, psImageMaskType maskVal) {
 
     Graphdata graphdata;
@@ -1118,5 +1118,5 @@
     for (int iy = 0; iy < source->pixels->numRows; iy++) {
 	for (int ix = 0; ix < source->pixels->numCols; ix++) {
-	    if (source->maskObj->data.U8[iy][ix]) {
+	    if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) {
 		// rb->data.F32[nb] = hypot (ix + 0.5 - Xo, iy + 0.5 - Yo) ;
 		rb->data.F32[nb] = hypot (ix - Xo, iy - Yo) ;
@@ -1227,5 +1227,5 @@
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     bool status;
-    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     assert (maskVal);
 
Index: /trunk/pswarp/src/pswarpLoop.c
===================================================================
--- /trunk/pswarp/src/pswarpLoop.c	(revision 21182)
+++ /trunk/pswarp/src/pswarpLoop.c	(revision 21183)
@@ -67,5 +67,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");
 
Index: /trunk/pswarp/src/pswarpPixelFraction.c
===================================================================
--- /trunk/pswarp/src/pswarpPixelFraction.c	(revision 21182)
+++ /trunk/pswarp/src/pswarpPixelFraction.c	(revision 21183)
@@ -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: /trunk/pswarp/src/pswarpSetMaskBits.c
===================================================================
--- /trunk/pswarp/src/pswarpSetMaskBits.c	(revision 21182)
+++ /trunk/pswarp/src/pswarpSetMaskBits.c	(revision 21183)
@@ -10,8 +10,7 @@
 bool pswarpSetMaskBits (pmConfig *config) {
 
-    psMaskType maskIn = 0x00;			// mask for the input image
-    psMaskType markIn = 0x00;			// mark for the input image
-    psMaskType maskOut = 0x00;			// mask for the output image
-    psMaskType markOut = 0x00;			// mark for the output image
+    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,18 +37,18 @@
 
     // 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;
-	} else {
-	    markOut = markOut;
-	}
+        if (maskOut & markTrial) {
+            markTrial <<= 1;
+        } else {
+            markOut = markTrial;
+        }
     }
-
     if (!markOut) {
-	psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!");
-	return false;
+        psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!");
+        return false;
     }
 
@@ -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: /trunk/pswarp/src/pswarpTransformReadout.c
===================================================================
--- /trunk/pswarp/src/pswarpTransformReadout.c	(revision 21182)
+++ /trunk/pswarp/src/pswarpTransformReadout.c	(revision 21183)
@@ -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: /trunk/pswarp/src/pswarpTransformTile.c
===================================================================
--- /trunk/pswarp/src/pswarpTransformTile.c	(revision 21182)
+++ /trunk/pswarp/src/pswarpTransformTile.c	(revision 21183)
@@ -49,6 +49,6 @@
     psF32 **outImageData     = args->output->image->data.F32;
     psF32 **outVarData       = (args->output->weight) ? args->output->weight->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;
             }
@@ -82,5 +82,5 @@
             // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates
             double imageValue, varValue; // Value of image and variance map
-            psMaskType maskValue = inMaskData ? inMaskData[(int)yIn][(int)xIn] : 0; // Value of mask
+            psImageMaskType maskValue = inMaskData ? inMaskData[(int)yIn][(int)xIn] : 0; // Value of mask
             if (!psImageInterpolate(&imageValue, &varValue, &maskValue, xIn, yIn, args->interp)) {
                 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
