Index: /trunk/psphot/src/psphot.h
===================================================================
--- /trunk/psphot/src/psphot.h	(revision 34214)
+++ /trunk/psphot/src/psphot.h	(revision 34215)
@@ -101,6 +101,6 @@
 bool            psphotMergeSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index);
 
-bool            psphotFitSourcesLinear (pmConfig *config, const pmFPAview *view, const char *filerule, bool final);
-bool            psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final, pmSourceFitVarMode fitVarMode);
+bool            psphotFitSourcesLinear (pmConfig *config, const pmFPAview *view, const char *filerule, bool final, bool skipNegativeFluxSources);
+bool            psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final, pmSourceFitVarMode fitVarMode, bool skipNegativeFluxSources);
 
 bool            psphotSourceSize (pmConfig *config, const pmFPAview *view, const char *filerule, bool getPSFsize);
Index: /trunk/psphot/src/psphotEfficiency.c
===================================================================
--- /trunk/psphot/src/psphotEfficiency.c	(revision 34214)
+++ /trunk/psphot/src/psphotEfficiency.c	(revision 34215)
@@ -420,5 +420,5 @@
 
     // psphotFitSourcesLinearReadout subtracts the model fits
-    if (!psphotFitSourcesLinearReadout(recipe, readout, fakeSourcesAll, psf, true, PM_SOURCE_PHOTFIT_CONST)) {
+    if (!psphotFitSourcesLinearReadout(recipe, readout, fakeSourcesAll, psf, true, PM_SOURCE_PHOTFIT_CONST, false)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to perform linear fit on fake sources.");
         psFree(fakeSources);
Index: /trunk/psphot/src/psphotFitSourcesLinear.c
===================================================================
--- /trunk/psphot/src/psphotFitSourcesLinear.c	(revision 34214)
+++ /trunk/psphot/src/psphotFitSourcesLinear.c	(revision 34215)
@@ -13,5 +13,5 @@
 
 // for now, let's store the detections on the readout->analysis for each readout
-bool psphotFitSourcesLinear (pmConfig *config, const pmFPAview *view, const char *filerule, bool final)
+bool psphotFitSourcesLinear (pmConfig *config, const pmFPAview *view, const char *filerule, bool final, bool skipNegativeFluxSources)
 {
     bool status = true;
@@ -66,5 +66,5 @@
         psAssert (psf, "missing psf?");
 
-        if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final, fitVarModePass1)) {
+        if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final, fitVarModePass1, skipNegativeFluxSources)) {
             psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for %s entry %d", filerule, i);
             return false;
@@ -85,5 +85,6 @@
 
 	    // rerun fit with correct fitVarMode
-	    if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final, fitVarMode)) {
+            // XXX: does skipNegativeFlux work here?
+	    if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final, fitVarMode, skipNegativeFluxSources)) {
 		psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for %s entry %d", filerule, i);
 		return false;
@@ -136,5 +137,5 @@
 }
 
-bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final, pmSourceFitVarMode fitVarMode) {
+bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final, pmSourceFitVarMode fitVarMode, bool skipNegativeFluxSources) {
     bool status;
     float x;
@@ -183,4 +184,7 @@
     float MIN_VALID_FLUX = psMetadataLookupF32(&status, recipe, "PSF_FIT_MIN_VALID_FLUX");
     if (!status) {
+        MIN_VALID_FLUX = 0.0;
+    }
+    if (skipNegativeFluxSources && MIN_VALID_FLUX < 0) {
         MIN_VALID_FLUX = 0.0;
     }
@@ -258,9 +262,9 @@
 	if (modelSum < 0.5) continue; // skip sources with no model constraint (somewhat arbitrary limit)
 	if (modelSum < 0.8) {
-	    fprintf (stderr, "low-sig model @ %f, %f (%f masked sum, %f sum, %f peak)\n",
+	    psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "low-sig model @ %f, %f (%f masked sum, %f sum, %f peak)\n",
 		     source->peak->xf, source->peak->yf, maskedSum, modelSum, source->peak->rawFlux);
 	}
 	if (maskedSum < 0.5) {
-	    fprintf (stderr, "worrying model @ %f, %f (%f masked sum, %f sum, %f peak)\n",
+	    psLogMsg ("psphot.ensemble",  PS_LOG_MINUTIA, "worrying model @ %f, %f (%f masked sum, %f sum, %f peak)\n",
 		     source->peak->xf, source->peak->yf, maskedSum, modelSum, source->peak->rawFlux);
 	}
Index: /trunk/psphot/src/psphotForcedReadout.c
===================================================================
--- /trunk/psphot/src/psphotForcedReadout.c	(revision 34214)
+++ /trunk/psphot/src/psphotForcedReadout.c	(revision 34215)
@@ -64,5 +64,5 @@
 
     // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
-    psphotFitSourcesLinear (config, view, filerule, false);
+    psphotFitSourcesLinear (config, view, filerule, false, false);
 
     // identify CRs and extended sources
Index: /trunk/psphot/src/psphotReadout.c
===================================================================
--- /trunk/psphot/src/psphotReadout.c	(revision 34214)
+++ /trunk/psphot/src/psphotReadout.c	(revision 34215)
@@ -185,5 +185,5 @@
 
     // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
-    psphotFitSourcesLinear (config, view, filerule, false); // pass 1 (detections->allSources)
+    psphotFitSourcesLinear (config, view, filerule, false, false); // pass 1 (detections->allSources)
 
     // measure the radial profiles to the sky
@@ -212,5 +212,5 @@
     // linear fit to include all sources (subtract again)
     // NOTE : apply to ALL sources (extended + psf)
-    psphotFitSourcesLinear (config, view, filerule, true); // pass 2 (detections->allSources)
+    psphotFitSourcesLinear (config, view, filerule, true, false); // pass 2 (detections->allSources)
 
     // if we only do one pass, skip to extended source analysis
@@ -261,5 +261,5 @@
 
 	// NOTE: apply to ALL sources
-	psphotFitSourcesLinear (config, view, filerule, true); // pass 3 (detections->allSources)
+	psphotFitSourcesLinear (config, view, filerule, true, false); // pass 3 (detections->allSources)
     }
 
@@ -302,5 +302,5 @@
 
 	// NOTE: apply to ALL sources
-	psphotFitSourcesLinear (config, view, filerule, true); // pass 3 (detections->allSources)
+	psphotFitSourcesLinear (config, view, filerule, true, false); // pass 3 (detections->allSources)
     }
 
Index: /trunk/psphot/src/psphotReadoutForcedKnownSources.c
===================================================================
--- /trunk/psphot/src/psphotReadoutForcedKnownSources.c	(revision 34214)
+++ /trunk/psphot/src/psphotReadoutForcedKnownSources.c	(revision 34215)
@@ -45,5 +45,5 @@
 
     // linear PSF fit to source peaks
-    psphotFitSourcesLinear (config, view, filerule, false);
+    psphotFitSourcesLinear (config, view, filerule, false, false);
 
     // calculate source magnitudes
Index: /trunk/psphot/src/psphotReadoutKnownSources.c
===================================================================
--- /trunk/psphot/src/psphotReadoutKnownSources.c	(revision 34214)
+++ /trunk/psphot/src/psphotReadoutKnownSources.c	(revision 34215)
@@ -57,5 +57,5 @@
 
     // linear PSF fit to source peaks
-    psphotFitSourcesLinear (config, view, filerule, false);
+    psphotFitSourcesLinear (config, view, filerule, false, false);
 
     // measure aperture photometry corrections
Index: /trunk/psphot/src/psphotReadoutMinimal.c
===================================================================
--- /trunk/psphot/src/psphotReadoutMinimal.c	(revision 34214)
+++ /trunk/psphot/src/psphotReadoutMinimal.c	(revision 34215)
@@ -70,5 +70,5 @@
 
     // linear PSF fit to source peaks
-    psphotFitSourcesLinear (config, view, filerule, false);
+    psphotFitSourcesLinear (config, view, filerule, false, false);
 
 // XXX eventually, add the extended source fits here
Index: /trunk/psphot/src/psphotStackReadout.c
===================================================================
--- /trunk/psphot/src/psphotStackReadout.c	(revision 34214)
+++ /trunk/psphot/src/psphotStackReadout.c	(revision 34215)
@@ -187,5 +187,5 @@
 
     // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
-    psphotFitSourcesLinear (config, view, STACK_SRC, false);
+    psphotFitSourcesLinear (config, view, STACK_SRC, false, false);
     psphotStackVisualFilerule(config, view, STACK_SRC);
 
@@ -215,5 +215,5 @@
     // NOTE : apply to ALL sources (extended + psf)
     // NOTE 2 : this function subtracts the models from the given filerule (SRC), not DET
-    psphotFitSourcesLinear (config, view, STACK_SRC, true); // pass 2 (detections->allSources)
+    psphotFitSourcesLinear (config, view, STACK_SRC, true, false); // pass 2 (detections->allSources)
 
     // NOTE: possibly re-measure background model here with objects subtracted / or masked
@@ -288,4 +288,10 @@
 pass1finish:
 
+#ifdef notyet
+    // Split the fit of detected sources from matched sources. But not yet.
+    // NOTE: apply to ALL sources. Only include sources with postitive flux in the fit
+    psphotFitSourcesLinear (config, view, STACK_SRC, true, true); // pass 3 (detections->allSources)
+#endif
+
     // generate the objects (objects unify the sources from the different images) NOTE: could
     // this just match the detections for the chisq image, and not bother measuring the source
@@ -302,6 +308,11 @@
     psphotStackObjectsSelectForAnalysis (config, view, STACK_SRC, objects);
 
-    // NOTE: apply to ALL sources
-    psphotFitSourcesLinear (config, view, STACK_SRC, true); // pass 3 (detections->allSources)
+#ifdef notyet
+    // NOTE: apply to Matched sources. Since the sources that we fit above are subtracted, they will
+    // not be included in this fit.
+    psphotFitSourcesLinear (config, view, STACK_SRC, true, false); // pass 4 (detections->allSources)
+#else
+    psphotFitSourcesLinear (config, view, STACK_SRC, true, false); // pass 3 (detections->allSources)
+#endif
 
     // measure the radial profiles to the sky (only measures new objects)
@@ -369,5 +380,5 @@
 
             // this is necessary to get the right normalization for the new models
-            psphotFitSourcesLinear (config, view, STACK_OUT, false);
+            psphotFitSourcesLinear (config, view, STACK_OUT, false, false);
 
             // measure circular, radial apertures (objects sorted by S/N)
