Index: /branches/eam_02_branch/psModules/src/objects/pmSource.c
===================================================================
--- /branches/eam_02_branch/psModules/src/objects/pmSource.c	(revision 12983)
+++ /branches/eam_02_branch/psModules/src/objects/pmSource.c	(revision 12984)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.25.4.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-04-24 03:15:27 $
+ *  @version $Revision: 1.25.4.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-04-24 17:04:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -755,4 +755,5 @@
     // in some places (psphotEnsemble), we need a normalized version
     // in others, we just want the model.  which is more commonly used?
+    // modelFlux always has unity normalization (I0 = 1.0)
     pmModelAdd (source->modelFlux, source->maskObj, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM);
     return true;
@@ -779,10 +780,16 @@
 	assert (dX >= 0);
 	assert (dY >= 0);
-	assert (dX + source->modelFlux->numCols < source->pixels->numCols);
-	assert (dY + source->modelFlux->numRows < source->pixels->numRows);
+	assert (dX + source->modelFlux->numCols <= source->pixels->numCols);
+	assert (dY + source->modelFlux->numRows <= source->pixels->numRows);
 	
-	float Io = 1.0;
+	// modelFlux has unity normalization
+	float Io = model->params->data.F32[PM_PAR_I0];
 	if (mode & PM_MODEL_OP_NORM) {
-	    Io = 1.0 / model->params->data.F32[PM_PAR_I0];
+	    Io = 1.0;
+	}
+
+	psU8 **mask = NULL;
+	if (source->maskObj) {
+	    mask = source->maskObj->data.U8;
 	}
 
@@ -792,4 +799,5 @@
 	    for (int ix = 0; ix < source->modelFlux->numCols; ix++) {
 		int ox = ix + dX;
+		if (mask && mask[iy][ix]) continue;
 		float value = Io*source->modelFlux->data.F32[iy][ix];
 		if (add) {
