Index: trunk/psModules/src/config/pmConfigMask.c
===================================================================
--- trunk/psModules/src/config/pmConfigMask.c	(revision 18554)
+++ trunk/psModules/src/config/pmConfigMask.c	(revision 18598)
@@ -11,5 +11,5 @@
 psMaskType pmConfigMaskGet(const char *masks, const pmConfig *config)
 {
-    assert (config);
+    psAssert(config, "Require configuration");
     PS_ASSERT_STRING_NON_EMPTY(masks, 0);
 
@@ -42,5 +42,5 @@
 bool pmConfigMaskSet(const pmConfig *config, const char *maskName, psMaskType maskValue)
 {
-    assert (config);
+    psAssert(config, "Require configuration");
     PS_ASSERT_STRING_NON_EMPTY(maskName, false);
 
@@ -58,5 +58,8 @@
 // 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, psMetadata *header) {
+bool pmConfigMaskReadHeader(pmConfig *config, const psMetadata *header)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_METADATA_NON_NULL(header, false);
 
     bool status = false;
@@ -78,26 +81,29 @@
     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);
-	psU8 bit = psMetadataLookupU8 (&status, header, valuekey);
-
-	// XXX validate that bit is a 2^n value?
-
-	psMetadataItem *item = psMetadataLookup (header, name);
-	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;
-	}
-    }
-    
+        snprintf (namekey,  64, "MSKNAM%02d", i);
+        snprintf (valuekey, 64, "MSKVAL%02d", i);
+
+        char *name = psMetadataLookupStr (&status, header, namekey);
+        psU8 bit = psMetadataLookupU8 (&status, header, valuekey);
+
+        // XXX validate that bit is a 2^n value?
+
+        psMetadataItem *item = psMetadataLookup (header, name);
+        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;
+        }
+    }
+
     return true;
 }
 
 // write the named mask bits to the header
-bool pmConfigMaskWriteHeader (pmConfig *config, psMetadata *header) {
+bool pmConfigMaskWriteHeader(const pmConfig *config, psMetadata *header)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_METADATA_NON_NULL(header, false);
 
     char namekey[80];
@@ -117,17 +123,17 @@
     while ((item = psMetadataGetAndIncrement(iter))) {
 
-	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 ++;
-    }
-    
+        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 ++;
+    }
+
     psMetadataAddS32 (header, PS_LIST_TAIL, "MSKNUM", 0, "Bitmask bit count", nMask);
     return true;
@@ -135,5 +141,5 @@
 
 // examine named mask values in mask recipe and set the bits for maskValue and markValue
-// this function sets an appropriate value for the following required named mask concepts: 
+// this function sets an appropriate value for the following required named mask concepts:
 // FLAT (used to mark out-of-range corrections in the flat-fielding)
 // BLANK (used to mark non-existent pixels)
@@ -143,10 +149,12 @@
 // If these latter do not exist, the value 0x01 is used.
 // The values actually used for these names are written back to the config file
-bool pmConfigMaskSetBits (psMaskType *outMaskValue, psMaskType *outMarkValue, pmConfig *config) {
+bool pmConfigMaskSetBits(psMaskType *outMaskValue, psMaskType *outMarkValue, const pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
 
     psMaskType maskValue = 0;
 
     // mask for generic detector defect
-    psMaskType detectorMask = pmConfigMaskGet("DETECTOR", config); 
+    psMaskType detectorMask = pmConfigMaskGet("DETECTOR", config);
     maskValue |= detectorMask;
 
@@ -156,24 +164,24 @@
 
     // mask for non-linear flat regions (default to DETECTOR if not defined)
-    psMaskType flatMask = pmConfigMaskGet("FLAT", config); 
+    psMaskType flatMask = pmConfigMaskGet("FLAT", config);
     if (!flatMask) {
-	flatMask = detectorMask;
-	pmConfigMaskSet (config, "FLAT", flatMask);
+        flatMask = detectorMask;
+        pmConfigMaskSet (config, "FLAT", flatMask);
     }
     if (!flatMask) {
-	flatMask = 0x01;
-	pmConfigMaskSet (config, "FLAT", flatMask);
+        flatMask = 0x01;
+        pmConfigMaskSet (config, "FLAT", flatMask);
     }
     maskValue |= flatMask;
 
     // mask for non-existent data  (default to DETECTOR if not defined)
-    psMaskType blankMask = pmConfigMaskGet("BLANK", config); 
+    psMaskType blankMask = pmConfigMaskGet("BLANK", config);
     if (!blankMask) {
-	blankMask = detectorMask;
-	pmConfigMaskSet (config, "BLANK", blankMask);
+        blankMask = detectorMask;
+        pmConfigMaskSet (config, "BLANK", blankMask);
     }
     if (!blankMask) {
-	blankMask = 0x01;
-	pmConfigMaskSet (config, "BLANK", blankMask);
+        blankMask = 0x01;
+        pmConfigMaskSet (config, "BLANK", blankMask);
     }
     maskValue |= blankMask;
@@ -186,22 +194,22 @@
     psMaskType satMask = pmConfigMaskGet("SAT", config);
     if (!satMask) {
-	satMask = rangeMask;
-	pmConfigMaskSet (config, "SAT", satMask);
+        satMask = rangeMask;
+        pmConfigMaskSet (config, "SAT", satMask);
     }
     if (!satMask) {
-	satMask = 0x01;
-	pmConfigMaskSet (config, "SAT", satMask);
+        satMask = 0x01;
+        pmConfigMaskSet (config, "SAT", satMask);
     }
     maskValue |= satMask;
-    
+
     // mask for below-range data  (default to RANGE if not defined)
     psMaskType badMask = pmConfigMaskGet("BAD", config);
     if (!badMask) {
-	badMask = rangeMask;
-	pmConfigMaskSet (config, "BAD", badMask);
+        badMask = rangeMask;
+        pmConfigMaskSet (config, "BAD", badMask);
     }
     if (!badMask) {
-	badMask = 0x01;
-	pmConfigMaskSet (config, "BAD", badMask);
+        badMask = 0x01;
+        pmConfigMaskSet (config, "BAD", badMask);
     }
     maskValue |= badMask;
@@ -219,22 +227,27 @@
     int nBits = sizeof(psMaskType) * 8;
     for (int i = 0; !markValue && (i < nBits); i++) {
-	if (maskValue & markValue) {
-	    markValue >>= 1;
-	} else {
-	    markValue = markValue;
-	}
+        if (maskValue & markValue) {
+            markValue >>= 1;
+        } else {
+            markValue = markValue;
+        }
     }
     if (!markValue) {
-	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;
+    }
+
 
     // update the config table
-    pmConfigMaskSet (config, "MASK.VALUE", maskValue);
-    pmConfigMaskSet (config, "MARK.VALUE", markValue);
-
-    *outMaskValue = maskValue;
-    *outMarkValue = markValue;
-
-    return true;
-}
+    pmConfigMaskSet(config, "MASK.VALUE", maskValue);
+    pmConfigMaskSet(config, "MARK.VALUE", markValue);
+
+    if (outMaskValue) {
+        *outMaskValue = maskValue;
+    }
+    if (outMarkValue) {
+        *outMarkValue = markValue;
+    }
+
+    return true;
+}
Index: trunk/psModules/src/config/pmConfigMask.h
===================================================================
--- trunk/psModules/src/config/pmConfigMask.h	(revision 18554)
+++ trunk/psModules/src/config/pmConfigMask.h	(revision 18598)
@@ -4,6 +4,6 @@
  *  @author Paul Price, IfA
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-07-15 20:25:00 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-07-17 20:37:20 $
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
  */
@@ -24,6 +24,6 @@
 /// The mask values are derived from the MASKS recipe
 psMaskType pmConfigMaskGet(const char *masks, ///< List of symbolic names, space/comma delimited
-                        const pmConfig *config ///< Configuration
-                        );
+                           const pmConfig *config ///< Configuration
+    );
 
 bool pmConfigMaskSet(const pmConfig *config, const char *maskName, psMaskType maskValue);
@@ -31,10 +31,10 @@
 // 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, psMetadata *header);
+bool pmConfigMaskReadHeader(pmConfig *config, const psMetadata *header);
 
 // write the named mask bits to the header
-bool pmConfigMaskWriteHeader (pmConfig *config, psMetadata *header);
+bool pmConfigMaskWriteHeader(const pmConfig *config, psMetadata *header);
 
-bool pmConfigMaskSetBits (psMaskType *outMaskValue, psMaskType *outMarkValue, pmConfig *config);
+bool pmConfigMaskSetBits(psMaskType *outMaskValue, psMaskType *outMarkValue, const pmConfig *config);
 
 #endif
