Index: /branches/cnb_branch_20081011/psModules/src/astrom/pmAstrometryVisual.c
===================================================================
--- /branches/cnb_branch_20081011/psModules/src/astrom/pmAstrometryVisual.c	(revision 20477)
+++ /branches/cnb_branch_20081011/psModules/src/astrom/pmAstrometryVisual.c	(revision 20478)
@@ -25,11 +25,11 @@
 # include <kapa.h>
 
-# define KAPAX 800
-# define KAPAY 800
+# define KAPAX 700
+# define KAPAY 700
 
 
 //variables to determine when things are plotted
 static bool isVisual             = false;
-static bool plotGridMatch        = false;
+static bool plotGridMatch        = true;
 static bool plotTweak            = true;
 
@@ -266,5 +266,9 @@
  * of these two profiles and adjusts the offset accordingly. This procedure plots the profiles.
  */
-bool pmAstromVisualPlotTweak (psVector *xHist, psVector *yHist, int xBin, int yBin)
+bool pmAstromVisualPlotTweak (psVector *xHist, ///< Smoothed Horizontal cut through the histogram
+                              psVector *yHist, ///< Smoothed Vertical cut throug the histogram
+                              int xBin,        ///< X Bin index of the histogram peak
+                              int yBin         ///< Y bin index of the histogram peak
+    )
 {
     //make sure we want to plot this
@@ -294,5 +298,5 @@
 
     // plot the X histogram
-    pmAstromVisualScaleGraphdata(&graphdata, xIndices, xHistNew, false);
+    pmAstromVisualScaleGraphdata(&graphdata, xIndices, xHist, false);
     KapaSetSection(kapa, &section1);
     KapaSetLimits (kapa, &graphdata);
@@ -321,8 +325,9 @@
 
     //plot the Y histogram
-    pmAstromVisualScaleGraphdata(&graphdata, yIndices, yHistNew, false);
+    pmAstromVisualScaleGraphdata(&graphdata, yIndices, yHist, false);
     KapaSetSection(kapa, &section2);
     KapaSetLimits (kapa, &graphdata);
     KapaSetFont(kapa, "helvetica", 14);
+    graphdata.color = KapaColorByName ("black");
     KapaBox(kapa, &graphdata);
     KapaSendLabel (kapa, "Y offset Bin", KAPA_LABEL_XM);
@@ -333,5 +338,4 @@
     graphdata.ptype = 0;
     graphdata.size = 0.4;
-    graphdata.color = KapaColorByName ("black");
 
     KapaPrepPlot (kapa, yHist->n, &graphdata);
Index: /branches/cnb_branch_20081011/psastro/src/psastroUtils.c
===================================================================
--- /branches/cnb_branch_20081011/psastro/src/psastroUtils.c	(revision 20477)
+++ /branches/cnb_branch_20081011/psastro/src/psastroUtils.c	(revision 20478)
@@ -77,5 +77,4 @@
             }
         }
-
     }
     psastroMosaicSetAstrom (fpa);
Index: /branches/cnb_branch_20081011/psastro/src/psastroVisual.c
===================================================================
--- /branches/cnb_branch_20081011/psastro/src/psastroVisual.c	(revision 20477)
+++ /branches/cnb_branch_20081011/psastro/src/psastroVisual.c	(revision 20478)
@@ -14,19 +14,19 @@
 # include <kapa.h>
 
-# define KAPAX  800
-# define KAPAY  800
+# define KAPAX  700
+# define KAPAY  700
 
 //variables to determine when things are plotted
 static bool isVisual             = false;
-static bool plotRawStars         = false;
+static bool plotRawStars         = true;
 static bool plotRefStars         = false;
-static bool plotLumFunc          = false;
-static bool plotRemoveClumps     = false;
-static bool plotOneChipFit       = false;
+static bool plotLumFunc          = true;
+static bool plotRemoveClumps     = true;
+static bool plotOneChipFit       = true;
 static bool plotFixChips         = true;
-static bool plotAstromGuessCheck = false;
-static bool plotMosaicMatches    = false;
+static bool plotAstromGuessCheck = true;
+static bool plotMosaicMatches    = true;
 static bool plotCommonScale      = true;
-static bool plotMosaicOneChip    = false;
+static bool plotMosaicOneChip    = true;
 
 // variables to store plotting window indices
@@ -37,5 +37,5 @@
 bool psastroVisualInitGraph (int kapa, KapaSection *section, Graphdata *graphdata);
 bool psastroVisualTriplePlot (int kapa, Graphdata *graphdata, psVector *xVec, psVector *yVec, psVector *zVec, bool increasing);
-bool psastroVisualScaleGraphdata(Graphdata *graphdata, psVector *xVec, psVector *yVec);
+bool psastroVisualScaleGraphdata(Graphdata *graphdata, psVector *xVec, psVector *yVec, bool clip);
 bool psastroVisualTripleOverplot (int kapa, Graphdata *graphdata, psVector *xVec, psVector *yVec, psVector *zVec, bool increasing);
 bool psastroVisualCreateScaleVec (psVector *zVec, psVector *zScale, bool increasing);
@@ -81,4 +81,5 @@
     if (key[0] == 'a') {
         psastroSetVisual(false);
+        pmAstromSetVisual(false);
     }
     return true;
@@ -101,5 +102,5 @@
 
 
-/**  psastroVisualPlotRawStars
+/**
  * Plot raw stars as determined from first pass astrometry fit
  * Called within psastroAstromGeuss
@@ -269,5 +270,5 @@
 
 
-/** psastroVisualPlotRefStars
+/**
  * plot the location of references stars over the entire fpa
  * invoked during psastroChooseRefStars
@@ -277,5 +278,4 @@
     //make sure we want to plot this
     if (!isVisual || !plotRefStars) return true;
-    Graphdata graphdata;
 
     //set up plotting variables
@@ -283,4 +283,5 @@
         return false;
 
+    Graphdata graphdata;
     KapaInitGraph (&graphdata);
     KapaClearSections (kapa);
@@ -333,11 +334,15 @@
 
 
-/** psastroVisualPlotLuminosityFunction
+/**
  * Plot the two luminosity functions created within psastroRefStarSubset
  * The luminosity functions are used to select a subset of reference stars,
  * so we plot the cutoff that defines this subset
  */
-bool psastroVisualPlotLuminosityFunction (psVector *lnMag, psVector *Mag,
-                                          pmLumFunc *lumFunc, pmLumFunc *rawFunc) {
+bool psastroVisualPlotLuminosityFunction (psVector *lnMag,   ///< Log(n) for each magnitude bin
+                                          psVector *Mag,     ///< magnitude bins
+                                          pmLumFunc *lumFunc,///< Fit to the reference star luminosity function
+                                          pmLumFunc *rawFunc ///< Fit to the raw star luminoisty function
+                                          )
+{
 
     // make sure we want to plot this
@@ -361,5 +366,5 @@
 
     //Determine Plot Limits
-    psastroVisualScaleGraphdata(&graphdata, Mag, lnMag);
+    psastroVisualScaleGraphdata(&graphdata, Mag, lnMag, false);
 
     //Make a line for the fit
@@ -422,10 +427,15 @@
 
 
-/** psastroVisualPlotRemoveClumps
+/**
  * Plot the stars in a region, and indicate which stars are part of 'clumps'
  * These stars are flagged during astrometric fitting, since dense regions are
  * harder to cross-match than sparse ones. Called during psastroRemoveClumps.
  */
-bool psastroVisualPlotRemoveClumps (psArray *input, psImage *count, int scale, float limit) {
+bool psastroVisualPlotRemoveClumps (psArray *input, ///< Array containing the field stars
+                                    psImage *count, ///< A 2D histogram of the field star distribution
+                                    int scale,      ///< The pixel size of the histogram
+                                    float limit     ///< The minimum numuber of stars in a bin flagged as a clump
+                                    )
+{
 
     //make sure we want to plot this
@@ -524,10 +534,15 @@
 
 
-/** psastroVisualPlotOneChipFit
- * assess the goodness of fit for a signle chip by
+/**
+ * Assess the goodness of fit for a signle chip by
  * plotting the fit residuals
  * invoked during psastroOneChipFit
  */
-bool psastroVisualPlotOneChipFit (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe) {
+bool psastroVisualPlotOneChipFit (psArray *rawstars, ///< stars detected in the image
+                                  psArray *refstars, ///< reference stars over the same region
+                                  psArray *match,    ///< contains which rawstars match to which refstars
+                                  psMetadata *recipe ///< data reduction recipe
+                                  )
+{
 
     //make sure we want to plot this
@@ -545,11 +560,12 @@
 
 
-/** Plots the chip corners in the FP before and after chips with inconsistent solutions have been fixed.
+/**
+ * Plots the chip corners in the FP before and after chips with inconsistent solutions have been fixed.
  * Invoked during psastroFixChips
  */
 bool psastroVisualPlotFixChips (pmFPAfile *input, ///< focal plane array file
-                            psVector *xOld, ///< old X location of chip cornerss
-                            psVector *yOld ///< old Y location of chip corners
-    )
+                                psVector *xOld, ///< old X location of chip cornerss
+                                psVector *yOld ///< old Y location of chip corners
+                                )
 {
     //make sure we want to plot this
@@ -565,6 +581,6 @@
     graphdata.style = 2;
 
-    psVector *xNew = psVectorAllocEmpty (xOld->n, PS_TYPE_F32);
-    psVector *yNew = psVectorAllocEmpty (yOld->n, PS_TYPE_F32);
+    psVector *xNew = psVectorAlloc (xOld->n, PS_TYPE_F32);
+    psVector *yNew = psVectorAlloc (yOld->n, PS_TYPE_F32);
 
     // copy of the code in psastroFixChips that generated xOld, yOld, but for xNew, yNew
@@ -607,5 +623,5 @@
 
     //set up graph
-    psastroVisualScaleGraphdata(&graphdata, xOld, yOld);
+    psastroVisualScaleGraphdata(&graphdata, xOld, yOld, true);
     psastroVisualInitGraph(kapa, &section, &graphdata);
     KapaSendLabel (kapa, "L (FP)", KAPA_LABEL_XM);
@@ -637,7 +653,12 @@
  *  old to new coordinates
  */
-bool psastroVisualPlotAstromGuessCheck (psVector *cornerPo, psVector *cornerQo,
-                                        psVector *cornerPn, psVector *cornerQn,
-                                        psVector *cornerPd, psVector *cornerQd) {
+bool psastroVisualPlotAstromGuessCheck (psVector *cornerPo, ///< P coordinates of chip corners before fitting
+                                        psVector *cornerQo, ///< Q coordinates of chip corners before fitting
+                                        psVector *cornerPn, ///< P coordinates of chip corners after fitting
+                                        psVector *cornerQn, ///< Q coordinates of chip corners after fitting
+                                        psVector *cornerPd, ///< P coordinate residuals of fit from old to new coordinates
+                                        psVector *cornerQd  ///< Q coordinate residuals of fit from old to new coordinates
+                                        )
+{
 
     //make sure we want to plot this
@@ -668,5 +689,5 @@
     psFree(section.name);
 
-    psastroVisualScaleGraphdata (&graphdata, cornerPo, cornerPo);
+    psastroVisualScaleGraphdata (&graphdata, cornerPo, cornerPo, true);
     KapaSetLimits (kapa, &graphdata);
     KapaBox (kapa, &graphdata);
@@ -705,5 +726,5 @@
     psFree(section.name);
 
-    psastroVisualScaleGraphdata (&graphdata, xResid, yResid);
+    psastroVisualScaleGraphdata (&graphdata, xResid, yResid, true);
     KapaSetLimits (kapa, &graphdata);
     KapaBox (kapa, &graphdata);
@@ -723,11 +744,12 @@
 }
 
-/** psastroVisualPlotCommonScale (fpa, oldScale, newScale)
+
+/**
  * Plots the pixel scales of the fpa before they are
  * equalized in psastroMosaicCommonScale
  */
-
 bool psastroVisualPlotCommonScale (pmFPA *fpa,         ///< the fpa
-                              psVector *oldScale) ///< the old pixel scale of each chip in the fpa
+                                   psVector *oldScale  ///< the old pixel scale of each chip in the fpa
+                                   )
 {
     //make sure we want to plot this
@@ -741,6 +763,7 @@
     ptCH.x = 0;
     ptCH.y = 0;
-    psVector *xVec = psVectorAllocEmpty (oldScale->n, PS_TYPE_F32);
-    psVector *yVec = psVectorAllocEmpty (oldScale->n, PS_TYPE_F32);
+    psVector *xVec = psVectorAlloc (oldScale->n, PS_TYPE_F32);
+    psVector *yVec = psVectorAlloc (oldScale->n, PS_TYPE_F32);
+
     int nobj = 0;
 
@@ -761,5 +784,5 @@
     KapaClearPlots (kapa);
     KapaSetSection (kapa, &section);
-    psastroVisualInitGraph(kapa, &section, &graphdata);
+    KapaSetFont (kapa, "helvetica", 14);
     psastroVisualTriplePlot (kapa, &graphdata, xVec, yVec, oldScale, false);
     KapaSendLabel (kapa, "L (FP)", KAPA_LABEL_XM);
@@ -773,5 +796,4 @@
 
 /**
- * psastroVisualPlotMosaicOneChip (rawstars, refstars, match);
  *   plot the residuals between raw stars and ref stars after
  *   fitting in psastroMosaicOneChip
@@ -820,9 +842,9 @@
 /*********************/
 
+
 /** psastroVisualInitGraph (kapa, *section, *graphdata)
  * Initializes graph, sets the section, sets the font,
  * sets the limits, draws the box
  */
-
 bool psastroVisualInitGraph (int kapa, KapaSection *section, Graphdata *graphdata)
 {
@@ -834,4 +856,5 @@
 }
 
+
 /** psastroVisualTriplePlot
  * plot 2 vectors whose point sizes are scaled by a third vector
@@ -840,5 +863,5 @@
 bool psastroVisualTriplePlot (int kapid, Graphdata *graphdata, psVector *xVec, psVector *yVec, psVector *zVec, bool increasing)
 {
-    psastroVisualScaleGraphdata (graphdata, xVec, yVec);
+    psastroVisualScaleGraphdata (graphdata, xVec, yVec, true);
     //printf("%f %f %f %f \n",graphdata->xmin, graphdata->xmax, graphdata->ymin, graphdata->ymax);
     // set the scale vector
@@ -851,4 +874,6 @@
 
     // the point size will be scaled from the z vector
+    graphdata->ptype = 7;
+    graphdata->style = 2;
     graphdata->size = -1;
     KapaPrepPlot (kapid, xVec->n, graphdata);
@@ -916,5 +941,5 @@
  * prevent outliers from making te plot region too big.
  */
-bool psastroVisualScaleGraphdata(Graphdata *graphdata, psVector *xVec, psVector *yVec) {
+bool psastroVisualScaleGraphdata(Graphdata *graphdata, psVector *xVec, psVector *yVec, bool clip) {
 
     graphdata->xmin = +FLT_MAX;
@@ -929,8 +954,11 @@
     psVectorStats (statsY, yVec, NULL, NULL, 0);
 
-    float xhi  = statsX->sampleMedian + 3 *statsX->sampleStdev;
-    float xlo = statsX->sampleMedian - 3 *statsX->sampleStdev;
-    float yhi = statsY->sampleMedian + 3 *statsY->sampleStdev;
-    float ylo = statsY->sampleMedian - 3 *statsY->sampleStdev;
+    float xhi = +FLT_MAX, xlo = -FLT_MAX, yhi = +FLT_MAX, ylo = -FLT_MAX;
+    if (clip) {
+        xhi  = statsX->sampleMedian + 3 *statsX->sampleStdev;
+        xlo = statsX->sampleMedian - 3 *statsX->sampleStdev;
+        yhi = statsY->sampleMedian + 3 *statsY->sampleStdev;
+        ylo = statsY->sampleMedian - 3 *statsY->sampleStdev;
+    }
 
     // abort if there is no good data
@@ -1220,5 +1248,5 @@
     float xmax = graphdata.xmax;
     float ymax = graphdata.ymax;
-    psastroVisualScaleGraphdata(&graphdata, xVec, yVec);
+    psastroVisualScaleGraphdata(&graphdata, xVec, yVec, true);
     graphdata.xmin = PS_MIN(xmin, graphdata.xmin);
     graphdata.ymin = PS_MIN(ymin, graphdata.ymin);
@@ -1260,4 +1288,6 @@
     return true;
 }
+
+// END OF PROGRAM
 #else
 
