Index: branches/pap/psphot/src/psphotVisual.c
===================================================================
--- branches/pap/psphot/src/psphotVisual.c	(revision 23948)
+++ branches/pap/psphot/src/psphotVisual.c	(revision 25027)
@@ -471,4 +471,5 @@
     bool status;
     Graphdata graphdata;
+    KapaSection section;
 
     if (!pmVisualIsVisual()) return true;
@@ -485,27 +486,43 @@
     KapaClearPlots (kapa3);
     KapaInitGraph (&graphdata);
-
-    // there are N regions: use the first (guaranteed to exist) to get the overall limits
-    psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, "PSF.CLUMP.REGION.000");
-
-    float psfX  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");
-    float psfY  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");
-
-    // examine sources to set data range
-    graphdata.xmin = -0.05;
-    graphdata.ymin = -0.05;
-    graphdata.xmax = 2.0*psfX;
-    graphdata.ymax = 2.0*psfY;
-    KapaSetLimits (kapa3, &graphdata);
-
-    KapaSetFont (kapa3, "helvetica", 14);
-    KapaBox (kapa3, &graphdata);
-    KapaSendLabel (kapa3, "&ss&h_x| (pixels)", KAPA_LABEL_XM);
-    KapaSendLabel (kapa3, "&ss&h_y| (pixels)", KAPA_LABEL_YM);
-
+    KapaSetFont (kapa3, "courier", 14);
+
+    float SN_LIM = psMetadataLookupF32(&status, recipe, "PSF_SN_LIM");
+
+    // select the max psfX,Y values for the plot limits
+    float Xmin = 0.0, Xmax = 0.0;
+    float Ymin = 0.0, Ymax = 0.0;
+    {
+        int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");
+        for (int n = 0; n < nRegions; n++) {
+
+            char regionName[64];
+            snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n);
+            psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);
+
+	    float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");
+            float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");
+            float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");
+            float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");
+
+	    float X0 = psfX - 4.0*psfdX;
+	    float X1 = psfX + 4.0*psfdX;
+	    float Y0 = psfY - 4.0*psfdY;
+	    float Y1 = psfY + 4.0*psfdY;
+
+	    if (isfinite(X0)) { Xmin = PS_MAX(Xmin, X0); }
+	    if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); }
+	    if (isfinite(Y0)) { Ymin = PS_MAX(Ymin, Y0); }
+	    if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); }
+        }
+    }
+
+    // storage vectors for data to be plotted
     psVector *xBright = psVectorAllocEmpty (sources->n, PS_TYPE_F32);
     psVector *yBright = psVectorAllocEmpty (sources->n, PS_TYPE_F32);
+    psVector *mBright = psVectorAllocEmpty (sources->n, PS_TYPE_F32);
     psVector *xFaint  = psVectorAllocEmpty (sources->n, PS_TYPE_F32);
     psVector *yFaint  = psVectorAllocEmpty (sources->n, PS_TYPE_F32);
+    psVector *mFaint  = psVectorAllocEmpty (sources->n, PS_TYPE_F32);
 
     // construct the vectors
@@ -519,19 +536,45 @@
         xFaint->data.F32[nF] = source->moments->Mxx;
         yFaint->data.F32[nF] = source->moments->Myy;
+        mFaint->data.F32[nF] = -2.5*log10(source->moments->Sum);
         nF++;
 
         // XXX make this a user-defined cutoff
-        if (source->moments->SN < 50)
+        if (source->moments->SN < SN_LIM)
             continue;
 
         xBright->data.F32[nB] = source->moments->Mxx;
         yBright->data.F32[nB] = source->moments->Myy;
+        mBright->data.F32[nB] = -2.5*log10(source->moments->Sum);
         nB++;
     }
     xFaint->n = nF;
     yFaint->n = nF;
+    mFaint->n = nF;
 
     xBright->n = nB;
     yBright->n = nB;
+    mBright->n = nB;
+
+    // three sections: MxxMyy, MagMxx, MagMyy
+
+    // first section: MxxMyy
+    section.dx = 0.75;
+    section.dy = 0.75;
+    section.x  = 0.00;
+    section.y  = 0.00;
+    section.name = psStringCopy ("MxxMyy");
+    KapaSetSection (kapa3, &section);
+    psFree (section.name);
+
+    graphdata.color = KapaColorByName ("black");
+    graphdata.xmin = Xmin;
+    graphdata.ymin = Ymin;
+    graphdata.xmax = Xmax;
+    graphdata.ymax = Ymax;
+    KapaSetLimits (kapa3, &graphdata);
+
+    KapaBox (kapa3, &graphdata);
+    KapaSendLabel (kapa3, "M_xx| (pixels)", KAPA_LABEL_XM);
+    KapaSendLabel (kapa3, "M_yy| (pixels)", KAPA_LABEL_YM);
 
     graphdata.color = KapaColorByName ("black");
@@ -551,6 +594,82 @@
     KapaPlotVector (kapa3, nB, yBright->data.F32, "y");
 
-    // XXX draw N circles to outline the clumps
+    // second section: MagMyy
+    section.dx = 0.75;
+    section.dy = 0.25;
+    section.x  = 0.00;
+    section.y  = 0.80;
+    section.name = psStringCopy ("MagMyy");
+    KapaSetSection (kapa3, &section);
+    psFree (section.name);
+
+    graphdata.color = KapaColorByName ("black");
+    graphdata.xmin = -17.1;
+    graphdata.xmax =  -7.9;
+    graphdata.ymin = Ymin;
+    graphdata.ymax = Ymax;
+    KapaSetLimits (kapa3, &graphdata);
+
+    strcpy (graphdata.labels, "0210");
+    KapaBox (kapa3, &graphdata);
+    KapaSendLabel (kapa3, "inst mag", KAPA_LABEL_XP);
+    KapaSendLabel (kapa3, "M_yy| (pixels)", KAPA_LABEL_YM);
+
+    graphdata.color = KapaColorByName ("black");
+    graphdata.ptype = 0;
+    graphdata.size = 0.3;
+    graphdata.style = 2;
+    KapaPrepPlot (kapa3, nF, &graphdata);
+    KapaPlotVector (kapa3, nF, mFaint->data.F32, "x");
+    KapaPlotVector (kapa3, nF, yFaint->data.F32, "y");
+
+    graphdata.color = KapaColorByName ("red");
+    graphdata.ptype = 2;
+    graphdata.size = 0.5;
+    graphdata.style = 2;
+    KapaPrepPlot (kapa3, nB, &graphdata);
+    KapaPlotVector (kapa3, nB, mBright->data.F32, "x");
+    KapaPlotVector (kapa3, nB, yBright->data.F32, "y");
+
+    // third section: MagMxx
+    section.dx = 0.25;
+    section.dy = 0.75;
+    section.x  = 0.80;
+    section.y  = 0.00;
+    section.name = psStringCopy ("MagMxx");
+    KapaSetSection (kapa3, &section);
+    psFree (section.name);
+
+    graphdata.color = KapaColorByName ("black");
+    graphdata.xmin = Xmin;
+    graphdata.xmax = Xmax;
+    graphdata.ymin =  -7.9;
+    graphdata.ymax = -17.1;
+    KapaSetLimits (kapa3, &graphdata);
+
+    strcpy (graphdata.labels, "2001");
+    KapaBox (kapa3, &graphdata);
+    KapaSendLabel (kapa3, "M_xx| (pixels)", KAPA_LABEL_XM);
+    KapaSendLabel (kapa3, "inst mag", KAPA_LABEL_YP);
+
+    graphdata.color = KapaColorByName ("black");
+    graphdata.ptype = 0;
+    graphdata.size = 0.3;
+    graphdata.style = 2;
+    KapaPrepPlot (kapa3, nF, &graphdata);
+    KapaPlotVector (kapa3, nF, xFaint->data.F32, "x");
+    KapaPlotVector (kapa3, nF, mFaint->data.F32, "y");
+
+    graphdata.color = KapaColorByName ("red");
+    graphdata.ptype = 2;
+    graphdata.size = 0.5;
+    graphdata.style = 2;
+    KapaPrepPlot (kapa3, nB, &graphdata);
+    KapaPlotVector (kapa3, nB, xBright->data.F32, "x");
+    KapaPlotVector (kapa3, nB, mBright->data.F32, "y");
+
+    // draw N circles to outline the clumps
     {
+        KapaSelectSection (kapa3, "MxxMyy");
+
         // draw a circle centered on psfX,Y with size of the psf limit
         psVector *xLimit  = psVectorAlloc (120, PS_TYPE_F32);
@@ -562,4 +681,10 @@
         graphdata.color = KapaColorByName ("blue");
         graphdata.style = 0;
+
+	graphdata.xmin = Xmin;
+	graphdata.ymin = Ymin;
+	graphdata.xmax = Xmax;
+	graphdata.ymax = Ymax;
+	KapaSetLimits (kapa3, &graphdata);
 
         for (int n = 0; n < nRegions; n++) {
@@ -626,6 +751,8 @@
     psFree (xBright);
     psFree (yBright);
+    psFree (mBright);
     psFree (xFaint);
     psFree (yFaint);
+    psFree (mFaint);
 
     // pause and wait for user input:
