Index: trunk/ppStack/src/ppStackFiles.c
===================================================================
--- trunk/ppStack/src/ppStackFiles.c	(revision 28253)
+++ trunk/ppStack/src/ppStackFiles.c	(revision 30620)
@@ -1,15 +1,8 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <unistd.h>
-#include <pslib.h>
-#include <psmodules.h>
-
 #include "ppStack.h"
 
-
 // Here follows lists of files for activation/deactivation at various stages.  Each must be NULL-terminated.
+
+/// NOP list
+static char *filesNOP[] = { NULL };
 
 /// Files required in preparation for convolution
@@ -41,4 +34,5 @@
 {
     switch (list) {
+      case PPSTACK_FILES_NONE:     return filesNOP;
       case PPSTACK_FILES_PREPARE:  return filesPrepare;
       case PPSTACK_FILES_TARGET:   return filesTarget;
@@ -206,2 +200,46 @@
     return true;
 }
+
+// Write an image to a FITS file
+bool ppStackWriteVariance(const char *name, // Name of image
+			  psMetadata *header, // Header
+			  const psImage *variance, // Variance
+			  const psImage *covariance, // Variance
+			  pmConfig *config // Configuration
+    )
+{
+    assert(name);
+    assert(variance);
+
+    psString resolved = pmConfigConvertFilename(name, config, true, true); // Resolved file name
+    psFits *fits = psFitsOpen(resolved, "w");
+    if (!fits) {
+        psError(PPSTACK_ERR_IO, false, "Unable to open FITS file %s to write image.", resolved);
+        psFree(resolved);
+        return false;
+    }
+    if (!psFitsWriteImage(fits, header, variance, 0, NULL)) {
+        psError(PPSTACK_ERR_IO, false, "Unable to write FITS image %s.", resolved);
+        psFitsClose(fits);
+        psFree(resolved);
+        return false;
+    }
+    if (covariance) {
+	psMetadata *tmphead = psMetadataAlloc();
+	psMetadataAddS32(tmphead, PS_LIST_TAIL, "COVARIANCE.CENTRE.X", PS_META_REPLACE, "center", (int)(covariance->numCols / 2));
+	psMetadataAddS32(tmphead, PS_LIST_TAIL, "COVARIANCE.CENTRE.Y", PS_META_REPLACE, "center", (int)(covariance->numRows / 2));
+	if (!psFitsWriteImage(fits, tmphead, covariance, 0, "COVAR_SkyChip_SkyCell")) {
+	    psError(PPSTACK_ERR_IO, false, "Unable to write FITS image %s.", resolved);
+	    psFitsClose(fits);
+	    psFree(resolved);
+	    return false;
+	}
+    }
+    if (!psFitsClose(fits)) {
+        psError(PPSTACK_ERR_IO, false, "Unable to close FITS image %s.", resolved);
+        psFree(resolved);
+        return false;
+    }
+    psFree(resolved);
+    return true;
+}
