Index: trunk/psModules/src/camera/pmFPAWrite.c
===================================================================
--- trunk/psModules/src/camera/pmFPAWrite.c	(revision 18177)
+++ trunk/psModules/src/camera/pmFPAWrite.c	(revision 19385)
@@ -36,56 +36,4 @@
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-
-// Update the FPA.OBS, CHIP.NAME and CELL.NAME in the FITS header, if required
-bool pmFPAUpdateNames(pmFPA *fpa, pmChip *chip, pmCell *cell)
-{
-    pmHDU *hdu = pmHDUGetHighest(fpa, chip, cell); // Highest HDU, i.e., the PHU
-    if (!hdu) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find HDU.\n");
-        return false;
-    }
-    if (!hdu->header) {
-        hdu->header = psMetadataAlloc();
-    }
-    bool mdok;                          // Status of MD lookup
-    psMetadata *fileData = psMetadataLookupMetadata(&mdok, hdu->format, "FILE"); // File information
-    if (!mdok || !fileData) {
-        psError(PS_ERR_UNKNOWN, true, "Unable to find FILE information in camera format.\n");
-        return false;
-    }
-    if (fpa) {
-        const char *fpaObsHdr = psMetadataLookupStr(&mdok, fileData, "FPA.OBS");
-        if (mdok && fpaObsHdr && strlen(fpaObsHdr) > 0) {
-            const char *fpaObs = psMetadataLookupStr(NULL, fpa->concepts, "FPA.OBS");
-            psMetadataAddStr(hdu->header, PS_LIST_TAIL, fpaObsHdr, PS_META_REPLACE,
-                             "Observation identifier", fpaObs);
-        }
-    }
-
-    if (fpa && !fpa->hdu && (chip || cell)) {
-        const char *rule = psMetadataLookupStr(NULL, fileData, "CONTENT.RULE"); // How to define the CONTENT
-        if (!rule) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to find CONTENT.RULE in FILE in camera format.");
-            return false;
-        }
-
-        pmFPAview *view = pmFPAviewGenerate(fpa, chip, cell, NULL); // View for fpa, chip, cell
-        psString content = pmFPANameFromRule(rule, fpa, view); // Content of this file, specified by the rule
-        psFree(view);
-
-        const char *contentKey = psMetadataLookupStr(NULL, fileData, "CONTENT"); // The CONTENT header keyword
-        if (!contentKey) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to find CONTENT in FILE in the camera format.");
-            psFree(content);
-            return false;
-        }
-
-        psMetadataAddStr(hdu->header, PS_LIST_TAIL, contentKey, PS_META_REPLACE, "Content of file", content);
-        psFree(content);                // Drop reference
-    }
-
-    return true;
-}
-
 // Return the appropriate image array for the given type
 static psArray **appropriateImageArray(pmHDU *hdu, // HDU containing the image arrays
@@ -109,4 +57,5 @@
 static bool appropriateWriteFunc(pmHDU *hdu, // HDU to write
                                  psFits *fits, // FITS file to which to write
+                                 const pmConfig *config, // Configuration
                                  fpaWriteType type // Type to write
                                 )
@@ -114,9 +63,9 @@
     switch (type) {
     case FPA_WRITE_TYPE_IMAGE:
-        return pmHDUWrite(hdu, fits);
+        return pmHDUWrite(hdu, fits, config);
     case FPA_WRITE_TYPE_MASK:
-        return pmHDUWriteMask(hdu, fits);
+        return pmHDUWriteMask(hdu, fits, config);
     case FPA_WRITE_TYPE_WEIGHT:
-        return pmHDUWriteWeight(hdu, fits);
+        return pmHDUWriteWeight(hdu, fits, config);
     default:
         psAbort("Unknown write type: %x\n", type);
@@ -165,5 +114,5 @@
             return false;
         }
-        if (!appropriateWriteFunc(hdu, fits, type)) {
+        if (!appropriateWriteFunc(hdu, fits, config, type)) {
             psError(PS_ERR_IO, false, "Unable to write HDU for cell.\n");
             return false;
@@ -215,5 +164,5 @@
                 return false;
             }
-            if (!appropriateWriteFunc(hdu, fits, type)) {
+            if (!appropriateWriteFunc(hdu, fits, config, type)) {
                 psError(PS_ERR_IO, false, "Unable to write HDU for chip.\n");
                 return false;
@@ -279,5 +228,5 @@
                 return false;
             }
-            if (!appropriateWriteFunc(hdu, fits, type))  {
+            if (!appropriateWriteFunc(hdu, fits, config, type))  {
                 psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n");
                 return false;
@@ -305,4 +254,55 @@
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
+// Update the FPA.OBS, CHIP.NAME and CELL.NAME in the FITS header, if required
+bool pmFPAUpdateNames(pmFPA *fpa, pmChip *chip, pmCell *cell)
+{
+    pmHDU *hdu = pmHDUGetHighest(fpa, chip, cell); // Highest HDU, i.e., the PHU
+    if (!hdu) {
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find HDU.\n");
+        return false;
+    }
+    if (!hdu->header) {
+        hdu->header = psMetadataAlloc();
+    }
+    bool mdok;                          // Status of MD lookup
+    psMetadata *fileData = psMetadataLookupMetadata(&mdok, hdu->format, "FILE"); // File information
+    if (!mdok || !fileData) {
+        psError(PS_ERR_UNKNOWN, true, "Unable to find FILE information in camera format.\n");
+        return false;
+    }
+    if (fpa) {
+        const char *fpaObsHdr = psMetadataLookupStr(&mdok, fileData, "FPA.OBS");
+        if (mdok && fpaObsHdr && strlen(fpaObsHdr) > 0) {
+            const char *fpaObs = psMetadataLookupStr(NULL, fpa->concepts, "FPA.OBS");
+            psMetadataAddStr(hdu->header, PS_LIST_TAIL, fpaObsHdr, PS_META_REPLACE,
+                             "Observation identifier", fpaObs);
+        }
+    }
+
+    if (fpa && !fpa->hdu && (chip || cell)) {
+        const char *rule = psMetadataLookupStr(NULL, fileData, "CONTENT.RULE"); // How to define the CONTENT
+        if (!rule) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to find CONTENT.RULE in FILE in camera format.");
+            return false;
+        }
+
+        pmFPAview *view = pmFPAviewGenerate(fpa, chip, cell, NULL); // View for fpa, chip, cell
+        psString content = pmFPANameFromRule(rule, fpa, view); // Content of this file, specified by the rule
+        psFree(view);
+
+        const char *contentKey = psMetadataLookupStr(NULL, fileData, "CONTENT"); // The CONTENT header keyword
+        if (!contentKey) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to find CONTENT in FILE in the camera format.");
+            psFree(content);
+            return false;
+        }
+
+        psMetadataAddStr(hdu->header, PS_LIST_TAIL, contentKey, PS_META_REPLACE, "Content of file", content);
+        psFree(content);                // Drop reference
+    }
+
+    return true;
+}
+
 bool pmReadoutWriteNext(pmReadout *readout, psFits *fits, int z)
 {
@@ -347,5 +347,6 @@
         return false;
     }
-    psImage *image = readout->image; // The image from the HDU to write
+    psImage *image = readout->image;    // The image from the HDU to write
+    //    psImage *mask = readout->mask;        // Corresponding mask image
     if (readout->row0 == 0 && readout->col0 == 0 && z == 0) {
         // Then we can assume that nothing has been written to the FITS file for now
