Index: trunk/psphot/src/psphotIsophotal.c
===================================================================
--- trunk/psphot/src/psphotIsophotal.c	(revision 15562)
+++ trunk/psphot/src/psphotIsophotal.c	(revision 17396)
@@ -1,3 +1,5 @@
-# include "psphot.h"
+# include "psphotInternal.h"
+
+static float ISOPHOT_FLUX = NAN;
 
 bool psphotIsophotal (pmSource *source, psMetadata *recipe, psMaskType maskVal) {
@@ -14,9 +16,12 @@
 
   // flux at which to measure isophotal parameters
-  // XXX cache this?
-  float ISOPHOT_FLUX = psMetadataLookupF32 (&status, recipe, "ISOPHOTAL_FLUX");
+  if (!isfinite(ISOPHOT_FLUX)) {
+    // XXX ISOPHOTAL_FLUX should be specified in mags, need the zero point to get counts/sec
+    ISOPHOT_FLUX = psMetadataLookupF32 (&status, recipe, "ISOPHOTAL_FLUX");
+    assert (status);
+  }
 
   // find the first bin below the flux level and the last above the level
-  // XXX can this be done faster with disection?
+  // XXX can this be done faster with bisection?
   // XXX do I need to worry about crazy outliers?  
   // XXX should i be smoothing or fitting the curve?
@@ -27,5 +32,17 @@
     if ((firstBelow < 0) && (flux->data.F32[i] < ISOPHOT_FLUX)) firstBelow = i;
   }
-
+  // if we don't go out far enough, we have a problem...
+  if (lastAbove == flux->n - 1) {
+    psTrace ("psphot", 5, "did not go out far enough to reach isophotal magnitude");
+    // XXX raise a flag ?
+    return false;
+  }
+  if (firstBelow < 0) {
+    psTrace ("psphot", 5, "did not go out far enough to bound isophotal magnitude: error unmeasured");
+    // XXX raise a flag ?
+    lastAbove = firstBelow;
+    return false;
+  }
+  
   // need to examine pixels in this vicinity
   float isophotalFluxFirst = 0;
@@ -56,4 +73,9 @@
   source->extpars->isophot->radErr = isophotalRadErr;
 
+  psTrace ("psphot", 5, "Isophot flux:%f +/- %f @ %f +/- %f for %f, %f\n",
+	   source->extpars->isophot->mag, source->extpars->isophot->magErr,
+	   source->extpars->isophot->rad, source->extpars->isophot->radErr,
+	   source->peak->xf, source->peak->yf);
+
   return true;
 
