Index: branches/eam_branches/ipp-20101205/ppStack/src/ppStack.h
===================================================================
--- branches/eam_branches/ipp-20101205/ppStack/src/ppStack.h	(revision 30117)
+++ branches/eam_branches/ipp-20101205/ppStack/src/ppStack.h	(revision 30228)
@@ -192,4 +192,11 @@
     );
 
+bool ppStackWriteVariance(const char *name, // Name of image
+			  psMetadata *header, // Header
+			  const psImage *variance, // Variance
+			  const psImage *covariance, // Variance
+			  pmConfig *config // Configuration
+    );
+
 /// Return an appropriate exit code based on the error code
 psExit ppStackExitCode(psExit exitValue);
Index: branches/eam_branches/ipp-20101205/ppStack/src/ppStackConvolve.c
===================================================================
--- branches/eam_branches/ipp-20101205/ppStack/src/ppStackConvolve.c	(revision 30117)
+++ branches/eam_branches/ipp-20101205/ppStack/src/ppStackConvolve.c	(revision 30228)
@@ -171,5 +171,5 @@
         }
         psFree(maskHeader);
-        if (!ppStackWriteImage(options->convVariances->data[i], hdu->header, readout->variance, config)) {
+        if (!ppStackWriteVariance(options->convVariances->data[i], hdu->header, readout->variance, readout->covariance->image, config)) {
             psError(PPSTACK_ERR_IO, false, "Unable to write convolved variance %d", i);
             psFree(fpaList);
Index: branches/eam_branches/ipp-20101205/ppStack/src/ppStackFiles.c
===================================================================
--- branches/eam_branches/ipp-20101205/ppStack/src/ppStackFiles.c	(revision 30117)
+++ branches/eam_branches/ipp-20101205/ppStack/src/ppStackFiles.c	(revision 30228)
@@ -200,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;
+}
