Index: /branches/cnb_branch_20081011/psModules/src/astrom/pmAstrometryObjects.c
===================================================================
--- /branches/cnb_branch_20081011/psModules/src/astrom/pmAstrometryObjects.c	(revision 20442)
+++ /branches/cnb_branch_20081011/psModules/src/astrom/pmAstrometryObjects.c	(revision 20443)
@@ -8,6 +8,6 @@
 *  @author EAM, IfA
 *
-*  @version $Revision: 1.41.4.2 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2008-10-27 22:50:07 $
+*  @version $Revision: 1.41.4.3 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2008-10-28 23:20:29 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -871,5 +871,5 @@
     tweak->offset.y += yPeak;
 
-    pmAstromVisualPlotTweak (xHist, yHist, xHistNew, yHistNew, xBin, yBin);
+    pmAstromVisualPlotTweak (xHistNew, yHistNew, xBin, yBin);
 
     psFree (rot);
Index: /branches/cnb_branch_20081011/psModules/src/astrom/pmAstrometryVisual.c
===================================================================
--- /branches/cnb_branch_20081011/psModules/src/astrom/pmAstrometryVisual.c	(revision 20442)
+++ /branches/cnb_branch_20081011/psModules/src/astrom/pmAstrometryVisual.c	(revision 20443)
@@ -259,6 +259,12 @@
 
 
-/** Plot the refinements that pmAstromGridTweak makes to the offset between raw and ref stars */
-bool pmAstromVisualPlotTweak (psVector *xHist, psVector *yHist, psVector *xHistNew, psVector *yHistNew, int xBin, int yBin)
+/** Plot the refinements made within pmAstromGridTweak.
+ * After pmAstromGridMatch finds the best rotaion/scale/offset between raw and reference stars
+ * within a coarse grid of rotations/scales, pmAstromGridTweak computes a higher precision
+ * estimate of the offset. It computes the 2 point correlation function between raw and ref
+ * stars along horizontal and vertical cuts through the first-guess offset. It finds the peak
+ * of these two profiles and adjusts the offset accordingly. This procedure plots the profiles.
+ */
+bool pmAstromVisualPlotTweak (psVector *xHist, psVector *yHist, int xBin, int yBin)
 {
     //make sure we want to plot this
@@ -274,5 +280,4 @@
     psVector *xIndices = psVectorAlloc (xHist->n, PS_TYPE_F32);
     psVector *yIndices = psVectorAlloc (yHist->n, PS_TYPE_F32);
-
 
     //populate the Indices vectors
@@ -298,5 +303,5 @@
     KapaSendLabel (kapa, "Horizontal Profile",
                    KAPA_LABEL_XP);
-    graphdata.style = 2;
+    graphdata.style = 1;
     graphdata.ptype = 0;
     graphdata.size = 0.4;
@@ -307,15 +312,8 @@
     KapaPlotVector (kapa, xHist->n, xHist->data.F32, "y");
 
-    //overplot smoothed line
-    graphdata.style = 1;
-    graphdata.color = KapaColorByName ("red");
-    KapaPrepPlot (kapa, xHist->n, &graphdata);
-    KapaPlotVector (kapa, xHist->n, xIndices->data.F32, "x");
-    KapaPlotVector (kapa, xHist->n, xHistNew->data.F32, "y");
-
     //overplot the peak
     float x[2] = {xBin, xBin};
     float y[2] = {-500, 500};
-    graphdata.color = KapaColorByName ("black");
+    graphdata.color = KapaColorByName ("red");
     KapaPrepPlot (kapa, 2, &graphdata);
     KapaPlotVector (kapa, 2, x, "x");
@@ -328,9 +326,9 @@
     KapaSetFont(kapa, "helvetica", 14);
     KapaBox(kapa, &graphdata);
-    KapaSendLabel (kapa, "X offset Bin", KAPA_LABEL_XM);
+    KapaSendLabel (kapa, "Y offset Bin", KAPA_LABEL_XM);
     KapaSendLabel (kapa, "Number of Sources", KAPA_LABEL_YM);
     KapaSendLabel (kapa, "Vertical Profile",
                    KAPA_LABEL_XP);
-    graphdata.style = 2;
+    graphdata.style = 1;
     graphdata.ptype = 0;
     graphdata.size = 0.4;
@@ -341,14 +339,7 @@
     KapaPlotVector (kapa, yHist->n, yHist->data.F32, "y");
 
-    //overplot smoothed line
-    graphdata.style = 1;
-    graphdata.color = KapaColorByName ("red");
-    KapaPrepPlot (kapa, yHist->n, &graphdata);
-    KapaPlotVector (kapa, yHist->n, yIndices->data.F32, "x");
-    KapaPlotVector (kapa, yHist->n, yHistNew->data.F32, "y");
-
     //overplot the peak
     x[0] = x[1] = yBin;
-    graphdata.color = KapaColorByName ("black");
+    graphdata.color = KapaColorByName ("red");
     KapaPrepPlot (kapa, 2, &graphdata);
     KapaPlotVector (kapa, 2, x, "x");
@@ -356,4 +347,5 @@
 
     //plot title
+    graphdata.color = KapaColorByName("black");
     KapaSection section3 = {"s3", 0, 0, 1, 1};
     KapaSetSection( kapa, &section3);
@@ -366,8 +358,8 @@
     psFree(yIndices);
     return true;
-}
-
-
-/** psastroVisualScaleGraphdata
+} //end of pmAstromPlotTweak
+
+
+/** pmAstromScaleGraphdata
  * Scale the graphdata structure based on x and y coordinates. Use sigma clipping to
  * prevent outliers from making te plot region too big.
@@ -441,5 +433,4 @@
 
 
-
 # else
 
@@ -449,4 +440,5 @@
 bool pmAstromVisualClose() { return true; }
 bool pmAstromVisualPlotGridMatch (const psArray *raw, const psArray *ref, psImage *gridNP, double offsetX, double offsetY, double maxOffpix, double Scale, double Offset) { return true; }
+bool pmAstromVisualPlotTweak (psVector *xHist, psVector *yHist, int xBin, int yBin) {return true;}
 
 # endif
Index: /branches/cnb_branch_20081011/psModules/src/astrom/pmAstrometryVisual.h
===================================================================
--- /branches/cnb_branch_20081011/psModules/src/astrom/pmAstrometryVisual.h	(revision 20442)
+++ /branches/cnb_branch_20081011/psModules/src/astrom/pmAstrometryVisual.h	(revision 20443)
@@ -4,3 +4,3 @@
 bool pmAstromVisualClose();
 bool pmAstromVisualPlotGridMatch (const psArray *raw, const psArray *ref, psImage *gridNP, double offsetX, double offsetY, double maxOffpix, double Scale, double Offset);
-bool pmAstromVisualPlotTweak (psVector *xHist, psVector *yHist, psVector *xHistNew, psVector *yHistNew, int xBin, int yBin);
+bool pmAstromVisualPlotTweak (psVector *xHist, psVector *yHist, int xBin, int yBin);
Index: /branches/cnb_branch_20081011/psastro/src/psastro.h
===================================================================
--- /branches/cnb_branch_20081011/psastro/src/psastro.h	(revision 20442)
+++ /branches/cnb_branch_20081011/psastro/src/psastro.h	(revision 20443)
@@ -83,7 +83,9 @@
 bool psastroVisualPlotRefStars (psArray *refstars, psMetadata *recipe);
 bool psastroVisualPlotRemoveClumps (psArray *input, psImage *count, int scale, float limit);
+bool psastroVisualPlotFixChips (pmFPAfile *input, psVector *xOld, psVector *yOld);
 bool psastroVisualPlotOneChipFit (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe);
 bool psastroVisualPlotAstromGuessCheck (psVector *cornerPo, psVector *cornerQo, psVector *cornerPn, psVector *cornerQn, psVector *cornerPd, psVector *cornerQd);
 bool psastroVisualPlotMosaicOneChip (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe);
+bool psastroVisualPlotCommonScale (pmFPA *fpa, psVector *oldScale);
 bool psastroVisualPlotMosaicMatches (psArray *rawstars, psArray *refstars, psArray *match, int iteration, psMetadata *recipe);
 
Index: /branches/cnb_branch_20081011/psastro/src/psastroFixChips.c
===================================================================
--- /branches/cnb_branch_20081011/psastro/src/psastroFixChips.c	(revision 20442)
+++ /branches/cnb_branch_20081011/psastro/src/psastroFixChips.c	(revision 20443)
@@ -109,7 +109,7 @@
   }
   xObs->n = yObs->n = xRef->n = yRef->n = nPts;
-	
+
   psPlaneTransform *map = psPlaneTransformAlloc (1, 1);
-  
+
   psVector *mask = psVectorAlloc (nPts, PS_TYPE_U8);
   psVectorInit (mask, 0);
@@ -127,9 +127,7 @@
 
   // loop over all chips, select the outliers, and replace the measured astrometry with the model
-  // the measured transformation above must be applied to make the comparison, and also then applied to the 
+  // the measured transformation above must be applied to make the comparison, and also then applied to the
   // model transformation
 
-  psFree (xObs);
-  psFree (yObs);
   psFree (xRef);
   psFree (yRef);
@@ -159,5 +157,5 @@
     psPlaneTransformApply (&tmpCoord, refChip->toFPA, &refPixel);
     psPlaneTransformApply (&refCoord, map, &tmpCoord);
-    
+
     psPlane offPixel = {100.0, 0.0, 100.0, 0.0};
     psPlane obsOffPt, refOffPt;
@@ -169,5 +167,5 @@
     psPlaneTransformApply (&tmpCoord, refChip->toFPA, &offPixel);
     psPlaneTransformApply (&refOffPt, map, &tmpCoord);
-    
+
     double obsAngle = PM_DEG_RAD*atan2 (obsOffPt.y - obsCoord.y, obsOffPt.x - obsCoord.x);
     double refAngle = PM_DEG_RAD*atan2 (refOffPt.y - refCoord.y, refOffPt.x - refCoord.x);
@@ -183,5 +181,5 @@
 
     psLogMsg ("psastro", PS_LOG_INFO, "fixing chip %d, angle: %f, pixel: %f,%f\n",
-	      view->chip, obsAngle - refAngle, obsCoord.x - refCoord.x, obsCoord.y - refCoord.y);
+              view->chip, obsAngle - refAngle, obsCoord.x - refCoord.x, obsCoord.y - refCoord.y);
 
     psFree (obsChip->toFPA);
@@ -192,13 +190,13 @@
     psPlaneTransform *toFPA = psPlaneTransformAlloc(refChip->toFPA->x->nX, refChip->toFPA->x->nY);
     for (int i = 0; i <= refChip->toFPA->x->nX; i++) {
-	for (int j = 0; j <= refChip->toFPA->x->nY; j++) {
-	    double f1 = refChip->toFPA->x->coeffMask[i][j] ? 0.0 : map->x->coeff[1][0]*refChip->toFPA->x->coeff[i][j];
-	    double f2 = refChip->toFPA->y->coeffMask[i][j] ? 0.0 : map->x->coeff[0][1]*refChip->toFPA->y->coeff[i][j];
-	    toFPA->x->coeff[i][j] = f1 + f2;
-
-	    double g1 = refChip->toFPA->x->coeffMask[i][j] ? 0.0 : map->y->coeff[1][0]*refChip->toFPA->x->coeff[i][j];
-	    double g2 = refChip->toFPA->y->coeffMask[i][j] ? 0.0 : map->y->coeff[0][1]*refChip->toFPA->y->coeff[i][j];
-	    toFPA->y->coeff[i][j] = g1 + g2;
-	}
+        for (int j = 0; j <= refChip->toFPA->x->nY; j++) {
+            double f1 = refChip->toFPA->x->coeffMask[i][j] ? 0.0 : map->x->coeff[1][0]*refChip->toFPA->x->coeff[i][j];
+            double f2 = refChip->toFPA->y->coeffMask[i][j] ? 0.0 : map->x->coeff[0][1]*refChip->toFPA->y->coeff[i][j];
+            toFPA->x->coeff[i][j] = f1 + f2;
+
+            double g1 = refChip->toFPA->x->coeffMask[i][j] ? 0.0 : map->y->coeff[1][0]*refChip->toFPA->x->coeff[i][j];
+            double g2 = refChip->toFPA->y->coeffMask[i][j] ? 0.0 : map->y->coeff[0][1]*refChip->toFPA->y->coeff[i][j];
+            toFPA->y->coeff[i][j] = g1 + g2;
+        }
     }
     toFPA->x->coeff[0][0] += map->x->coeff[0][0];
@@ -209,5 +207,5 @@
     obsChip->fromFPA = psPlaneTransformInvert(NULL, obsChip->toFPA, *region, 50);
     psFree (region);
-    
+
     // XXX this stuff below should be applied to each readout...
     // XXX for now, just use first readout
@@ -226,9 +224,9 @@
     // the absolute minimum number of stars is 4 (for order = 1)
     if ((rawstars->n < 4) || (refstars->n < 4)) {
-	readout->data_exists = false;
-	psLogMsg ("psastro", 3, "insufficient rawstars (%ld) or refstars (%ld)", 
-		  rawstars->n, refstars->n);
-	continue;
-    } 
+        readout->data_exists = false;
+        psLogMsg ("psastro", 3, "insufficient rawstars (%ld) or refstars (%ld)",
+                  rawstars->n, refstars->n);
+        continue;
+    }
 
     psastroUpdateChipToFPA (input->fpa, obsChip, rawstars, refstars);
@@ -237,13 +235,13 @@
     psMetadata *updates = psMemIncrRefCounter (psMetadataLookupMetadata (&status, readout->analysis, "PSASTRO.HEADER"));
     if (!updates) {
-	updates = psMetadataAlloc ();
+        updates = psMetadataAlloc ();
     }
 
     // XXX update the header with info to reflect the failure
     if (!psastroOneChipFit (input->fpa, obsChip, refstars, rawstars, recipe, updates)) {
-	readout->data_exists = false;
-	psLogMsg ("psastro", 3, "failed to find a solution\n");
-	psFree (updates);
-	continue;
+        readout->data_exists = false;
+        psLogMsg ("psastro", 3, "failed to find a solution\n");
+        psFree (updates);
+        continue;
     }
 
@@ -253,4 +251,7 @@
   }
 
+  psastroVisualPlotFixChips (input, xObs, yObs);
+  psFree (xObs);
+  psFree (yObs);
   psFree (map);
   psFree (view);
Index: /branches/cnb_branch_20081011/psastro/src/psastroUtils.c
===================================================================
--- /branches/cnb_branch_20081011/psastro/src/psastroUtils.c	(revision 20442)
+++ /branches/cnb_branch_20081011/psastro/src/psastroUtils.c	(revision 20443)
@@ -20,60 +20,68 @@
 
     float pixelScaleUse = 1.0, pixelScale1 = 1.0,  pixelScale2 = 1.0,  pixelScale = 1.0;
+    psVector *oldScale = psVectorAllocEmpty (fpa->chips->n, PS_TYPE_F32);
 
     char *option = psMetadataLookupStr (NULL, recipe, "PSASTRO.COMMON.SCALE.OPTION");
     if (option == NULL) {
-	psError(PSASTRO_ERR_DATA, false, "no choice set for common scale option\n");
-	return false;
+        psError(PSASTRO_ERR_DATA, false, "no choice set for common scale option\n");
+        return false;
     }
 
     bool useExternal = true;
+    int nobj = 0;
 
     // find the min or max scale chip
     if (!strcasecmp (option, "MIN") || !strcasecmp (option, "MAX")) {
 
-	bool useMax = !strcasecmp (option, "MAX");
-	pixelScaleUse = (useMax) ? FLT_MIN : FLT_MAX;
-
-	for (int i = 0; i < fpa->chips->n; i++) {
-	    pmChip *chip = fpa->chips->data[i];
-	    if (!chip->process || !chip->file_exists) { continue; }
-	    if (!chip->toFPA) { continue; }
-
-	    pixelScale1 = hypot (chip->toFPA->x->coeff[1][0], chip->toFPA->x->coeff[0][1]);
-	    pixelScale2 = hypot (chip->toFPA->y->coeff[1][0], chip->toFPA->y->coeff[0][1]);
-	    pixelScale = 0.5*(pixelScale1 + pixelScale2);
-	    
-	    pixelScaleUse = (useMax) ? PS_MAX (pixelScale, pixelScaleUse) : PS_MIN (pixelScale, pixelScaleUse);
-	}
-	useExternal = false;
-    }
+        bool useMax = !strcasecmp (option, "MAX");
+        pixelScaleUse = (useMax) ? FLT_MIN : FLT_MAX;
+
+        for (int i = 0; i < fpa->chips->n; i++) {
+            pmChip *chip = fpa->chips->data[i];
+            if (!chip->process || !chip->file_exists) { continue; }
+            if (!chip->toFPA) { continue; }
+
+            pixelScale1 = hypot (chip->toFPA->x->coeff[1][0], chip->toFPA->x->coeff[0][1]);
+            pixelScale2 = hypot (chip->toFPA->y->coeff[1][0], chip->toFPA->y->coeff[0][1]);
+            pixelScale = 0.5*(pixelScale1 + pixelScale2);
+            oldScale->data.F32[nobj++] = pixelScale;
+            pixelScaleUse = (useMax) ? PS_MAX (pixelScale, pixelScaleUse) : PS_MIN (pixelScale, pixelScaleUse);
+        }
+        useExternal = false;
+        oldScale->n = nobj;
+    }
+
 
     // rescale each chip by the reference scale
     for (int i = 0; i < fpa->chips->n; i++) {
-	pmChip *chip = fpa->chips->data[i];
-	if (!chip->process || !chip->file_exists) { continue; }
-	if (!chip->toFPA) { continue; }
-
-	psPlaneTransform *toFPA = chip->toFPA;
-	psPlaneTransform *fromFPA = chip->fromFPA;
-	    
-	pixelScale1 = hypot (toFPA->x->coeff[1][0], toFPA->x->coeff[0][1]);
-	pixelScale2 = hypot (toFPA->y->coeff[1][0], toFPA->y->coeff[0][1]);
-
-	if (useExternal) {
-	    pixelScaleUse = getChipPixelScale (chip);
-	}
-
-	for (int i = 0; i <= toFPA->x->nX; i++) {
-	    for (int j = 0; j <= toFPA->x->nX; j++) {
-		toFPA->x->coeff[i][j] *= pixelScaleUse/pixelScale1;
-		toFPA->y->coeff[i][j] *= pixelScaleUse/pixelScale2;
-		fromFPA->x->coeff[i][j] *= pixelScale1/pixelScaleUse;
-		fromFPA->y->coeff[i][j] *= pixelScale2/pixelScaleUse;
-	    }
-	}
+        pmChip *chip = fpa->chips->data[i];
+        if (!chip->process || !chip->file_exists) { continue; }
+        if (!chip->toFPA) { continue; }
+
+        psPlaneTransform *toFPA = chip->toFPA;
+        psPlaneTransform *fromFPA = chip->fromFPA;
+
+        pixelScale1 = hypot (toFPA->x->coeff[1][0], toFPA->x->coeff[0][1]);
+        pixelScale2 = hypot (toFPA->y->coeff[1][0], toFPA->y->coeff[0][1]);
+
+        if (useExternal) {
+            pixelScaleUse = getChipPixelScale (chip);
+        }
+
+        for (int i = 0; i <= toFPA->x->nX; i++) {
+            for (int j = 0; j <= toFPA->x->nX; j++) {
+                toFPA->x->coeff[i][j] *= pixelScaleUse/pixelScale1;
+                toFPA->y->coeff[i][j] *= pixelScaleUse/pixelScale2;
+                fromFPA->x->coeff[i][j] *= pixelScale1/pixelScaleUse;
+                fromFPA->y->coeff[i][j] *= pixelScale2/pixelScaleUse;
+            }
+        }
 
     }
     psastroMosaicSetAstrom (fpa);
+    if (!useExternal) {
+        psastroVisualPlotCommonScale (fpa, oldScale);
+    }
+    psFree (oldScale);
     return true;
 }
Index: /branches/cnb_branch_20081011/psastro/src/psastroVisual.c
===================================================================
--- /branches/cnb_branch_20081011/psastro/src/psastroVisual.c	(revision 20442)
+++ /branches/cnb_branch_20081011/psastro/src/psastroVisual.c	(revision 20443)
@@ -2,4 +2,8 @@
 /***Diagnostic plots for psastro****/
 /***********************************/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 # include "psastroInternal.h"
 # include <string.h>
@@ -20,6 +24,8 @@
 static bool plotRemoveClumps     = false;
 static bool plotOneChipFit       = false;
+static bool plotFixChips         = true;
 static bool plotAstromGuessCheck = false;
 static bool plotMosaicMatches    = false;
+static bool plotCommonScale      = true;
 static bool plotMosaicOneChip    = false;
 
@@ -29,4 +35,5 @@
 
 // helper routine prototypes
+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);
@@ -538,4 +545,89 @@
 
 
+/** 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
+    )
+{
+    //make sure we want to plot this
+    if(!isVisual || !plotFixChips) return true;
+
+    if(!psastroVisualInitWindow(&kapa, "psastro:plots")) return false;
+
+    KapaSection section = {"s1", .05, .05, .9, .9};
+    Graphdata graphdata;
+    KapaInitGraph( &graphdata);
+    KapaClearPlots (kapa);
+    graphdata.ptype = 2;
+    graphdata.style = 2;
+
+    psVector *xNew = psVectorAllocEmpty (xOld->n, PS_TYPE_F32);
+    psVector *yNew = psVectorAllocEmpty (yOld->n, PS_TYPE_F32);
+
+    // copy of the code in psastroFixChips that generated xOld, yOld, but for xNew, yNew
+    pmFPAview *view = pmFPAviewAlloc (0);
+    int nPts = 0;
+    pmChip *obsChip = NULL;
+    while ((obsChip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
+        if (!obsChip->process || !obsChip->file_exists || !obsChip->data_exists) { continue; }
+
+        psRegion *region = pmChipPixels (obsChip);
+        psPlane ptCP, ptFP;
+
+        ptCP.x = region->x0; ptCP.y = region->y0;
+        psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP);
+        xNew->data.F32[nPts] = ptFP.x;
+        yNew->data.F32[nPts] = ptFP.y;
+        nPts ++;
+
+        ptCP.x = region->x0; ptCP.y = region->y1;
+        psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP);
+        xNew->data.F32[nPts] = ptFP.x;
+        yNew->data.F32[nPts] = ptFP.y;
+        nPts ++;
+
+        ptCP.x = region->x1; ptCP.y = region->y1;
+        psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP);
+        xNew->data.F32[nPts] = ptFP.x;
+        yNew->data.F32[nPts] = ptFP.y;
+        nPts ++;
+
+        ptCP.x = region->x1; ptCP.y = region->y0;
+        psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP);
+        xNew->data.F32[nPts] = ptFP.x;
+        yNew->data.F32[nPts] = ptFP.y;
+        nPts ++;
+
+        psFree (region);
+    }
+    xNew->n = yNew->n = nPts;
+
+    //set up graph
+    psastroVisualScaleGraphdata(&graphdata, xOld, yOld);
+    psastroVisualInitGraph(kapa, &section, &graphdata);
+    KapaSendLabel (kapa, "L (FP)", KAPA_LABEL_XM);
+    KapaSendLabel (kapa, "M (FP)", KAPA_LABEL_YM);
+    KapaSendLabel (kapa, "Chip corners before (black) and after (red) FixChips", KAPA_LABEL_XP);
+    KapaPrepPlot (kapa, xOld->n, &graphdata);
+    KapaPlotVector (kapa, xOld->n, xOld->data.F32, "x");
+    KapaPlotVector (kapa, xOld->n, yOld->data.F32, "y");
+
+    graphdata.ptype = 1;
+    graphdata.color = KapaColorByName("red");
+    KapaPrepPlot (kapa, xNew->n, &graphdata);
+    KapaPlotVector (kapa, xNew->n, xNew->data.F32, "x");
+    KapaPlotVector (kapa, xNew->n, yNew->data.F32, "y");
+
+    psastroVisualAskUser(&plotFixChips);
+    psFree(xNew);
+    psFree(yNew);
+    psFree(view);
+    return true;
+}
+
+
 /**
  *  Plots the fpa chip corners projected on to the tangential plane before and after
@@ -631,4 +723,52 @@
 }
 
+/** 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
+{
+    //make sure we want to plot this
+    if (!isVisual || !plotCommonScale) return false;
+
+    if (!psastroVisualInitWindow(&kapa, "psastro:plots")) return false;
+
+    KapaSection section = {"s1", .05, .05, .9, .9};
+    Graphdata graphdata;
+    psPlane ptCH, ptFP;
+    ptCH.x = 0;
+    ptCH.y = 0;
+    psVector *xVec = psVectorAllocEmpty (oldScale->n, PS_TYPE_F32);
+    psVector *yVec = psVectorAllocEmpty (oldScale->n, PS_TYPE_F32);
+    int nobj = 0;
+
+    //project each chip corner to the Focal Plane
+    for(int i = 0; i < fpa->chips->n; i++) {
+        pmChip *chip = fpa->chips->data[i];
+        if (!chip->process || !chip->file_exists) { continue; }
+        if (!chip->toFPA) { continue; }
+
+        psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
+        xVec->data.F32[nobj] = ptFP.x;
+        yVec->data.F32[nobj] = ptFP.y;
+        nobj++;
+    }
+
+    //set up plot window
+    KapaInitGraph (&graphdata);
+    KapaClearPlots (kapa);
+    KapaSetSection (kapa, &section);
+    psastroVisualInitGraph(kapa, &section, &graphdata);
+    psastroVisualTriplePlot (kapa, &graphdata, xVec, yVec, oldScale, false);
+    KapaSendLabel (kapa, "L (FP)", KAPA_LABEL_XM);
+    KapaSendLabel (kapa, "M (FP)", KAPA_LABEL_YM);
+    KapaSendLabel (kapa, "Old Pixel Scale of FPA Chips (Not to Scale)", KAPA_LABEL_XP);
+
+    psastroVisualAskUser (&plotCommonScale);
+    return true;
+}
+
 
 /**
@@ -663,25 +803,7 @@
     //make sure we want to plot this
     if (!isVisual || !plotMosaicMatches) return true;
-    char *title;
-    switch(iteration) {
-      case 0:
-        title = "Matches found during psastroMosaicSetMatch iteration 0";
-        break;
-      case 1 :
-        title = "Matches found during psastroMosaicSetMatch iteration 1";
-        break;
-      case 2:
-        title = "Matches found during psastroMosaicSetMatch iteration 2";
-        break;
-      case 3:
-        title = "Matches found during psastroMosaicSetMatch iteration 3";
-        break;
-      case 4:
-         title = "Matches found during psastroMosaicSetMatch iteration 4";
-         break;
-      default:
-        title = "Matches found during psastroMosaicSetMatch";
-        break;
-    }
+
+    char title[60];
+    sprintf(title, "Matches found during psastroMosaicSetMatch iteration %d", iteration);
 
     if (!psastroVisualResidPlot(rawstars, refstars, match, recipe, title))
@@ -698,4 +820,17 @@
 /*********************/
 
+/** 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)
+{
+    KapaSetSection (kapa, section);
+    KapaSetFont (kapa, "helvetica", 14);
+    KapaSetLimits (kapa, graphdata);
+    KapaBox (kapa, graphdata);
+    return true;
+}
 
 /** psastroVisualTriplePlot
@@ -1125,4 +1260,18 @@
     return true;
 }
+#else
+
+bool psastroSetVisual (bool mode) {return true};
+bool psastroVisualClose() {return true};
+bool psastroVisualPlotLuminosityFunction (psVector *lnMag, psVector *Mag, pmLumFunc *lumFunc, pmLumFunc *rawFunc) {return true};
+bool psastroVisualPlotRawStars (psArray *rawstars, pmFPA *fpa, pmChip *chip, psMetadata *recipe) {return true};
+bool psastroVisualPlotRefStars (psArray *refstars, psMetadata *recipe) {return true};
+bool psastroVisualPlotRemoveClumps (psArray *input, psImage *count, int scale, float limit) {return true};
+bool psastroVisualPlotFixChips (pmFPAfile *input, psVector *xOld, psVector *yOld) {return true};
+bool psastroVisualPlotOneChipFit (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe) {return true};
+bool psastroVisualPlotAstromGuessCheck (psVector *cornerPo, psVector *cornerQo, psVector *cornerPn, psVector *cornerQn, psVector *cornerPd, psVector *cornerQd) {return true};
+bool psastroVisualPlotMosaicOneChip (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe) {return true};
+bool psastroVisualPlotCommonScale (pmFPA *fpa, psVector *oldScale) {return true};
+bool psastroVisualPlotMosaicMatches (psArray *rawstars, psArray *refstars, psArray *match, int iteration, psMetadata *recipe) {return true};
 
 # endif
