Index: trunk/psModules/src/objects/pmModelFuncs.h
===================================================================
--- trunk/psModules/src/objects/pmModelFuncs.h	(revision 33913)
+++ trunk/psModules/src/objects/pmModelFuncs.h	(revision 33963)
@@ -46,13 +46,14 @@
 
 typedef enum {
-    PM_MODEL_OP_NONE    = 0x00,
-    PM_MODEL_OP_FUNC    = 0x01,
-    PM_MODEL_OP_RES0    = 0x02,
-    PM_MODEL_OP_RES1    = 0x04,
-    PM_MODEL_OP_FULL    = 0x07,
-    PM_MODEL_OP_SKY     = 0x08,
-    PM_MODEL_OP_CENTER  = 0x10,
-    PM_MODEL_OP_NORM    = 0x20,
-    PM_MODEL_OP_NOISE   = 0x40,
+    PM_MODEL_OP_NONE     = 0x00,
+    PM_MODEL_OP_FUNC     = 0x01,
+    PM_MODEL_OP_RES0     = 0x02,
+    PM_MODEL_OP_RES1     = 0x04,
+    PM_MODEL_OP_FULL     = 0x07,
+    PM_MODEL_OP_SKY      = 0x08,
+    PM_MODEL_OP_CENTER   = 0x10,
+    PM_MODEL_OP_NORM     = 0x20,
+    PM_MODEL_OP_NOISE    = 0x40,
+    PM_MODEL_OP_MODELVAR = 0x80,
 } pmModelOpMode;
 
Index: trunk/psModules/src/objects/pmSource.c
===================================================================
--- trunk/psModules/src/objects/pmSource.c	(revision 33913)
+++ trunk/psModules/src/objects/pmSource.c	(revision 33963)
@@ -51,4 +51,5 @@
     psFree(tmp->pixels);
     psFree(tmp->variance);
+    psFree(tmp->modelVar);
     psFree(tmp->maskObj);
     psFree(tmp->maskView);
@@ -77,4 +78,5 @@
     psFree (source->pixels);
     psFree (source->variance);
+    psFree (source->modelVar);
     psFree (source->maskObj);
     psFree (source->maskView);
@@ -84,4 +86,5 @@
     source->pixels = NULL;
     source->variance = NULL;
+    source->modelVar = NULL;
     source->maskObj = NULL;
     source->maskView = NULL;
@@ -113,4 +116,5 @@
     source->pixels = NULL;
     source->variance = NULL;
+    source->modelVar = NULL;
     source->maskObj = NULL;
     source->maskView = NULL;
@@ -200,4 +204,5 @@
     source->pixels   = in->pixels   ? psImageCopyView(NULL, in->pixels)   : NULL;
     source->variance = in->variance ? psImageCopyView(NULL, in->variance) : NULL;
+    source->modelVar = NULL;
     source->maskView = in->maskView ? psImageCopyView(NULL, in->maskView) : NULL;
 
@@ -1028,4 +1033,7 @@
 
     bool addNoise = mode & PM_MODEL_OP_NOISE;
+    bool addModelVar = mode & PM_MODEL_OP_MODELVAR;
+
+    if (addModelVar) psAssert (source->modelVar, "programming error");
 
     // require the use of pmModelAddWithOffset if we are adding noise (because the model size and norm are rescaled)
@@ -1050,5 +1058,5 @@
         }
 
-        psF32 **target = source->pixels->data.F32;
+        psF32 **target = addModelVar ? source->modelVar->data.F32 : source->pixels->data.F32;
 
         for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
@@ -1065,8 +1073,10 @@
             }
         }
-	if (add) {
-	    source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
-	} else {
-	    source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
+	if (!addModelVar) {
+	    if (add) {
+		source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
+	    } else {
+		source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
+	    }
 	}
         return true;
@@ -1077,11 +1087,14 @@
         target = source->variance;
     }
+    if (addModelVar) {
+        target = source->modelVar;
+    }
 
     if (add) {
 	status = pmModelAddWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
-	source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
+	if (!addNoise && !addModelVar) source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     } else {
 	status = pmModelSubWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
-	source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
+	if (!addNoise && !addModelVar) source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     }
 
Index: trunk/psModules/src/objects/pmSource.h
===================================================================
--- trunk/psModules/src/objects/pmSource.h	(revision 33913)
+++ trunk/psModules/src/objects/pmSource.h	(revision 33963)
@@ -72,4 +72,5 @@
     psImage *pixels;                    ///< Rectangular region including object pixels.
     psImage *variance;			///< Image variance.
+    psImage *modelVar;			///< variance based on current models
     psImage *maskObj;                   ///< unique mask for this object which marks included pixels associated with objects.
     psImage *maskView;                  ///< view into global image mask for this object region
Index: trunk/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- trunk/psModules/src/objects/pmSourcePhotometry.c	(revision 33913)
+++ trunk/psModules/src/objects/pmSourcePhotometry.c	(revision 33963)
@@ -899,15 +899,28 @@
 }
 
-double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
+double pmSourceModelWeight(const pmSource *Mi, int term, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(Mi, NAN);
-    double flux = 0, wt = 0, factor = 0;
+    double flux = 0, wt = 1.0, factor = 0;
 
     const psImage *Pi = Mi->modelFlux;
     assert (Pi != NULL);
-    const psImage *Wi = Mi->variance;
-    if (!unweighted_sum) {
-        assert (Wi != NULL);
-    }
+
+    const psImage *Wi = NULL;
+    switch (fitVarMode) {
+      case PM_SOURCE_PHOTFIT_CONST:
+	break;
+      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
+	Wi = Mi->variance;
+        psAssert (Wi, "programming error");
+	break;
+      case PM_SOURCE_PHOTFIT_MODEL_VAR:
+	Wi = Mi->modelVar;
+        psAssert (Wi, "programming error");
+	break;
+      case PM_SOURCE_PHOTFIT_NONE:
+	psAbort("programming error");
+    }	
+
     const psImage *Ti = Mi->maskObj;
     assert (Ti != NULL);
@@ -915,10 +928,8 @@
     for (int yi = 0; yi < Pi->numRows; yi++) {
         for (int xi = 0; xi < Pi->numCols; xi++) {
-            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal)
-                continue;
-            if (!unweighted_sum) {
+            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal) continue;
+            if (fitVarMode != PM_SOURCE_PHOTFIT_CONST) {
                 wt = covarFactor * Wi->data.F32[yi][xi];
-                if (wt == 0)
-                    continue;
+                if (wt == 0) continue;
             }
 
@@ -937,9 +948,6 @@
             }
 
-            if (unweighted_sum) {
-                flux += (factor * Pi->data.F32[yi][xi]);
-            } else {
-                flux += (factor * Pi->data.F32[yi][xi]) / wt;
-            }
+	    // wt is 1.0 for CONST
+	    flux += (factor * Pi->data.F32[yi][xi]) / wt;
         }
     }
@@ -947,5 +955,5 @@
 }
 
-double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
+double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(Mi, NAN);
@@ -955,5 +963,6 @@
     int xIs, xJs, yIs, yJs;
     int xIe, yIe;
-    double flux, wt;
+    double flux;
+    double wt = 1.0;
 
     const psImage *Pi = Mi->modelFlux;
@@ -962,8 +971,19 @@
     assert (Pj != NULL);
 
-    const psImage *Wi = Mi->variance;
-    if (!unweighted_sum) {
-        assert (Wi != NULL);
-    }
+    const psImage *Wi = NULL;
+    switch (fitVarMode) {
+      case PM_SOURCE_PHOTFIT_CONST:
+	break;
+      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
+	Wi = Mi->variance;
+        psAssert (Wi, "programming error");
+	break;
+      case PM_SOURCE_PHOTFIT_MODEL_VAR:
+	Wi = Mi->modelVar;
+        psAssert (Wi, "programming error");
+	break;
+      case PM_SOURCE_PHOTFIT_NONE:
+	psAbort("programming error");
+    }	
 
     const psImage *Ti = Mi->maskObj;
@@ -995,13 +1015,20 @@
                 continue;
 
-            // XXX skip the nonsense weight pixels?
-            if (unweighted_sum) {
-                flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
-            } else {
+	    float value = (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
+	    switch (fitVarMode) {
+	      case PM_SOURCE_PHOTFIT_CONST:
+		wt = 1.0;
+		break;
+	      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
+	      case PM_SOURCE_PHOTFIT_MODEL_VAR:
                 wt = covarFactor * Wi->data.F32[yi][xi];
-                if (wt > 0) {
-                    flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]) / wt;
-                }
-            }
+		break;
+	      case PM_SOURCE_PHOTFIT_NONE:
+		psAbort("programming error");
+	    }
+            // skip pixels with nonsense weight values
+	    if (wt <= 0) continue;
+
+	    flux += value / wt;
         }
     }
@@ -1009,5 +1036,5 @@
 }
 
-double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
+double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(Mi, NAN);
@@ -1017,5 +1044,6 @@
     int xIs, xJs, yIs, yJs;
     int xIe, yIe;
-    double flux, wt;
+    double flux;
+    double wt = 1.0;
 
     const psImage *Pi = Mi->pixels;
@@ -1024,8 +1052,19 @@
     assert (Pj != NULL);
 
-    const psImage *Wi = Mi->variance;
-    if (!unweighted_sum) {
-        assert (Wi != NULL);
-    }
+    const psImage *Wi = NULL;
+    switch (fitVarMode) {
+      case PM_SOURCE_PHOTFIT_CONST:
+	break;
+      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
+	Wi = Mi->variance;
+        psAssert (Wi, "programming error");
+	break;
+      case PM_SOURCE_PHOTFIT_MODEL_VAR:
+	Wi = Mi->modelVar;
+        psAssert (Wi, "programming error");
+	break;
+      case PM_SOURCE_PHOTFIT_NONE:
+	psAbort("programming error");
+    }	
 
     const psImage *Ti = Mi->maskObj;
@@ -1057,13 +1096,21 @@
                 continue;
 
-            // XXX skip the nonsense weight pixels?
-            if (unweighted_sum) {
-                flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
-            } else {
+	    float value = (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
+	    switch (fitVarMode) {
+	      case PM_SOURCE_PHOTFIT_CONST:
+		wt = 1.0;
+		break;
+	      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
+	      case PM_SOURCE_PHOTFIT_MODEL_VAR:
                 wt = covarFactor * Wi->data.F32[yi][xi];
-                if (wt > 0) {
-                    flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]) / wt;
-                }
-            }
+		break;
+	      case PM_SOURCE_PHOTFIT_NONE:
+		psAbort("programming error");
+	    }
+            // skip pixels with nonsense weight values
+	    if (wt <= 0) continue;
+
+	    flux += value / wt;
+
         }
     }
Index: trunk/psModules/src/objects/pmSourcePhotometry.h
===================================================================
--- trunk/psModules/src/objects/pmSourcePhotometry.h	(revision 33913)
+++ trunk/psModules/src/objects/pmSourcePhotometry.h	(revision 33963)
@@ -38,4 +38,11 @@
 } pmSourcePhotometryMode;
 
+typedef enum {
+    PM_SOURCE_PHOTFIT_NONE       = 0,
+    PM_SOURCE_PHOTFIT_CONST      = 1,
+    PM_SOURCE_PHOTFIT_IMAGE_VAR  = 2,
+    PM_SOURCE_PHOTFIT_MODEL_VAR  = 3,
+} pmSourceFitVarMode;
+
 bool pmSourcePhotometryModel(
     float *fitMag,                      ///< integrated fit magnitude
@@ -75,7 +82,7 @@
 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
 
-double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
-double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
-double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
+double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal);
+double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal);
+double pmSourceModelWeight(const pmSource *Mi, int term, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal);
 
 bool pmSourceNeighborFlags (pmSource *source);
