Index: trunk/psphot/src/psphotFitSourcesLinear.c
===================================================================
--- trunk/psphot/src/psphotFitSourcesLinear.c	(revision 33963)
+++ trunk/psphot/src/psphotFitSourcesLinear.c	(revision 33993)
@@ -12,7 +12,9 @@
 static bool SetBorderMatrixElements (psSparseBorder *border, pmReadout *readout, psArray *sources, bool constant_weights, int SKY_FIT_ORDER, psImageMaskType markVal);
 
+# if (HAVE_MODEL_VAR)
 bool psphotGenerateModelVariance (pmConfig *config, const pmFPAview *view, pmFPAfile *file, int index, psMetadata *recipe, pmReadout *readout, psArray *sources);
 pmSourceFitVarMode psphotGetFitVarMode (psMetadata *recipe);
 bool psphotFreeModelVariance (pmReadout *readout, psArray *sources);
+# endif
 
 // for now, let's store the detections on the readout->analysis for each readout
@@ -28,4 +30,5 @@
     assert (recipe);
 
+# if (HAVE_MODEL_VAR)
     pmSourceFitVarMode fitVarMode = psphotGetFitVarMode (recipe);
     if (!fitVarMode) {
@@ -37,4 +40,5 @@
     // do a single pass.
     pmSourceFitVarMode fitVarModePass1 = (fitVarMode == PM_SOURCE_PHOTFIT_MODEL_VAR) ? PM_SOURCE_PHOTFIT_CONST : fitVarMode;
+# endif
 
     int num = psphotFileruleCount(config, filerule);
@@ -64,9 +68,14 @@
         psAssert (psf, "missing psf?");
 
+# if (HAVE_MODEL_VAR)
         if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final, fitVarModePass1)) {
+# else
+        if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final)) {
+# endif
             psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for %s entry %d", filerule, i);
             return false;
         }
 
+# if (HAVE_MODEL_VAR)
 	// the MODEL_VAR weighting scheme requires knowledge of the model fluxes to generate the variance
 	// after we have determined the initial set of fits, then we can generate the variance image and 
@@ -94,4 +103,5 @@
 	    }
 	}
+# endif
 
 	psphotVisualShowResidualImage (readout, (num > 0)); 
@@ -102,4 +112,5 @@
 }
 
+# if (HAVE_MODEL_VAR)
 // look up the fit variance mode from the recipe; older recipes do not have the value
 // 'LINEAR_FIT_VARIANCE_MODE'; in those cases, look for 'CONSTANT_PHOTOMETRIC_WEIGHTS' as a boolean and
@@ -130,6 +141,11 @@
     return PM_SOURCE_PHOTFIT_NONE;
 }
-
+# endif
+
+# if (HAVE_MODEL_VAR)
 bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final, pmSourceFitVarMode fitVarMode) {
+# else
+bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final) {
+# endif
 
     bool status;
@@ -168,4 +184,11 @@
     if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined");
 
+# if (!HAVE_MODEL_VAR)
+    bool CONSTANT_PHOTOMETRIC_WEIGHTS =
+        psMetadataLookupBool(&status, recipe, "CONSTANT_PHOTOMETRIC_WEIGHTS");
+    if (!status) {
+        psAbort("You must provide a value for the BOOL recipe CONSTANT_PHOTOMETRIC_WEIGHTS");
+    }
+# endif
     int SKY_FIT_ORDER = psMetadataLookupS32(&status, recipe, "SKY_FIT_ORDER");
     if (!status) {
@@ -295,4 +318,5 @@
     psSparseBorder *border = psSparseBorderAlloc (sparse, nBorder);
 
+# if (HAVE_MODEL_VAR)
     // if fitVarMode is MODEL_VAR, then we need to generate the model image variance
     // XXX we have two possibilities here: 
@@ -302,4 +326,5 @@
 
     // 2) do a single pass, and use the model guess to define the model variance (but do I trust the Model Guess?)
+# endif
 
     // fill out the sparse matrix elements and border elements (B)
@@ -310,7 +335,12 @@
 
         // diagonal elements of the sparse matrix (auto-cross-product)
+# if (HAVE_MODEL_VAR)
         f = pmSourceModelDotModel (SRCi, SRCi, fitVarMode, covarFactor, maskVal);
+# else
+        f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
+# endif
         psSparseMatrixElement (sparse, i, i, f);
 
+# if (HAVE_MODEL_VAR)
         // if we have used CONSTANT errors, then we need to calculate the value of the parameter error
         if (fitVarMode != PM_SOURCE_PHOTFIT_IMAGE_VAR) {
@@ -320,8 +350,20 @@
             errors->data.F32[i] = 1.0 / sqrt(f);
         }
-
+# else
+        // the formal error depends on the weighting scheme
+        if (CONSTANT_PHOTOMETRIC_WEIGHTS) {
+            float var = pmSourceModelDotModel (SRCi, SRCi, false, covarFactor, maskVal);
+            errors->data.F32[i] = 1.0 / sqrt(var);
+        } else {
+            errors->data.F32[i] = 1.0 / sqrt(f);
+        }
+# endif
 
         // find the image x model value
+# if (HAVE_MODEL_VAR)
         f = pmSourceDataDotModel (SRCi, SRCi, fitVarMode, covarFactor, maskVal);
+# else
+        f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
+# endif
         psSparseVectorElement (sparse, i, f);
 
@@ -329,11 +371,22 @@
         switch (SKY_FIT_ORDER) {
           case 1:
+# if (HAVE_MODEL_VAR)
             f = pmSourceModelWeight (SRCi, 1, fitVarMode, covarFactor, maskVal);
             psSparseBorderElementB (border, i, 1, f);
             f = pmSourceModelWeight (SRCi, 2, fitVarMode, covarFactor, maskVal);
             psSparseBorderElementB (border, i, 2, f);
+# else
+            f = pmSourceModelWeight (SRCi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
+            psSparseBorderElementB (border, i, 1, f);
+            f = pmSourceModelWeight (SRCi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
+            psSparseBorderElementB (border, i, 2, f);
+# endif
 
           case 0:
+# if (HAVE_MODEL_VAR)
             f = pmSourceModelWeight (SRCi, 0, fitVarMode, covarFactor, maskVal);
+# else
+            f = pmSourceModelWeight (SRCi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
+# endif
             psSparseBorderElementB (border, i, 0, f);
             break;
@@ -355,5 +408,9 @@
 
             // got an overlap; calculate cross-product and add to output array
+# if (HAVE_MODEL_VAR)
             f = pmSourceModelDotModel (SRCi, SRCj, fitVarMode, covarFactor, maskVal);
+# else
+            f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
+# endif
             psSparseMatrixElement (sparse, j, i, f);
         }
@@ -393,5 +450,9 @@
 
     // set the sky, sky_x, sky_y components of border matrix
+# if (HAVE_MODEL_VAR)
     SetBorderMatrixElements (border, readout, fitSources, (fitVarMode == PM_SOURCE_PHOTFIT_CONST), SKY_FIT_ORDER, markVal);
+# else
+    SetBorderMatrixElements (border, readout, fitSources, CONSTANT_PHOTOMETRIC_WEIGHTS, SKY_FIT_ORDER, markVal);
+# endif
 
     psSparseConstraint constraint;
@@ -552,4 +613,5 @@
 }
 
+# if (HAVE_MODEL_VAR)
 bool psphotModelBackgroundReadout(psImage *model,  // Model image
 				  psImage *modelStdev, // Model stdev image
@@ -661,2 +723,3 @@
     return true;
 }
+# endif
