Index: /branches/eam_branches/ipp-20111122/psModules/src/objects/pmModelFuncs.h
===================================================================
--- /branches/eam_branches/ipp-20111122/psModules/src/objects/pmModelFuncs.h	(revision 33084)
+++ /branches/eam_branches/ipp-20111122/psModules/src/objects/pmModelFuncs.h	(revision 33085)
@@ -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: /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSource.c
===================================================================
--- /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSource.c	(revision 33084)
+++ /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSource.c	(revision 33085)
@@ -50,4 +50,5 @@
     psFree(tmp->pixels);
     psFree(tmp->variance);
+    psFree(tmp->modelVar);
     psFree(tmp->maskObj);
     psFree(tmp->maskView);
@@ -76,4 +77,5 @@
     psFree (source->pixels);
     psFree (source->variance);
+    psFree (source->modelVar);
     psFree (source->maskObj);
     psFree (source->maskView);
@@ -83,4 +85,5 @@
     source->pixels = NULL;
     source->variance = NULL;
+    source->modelVar = NULL;
     source->maskObj = NULL;
     source->maskView = NULL;
@@ -112,4 +115,5 @@
     source->pixels = NULL;
     source->variance = NULL;
+    source->modelVar = NULL;
     source->maskObj = NULL;
     source->maskView = NULL;
@@ -197,4 +201,5 @@
     source->pixels   = in->pixels   ? psImageCopyView(NULL, in->pixels)   : NULL;
     source->variance = in->variance ? psImageCopyView(NULL, in->variance) : NULL;
+    source->modelVar = in->modelVar ? psImageCopyView(NULL, in->modelVar) : NULL;
     source->maskView = in->maskView ? psImageCopyView(NULL, in->maskView) : NULL;
 
@@ -1025,4 +1030,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)
@@ -1047,5 +1055,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++) {
@@ -1062,8 +1070,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;
@@ -1074,11 +1084,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: /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.c	(revision 33084)
+++ /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.c	(revision 33085)
@@ -903,5 +903,5 @@
 {
     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;
@@ -920,4 +920,6 @@
         psAssert (Wi, "programming error");
 	break;
+      case PM_SOURCE_PHOTFIT_NONE:
+	psAbort("programming error");
     }	
 
@@ -947,9 +949,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;
         }
     }
@@ -984,4 +983,6 @@
         psAssert (Wi, "programming error");
 	break;
+      case PM_SOURCE_PHOTFIT_NONE:
+	psAbort("programming error");
     }	
 
@@ -1023,4 +1024,6 @@
                 wt = covarFactor * Wi->data.F32[yi][xi];
 		break;
+	      case PM_SOURCE_PHOTFIT_NONE:
+		psAbort("programming error");
 	    }
             // skip pixels with nonsense weight values
@@ -1060,4 +1063,6 @@
         psAssert (Wi, "programming error");
 	break;
+      case PM_SOURCE_PHOTFIT_NONE:
+	psAbort("programming error");
     }	
 
@@ -1099,4 +1104,6 @@
                 wt = covarFactor * Wi->data.F32[yi][xi];
 		break;
+	      case PM_SOURCE_PHOTFIT_NONE:
+		psAbort("programming error");
 	    }
             // skip pixels with nonsense weight values
Index: /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.h
===================================================================
--- /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.h	(revision 33084)
+++ /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.h	(revision 33085)
@@ -39,4 +39,5 @@
 
 typedef enum {
+    PM_SOURCE_PHOTFIT_NONE,
     PM_SOURCE_PHOTFIT_CONST,
     PM_SOURCE_PHOTFIT_IMAGE_VAR,
