Index: trunk/pswarp/src/pswarpLoop.c
===================================================================
--- trunk/pswarp/src/pswarpLoop.c	(revision 21323)
+++ trunk/pswarp/src/pswarpLoop.c	(revision 21368)
@@ -6,6 +6,6 @@
  *
  *  @author IfA
- *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-05 20:44:04 $
+ *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-06 03:10:36 $
  *  Copyright 2009 Institute for Astronomy, University of Hawaii
  */
@@ -13,18 +13,16 @@
 #include "pswarp.h"
 #include <ppStats.h>
-
-#define WCS_NONLIN_TOL 0.001            ///< Non-linear tolerance for header WCS
-#define PSPHOT_FIND_PSF 1               ///< Use psphot's findPSF function?
-#define TESTING 0                       ///< Testing output?
-
-#include "pswarpFileNames.h" ///< Lists of file rules used at different stages
-
-/**
- * XXX these are generic functions which should be moved to psModules
- * Activate a list of files
- */
-static void fileActivation(pmConfig *config, ///< Configuration
-                           char **files, ///< Files to turn on/off
-                           bool state   ///< Activation state
+#include "pswarpFileNames.h"            // Lists of file rules used at different stages
+
+#define WCS_NONLIN_TOL 0.001            // Non-linear tolerance for header WCS
+#define PSPHOT_FIND_PSF 1               // Use psphot's findPSF function?
+#define TESTING 0                       // Testing output?
+
+
+// XXX these are generic functions which should be moved to psModules
+// Activate a list of files
+static void fileActivation(pmConfig *config, // Configuration
+                           char **files, // Files to turn on/off
+                           bool state   // Activation state
     )
 {
@@ -293,4 +291,15 @@
     }
 
+    // Set covariance matrix for output
+    {
+        psList *covariances = psMetadataLookupPtr(&mdok, output->analysis,
+                                                  PSWARP_ANALYSIS_COVARIANCES); // Covariance matrices
+        psAssert(covariances, "Should be there");
+        psArray *covars = psListToArray(covariances); // Array of covariance matrices
+        output->covariance = psImageCovarianceAverage(covars);
+        psFree(covars);
+        psMetadataRemoveKey(output->analysis, PSWARP_ANALYSIS_COVARIANCES);
+    }
+
     if (!pmConceptsAverageCells(outCell, cells, NULL, NULL, false)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to average cell concepts.");
@@ -348,5 +357,5 @@
         ioChecksBefore(config);
 
-	// supply the readout and fpa of interest to psphot
+        // supply the readout and fpa of interest to psphot
         pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT");
         pmFPACopy(photFile->fpa, outFPA);
@@ -359,15 +368,15 @@
         // We can adjust the weight directly since this is a deep copy
         pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa);
-        float vf = psMetadataLookupF32(NULL, photRO->parent->concepts, "CELL.VARFACTOR"); ///< Variance factor
-        psBinaryOp(photRO->weight, photRO->weight, "*", psScalarAlloc(vf, PS_TYPE_F32));
-
-	// grab the sources of interest from the storage location (pmFPAfile PSPHOT.INPUT.CMF)
-	psArray *sources = psphotLoadPSFSources (config, view);
-	if (!sources) {
+        float vf = psMetadataLookupF32(NULL, photRO->parent->concepts, "CELL.VARFACTOR"); // Variance factor
+        psBinaryOp(photRO->variance, photRO->variance, "*", psScalarAlloc(vf, PS_TYPE_F32));
+
+        // grab the sources of interest from the storage location (pmFPAfile PSPHOT.INPUT.CMF)
+        psArray *sources = psphotLoadPSFSources (config, view);
+        if (!sources) {
             psError(PS_ERR_UNKNOWN, false, "No sources supplied to measure PSF");
             return false;
         }
 
-	// measure the PSF using these sources
+        // measure the PSF using these sources
         if (!psphotReadoutFindPSF(config, view, sources)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to determine PSF for warped image.");
