Index: /branches/eam_branch_20080706/psModules/src/config/pmConfigMask.c
===================================================================
--- /branches/eam_branch_20080706/psModules/src/config/pmConfigMask.c	(revision 18424)
+++ /branches/eam_branch_20080706/psModules/src/config/pmConfigMask.c	(revision 18425)
@@ -39,2 +39,68 @@
     return mask;
 }
+
+// replace the named masks in the recipe with values in the header
+void pmConfigMasksReadHeader (pmConfig *config, psMetadata *header) {
+
+    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 (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 ++;
+    }
+    
+    psMetadataAddU8 (header, PS_LIST_TAIL, "MSKNUM", 0, "Bitmask bit count", nMask);
+    return true;
+}
+
+// write the named mask bits to the header
+bool pmConfigMasksWriteHeader (pmConfig *config, psMetadata *header) {
+
+    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 (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 ++;
+    }
+    
+    psMetadataAddU8 (header, PS_LIST_TAIL, "MSKNUM", 0, "Bitmask bit count", nMask);
+    return true;
+}
