Index: trunk/ppImage/src/ppImageAuxiliaryMask.c
===================================================================
--- trunk/ppImage/src/ppImageAuxiliaryMask.c	(revision 35528)
+++ trunk/ppImage/src/ppImageAuxiliaryMask.c	(revision 35531)
@@ -40,4 +40,16 @@
 }
 
+bool recordFileInHeader(pmChip *chip, psString tag, psString desc, psString filename)
+{
+    pmHDU *hdu = pmHDUGetHighest(chip->parent, chip, NULL);
+
+    // strip off the directories and nebulous bits
+    char *base = filename;
+    for (char *new = base; (new = strpbrk(base, "/:")); base = new + 1);
+
+    psMetadataAddStr(hdu->header, PS_LIST_TAIL, tag, PS_META_DUPLICATE_OK, desc, base);
+    return true;
+}
+
 // In this function, we augment the mask with the more conservative auxiliary mask
 bool ppImageAuxiliaryMask(pmConfig *config, const pmFPAview *view, const ppImageOptions *options)
@@ -51,5 +63,6 @@
     }
 
-    bool status;                        // Status of MD lookup
+    bool status;
+    // Our target chip
     pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "PPIMAGE.CHIP"); // File to correct
     if (!status) {
@@ -58,4 +71,6 @@
     }
 
+    // Find a suitable detRun with type AUXMASK
+
     psTime *time = psMetadataLookupPtr(NULL, input->fpa->concepts, "FPA.TIME");
     if (time->sec == 0 && time->nsec == 0) {
@@ -63,5 +78,4 @@
     }
 
-    // XXX careful about this: is this set correctly in the camera.config files?
     char *cameraName = psMetadataLookupStr(NULL, input->fpa->concepts, "FPA.CAMERA");
     pmDetrendSelectOptions *detrendOptions = pmDetrendSelectOptionsAlloc(cameraName, *time, PM_DETREND_TYPE_AUXMASK);
@@ -80,18 +94,6 @@
     }
     
-#ifdef notdef
-    psMetadata *ppImageRecipe = psMetadataLookupPtr(NULL, config->recipes, RECIPE_NAME);
-    psAssert(ppImageRecipe, "Need PPIMAGE recipe");
-    psMetadata *psphotRecipe = psMetadataLookupPtr(NULL, config->recipes, PSPHOT_RECIPE);
-    psAssert(psphotRecipe, "Need PSPHOT recipe");
-
-    // XXX Should this be options->maskValue or options->maskValue & ~options->satMask?
-    //     The latter will leave saturated pixels high
-    psImageMaskType maskVal = options->maskValue;
-
-    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
-    psMetadataAddImageMask(psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskVal);
-#endif
-
+    // Go find the readout
+    // code to find the readouts was adapted from ppImageSubtractBackground
     // XXX: shouldn't most of these psWarnings be psAsserts?
 
@@ -129,5 +131,5 @@
     psImage *mask = ro->mask;
 
-    // now read the mask file
+    // now read the auxiliary mask file
     psString class_id = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME");
 
@@ -139,9 +141,13 @@
 
     psFree(results);
+    // record that we read this file in the config dump file.
+    // Note: this value isn't used during updates though.
+    pmConfigRunFilenameAddRead(config, "PPIMAGE.AUXMASK", auxMaskFileName);
+    recordFileInHeader(chip, "DETREND.AUXMASK", "auxiliary mask", auxMaskFileName);
 
     psImage *auxMask = readAuxiliaryMask(config, auxMaskFileName);
     psFree(auxMaskFileName);
     if (!auxMask) {
-        // readAuxiliaryMask prints enough diagnostic information
+        psError(PS_ERR_UNKNOWN, false, "failed to read auxiliary mask file");
         return false;
     }
@@ -151,7 +157,11 @@
         psImage *videoMask = readAuxiliaryMask(config, options->auxVideoMask);
         if (!videoMask) {
+            psError(PS_ERR_UNKNOWN, false, "failed to read auxiliary video mask file");
             return false;
         }
-        // auxMask *= videoMask
+        pmConfigRunFilenameAddRead(config, "PPIMAGE.AUXVIDEOMASK", options->auxVideoMask);
+        recordFileInHeader(chip, "DETREND.AUXVIDEOMASK", "auxiliary video mask", options->auxVideoMask);
+
+        // compute auxMask *= videoMask
         if (!psBinaryOp(auxMask, auxMask, "*", videoMask)) {
             psError(PS_ERR_UNKNOWN, false, "mulitplication of auxiliary mask and auxiliary video mask failed");
