Index: trunk/psModules/src/astrom/pmAstrometryObjects.c
===================================================================
--- trunk/psModules/src/astrom/pmAstrometryObjects.c	(revision 20039)
+++ trunk/psModules/src/astrom/pmAstrometryObjects.c	(revision 20801)
@@ -8,6 +8,6 @@
 *  @author EAM, IfA
 *
-*  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2008-10-10 02:33:35 $
+*  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2008-11-20 01:26:07 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -29,5 +29,4 @@
 #include <unistd.h>   // for unlink
 #include <pslib.h>
-#include <kapa.h> // cnb: do I need an IFDEF?
 
 #include "pmHDU.h"
@@ -35,4 +34,5 @@
 #include "pmAstrometryObjects.h"
 #include "pmKapaPlots.h"
+#include "pmAstrometryVisual.h"
 
 #define PM_ASTROMETRYOBJECTS_DEBUG 1
@@ -120,5 +120,4 @@
         i++;
     }
-
     return (matches);
 }
@@ -564,10 +563,4 @@
     psF32 **D2 = gridD2->data.F32;
 
-#ifdef PLOTS
-    // vectors to hold dX and dY
-    int nplot = raw->n * ref->n;
-    float dXplot[nplot];
-    float dYplot[nplot];
-#endif
 
     // accumulate grids for focal plane (L,M) matches
@@ -579,9 +572,4 @@
             dY = ob1->FP->y - ob2->FP->y;
 
-#ifdef PLOTS
-            dXplot[(i * ref->n) + j] = dX;
-            dYplot[(i * ref->n) + j] = dY;
-            // fprintf (f, "dX,dY: %8.2f %8.2f : %8.2f %8.2f : %8.2f %8.2f\n", dX, dY, ob1->FP->x, ob2->FP->x, ob1->FP->y, ob2->FP->y);
-#endif
             // find bin coordinates for this delta-delta
             if (!AstromGridBin (&iX, &iY, dX, dY)) {
@@ -618,5 +606,5 @@
         }
 
-        # if 0
+# if 0
         char line[16];
         psFits *fits = psFitsOpen ("grid.image.fits", "w");
@@ -625,5 +613,5 @@
         fprintf (stderr, "wrote grid image, press return to continue\n");
         fgets (line, 15, stdin);
-        # endif
+# endif
 
         // only check bins with at least 1/2 of max bin
@@ -670,4 +658,7 @@
         }
 
+        pmAstromVisualPlotGridMatch(raw, ref, gridNP, stats->offset.x, stats->offset.y,
+                                    maxOffpix, Scale, Offset);
+
         psFree (imStats);
         // XXX EAM : This routine, and pmAstromGridMatch, need to handle failure cases better
@@ -689,59 +680,4 @@
     // fprintf (stderr, "sigma: nMatch: %d, nTest: %d, nTen: %d\n", stats->nMatch, stats->nTest, sort->data.U32[sort->n - 10]);
 
-#ifdef PLOTS
-    /*** plot DXs and DYs ***/
-    KapaSection section = {"s1", 0.00, 0.00, 1.0, 1.0};
-    //KapaSection left = {"s2", 0.05, 0.05, 0.35, 0.8};
-    //KapaSection right = {"s3", 0.55, 0.05, 0.35, 0.8};
-    //KapaSection yprof = {"s4", 0.45, 0.05, 0.10, 0.9};
-    //KapaSection xprof = {"s5", .05, .90, .35, .1};
-
-    Graphdata graphdata;
-    int kapa = pmKapaOpen(true);
-    KapaClearPlots(kapa);
-    KapaInitGraph(&graphdata);
-    KapaSetSection(kapa, &section);
-    graphdata.xmin = stats->offset.x - 1.5 * maxOffpix;
-    graphdata.xmax = stats->offset.x + 1.5 * maxOffpix;
-    graphdata.ymin = stats->offset.y - 1.5 * maxOffpix;
-    graphdata.ymax = stats->offset.y + 1.5 * maxOffpix;
-
-    KapaSetLimits(kapa, &graphdata);
-    KapaSetFont(kapa, "helvetica", 14);
-    KapaBox(kapa, &graphdata);
-    KapaSendLabel (kapa, "X offset", KAPA_LABEL_XM);
-    KapaSendLabel (kapa, "Y offset", KAPA_LABEL_YM);
-    KapaSendLabel (kapa, "pmAstromGridAngle residuals. Big Box: Serach Region. Small Box: Correlation Peak.",
-                   KAPA_LABEL_XP);
-    graphdata.style = 2;
-    graphdata.ptype = 0;
-    graphdata.size = 0.4;
-    graphdata.color = KapaColorByName ("black");
-    KapaPrepPlot(kapa, nplot, &graphdata);
-    KapaPlotVector (kapa, nplot, dXplot, "x");
-    KapaPlotVector (kapa, nplot, dYplot, "y");
-
-    //Overplot bounding box, peak of distribution
-    float xbound[5] = { -maxOffpix, maxOffpix, maxOffpix, -maxOffpix, -maxOffpix};
-    float ybound[5] = { -maxOffpix, -maxOffpix, maxOffpix, maxOffpix, -maxOffpix};
-    float xbin[5] = {stats->offset.x - 0.5 * Scale, stats->offset.x + 0.5 * Scale, stats->offset.x + 0.5 * Scale,
-                     stats->offset.x - 0.5 * Scale, stats->offset.x - 0.5 * Scale};
-    float ybin[5] = {stats->offset.y - 0.5 * Scale, stats->offset.y - 0.5 * Scale, stats->offset.y + 0.5 * Scale,
-                     stats->offset.y + 0.5 * Scale, stats->offset.y - 0.5 * Scale};
-    graphdata.color = KapaColorByName("red");
-    graphdata.style = 0;
-    graphdata.size = 1.0;
-    KapaPrepPlot(kapa, 5, &graphdata);
-    KapaPlotVector (kapa, 5, xbound, "x");
-    KapaPlotVector (kapa, 5, ybound, "y");
-    KapaPrepPlot(kapa, 5, &graphdata);
-    KapaPlotVector (kapa, 5, xbin, "x");
-    KapaPlotVector (kapa, 5, ybin, "y");
-
-    KapaPNG(kapa, "dXdY.png");
-    char c;
-    fscanf(stdin, "%c", &c);
-    /*** end ***/
-#endif
 
   psFree (sort);
@@ -767,5 +703,4 @@
     PS_ASSERT_PTR_NON_NULL(ref, NULL);
     PS_ASSERT_PTR_NON_NULL(config, NULL);
-
     bool status;
     double xMin, xMax, yMin, yMax;
@@ -911,8 +846,4 @@
     psVector *xHistNew = psVectorSmooth(NULL, xHist, tweakSmooth, tweakNsigma);
     psVector *yHistNew = psVectorSmooth(NULL, yHist, tweakSmooth, tweakNsigma);
-    psFree(xHist);
-    psFree(yHist);
-    xHist = xHistNew;
-    yHist = yHistNew;
 
     // select peak in x and in y
@@ -921,11 +852,11 @@
     double yMax = 0;
     for (int i = 0; i < nBin; i++) {
-        if (xHist->data.F32[i] > xMax) {
+        if (xHistNew->data.F32[i] > xMax) {
             xBin = i;
-            xMax = xHist->data.F32[i];
-        }
-        if (yHist->data.F32[i] > yMax) {
+            xMax = xHistNew->data.F32[i];
+        }
+        if (yHistNew->data.F32[i] > yMax) {
             yBin = i;
-            yMax = yHist->data.F32[i];
+            yMax = yHistNew->data.F32[i];
         }
     }
@@ -940,7 +871,11 @@
     tweak->offset.y += yPeak;
 
+    pmAstromVisualPlotTweak (xHistNew, yHistNew, xBin, yBin);
+
     psFree (rot);
     psFree (xHist);
     psFree (yHist);
+    psFree (xHistNew);
+    psFree (yHistNew);
 
     return tweak;
