Index: /trunk/psphot/configure.ac
===================================================================
--- /trunk/psphot/configure.ac	(revision 6494)
+++ /trunk/psphot/configure.ac	(revision 6495)
@@ -24,4 +24,11 @@
 )
 
+dnl handle profiler building
+AC_ARG_ENABLE(profile,
+  [AS_HELP_STRING(--enable-profile,enable compiler profiler information inclusion)],
+  [AC_MSG_RESULT(compile optimization enabled)
+   CFLAGS="${CFLAGS=} -pg"]
+)
+
 AC_CHECK_LIB(jpeg,jpeg_CreateCompress,[],[AC_MSG_ERROR([jpeg library not found.])])
 PKG_CHECK_MODULES(PSLIB, pslib >= 0.9.0)
Index: /trunk/psphot/src/pmModelFitSet.c
===================================================================
--- /trunk/psphot/src/pmModelFitSet.c	(revision 6494)
+++ /trunk/psphot/src/pmModelFitSet.c	(revision 6495)
@@ -38,20 +38,28 @@
     psF32 *dPAR = oneDeriv->data.F32;
 
+    psF32 *pars = params->data.F32;
+    psF32 *dpars = (deriv == NULL) ? NULL : deriv->data.F32;
+
     int nSrc = (params->n - 1) / (nPar - 1);
 
-    model = params->data.F32[0];
-
-    PAR[0] = params->data.F32[0];
+    PAR[0] = model = pars[0];
     for (int i = 0; i < nSrc; i++) {
+	int nOff = i*nPar - i;
 	for (int n = 1; n < nPar; n++) {
-	    PAR[n] = params->data.F32[i*nPar - i + n];
+	    PAR[n] = pars[nOff + n];
 	}
-	value = mFunc (oneDeriv, onePar, x);
+	if (deriv == NULL) {
+	    value = mFunc (NULL, onePar, x);
+	} else {
+	    value = mFunc (oneDeriv, onePar, x);
+	    for (int n = 1; n < nPar; n++) {
+		dpars[nOff + n] = dPAR[n];
+	    }
+	}
 	model += value;
-	for (int n = 1; n < nPar; n++) {
-	    deriv->data.F32[i*nPar - i + n] = dPAR[n];
-	}
     }
-    deriv->data.F32[0] = dPAR[0]*2.0;
+    if (deriv != NULL) {
+	dpars[0] = dPAR[0]*2.0;
+    }
     return (model);
 }
Index: /trunk/psphot/src/psphotApResid.c
===================================================================
--- /trunk/psphot/src/psphotApResid.c	(revision 6494)
+++ /trunk/psphot/src/psphotApResid.c	(revision 6495)
@@ -11,4 +11,7 @@
 
     psTimerStart ("psphot");
+
+    // S/N limit to perform full non-linear fits
+    float FIT_SN_LIM = psMetadataLookupF32 (&status, config, "FULL_FIT_SN_LIM");
 
     // measure the aperture loss as a function of radius for PSF
@@ -37,4 +40,7 @@
 	if (source->mode &  PM_SOURCE_POOR) continue;
 
+	// XXX tune independently?
+	if (source->moments->SN < 2*FIT_SN_LIM) continue;
+
 	// get uncorrected magnitudes in scaled apertures
 	model = pmSourceMagnitudes (source, NULL, 0);
Index: /trunk/psphot/src/psphotBlendFit.c
===================================================================
--- /trunk/psphot/src/psphotBlendFit.c	(revision 6494)
+++ /trunk/psphot/src/psphotBlendFit.c	(revision 6495)
@@ -4,4 +4,5 @@
 bool psphotBlendFit (pmReadout *readout, psMetadata *config, psArray *sources, pmPSF *psf) { 
 
+    int Nfit = 0;
     bool status;
 
@@ -45,4 +46,5 @@
 	// replace object in image
 	pmSourceAddModel (source->pixels, source->mask, source->modelPSF, false, false);
+	Nfit ++;
 
 	psTrace ("psphot.blend", 5, "trying source at %f, %f\n", source->moments->x, source->moments->y);
@@ -60,5 +62,5 @@
     }
 
-    psLogMsg ("psphot", 3, "fit PSF models: %f sec for %d objects\n", psTimerMark ("psphot"), sources->n);
+    psLogMsg ("psphot", 3, "fit PSF models: %f sec for %d objects (%d total)\n", psTimerMark ("psphot"), Nfit, sources->n);
     return (true);
 }
Index: /trunk/psphot/src/psphotFindPeaks.c
===================================================================
--- /trunk/psphot/src/psphotFindPeaks.c	(revision 6494)
+++ /trunk/psphot/src/psphotFindPeaks.c	(revision 6495)
@@ -22,4 +22,6 @@
     psImageSmooth (smooth_wt, SIGMA, NSIGMA);
     psLogMsg ("psphot", 4, "smooth weight: %f sec\n", psTimerMark ("psphot"));
+
+    // psphotSaveImage (NULL, smooth_im, "smooth.fits");
 
     psTimerStart ("psphot");
Index: /trunk/psphot/src/psphotMagnitudes.c
===================================================================
--- /trunk/psphot/src/psphotMagnitudes.c	(revision 6494)
+++ /trunk/psphot/src/psphotMagnitudes.c	(revision 6495)
@@ -76,4 +76,6 @@
     bool status;
 
+    psTimerStart ("psphot");
+
     float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");
     for (int i = 0; i < sources->n; i++) {
@@ -81,4 +83,6 @@
 	pmSourceMagnitudes (source, psf, RADIUS);
     }	
+
+    psLogMsg ("psphot.magnitudes", 4, "measure magnitudes : %f sec for %d objects\n", psTimerMark ("psphot"), sources->n);
     return true;
 }
Index: /trunk/psphot/src/psphotOutput.c
===================================================================
--- /trunk/psphot/src/psphotOutput.c	(revision 6494)
+++ /trunk/psphot/src/psphotOutput.c	(revision 6495)
@@ -175,5 +175,5 @@
 
     bool status;
-    char *outputFile;
+    char *outputFile = NULL;
 
     psMetadata *header = pmReadoutGetHeader (readout);
Index: /trunk/psphot/src/psphotSourceStats.c
===================================================================
--- /trunk/psphot/src/psphotSourceStats.c	(revision 6494)
+++ /trunk/psphot/src/psphotSourceStats.c	(revision 6495)
@@ -26,4 +26,6 @@
 	// allocate image, weight, mask arrays for each peak (square of radius OUTER)
 	psphotDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER);
+
+	// XXX skip faint sources?
 
 	// measure a local sky value
