Index: trunk/psModules/src/detrend/pmBias.c
===================================================================
--- trunk/psModules/src/detrend/pmBias.c	(revision 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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 20669)
+++ 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;
                 }
             }
