Index: /trunk/ppImage/src/ppImageArguments.c
===================================================================
--- /trunk/ppImage/src/ppImageArguments.c	(revision 23241)
+++ /trunk/ppImage/src/ppImageArguments.c	(revision 23242)
@@ -81,5 +81,5 @@
     if ((argnum = psArgumentGet(argc, argv, "-visual"))) {
         psArgumentRemove(argnum, &argc, argv);
-	psphotSetVisual (true);
+        pmVisualSetVisual(true);
     }
 
@@ -87,11 +87,11 @@
     if ((argnum = psArgumentGet(argc, argv, "-threads"))) {
         psArgumentRemove(argnum, &argc, argv);
-	int nThreads = atoi(argv[argnum]);
+        int nThreads = atoi(argv[argnum]);
         psMetadataAddS32(config->arguments, PS_LIST_TAIL, "NTHREADS", 0, "number of warp threads", nThreads);
         psArgumentRemove(argnum, &argc, argv);
 
-	// create the thread pool with number of desired threads, supplying our thread launcher function
-	// XXX need to determine the number of threads from the config data
-	psThreadPoolInit (nThreads);
+        // create the thread pool with number of desired threads, supplying our thread launcher function
+        // XXX need to determine the number of threads from the config data
+        psThreadPoolInit (nThreads);
     }
 
Index: /trunk/ppStack/src/ppStack.c
===================================================================
--- /trunk/ppStack/src/ppStack.c	(revision 23241)
+++ /trunk/ppStack/src/ppStack.c	(revision 23242)
@@ -76,5 +76,5 @@
     pmConfigDone();
     psLibFinalize();
-
+    pmVisualClose();
     exit(exitValue);
 }
Index: /trunk/ppStack/src/ppStackArguments.c
===================================================================
--- /trunk/ppStack/src/ppStackArguments.c	(revision 23241)
+++ /trunk/ppStack/src/ppStackArguments.c	(revision 23242)
@@ -185,5 +185,5 @@
                       "Delete temporary files on completion?", false);
     psMetadataAddS32(arguments, PS_LIST_TAIL, "-threads", 0, "Number of threads to use", 0);
-    psMetadataAddBool(arguments, PS_LIST_TAIL, "-psphot-visual", 0, "psphot visualisation", 0);
+    psMetadataAddBool(arguments, PS_LIST_TAIL, "-visual", 0, "visualisation", false);
 
     if (argc == 1 || !psArgumentParse(arguments, &argc, argv) || argc != 3) {
@@ -262,4 +262,8 @@
     valueArgRecipeStr(arguments, recipe, "-psf-model", "PSF.MODEL", recipe);
 
+    if (psMetadataLookupBool(NULL, arguments, "-visual")) {
+        pmVisualSetVisual(true);
+    }
+
     if (psMetadataLookupBool(NULL, arguments, "-photometry") ||
         psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) {
Index: /trunk/ppStack/src/ppStackLoop.c
===================================================================
--- /trunk/ppStack/src/ppStackLoop.c	(revision 23241)
+++ /trunk/ppStack/src/ppStackLoop.c	(revision 23242)
@@ -517,4 +517,5 @@
             psStringAppend(&name, "covariance_%d.fits", i);
             writeImage(name, hdu->header, readout->covariance->image, config);
+            pmStackVisualPlotTestImage(readout->covariance->image, name);
             psFree(name);
         }
@@ -815,4 +816,5 @@
 #ifdef TESTING
     writeImage("combined_initial.fits", NULL, outRO->image, config);
+    pmStackVisualPlotTestImage(outRO->image, "combined_initial.fits");
 #endif
 
@@ -898,4 +900,5 @@
                 psString name = NULL;           // Name of image
                 psStringAppend(&name, "inspect_%03d.fits", i);
+                pmStackVisualPlotTestImage(mask, name);
                 psFits *fits = psFitsOpen(name, "w");
                 psFree(name);
@@ -915,4 +918,5 @@
                 psString name = NULL;           // Name of image
                 psStringAppend(&name, "reject_%03d.fits", i);
+                pmStackVisualPlotTestImage(mask, name);
                 psFits *fits = psFitsOpen(name, "w");
                 psFree(name);
@@ -1048,4 +1052,5 @@
 
 #ifdef TESTING
+    pmStackVisualPlotTestImage(outRO->image, "combined_initial.fits");
     writeImage("combined_final.fits", NULL, outRO->image, config);
 #endif
Index: /trunk/ppStack/src/ppStackMatch.c
===================================================================
--- /trunk/ppStack/src/ppStackMatch.c	(revision 23241)
+++ /trunk/ppStack/src/ppStackMatch.c	(revision 23242)
@@ -358,4 +358,5 @@
                 psString name = NULL;
                 psStringAppend(&name, "fake_%03d.fits", numInput);
+                pmStackVisualPlotTestImage(fake->image, name);
                 psFits *fits = psFitsOpen(name, "w");
                 psFree(name);
@@ -367,4 +368,5 @@
                 psString name = NULL;
                 psStringAppend(&name, "real_%03d.fits", numInput);
+                pmStackVisualPlotTestImage(readout->image, name);
                 psFits *fits = psFitsOpen(name, "w");
                 psFree(name);
@@ -397,4 +399,5 @@
                 psString name = NULL;
                 psStringAppend(&name, "conv_%03d.fits", numInput);
+                pmStackVisualPlotTestImage(output->image, name);
                 psFits *fits = psFitsOpen(name, "w");
                 psFree(name);
@@ -406,4 +409,5 @@
                 psString name = NULL;
                 psStringAppend(&name, "diff_%03d.fits", numInput);
+                pmStackVisualPlotTestImage(fake->image, name);
                 psFits *fits = psFitsOpen(name, "w");
                 psFree(name);
@@ -633,4 +637,5 @@
         psString name = NULL;
         psStringAppend(&name, "convolved_%03d.fits", numInput);
+        pmStackVisualPlotTestImage(output->image, name);
         psFits *fits = psFitsOpen(name, "w");
         psFree(name);
Index: /trunk/ppStack/src/ppStackPhotometry.c
===================================================================
--- /trunk/ppStack/src/ppStackPhotometry.c	(revision 23241)
+++ /trunk/ppStack/src/ppStackPhotometry.c	(revision 23242)
@@ -118,6 +118,6 @@
     pmFPACopy(photFile->fpa, readout->parent->parent->parent);
 
-    if (psMetadataLookupBool(NULL, config->arguments, "-psphot-visual")) {
-        psphotSetVisual(true);
+    if (psMetadataLookupBool(NULL, config->arguments, "-visual")) {
+        pmVisualSetVisual(true);
     }
 
Index: /trunk/ppStack/src/ppStackSources.c
===================================================================
--- /trunk/ppStack/src/ppStackSources.c	(revision 23241)
+++ /trunk/ppStack/src/ppStackSources.c	(revision 23242)
@@ -121,4 +121,5 @@
         psString name = NULL;
         psStringAppend(&name, "start_%03d.fits", i);
+        pmStackVisualPlotTestImage(fake->image, name);
         psFits *fits = psFitsOpen(name, "w");
         psFree(name);
Index: /trunk/ppSub/src/ppSub.c
===================================================================
--- /trunk/ppSub/src/ppSub.c	(revision 23241)
+++ /trunk/ppSub/src/ppSub.c	(revision 23242)
@@ -77,5 +77,5 @@
     psTimerStop();
 
-    pmSubtractionVisualClose(); //close plot windows, if -visual is set
+    pmVisualClose(); //close plot windows, if -visual is set
     psFree(config);
     pmModelClassCleanup();
Index: /trunk/ppSub/src/ppSubArguments.c
===================================================================
--- /trunk/ppSub/src/ppSubArguments.c	(revision 23241)
+++ /trunk/ppSub/src/ppSubArguments.c	(revision 23242)
@@ -191,5 +191,5 @@
 bool ppSubArgumentsSetup(int argc, char *argv[], pmConfig *config)
 {
-    int argnum;                         // Argument Number
+    //    int argnum;                         // Argument Number
     assert(config);
 
@@ -200,8 +200,4 @@
     }
 
-    if ((argnum = psArgumentGet(argc, argv, "-psphot-visual"))) {
-        psArgumentRemove(argnum, &argc, argv);
-        psphotSetVisual(true);
-    }
 
     psMetadata *arguments = config->arguments; // Command-line arguments
@@ -370,5 +366,5 @@
 
     if (psMetadataLookupBool(NULL, arguments, "-visual")) {
-        pmSubtractionSetVisual(true);
+        pmVisualSetVisual(true);
     }
 
Index: /trunk/psModules/src/astrom/pmAstrometryVisual.c
===================================================================
--- /trunk/psModules/src/astrom/pmAstrometryVisual.c	(revision 23241)
+++ /trunk/psModules/src/astrom/pmAstrometryVisual.c	(revision 23242)
@@ -23,5 +23,4 @@
 
 //variables to determine when things are plotted
-static bool isVisual             = false;
 static bool plotGridMatch        = true;
 static bool plotTweak            = true;
@@ -48,10 +47,4 @@
 /* Initialization Routines  */
 
-bool pmAstromSetVisual (bool mode) {
-    isVisual = mode;
-    return true;
-}
-
-
 bool pmAstromVisualClose()
 {
@@ -68,9 +61,8 @@
 {
     // make sure we want to plot this
-    if (!plotRawStars || !isVisual) return true;
+    if (!plotRawStars || !pmVisualIsVisual()) return true;
 
     //set up plot region
     if (!pmVisualInitWindow (&kapa, "psastro:plots")){
-        isVisual = false;
         return false;
     }
@@ -222,5 +214,5 @@
 
     // pause and wait for user input:
-    pmVisualAskUser(&plotRawStars, &isVisual);
+    pmVisualAskUser(&plotRawStars);
 
     psFree (xVec);
@@ -234,9 +226,8 @@
 {
     //make sure we want to plot this
-    if (!isVisual || !plotRefStars) return true;
+    if (!pmVisualIsVisual() || !plotRefStars) return true;
 
     //set up plotting variables
     if (!pmVisualInitWindow (&kapa, "psastro:plots")) {
-        isVisual = false;
         return false;
     }
@@ -284,5 +275,5 @@
 
     // pause and wait for user input:
-    pmVisualAskUser(&plotRefStars, &isVisual);
+    pmVisualAskUser(&plotRefStars);
 
     psFree (xVec);
@@ -301,9 +292,8 @@
 
     // make sure we want to plot this
-    if ( !isVisual || !plotLumFunc ) return true;
+    if ( !pmVisualIsVisual() || !plotLumFunc ) return true;
 
     //set up plotting variables
     if ( !pmVisualInitWindow (&kapa, "psastro:plots")){
-        isVisual = false;
         return false;
     }
@@ -377,5 +367,5 @@
 
         // pause and wait for user input:
-        pmVisualAskUser (&plotLumFunc, &isVisual);
+        pmVisualAskUser (&plotLumFunc);
     }
     return true;
@@ -391,9 +381,8 @@
 
     //make sure we want to plot this
-    if (!isVisual || !plotRemoveClumps) return true;
+    if (!pmVisualIsVisual() || !plotRemoveClumps) return true;
 
     //set up plot variables
     if ( !pmVisualInitWindow (&kapa, "psastro:plots")) {
-        isVisual = false;
         return false;
     }
@@ -480,5 +469,5 @@
 
     //ask for user input and finish
-    pmVisualAskUser (&plotRemoveClumps, &isVisual);
+    pmVisualAskUser (&plotRemoveClumps);
     psFree (xVec);
     psFree (yVec);
@@ -496,9 +485,8 @@
 
     //make sure we want to plot this
-    if (!isVisual || !plotOneChipFit)
+    if (!pmVisualIsVisual() || !plotOneChipFit)
         return true;
 
     if(!pmVisualInitWindow(&kapa, "psastro:plots") || !pmVisualInitWindow(&kapa2, "psastro:plots")) {
-        isVisual = false;
         return false;
     }
@@ -511,5 +499,5 @@
 
     //ask for user input and finish
-    pmVisualAskUser(&plotOneChipFit, &isVisual);
+    pmVisualAskUser(&plotOneChipFit);
     return true;
 }
@@ -522,8 +510,7 @@
 {
     //make sure we want to plot this
-    if(!isVisual || !plotFixChips) return true;
+    if(!pmVisualIsVisual() || !plotFixChips) return true;
 
     if(!pmVisualInitWindow(&kapa, "psastro:plots")) {
-        isVisual = false;
         return false;
     }
@@ -588,5 +575,5 @@
     KapaPlotVector (kapa, xNew->n, yNew->data.F32, "y");
 
-    pmVisualAskUser(&plotFixChips, &isVisual);
+    pmVisualAskUser(&plotFixChips);
     psFree(xNew);
     psFree(yNew);
@@ -606,9 +593,8 @@
 
     //make sure we want to plot this
-    if (!isVisual || !plotAstromGuessCheck) return true;
+    if (!pmVisualIsVisual() || !plotAstromGuessCheck) return true;
 
     //set up graph window
     if ( !pmVisualInitWindow (&kapa, "psastro:plots")) {
-        isVisual = false;
         return false;
     }
@@ -686,5 +672,5 @@
     psFree(xResid);
     psFree(yResid);
-    pmVisualAskUser (&plotAstromGuessCheck, &isVisual);
+    pmVisualAskUser (&plotAstromGuessCheck);
     return true;
 }
@@ -696,8 +682,7 @@
 {
     //make sure we want to plot this
-    if (!isVisual || !plotCommonScale) return true;
+    if (!pmVisualIsVisual() || !plotCommonScale) return true;
 
     if (!pmVisualInitWindow(&kapa, "psastro:plots")){
-        isVisual = false;
         return false;
     }
@@ -736,5 +721,5 @@
     KapaSendLabel (kapa, "Old Pixel Scale of FPA Chips (Not to Scale)", KAPA_LABEL_XP);
 
-    pmVisualAskUser (&plotCommonScale, &isVisual);
+    pmVisualAskUser (&plotCommonScale);
 
     psFree(xVec);
@@ -750,8 +735,7 @@
 
     //make sure we want to plot this
-    if (!isVisual || !plotMosaicOneChip) return true;
+    if (!pmVisualIsVisual() || !plotMosaicOneChip) return true;
 
     if(!pmVisualInitWindow(&kapa, "psastro:plots") || !pmVisualInitWindow(&kapa2, "psastro:plots")) {
-        isVisual = false;
         return false;
     }
@@ -759,10 +743,10 @@
     //plot the residuals
     if (!residPlot(rawstars, refstars, match, recipe, "Single Chip Fit Residuals - Mosaic Mode")) {
-        isVisual = false;
+        pmVisualSetVisual(false);
         return false;
     }
 
     //ask for user input and finish
-    pmVisualAskUser(&plotMosaicOneChip, &isVisual);
+    pmVisualAskUser(&plotMosaicOneChip);
 
     return true;
@@ -775,5 +759,5 @@
 {
     //make sure we want to plot this
-    if (!isVisual || !plotMosaicMatches) return true;
+    if (!pmVisualIsVisual() || !plotMosaicMatches) return true;
 
     char title[60];
@@ -782,15 +766,14 @@
 
     if(!pmVisualInitWindow(&kapa, "psastro:plots") || !pmVisualInitWindow(&kapa2, "psastro:plots")) {
-        isVisual = false;
         return false;
     }
 
     if (!residPlot(rawstars, refstars, match, recipe, title)){
-        isVisual = false;
+        pmVisualSetVisual(false);
         return false;
     }
 
     //ask for user input
-    pmVisualAskUser (&plotMosaicMatches, &isVisual);
+    pmVisualAskUser (&plotMosaicMatches);
     return true;
 }
@@ -807,7 +790,6 @@
 {
     //make sure we want to plot this
-    if (!isVisual || !plotGridMatch) return true;
+    if (!pmVisualIsVisual() || !plotGridMatch) return true;
     if (!pmVisualInitWindow(&kapa, "psastro:plots")){
-        isVisual = false;
         return false;
     }
@@ -952,5 +934,5 @@
     KapaPlotVector (kapa, 2, yslice, "y");
 
-    pmVisualAskUser(&plotGridMatch, &isVisual);
+    pmVisualAskUser(&plotGridMatch);
     psFree(dXplot);
     psFree(dYplot);
@@ -966,7 +948,6 @@
 {
     //make sure we want to plot this
-    if (!isVisual || !plotTweak) return true;
+    if (!pmVisualIsVisual() || !plotTweak) return true;
     if (!pmVisualInitWindow(&kapa, "psastro:plots")) {
-        isVisual = false;
         return false;
     }
@@ -1051,5 +1032,5 @@
                    KAPA_LABEL_XP);
 
-    pmVisualAskUser(&plotTweak, &isVisual);
+    pmVisualAskUser(&plotTweak);
 
     psFree(xIndices);
@@ -1341,5 +1322,4 @@
 # else
 
-bool pmAstromSetVisual(bool mode) { return true; }
 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; }
Index: /trunk/psModules/src/astrom/pmAstrometryVisual.h
===================================================================
--- /trunk/psModules/src/astrom/pmAstrometryVisual.h	(revision 23241)
+++ /trunk/psModules/src/astrom/pmAstrometryVisual.h	(revision 23242)
@@ -22,10 +22,4 @@
     int sPeak;                          ///< sum of stars to peak bin
 } pmLumFunc;
-
-
-/** Enable or disable visual plotting for psastro routines
- * @param mode true/false to enable/disable plotting
- * @return true for success */
-bool pmAstromSetVisual(bool mode);
 
 
Index: /trunk/psModules/src/extras/pmVisual.c
===================================================================
--- /trunk/psModules/src/extras/pmVisual.c	(revision 23241)
+++ /trunk/psModules/src/extras/pmVisual.c	(revision 23242)
@@ -18,5 +18,8 @@
 #include "pmHDU.h"
 #include "pmFPA.h"
+#include "pmFPAfile.h"
 #include "pmAstrometryObjects.h"
+#include "pmSubtractionStamps.h"
+#include "pmTrend2D.h"
 #include "pmFPAExtent.h"
 
@@ -28,4 +31,31 @@
 # define KAPAY 700
 
+#include "pmAstrometryVisual.h"
+#include "pmSubtractionVisual.h"
+#include "pmStackVisual.h"
+#include "pmSourceVisual.h"
+
+//#define TESTING
+
+static bool isVisual = false;
+
+
+bool pmVisualSetVisual(bool value) {
+    isVisual = value;
+    return true;
+}
+
+
+bool pmVisualIsVisual(void) {return isVisual;}
+
+bool pmVisualClose(void) {
+    pmAstromVisualClose();
+    pmSubtractionVisualClose();
+    pmStackVisualClose();
+    pmSourceVisualClose();
+    //XXX handle psphot
+    //    psphotVisualClose();
+    return true;
+}
 
 bool pmVisualInitWindow (int *kapid, char *name) {
@@ -34,4 +64,5 @@
         if (*kapid == -1) {
             fprintf (stderr, "Failure to open kapa.\n");
+            isVisual = false;
             return false;
         }
@@ -52,5 +83,5 @@
 
 
-bool pmVisualAskUser(bool *plotFlag, bool *packageFlag)
+bool pmVisualAskUser(bool *plotFlag)
 {
     char key[10];
@@ -63,5 +94,5 @@
     }
     if (key[0] == 'a') {
-        *packageFlag = false;
+        isVisual = false;
     }
     return true;
@@ -182,10 +213,14 @@
 
 bool pmVisualScaleImage(int kapaFD, psImage *inImage, const char *name, int channel, bool clip) {
-
     KiiImage image;
     KapaImageData data;
     Coords coords;
 
-    //make sure we have a compatible image type
+    //make sure we have a compatible image
+    if (inImage == NULL) {
+        fprintf(stderr, "Image is NULL, and cannot be displayed\n");
+        return false;
+    }
+
     if(inImage->type.type != PS_TYPE_F32) {
         fprintf(stderr, "Cannot display this image (imcompatible data type)\n");
@@ -194,4 +229,5 @@
 
     strcpy (coords.ctype, "RA---TAN");
+
 
     double min, max, stdev, mean;
@@ -304,9 +340,11 @@
 
 #else
-
+bool pmVisualSetVisual(bool value) {return true;}
+bool pmVisualIsVisual(void) {return false;}
+bool pmVisualClose(void) {return true;}
 bool pmVisualInitWindow(int *kapid, char *name){return true;}
 bool pmVisualInitGraph (int kapa, void *section, void *graphdata){return true;}
 
-bool pmVisualAskUser(bool *plotFlag, bool *packageFlag){return true;}
+bool pmVisualAskUser(bool *plotFlag){return true;}
 bool pmVisualImStats(psImage *image, double *mean,
                      double *stdev, double *min, double *max){return true;}
Index: /trunk/psModules/src/extras/pmVisual.h
===================================================================
--- /trunk/psModules/src/extras/pmVisual.h	(revision 23241)
+++ /trunk/psModules/src/extras/pmVisual.h	(revision 23242)
@@ -10,4 +10,22 @@
 
 #if (HAVE_KAPA)
+
+
+/** Globally enable or disable plotting
+ * @param value - true to enable plotting
+ * @return true
+ */
+bool pmVisualSetVisual(bool value);
+
+
+/** Check whether plotting is enabled
+ * @retrun true if plots should be generated
+ */
+bool pmVisualIsVisual(void);
+
+
+/** Destroy plotting windows at the end of a run
+ * @return true for success */
+bool pmVisualClose(void);
 
 
@@ -32,8 +50,6 @@
  * At the user's request, this will disable diagnostic plotting.
  * @param plotFlag, set to false if this plot should be disabled in the future
- * @param packageFlag, set to false if all plots from this package (e.g. psastro, pmSubtraction)
- *                      should be disabled.
  */
-bool pmVisualAskUser(bool *plotFlag, bool *packageFlag);
+bool pmVisualAskUser(bool *plotFlag);
 
 
@@ -115,7 +131,10 @@
 
 // kapa-specific data types are changed to void
+bool pmVisualSetVisual(bool value);
+bool pmVisualIsVisual(void);
+bool pmVisualClose(void);
 bool pmVisualInitWindow (int *kapid, char *name);
 bool pmVisualInitGraph (int kapa, void *section, void *graphdata);
-bool pmVisualAskUser(bool *plotFlag, bool *packageFlag);
+bool pmVisualAskUser(bool *plotFlag);
 bool pmVisualScaleImage(int kapaFD, psImage *inImage,
                         const char *name, int channel, bool clip);
Index: /trunk/psModules/src/imcombine/Makefile.am
===================================================================
--- /trunk/psModules/src/imcombine/Makefile.am	(revision 23241)
+++ /trunk/psModules/src/imcombine/Makefile.am	(revision 23242)
@@ -19,5 +19,6 @@
 	pmSubtractionThreads.c	\
 	pmPSFEnvelope.c         \
-	pmSubtractionVisual.c
+	pmSubtractionVisual.c   \
+	pmStackVisual.c
 
 pkginclude_HEADERS = \
@@ -37,5 +38,6 @@
 	pmSubtractionThreads.h	\
 	pmPSFEnvelope.h         \
-	pmSubtractionVisual.h
+	pmSubtractionVisual.h   \
+	pmStackVisual.h
 
 CLEANFILES = *~
Index: /trunk/psModules/src/imcombine/pmPSFEnvelope.c
===================================================================
--- /trunk/psModules/src/imcombine/pmPSFEnvelope.c	(revision 23241)
+++ /trunk/psModules/src/imcombine/pmPSFEnvelope.c	(revision 23242)
@@ -30,5 +30,5 @@
 
 #include "pmPSFEnvelope.h"
-
+#include "pmStackVisual.h"
 
 
@@ -165,4 +165,5 @@
             psStringAppend(&name, "psf_field_%03d.fits", i);
             psFits *fits = psFitsOpen(name, "w");
+            pmStackVisualPlotTestImage(fakeRO->image, name);
             psFitsWriteImage(fits, NULL, fakeRO->image, 0, NULL);
             psFitsClose(fits);
@@ -182,4 +183,5 @@
         // Write out the envelope
         psFits *fits = psFitsOpen("psf_field_envelope.fits", "w");
+        pmStackVisualPlotTestImage(envelope, "psf_field_envelope.fits");
         psFitsWriteImage(fits, NULL, envelope, 0, NULL);
         psFitsClose(fits);
@@ -234,4 +236,5 @@
         // Write out the envelope
         psFits *fits = psFitsOpen("psf_field_full.fits", "w");
+        pmStackVisualPlotTestImage(readout->image, "psf_field_full.fits");
         psFitsWriteImage(fits, NULL, readout->image, 0, NULL);
         psFitsClose(fits);
@@ -315,4 +318,5 @@
         {
             psFits *fits = psFitsOpen("psf_field_model.fits", "w");
+            pmStackVisualPlotTestImage(generated->image, "psf_field_model.fits");
             psFitsWriteImage(fits, NULL, generated->image, 0, NULL);
             psFitsClose(fits);
@@ -321,4 +325,5 @@
         {
             psFits *fits = psFitsOpen("psf_field_resid.fits", "w");
+            pmStackVisualPlotTestImage(generated->image, "psf_field_resid.fits");
             psFitsWriteImage(fits, NULL, generated->image, 0, NULL);
             psFitsClose(fits);
Index: /trunk/psModules/src/imcombine/pmStack.c
===================================================================
--- /trunk/psModules/src/imcombine/pmStack.c	(revision 23241)
+++ /trunk/psModules/src/imcombine/pmStack.c	(revision 23242)
@@ -8,6 +8,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-13 23:52:14 $
+ *  @version $Revision: 1.48.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-19 17:59:50 $
  *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
  *
Index: /trunk/psModules/src/imcombine/pmStackVisual.c
===================================================================
--- /trunk/psModules/src/imcombine/pmStackVisual.c	(revision 23242)
+++ /trunk/psModules/src/imcombine/pmStackVisual.c	(revision 23242)
@@ -0,0 +1,60 @@
+/** Diagnostic plots for pmStack
+ * @author Chris Beaumont, IfA
+ */
+
+/* Include Files   */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <strings.h>
+#include <string.h>
+#include <math.h>
+#include <assert.h>
+#include <pslib.h>
+
+#include "pmKapaPlots.h"
+#include "pmVisual.h"
+
+#include "pmHDU.h"
+#include "pmFPA.h"
+#include "pmAstrometryObjects.h"
+
+# if (HAVE_KAPA)
+# include <kapa.h>
+
+//variables to determine when things are plotted
+static bool plotTestImage        = true;
+
+// variables to store plotting window indices
+static int kapa  = -1;
+static int kapa2 = -1;
+
+/** destroy windows at the end of a run*/
+bool pmStackVisualClose()
+{
+    if(kapa != -1)
+        KiiClose(kapa);
+    if(kapa2 != -1)
+        KiiClose(kapa2);
+    return true;
+}
+
+/** Display a test image
+ * @param image to plot
+ * @param name for plot. No spaces allowed.
+ */
+bool pmStackVisualPlotTestImage(psImage *image, char *name) {
+    if (!pmVisualIsVisual() || !plotTestImage) return true;
+    if (!pmVisualInitWindow(&kapa, "pmStack:Images")) return false;
+
+    if(!pmVisualScaleImage(kapa, image, (const char*)name, 0, true)) return false;
+    pmVisualAskUser(&plotTestImage);
+    return true;
+}
+
+#else
+bool pmStackVisualClose() {return true;}
+bool pmStackVisualPlotTestImage(psImage *image, char *name) {return true;}
+#endif
Index: /trunk/psModules/src/imcombine/pmStackVisual.h
===================================================================
--- /trunk/psModules/src/imcombine/pmStackVisual.h	(revision 23242)
+++ /trunk/psModules/src/imcombine/pmStackVisual.h	(revision 23242)
@@ -0,0 +1,7 @@
+#ifndef PM_STACK_VISUAL_H
+#define PM_STACK_VISUAL_H
+
+bool pmStackVisualClose(void);
+bool pmStackVisualPlotTestImage(psImage *image, char *name);
+
+#endif
Index: /trunk/psModules/src/imcombine/pmSubtractionIO.c
===================================================================
--- /trunk/psModules/src/imcombine/pmSubtractionIO.c	(revision 23241)
+++ /trunk/psModules/src/imcombine/pmSubtractionIO.c	(revision 23242)
@@ -16,4 +16,5 @@
 
 #include "pmSubtractionIO.h"
+#include "pmStackVisual.h"
 
 #define ARRAY_BUFFER 16                 // Number to add to array at a time
@@ -144,6 +145,6 @@
     // CVS tags, used to identify the version of this file (in case incompatibilities are introduced)
     psString cvsFile = psStringCopy("$RCSfile: pmSubtractionIO.c,v $");
-    psString cvsRev  = psStringCopy("$Revision: 1.9 $");
-    psString cvsDate = psStringCopy("$Date: 2008-10-24 21:21:06 $");
+    psString cvsRev  = psStringCopy("$Revision: 1.9.18.1 $");
+    psString cvsDate = psStringCopy("$Date: 2009-02-19 17:59:50 $");
     psStringSubstitute(&cvsFile, NULL, "RCSfile: ");
     psStringSubstitute(&cvsRev,  NULL, "Revision: ");
@@ -167,4 +168,6 @@
 
     psImage *image = psMetadataLookupPtr(NULL, ro->analysis, PM_SUBTRACTION_ANALYSIS_KERNEL_IMAGE); // Image
+    pmStackVisualPlotTestImage(image, "Subtraction_kernels.fits");
+
     if (image && !psFitsWriteImage(fits, header, image, 0, EXTNAME_IMAGE)) {
         psError(PS_ERR_IO, false, "Unable to write subtraction kernel image.");
Index: /trunk/psModules/src/imcombine/pmSubtractionVisual.c
===================================================================
--- /trunk/psModules/src/imcombine/pmSubtractionVisual.c	(revision 23241)
+++ /trunk/psModules/src/imcombine/pmSubtractionVisual.c	(revision 23242)
@@ -28,5 +28,4 @@
 
 //variables to determine when things are plotted
-static bool isVisual             = false;
 static bool plotConvKernels      = true;
 static bool plotStamps           = true;
@@ -42,9 +41,4 @@
 // Initialization Routines
 
-/** start or stop plotting */
-bool pmSubtractionSetVisual (bool mode) {
-    isVisual = mode;
-    return true;
-}
 
 
@@ -65,11 +59,10 @@
  *    @return true for success */
 bool pmSubtractionVisualPlotConvKernels(psImage *convKernels) {
-    if (!isVisual || !plotConvKernels) return true;
+    if (!pmVisualIsVisual() || !plotConvKernels) return true;
     if (!pmVisualInitWindow(&kapa, "ppSub:Images")) {
-        isVisual = false;
         return false;
     }
     pmVisualScaleImage(kapa, convKernels, "Convolution_Kernels", 0, true);
-    pmVisualAskUser(&plotConvKernels, &isVisual);
+    pmVisualAskUser(&plotConvKernels);
     return true;
 }
@@ -80,11 +73,9 @@
     @return true for success */
 bool pmSubtractionVisualPlotStamps(pmSubtractionStampList *stamps, pmReadout *ro) {
-    if (!isVisual || !plotStamps) return true;
+    if (!pmVisualIsVisual() || !plotStamps) return true;
     if (!pmVisualInitWindow (&kapa, "ppSub:Images")) {
-        isVisual = false;
         return false;
     }
     if (!pmVisualInitWindow (&kapa2, "ppSub:StampMasterImage")) {
-        isVisual = false;
         return false;
     }
@@ -145,5 +136,5 @@
     pmVisualScaleImage(kapa, canvas, "Subtraction_Stamps", 0, true);
 
-    pmVisualAskUser(&plotStamps, &isVisual);
+    pmVisualAskUser(&plotStamps);
     return true;
 }
@@ -152,7 +143,6 @@
 bool pmSubtractionVisualPlotLeastSquares (pmSubtractionStampList *stamps, bool dual) {
 
-    if (!isVisual || !plotLeastSquares) return true;
+    if (!pmVisualIsVisual() || !plotLeastSquares) return true;
     if (!pmVisualInitWindow (&kapa, "PPSub:Images")) {
-        isVisual = false;
         return false;
     }
@@ -209,5 +199,5 @@
     pmVisualScaleImage(kapa, canvas32, "Least_Squares", 0, true);
 
-    pmVisualAskUser(&plotLeastSquares, &isVisual);
+    pmVisualAskUser(&plotLeastSquares);
     psFree(canvas);
     psFree(canvas32);
@@ -216,7 +206,6 @@
 
 bool pmSubtractionVisualShowSubtraction(psImage *image, psImage *ref, psImage *sub) {
-    if (!isVisual || !plotImage) return true;
+    if (!pmVisualIsVisual() || !plotImage) return true;
     if (!pmVisualInitWindow (&kapa, "PPSub:Images")) {
-        isVisual = false;
         return false;
     }
@@ -225,5 +214,5 @@
     pmVisualScaleImage(kapa, ref, "Reference", 1, true);
     pmVisualScaleImage(kapa, sub, "Subtraction", 2, true);
-    pmVisualAskUser(&plotImage, &isVisual);
+    pmVisualAskUser(&plotImage);
     return true;
 }
@@ -267,5 +256,4 @@
 
 #else
-bool pmSubtractionSetVisual (bool mode) {return true;}
 bool pmSubtractionVisualClose() {return true;}
 bool pmSubtractionVisualPlotConvKernels(psImage *convKernels) {return true;}
Index: /trunk/psModules/src/imcombine/pmSubtractionVisual.h
===================================================================
--- /trunk/psModules/src/imcombine/pmSubtractionVisual.h	(revision 23241)
+++ /trunk/psModules/src/imcombine/pmSubtractionVisual.h	(revision 23242)
@@ -2,5 +2,4 @@
 #define PM_SUBTRACTION_VISUAL_H
 
-bool pmSubtractionSetVisual (bool mode);
 bool pmSubtractionVisualClose();
 bool pmSubtractionVisualPlotConvKernels(psImage *convKernels);
Index: /trunk/psModules/src/objects/pmSourceVisual.c
===================================================================
--- /trunk/psModules/src/objects/pmSourceVisual.c	(revision 23241)
+++ /trunk/psModules/src/objects/pmSourceVisual.c	(revision 23242)
@@ -9,20 +9,22 @@
 #if (HAVE_KAPA)
 #include <kapa.h>
+#include "pmVisual.h"
 
 // functions used to visualize the analysis as it goes
 // these are invoked by the -visual options
 
-static bool isVisual = false;
 static int kapa1 = -1;
+static bool plotPSF = true;
 // static int kapa2 = -1;
 // static int kapa3 = -1;
 
+bool pmSourceVisualClose() {
+    if (kapa1 != -1)
+        KiiClose(kapa1);
+    return true;
+}
+
 bool pmSourcePlotPoints3D (int myKapa, Graphdata *graphdata, psVector *xn, psVector *yn, psVector *zn, float theta, float phi);
 
-bool pmSourceSetVisual (bool mode) {
-
-    isVisual = mode;
-    return true;
-}
 
 bool pmSourceVisualPSFModelResid (pmTrend2D *trend, psVector *x, psVector *y, psVector *param, psVector *mask) {
@@ -32,5 +34,5 @@
     Graphdata graphdata;
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual() || !plotPSF) return true;
 
     if (kapa1 == -1) {
@@ -38,5 +40,5 @@
         if (kapa1 == -1) {
             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
+            pmVisualSetVisual(false);
             return false;
         }
@@ -152,9 +154,6 @@
     // pause and wait for user input:
     // continue, save (provide name), ??
-    char key[10];
-    fprintf (stdout, "[c]ontinue? ");
-    if (!fgets(key, 8, stdin)) {
-        psWarning("Unable to read option");
-    }
+    pmVisualAskUser(&plotPSF);
+
     return true;
 }
Index: /trunk/psModules/src/objects/pmSourceVisual.h
===================================================================
--- /trunk/psModules/src/objects/pmSourceVisual.h	(revision 23241)
+++ /trunk/psModules/src/objects/pmSourceVisual.h	(revision 23242)
@@ -1,9 +1,9 @@
 /* @file  pmKapaPlots.h
- * @brief functions to make plots with the external program 'kapa' 
+ * @brief functions to make plots with the external program 'kapa'
  *
  * @author EAM, IfA
  *
- * @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-11-08 01:52:34 $
+ * @version $Revision: 1.1.16.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-02-19 17:59:50 $
  * Copyright 2006 Institute for Astronomy, University of Hawaii
  */
@@ -12,8 +12,9 @@
 #define PM_SOURCE_VISUAL_H
 
+bool pmSourceVisualClose(void);
+
 /// @addtogroup Extras Miscellaneous Funtions
 /// @{
 
-bool pmSourceSetVisual (bool mode);
 bool pmSourceVisualPSFModelResid (pmTrend2D *trend, psVector *x, psVector *y, psVector *param, psVector *mask);
 
Index: /trunk/psModules/src/psmodules.h
===================================================================
--- /trunk/psModules/src/psmodules.h	(revision 23241)
+++ /trunk/psModules/src/psmodules.h	(revision 23242)
@@ -101,4 +101,5 @@
 #include <pmReadoutCombine.h>
 #include <pmSubtractionVisual.h>
+#include <pmStackVisual.h>
 
 // the following headers are from psModule:objects
Index: /trunk/psastro/src/psastroArguments.c
===================================================================
--- /trunk/psastro/src/psastroArguments.c	(revision 23241)
+++ /trunk/psastro/src/psastroArguments.c	(revision 23242)
@@ -6,6 +6,6 @@
  *
  *  @author IfA
- *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-09 21:25:34 $
+ *  @version $Revision: 1.34.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-19 17:59:50 $
  *  Copyright 2009 Institute for Astronomy, University of Hawaii
  */
@@ -100,5 +100,5 @@
     if ((N = psArgumentGet (argc, argv, "-visual"))) {
         psArgumentRemove (N, &argc, argv);
-        pmAstromSetVisual (true);
+        pmVisualSetVisual (true);
     }
 
Index: /trunk/psastro/src/psastroCleanup.c
===================================================================
--- /trunk/psastro/src/psastroCleanup.c	(revision 23241)
+++ /trunk/psastro/src/psastroCleanup.c	(revision 23242)
@@ -6,6 +6,6 @@
  *
  *  @author IfA
- *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-09 21:25:34 $
+ *  @version $Revision: 1.8.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-19 17:59:50 $
  *  Copyright 2009 Institute for Astronomy, University of Hawaii
  */
@@ -16,5 +16,5 @@
 
     psFree (config);
-    pmAstromVisualClose ();
+    pmVisualClose ();
 
     psTimerStop ();
Index: unk/psastro/src/psastroVisual.c
===================================================================
--- /trunk/psastro/src/psastroVisual.c	(revision 23241)
+++ 	(revision )
@@ -1,1320 +1,0 @@
-/** @file psastroVisual.c
- *
- *  @brief Diagnostic plots for psastro
- *
- *  @ingroup libpsastro
- *
- *  @author IfA
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-07 02:03:34 $
- *  Copyright 2009 Institute for Astronomy, University of Hawaii
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-# include "psastroInternal.h"
-# include <string.h>
-# include <stdlib.h>
-# include <stdio.h>
-
-# if (HAVE_KAPA)
-# include <kapa.h>
-
-# define KAPAX  700
-# define KAPAY  700
-
-//variables to determine when things are plotted
-static bool isVisual             = false;
-static bool plotRawStars         = true;
-static bool plotRefStars         = false;
-static bool plotLumFunc          = true;
-static bool plotRemoveClumps     = true;
-static bool plotOneChipFit       = true;
-static bool plotFixChips         = true;
-static bool plotAstromGuessCheck = true;
-static bool plotMosaicMatches    = true;
-static bool plotCommonScale      = true;
-static bool plotMosaicOneChip    = true;
-
-// variables to store plotting window indices
-static int kapa = -1;
-static int kapa2 = -1;
-
-// 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, bool clip);
-bool psastroVisualTripleOverplot (int kapa, Graphdata *graphdata, psVector *xVec, psVector *yVec, psVector *zVec, bool increasing);
-bool psastroVisualCreateScaleVec (psVector *zVec, psVector *zScale, bool increasing);
-bool psastroVisualResidPlot (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe, char *title);
-
-
-/*****************************/
-/** Initialization Routines **/
-/*****************************/
-
-/**  
- * start or stop plotting 
- */
-bool psastroSetVisual (bool mode) {
-    isVisual = mode;
-    return true;
-}
-
-
-/** 
- * open, name, and resize a window if necessary
- */
-bool psastroVisualInitWindow( int *kapid, char *name ) {
-    if (*kapid == -1) {
-        *kapid = KapaOpenNamedSocket("kapa", name);
-        if (*kapid == -1) {
-            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
-            return false;
-        }
-        KapaResize (*kapid, KAPAX, KAPAY);
-    }
-    return true;
-}
-
-
-/** 
- * ask the user how to proceed
- */
-bool psastroVisualAskUser( bool *plotflag ) {
-    char key[10];
-    fprintf (stdout, "[c]ontinue? [s]kip the rest of these plots? [a]bort all visual plots?");
-    if (!fgets(key, 8, stdin)) {
-        psWarning("Unable to read option");
-    }
-    if (key[0] == 's') {
-        *plotflag = false;
-    }
-    if (key[0] == 'a') {
-        psastroSetVisual(false);
-        pmAstromSetVisual(false);
-    }
-    return true;
-}
-
-
-/** 
- * destroy windows at the end of a run
- */
-bool psastroVisualClose() {
-    if(kapa != -1)
-        KiiClose(kapa);
-    if (kapa2 != -1)
-        KiiClose(kapa2);
-    return true;
-}
-
-
-/***********************/
-/** Plotting Routines **/
-/***********************/
-
-
-/**
- * Plot raw stars as determined from first pass astrometry fit
- * Called within psastroAstromGeuss
- */
-bool psastroVisualPlotRawStars (psArray *rawstars, pmFPA *fpa, pmChip *chip, psMetadata *recipe)
-{
-    // make sure we want to plot this
-    if (!plotRawStars || !isVisual) return true;
-
-    //set up plot region
-    if (!psastroVisualInitWindow (&kapa, "psastro:plots"))
-        return false;
-    Graphdata graphdata;
-    KapaSection section;
-
-    KapaInitGraph (&graphdata);
-    KapaClearPlots (kapa);
-
-    graphdata.color = KapaColorByName ("black");
-    graphdata.ptype = 7;
-    graphdata.size = 0.5;
-    graphdata.style = 2;
-
-    section.dx = 0.4;
-    section.dy = 0.4;
-
-    //initialize and populate plotting vectors
-    bool status = false;
-    float iMagMin = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLOT.INST.MAG.MIN");
-    float iMagMax = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLOT.INST.MAG.MAX");
-
-    psVector *xVec = psVectorAlloc (rawstars->n, PS_TYPE_F32);
-    psVector *yVec = psVectorAlloc (rawstars->n, PS_TYPE_F32);
-    psVector *zVec = psVectorAlloc (rawstars->n, PS_TYPE_F32);
-
-    section.x = 0.0;
-    section.y = 0.5;
-    section.name = NULL;
-    psStringAppend (&section.name, "a0");
-    KapaSetSection (kapa, &section);
-    psFree (section.name);
-
-    //Chip coordinates
-    int n = 0;
-    for (int i = 0; i < rawstars->n; i++) {
-        pmAstromObj *raw = rawstars->data[i];
-        if (!isfinite(raw->Mag)) continue;
-        if (raw->Mag < iMagMin) continue;
-        if (raw->Mag > iMagMax) continue;
-
-        xVec->data.F32[n] = raw->chip->x;
-        yVec->data.F32[n] = raw->chip->y;
-        zVec->data.F32[n] = raw->Mag;
-        n++;
-    }
-    xVec->n = yVec->n = zVec->n = n;
-
-    KapaSendLabel(kapa, "Chip", KAPA_LABEL_XP);
-    KapaSendLabel(kapa, "X", KAPA_LABEL_XM);
-    KapaSendLabel(kapa, "Y", KAPA_LABEL_YM);
-    psastroVisualTriplePlot (kapa, &graphdata, xVec, yVec, zVec, false);
-
-    //Focal Plane Coordinates
-    section.x = 0.5;
-    section.y = 0.5;
-    section.name = NULL;
-    psStringAppend (&section.name, "a1");
-    KapaSetSection (kapa, &section);
-    psFree (section.name);
-
-    n = 0;
-    for (int i = 0; i < rawstars->n; i++) {
-        pmAstromObj *raw = rawstars->data[i];
-        if (!isfinite(raw->Mag)) continue;
-        if (raw->Mag < iMagMin) continue;
-        if (raw->Mag > iMagMax) continue;
-
-        xVec->data.F32[n] = raw->FP->x;
-        yVec->data.F32[n] = raw->FP->y;
-        zVec->data.F32[n] = raw->Mag;
-        n++;
-    }
-    xVec->n = yVec->n = zVec->n = n;
-
-    KapaSendLabel (kapa, "Focal Plane", KAPA_LABEL_XP);
-    KapaSendLabel (kapa, "L", KAPA_LABEL_XM);
-    KapaSendLabel (kapa, "M", KAPA_LABEL_YM);
-    psastroVisualTriplePlot (kapa, &graphdata, xVec, yVec, zVec, false);
-
-    // Tangent Plane Coordinates
-    section.x = 0.0;
-    section.y = 0.0;
-    section.name = NULL;
-    psStringAppend (&section.name, "a2");
-    KapaSetSection (kapa, &section);
-    psFree (section.name);
-
-    n = 0;
-    for (int i = 0; i < rawstars->n; i++) {
-        pmAstromObj *raw = rawstars->data[i];
-        if (!isfinite(raw->Mag)) continue;
-        if (raw->Mag < iMagMin) continue;
-        if (raw->Mag > iMagMax) continue;
-
-        xVec->data.F32[n] = raw->TP->x;
-        yVec->data.F32[n] = raw->TP->y;
-        zVec->data.F32[n] = raw->Mag;
-        n++;
-    }
-    xVec->n = yVec->n = zVec->n = n;
-
-    KapaSendLabel (kapa, "Tangential Plane", KAPA_LABEL_XP);
-    KapaSendLabel (kapa, "P", KAPA_LABEL_XM);
-    KapaSendLabel (kapa, "Q", KAPA_LABEL_YM);
-    psastroVisualTriplePlot (kapa, &graphdata, xVec, yVec, zVec, false);
-
-    //sky coordinates
-    section.x = 0.5;
-    section.y = 0.0;
-    section.name = NULL;
-    psStringAppend (&section.name, "a3");
-    KapaSetSection (kapa, &section);
-    psFree (section.name);
-
-    n = 0;
-    for (int i = 0; i < rawstars->n; i++) {
-        pmAstromObj *raw = rawstars->data[i];
-        if (!isfinite(raw->Mag)) continue;
-        if (raw->Mag < iMagMin) continue;
-        if (raw->Mag > iMagMax) continue;
-
-        xVec->data.F32[n] = DEG_RAD*raw->sky->r;
-        yVec->data.F32[n] = DEG_RAD*raw->sky->d;
-        zVec->data.F32[n] = raw->Mag;
-        n++;
-    }
-    xVec->n = yVec->n = zVec->n = n;
-
-    KapaSendLabel (kapa, "Sky", KAPA_LABEL_XP);
-    KapaSendLabel(kapa, "RA", KAPA_LABEL_XM);
-    KapaSendLabel(kapa, "Dec", KAPA_LABEL_YM);
-    psastroVisualTriplePlot (kapa, &graphdata, xVec, yVec, zVec, false);
-
-    // flip x (East increase to left)
-    SWAP (graphdata.xmin, graphdata.xmax);
-    KapaSetLimits (kapa, &graphdata);
-
-    // plot label
-    section.x = 0.0;
-    section.y = 0.0;
-    section.dx = .95;
-    section.dy = .95;
-    section.name = NULL;
-    psStringAppend (&section.name, "a5");
-    KapaSetSection (kapa, &section);
-    KapaSendLabel (kapa, "Raw Star Selection - Initial Astrometry", KAPA_LABEL_XP);
-    psFree (section.name);
-
-    // pause and wait for user input:
-    psastroVisualAskUser( &plotRawStars );
-
-    psFree (xVec);
-    psFree (yVec);
-    psFree (zVec);
-    return true;
-}
-
-
-/**
- * plot the location of references stars over the entire fpa
- * invoked during psastroChooseRefStars
- */
-bool psastroVisualPlotRefStars (psArray *refstars, psMetadata *recipe)
-{
-    //make sure we want to plot this
-    if (!isVisual || !plotRefStars) return true;
-
-    //set up plotting variables
-    if (!psastroVisualInitWindow (&kapa, "psastro:plots"))
-        return false;
-
-    Graphdata graphdata;
-    KapaInitGraph (&graphdata);
-    KapaClearSections (kapa);
-
-    graphdata.color = KapaColorByName ("black");
-    graphdata.ptype = 7;
-    graphdata.size = 0.5;
-    graphdata.style = 2;
-
-    //initialize and populate plot vectors
-    bool status = false;
-    float rMagMin = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLOT.REF.MAG.MIN");
-    float rMagMax = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLOT.REF.MAG.MAX");
-
-    psVector *xVec = psVectorAlloc (refstars->n, PS_TYPE_F32);
-    psVector *yVec = psVectorAlloc (refstars->n, PS_TYPE_F32);
-    psVector *zVec = psVectorAlloc (refstars->n, PS_TYPE_F32);
-
-    int n = 0;
-    for (int i = 0; i < refstars->n; i++) {
-        pmAstromObj *ref = refstars->data[i];
-        if (!isfinite(ref->Mag)) continue;
-        if (ref->Mag > rMagMax) continue;
-        if (ref->Mag < rMagMin) continue;
-
-        xVec->data.F32[n] = DEG_RAD*ref->sky->r;
-        yVec->data.F32[n] = DEG_RAD*ref->sky->d;
-        zVec->data.F32[n] = ref->Mag;
-        n++;
-    }
-    xVec->n = yVec->n = zVec->n = n;
-
-    KapaSendLabel (kapa, "RA", KAPA_LABEL_XM);
-    KapaSendLabel (kapa, "Dec", KAPA_LABEL_YM);
-    KapaSendLabel (kapa, "Reference Stars", KAPA_LABEL_XP);
-    psastroVisualTriplePlot(kapa, &graphdata, xVec, yVec, zVec, false);
-
-    // flip x (East increase to left)
-    SWAP (graphdata.xmin, graphdata.xmax);
-    KapaSetLimits (kapa, &graphdata);
-
-    // pause and wait for user input:
-    psastroVisualAskUser(&plotRefStars);
-
-    psFree (xVec);
-    psFree (yVec);
-    psFree (zVec);
-    return true;
-}
-
-
-/**
- * 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,   ///< 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
-    if ( !isVisual || !plotLumFunc ) return true;
-
-    //set up plotting variables
-    if ( !psastroVisualInitWindow (&kapa, "psastro:plots"))
-        return false;
-
-    Graphdata graphdata;
-    KapaSection section1 = {"s1", .1, .1, .85, .35};
-    KapaSection section2 =  {"s2", .1, .5, .85, .35};
-    KapaSection section;
-    if(rawFunc == NULL)
-        section = section1;
-    else
-        section = section2;
-    if (rawFunc == NULL)
-        KapaClearPlots(kapa);
-    KapaInitGraph(&graphdata);
-
-    //Determine Plot Limits
-    psastroVisualScaleGraphdata(&graphdata, Mag, lnMag, false);
-
-    //Make a line for the fit
-    float x[2] = {graphdata.xmin, graphdata.xmax};
-    float y[2] = {lumFunc->offset + x[0] * lumFunc->slope,
-                 lumFunc->offset + x[1] * lumFunc->slope};
-
-    //Plot Data
-    KapaSetSection(kapa, &section);
-    KapaSetLimits(kapa, &graphdata);
-
-    KapaSetFont (kapa, "helvetica", 14);
-    KapaBox (kapa, &graphdata);
-    KapaSendLabel (kapa, "Magnitude", KAPA_LABEL_XM);
-    KapaSendLabel (kapa, "Log(N)", KAPA_LABEL_YM);
-    if (rawFunc == NULL)
-        KapaSendLabel (kapa, "Raw Star Luminosity Function", KAPA_LABEL_XP);
-    else
-        KapaSendLabel (kapa,
-                       "Reference Star Luminosity Function, Shifted Raw Fit, and Cutoff",
-                       KAPA_LABEL_XP);
-    graphdata.color=KapaColorByName("black");
-    graphdata.style = 1;
-    KapaPrepPlot (kapa, lnMag->n, &graphdata);
-    KapaPlotVector(kapa, lnMag->n,   Mag->data.F32, "x");
-    KapaPlotVector(kapa, lnMag->n, lnMag->data.F32, "y");
-
-    //Overplot fit
-    graphdata.style=0;
-    KapaPrepPlot(kapa,2,&graphdata);
-    KapaPlotVector(kapa, 2, x, "x");
-    KapaPlotVector(kapa, 2, y, "y");
-
-    //If rawFunc was supplied, overplot the raw star fit + cutoff
-    if( rawFunc != NULL) {
-        double mRef = 0.5*(lumFunc->mMin + lumFunc->mMax);
-        double logRho = mRef * lumFunc->slope + lumFunc->offset;
-        double mRaw = (logRho - rawFunc->offset) / rawFunc->slope;
-        double deltaM = mRef - mRaw;
-        double mRefMax = rawFunc->mMax + deltaM;
-
-        float xraw[2] = {rawFunc->mMin + deltaM, rawFunc->mMax + deltaM};
-        float yraw[2] = {rawFunc->offset + (rawFunc->slope) * rawFunc->mMin,
-                        rawFunc->offset + (rawFunc->slope) * rawFunc->mMax};
-        float x[2] = {mRefMax, mRefMax};
-        float y[2] = {graphdata.ymin, graphdata.ymax};
-        graphdata.color= KapaColorByName("red");
-        KapaPrepPlot(kapa, 2, &graphdata);
-        KapaPlotVector(kapa, 2, x, "x");
-        KapaPlotVector(kapa, 2, y, "y");
-        KapaPrepPlot (kapa, 2, &graphdata);
-        KapaPlotVector (kapa, 2, xraw, "x");
-        KapaPlotVector (kapa, 2, yraw, "y");
-
-        // pause and wait for user input:
-        psastroVisualAskUser (&plotLumFunc);
-    }
-    return true;
-} // end of psastroVisualPlotLuminosityFunction
-
-
-/**
- * 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, ///< 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
-    if (!isVisual || !plotRemoveClumps) return true;
-
-    //set up plot variables
-    if ( !psastroVisualInitWindow (&kapa, "psastro:plots")) return false;
-
-    KapaSection section;
-    Graphdata graphdata;
-    section.x = 0;
-    section.dx = .9;
-    section.y = 0;
-    section.dy = .9;
-    section.name = NULL;
-    psStringAppend( &section.name, "a0");
-    KapaInitGraph(&graphdata);
-    KapaSetSection(kapa, &section);
-    psFree(section.name);
-
-    graphdata.ptype = 7;
-    graphdata.size = 0.5;
-    graphdata.style = 2;
-    graphdata.color = KapaColorByName ("black");
-    KapaClearPlots(kapa);
-
-    //set up plot vectors
-    float Xmin = +FLT_MAX;
-    float Xmax = -FLT_MAX;
-    float Ymin = +FLT_MAX;
-    float Ymax = -FLT_MAX;
-    psVector *xVec = psVectorAlloc (input->n, PS_TYPE_F32);
-    psVector *yVec = psVectorAlloc (input->n, PS_TYPE_F32);
-
-    //determine boundaries for histogram bin calculation
-    int n = 0;
-    for (int i=0; i< input->n; i++) {
-        pmAstromObj *obj = (pmAstromObj *)input->data[i];
-        if (!isfinite(obj->FP->x)) continue;
-        if (!isfinite(obj->FP->y)) continue;
-        xVec->data.F32[n] = obj->FP->x;
-        yVec->data.F32[n] = obj->FP->y;
-        Xmin = PS_MIN (Xmin, xVec->data.F32[n]);
-        Xmax = PS_MAX (Xmax, xVec->data.F32[n]);
-        Ymin = PS_MIN (Ymin, yVec->data.F32[n]);
-        Ymax = PS_MAX (Ymax, yVec->data.F32[n]);
-        n++;
-    }
-    xVec->n = yVec->n = n;
-
-    //plot stars
-    graphdata.xmax = Xmax;
-    graphdata.xmin = Xmin;
-    graphdata.ymax = Ymax;
-    graphdata.ymin = Ymin;
-    KapaSetLimits (kapa, &graphdata);
-    KapaSetFont (kapa, "helvetica", 14);
-
-    KapaBox (kapa, &graphdata);
-
-    KapaSendLabel (kapa, "L (pixels)", KAPA_LABEL_XM);
-    KapaSendLabel (kapa, "M (pixels)", KAPA_LABEL_YM);
-    KapaSendLabel (kapa, "Regions Flagged as Clumps (Red Boxes)",
-                   KAPA_LABEL_XP);
-
-    KapaPrepPlot (kapa, xVec->n, &graphdata);
-    KapaPlotVector (kapa, xVec->n, xVec->data.F32, "x");
-    KapaPlotVector (kapa, yVec->n, yVec->data.F32, "y");
-
-    graphdata.color = KapaColorByName ("red");
-    graphdata.style = 1;
-
-    //overplot clumpy regions excluded from analysis
-    for(int i = 0; i < count->numCols; i++) {
-        for (int j = 0; j < count->numRows; j++) {
-            if(count->data.U32[j][i] <= limit) continue; //not a clump
-            float Xbot = (i - 5) * scale + Xmin;
-            float Ybot = (j - 5) * scale + Ymin;
-            if(Xbot < graphdata.xmin || Xbot > graphdata.xmax ||
-               Ybot < graphdata.ymin || Ybot > graphdata.ymax) continue;
-            float x[5] = {Xbot, Xbot + scale, Xbot + scale, Xbot, Xbot};
-            float y[5] = {Ybot, Ybot, Ybot + scale, Ybot + scale, Ybot};
-            KapaPrepPlot (kapa, 5, &graphdata);
-            KapaPlotVector (kapa, 5, x, "x");
-            KapaPlotVector (kapa, 5, y, "y");
-        }
-    }
-
-    //ask for user input and finish
-    psastroVisualAskUser (&plotRemoveClumps);
-    psFree (xVec);
-    psFree (yVec);
-
-    return true;
-}
-
-
-/**
- * Assess the goodness of fit for a signle chip by
- * plotting the fit residuals
- * invoked during psastroOneChipFit
- */
-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
-    if (!isVisual || !plotOneChipFit)
-        return true;
-
-    //plot the residuals
-    if (!psastroVisualResidPlot(rawstars, refstars, match, recipe, "Single Chip Fit Residuals (Chip Coordinates)"))
-        return false;
-
-    //ask for user input and finish
-    psastroVisualAskUser(&plotOneChipFit);
-    return true;
-}
-
-
-/**
- * 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);
-
-    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);
-	psVectorAppend (xNew, ptFP.x);
-	psVectorAppend (yNew, ptFP.y);
-
-        ptCP.x = region->x0; ptCP.y = region->y1;
-        psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP);
-	psVectorAppend (xNew, ptFP.x);
-	psVectorAppend (yNew, ptFP.y);
-
-        ptCP.x = region->x1; ptCP.y = region->y1;
-        psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP);
-	psVectorAppend (xNew, ptFP.x);
-	psVectorAppend (yNew, ptFP.y);
-
-        ptCP.x = region->x1; ptCP.y = region->y0;
-        psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP);
-	psVectorAppend (xNew, ptFP.x);
-	psVectorAppend (yNew, ptFP.y);
-
-        psFree (region);
-    }
-
-    //set up graph
-    psastroVisualScaleGraphdata(&graphdata, xOld, yOld, true);
-    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
- *  the astrometry solution has been applied. In psastroAstromGuessCheck, the old corners
- *  are then fit to the new corners to get a sense at how far off the initial WCS info was
- *  in offset, rotation, and scale. This procedure also plots the residuals of the fit from
- *  old to new coordinates
- */
-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
-    if (!isVisual || !plotAstromGuessCheck) return true;
-
-    //set up graph window
-    if ( !psastroVisualInitWindow (&kapa, "psastro:plots"))
-        return false;
-    Graphdata graphdata;
-    KapaSection section;
-    KapaInitGraph(&graphdata);
-    KapaClearPlots (kapa);
-
-    graphdata.color = KapaColorByName ("black");
-    graphdata.ptype = 2;
-    graphdata.size = 0.5;
-    graphdata.style = 2;
-
-    section.dx = 0.4;
-    section.dy = 0.4;
-
-    //Old Corners
-    section.x = 0.30;
-    section.y = 0.50;
-    section.name = NULL;
-    psStringAppend (&section.name, "a0");
-    KapaSetSection (kapa, &section);
-    psFree(section.name);
-
-    psastroVisualScaleGraphdata (&graphdata, cornerPo, cornerPo, true);
-    KapaSetLimits (kapa, &graphdata);
-    KapaBox (kapa, &graphdata);
-    KapaSendLabel (kapa, "P (Pixels)", KAPA_LABEL_XM);
-    KapaSendLabel (kapa, "Q (Pixels)", KAPA_LABEL_YM);
-    KapaSendLabel (kapa,
-                   "Fiducial Points in the Tangent Plane. Black: Initial Astrometry. Red: Final Astrometry",
-                   KAPA_LABEL_XP);
-    KapaPrepPlot (kapa, cornerPo->n, &graphdata);
-    KapaPlotVector (kapa, cornerPo->n, cornerPo->data.F32, "x");
-    KapaPlotVector (kapa, cornerQo->n, cornerQo->data.F32, "y");
-
-    // New Corners
-    graphdata.color = KapaColorByName("red");
-    graphdata.ptype = 7;
-    graphdata.size = 1.5;
-    KapaPrepPlot (kapa, cornerPn->n, &graphdata);
-    KapaPlotVector (kapa, cornerPn->n, cornerPn->data.F32, "x");
-    KapaPlotVector (kapa, cornerQn->n, cornerQn->data.F32, "y");
-
-    // Residuals
-    psVector *xResid = psVectorAlloc(cornerPn->n, PS_DATA_F32);
-    psVector *yResid = psVectorAlloc(cornerQn->n, PS_DATA_F32);
-    for(int i=0; i < cornerPn->n; i++) {
-        xResid->data.F32[i] = (cornerPd->data.F32[i]);
-        yResid->data.F32[i] = (cornerQd->data.F32[i]);
-    }
-
-    graphdata.color = KapaColorByName("black");
-    graphdata.size=0.5;
-    section.x = 0.3;
-    section.y = 0.0;
-    section.name = NULL;
-    psStringAppend (&section.name, "a1");
-    KapaSetSection (kapa, &section);
-    psFree(section.name);
-
-    psastroVisualScaleGraphdata (&graphdata, xResid, yResid, true);
-    KapaSetLimits (kapa, &graphdata);
-    KapaBox (kapa, &graphdata);
-    KapaSendLabel (kapa, "dP", KAPA_LABEL_XM);
-    KapaSendLabel (kapa, "dQ", KAPA_LABEL_YM);
-    KapaSendLabel (kapa,
-                   "Residual of the Fit from the Initial Astrometry to the Final Astrometry",
-                   KAPA_LABEL_XP);
-    KapaPrepPlot (kapa, cornerPd->n, &graphdata);
-    KapaPlotVector (kapa, cornerPd->n, xResid->data.F32, "x");
-    KapaPlotVector (kapa, cornerQd->n, yResid->data.F32, "y");
-
-    psFree(xResid);
-    psFree(yResid);
-    psastroVisualAskUser (&plotAstromGuessCheck);
-    return true;
-}
-
-
-/**
- * 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 = psVectorAlloc (oldScale->n, PS_TYPE_F32);
-    psVector *yVec = psVectorAlloc (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);
-    KapaSetFont (kapa, "helvetica", 14);
-    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;
-}
-
-
-/**
- *   plot the residuals between raw stars and ref stars after
- *   fitting in psastroMosaicOneChip
- */
-bool psastroVisualPlotMosaicOneChip (psArray *rawstars, psArray *refstars,
-                                     psArray *match, psMetadata *recipe)
-{
-
-    //make sure we want to plot this
-    if (!isVisual || !plotMosaicOneChip) return false;
-
-    //plot the residuals
-    if (!psastroVisualResidPlot(rawstars, refstars, match, recipe, "Single Chip Fit Residuals - Mosaic Mode"))
-        return false;
-
-    //ask for user input and finish
-    psastroVisualAskUser(&plotMosaicOneChip);
-
-    return true;
-}
-
-/** psastroVisualPlotMosaicMatches
- * Plot the matches between raw and reference stars during psastroVisualMosaicSetMatch
- */
-bool psastroVisualPlotMosaicMatches( psArray *rawstars, psArray *refstars,
-                                    psArray *match, int iteration,
-                                    psMetadata *recipe)
-{
-    //make sure we want to plot this
-    if (!isVisual || !plotMosaicMatches) return true;
-
-    char title[60];
-    sprintf(title, "Matches found during psastroMosaicSetMatch iteration %d", iteration);
-
-    if (!psastroVisualResidPlot(rawstars, refstars, match, recipe, title))
-        return false;
-
-    //ask for user input
-    psastroVisualAskUser (&plotMosaicMatches);
-    return true;
-}
-
-
-/*********************/
-/** Helper Routines **/
-/*********************/
-
-
-/** 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
- * plot 2 vectors whose point sizes are scaled by a third vector
- * autoscales the plot
- */
-bool psastroVisualTriplePlot (int kapid, Graphdata *graphdata, psVector *xVec, psVector *yVec, psVector *zVec, bool increasing)
-{
-    psastroVisualScaleGraphdata (graphdata, xVec, yVec, true);
-    //printf("%f %f %f %f \n",graphdata->xmin, graphdata->xmax, graphdata->ymin, graphdata->ymax);
-    // set the scale vector
-    psVector *zScale = psVectorAlloc (zVec->n, PS_DATA_F32);
-    psastroVisualCreateScaleVec (zVec, zScale, increasing);
-
-    KapaSetFont (kapid, "helvetica", 14);
-    KapaSetLimits(kapid, graphdata);
-    KapaBox (kapid, graphdata);
-
-    // the point size will be scaled from the z vector
-    graphdata->ptype = 7;
-    graphdata->style = 2;
-    graphdata->size = -1;
-    KapaPrepPlot (kapid, xVec->n, graphdata);
-    KapaPlotVector (kapid, xVec->n, xVec->data.F32, "x");
-    KapaPlotVector (kapid, yVec->n, yVec->data.F32, "y");
-    KapaPlotVector (kapid, zVec->n, zScale->data.F32, "z");
-    psFree (zScale);
-    return true;
-}
-
-
-/** psastroVisualTripleOverplot
- * same as above, but does not rescale the plot or redraw the bounding box
- */
-bool psastroVisualTripleOverplot (int kapid, Graphdata *graphdata, psVector *xVec, psVector *yVec, psVector *zVec, bool increasing) {
-
-    // set the scale vector
-    psVector *zScale = psVectorAlloc (zVec->n, PS_DATA_F32);
-    psastroVisualCreateScaleVec (zVec, zScale, increasing);
-
-    KapaSetFont (kapid, "helvetica", 14);
-
-    // the point size will be scaled from the z vector
-    graphdata->size = -1;
-    KapaPrepPlot (kapid, xVec->n, graphdata);
-    KapaPlotVector (kapid, xVec->n, xVec->data.F32, "x");
-    KapaPlotVector (kapid, yVec->n, yVec->data.F32, "y");
-    KapaPlotVector (kapid, zVec->n, zScale->data.F32, "z");
-    psFree (zScale);
-    return true;
-}
-
-
-/** psastroVisualCreateScaleVec
- * create a vector of plot point sizes from a vector
- */
-bool psastroVisualCreateScaleVec (psVector *zVec, psVector *zScale, bool increasing) {
-    // set limits based on data values
-    float zmin = +FLT_MAX;
-    float zmax = -FLT_MAX;
-
-    for (int i = 0; i < zVec->n; i++) {
-        zmin = PS_MIN (zmin, zVec->data.F32[i]);
-        zmax = PS_MAX (zmax, zVec->data.F32[i]);
-    }
-
-    float range = zmax - zmin;
-    if (range == 0.0) {
-        psVectorInit (zScale, 1.0);
-    } else {
-        for (int i = 0; i < zVec->n; i++) {
-            if (increasing) {
-                zScale->data.F32[i] = PS_MIN (1.5, PS_MAX(0.05, 1.5*(zVec->data.F32[i] - zmin)/range));
-            } else {
-                zScale->data.F32[i] = PS_MIN (1.5, PS_MAX(0.05, 1.5*(zmax - zVec->data.F32[i])/range));
-            }
-        }
-    }
-    return true;
-}
-
-
-/** psastroVisualScaleGraphdata
- * Scale the graphdata structure based on x and y coordinates. Use sigma clipping to
- * prevent outliers from making te plot region too big.
- */
-bool psastroVisualScaleGraphdata(Graphdata *graphdata, psVector *xVec, psVector *yVec, bool clip) {
-
-    graphdata->xmin = +FLT_MAX;
-    graphdata->xmax = -FLT_MAX;
-    graphdata->ymin = +FLT_MAX;
-    graphdata->ymax = -FLT_MAX;
-
-    //determine standard deviation of xVec and yVec
-    psStats *statsX = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
-    psStats *statsY = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
-    psVectorStats (statsX, xVec, NULL, NULL, 0);
-    psVectorStats (statsY, yVec, NULL, NULL, 0);
-
-    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
-    if (!isfinite(xhi) || !isfinite(xlo) || !isfinite(yhi) || !isfinite(ylo)) {
-        graphdata->xmin = -1;
-        graphdata->ymin  = -1;
-        graphdata->xmax = 1;
-        graphdata->ymax = 1;
-        psFree(statsX);
-        psFree(statsY);
-        return false;
-    }
-
-    for(int i = 0; i < xVec->n; i++) {
-        if (!isfinite(xVec->data.F32[i])) continue;
-        if (xVec->data.F32[i] > xhi || xVec->data.F32[i] < xlo) continue;
-        graphdata->xmin = PS_MIN (graphdata->xmin, xVec->data.F32[i]);
-        graphdata->xmax = PS_MAX (graphdata->xmax, xVec->data.F32[i]);
-    }
-
-    for (int i = 0; i < yVec->n; i++) {
-        if (!isfinite(xVec->data.F32[i])) continue;
-        if (yVec->data.F32[i] > yhi || yVec->data.F32[i] < ylo) continue;
-        graphdata->ymin = PS_MIN (graphdata->ymin, yVec->data.F32[i]);
-        graphdata->ymax = PS_MAX (graphdata->ymax, yVec->data.F32[i]);
-    }
-
-    // add a whitespace border
-    float range = graphdata->xmax - graphdata->xmin;
-    if (range == 0) range = 1;
-    graphdata->xmin -= .05 * range;
-    graphdata->xmax += .05 * range;
-
-    range = graphdata->ymax - graphdata->ymin;
-    if (range == 0) range = 1;
-    graphdata->ymin -= .05 * range;
-    graphdata->ymax += .05 * range;
-
-    psFree (statsX);
-    psFree (statsY);
-    return true;
-}
-
-
-/** psastroVisualResdiPlot
- * Plots the residuals between matched raw and reference stars. Used to assess the quality of an
- * astrometry solution
- */
-bool psastroVisualResidPlot (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe, char *title) {
-
-    //set up the first window
-    if (!psastroVisualInitWindow( &kapa, "psastro:plots")) return false;
-
-    //initialize graph information
-    Graphdata graphdata;
-    KapaSection section;
-
-    KapaInitGraph (&graphdata);
-    KapaClearPlots (kapa);
-
-    graphdata.color = KapaColorByName ("black");
-    graphdata.ptype = 7;
-    graphdata.size = 0.5;
-    graphdata.style = 2;
-
-    section.dx = 0.4;
-    section.dy = 0.4;
-
-    //initialize and populate the plotting vectors
-    bool status = false;
-    float iMagMin = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLOT.INST.MAG.MIN");
-    float iMagMax = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLOT.INST.MAG.MAX");
-    float rMagMin = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLOT.REF.MAG.MIN");
-    float rMagMax = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLOT.REF.MAG.MAX");
-
-    psVector *xVec = psVectorAlloc (match->n, PS_TYPE_F32);
-    psVector *yVec = psVectorAlloc (match->n, PS_TYPE_F32);
-    psVector *zVec = psVectorAlloc (match->n, PS_TYPE_F32);
-
-    // X vs dX
-    section.x = 0.0;
-    section.y = 0.5;
-    section.name = NULL;
-    psStringAppend (&section.name, "a0");
-    KapaSetSection (kapa, &section);
-    psFree (section.name);
-
-    int n = 0;
-    for (int i = 0; i < match->n; i++) {
-        pmAstromMatch *pair = match->data[i];
-        pmAstromObj *raw = rawstars->data[pair->raw];
-        pmAstromObj *ref = refstars->data[pair->ref];
-
-        if (!isfinite(raw->Mag)) continue;
-        if (raw->Mag < iMagMin) continue;
-        if (raw->Mag > iMagMax) continue;
-        if (ref->Mag < rMagMin) continue;
-        if (ref->Mag > rMagMax) continue;
-
-        xVec->data.F32[n] = raw->chip->x;
-        yVec->data.F32[n] = raw->chip->x - ref->chip->x;
-        zVec->data.F32[n] = raw->Mag;
-        n++;
-    }
-    xVec->n = yVec->n = zVec->n = n;
-
-    KapaSendLabel (kapa, "X", KAPA_LABEL_XM);
-    KapaSendLabel (kapa, "dX", KAPA_LABEL_YM);
-    psastroVisualTriplePlot (kapa, &graphdata, xVec, yVec, zVec, false);
-
-    // X vs dY
-    section.x = 0.5;
-    section.y = 0.5;
-    section.name = NULL;
-    psStringAppend (&section.name, "a1");
-    KapaSetSection (kapa, &section);
-    psFree (section.name);
-
-    n = 0;
-    for (int i = 0; i < match->n; i++) {
-        pmAstromMatch *pair = match->data[i];
-        pmAstromObj *raw = rawstars->data[pair->raw];
-        pmAstromObj *ref = refstars->data[pair->ref];
-
-        if (!isfinite(raw->Mag)) continue;
-        if (raw->Mag < iMagMin) continue;
-        if (raw->Mag > iMagMax) continue;
-        if (ref->Mag < rMagMin) continue;
-        if (ref->Mag > rMagMax) continue;
-
-        xVec->data.F32[n] = raw->chip->x;
-        yVec->data.F32[n] = raw->chip->y - ref->chip->y;
-        zVec->data.F32[n] = raw->Mag;
-        n++;
-    }
-    xVec->n = yVec->n = zVec->n = n;
-
-    KapaSendLabel (kapa, "X", KAPA_LABEL_XM);
-    KapaSendLabel (kapa, "dY", KAPA_LABEL_YM);
-    psastroVisualTriplePlot (kapa, &graphdata, xVec, yVec, zVec, false);
-
-    // Y vs dX
-    section.x = 0.0;
-    section.y = 0.0;
-    section.name = NULL;
-    psStringAppend (&section.name, "a2");
-    KapaSetSection (kapa, &section);
-    psFree (section.name);
-
-    n = 0;
-    for (int i = 0; i < match->n; i++) {
-        pmAstromMatch *pair = match->data[i];
-        pmAstromObj *raw = rawstars->data[pair->raw];
-        pmAstromObj *ref = refstars->data[pair->ref];
-
-        if (!isfinite(raw->Mag)) continue;
-        if (raw->Mag < iMagMin) continue;
-        if (raw->Mag > iMagMax) continue;
-        if (ref->Mag < rMagMin) continue;
-        if (ref->Mag > rMagMax) continue;
-
-        xVec->data.F32[n] = raw->chip->y;
-        yVec->data.F32[n] = raw->chip->x - ref->chip->x;
-        zVec->data.F32[n] = raw->Mag;
-        n++;
-    }
-    xVec->n = yVec->n = zVec->n = n;
-
-    KapaSendLabel (kapa, "Y", KAPA_LABEL_XM);
-    KapaSendLabel (kapa, "dX", KAPA_LABEL_YM);
-    psastroVisualTriplePlot (kapa, &graphdata, xVec, yVec, zVec, false);
-
-    // Y vs dY
-    section.x = 0.5;
-    section.y = 0.0;
-    section.name = NULL;
-    psStringAppend (&section.name, "a3");
-    KapaSetSection (kapa, &section);
-    psFree (section.name);
-
-    n = 0;
-    for (int i = 0; i < match->n; i++) {
-        pmAstromMatch *pair = match->data[i];
-        pmAstromObj *raw = rawstars->data[pair->raw];
-        pmAstromObj *ref = refstars->data[pair->ref];
-
-        if (!isfinite(raw->Mag)) continue;
-        if (raw->Mag < iMagMin) continue;
-        if (raw->Mag > iMagMax) continue;
-        if (ref->Mag < rMagMin) continue;
-        if (ref->Mag > rMagMax) continue;
-
-        xVec->data.F32[n] = raw->chip->y;
-        yVec->data.F32[n] = raw->chip->y - ref->chip->y;
-        zVec->data.F32[n] = raw->Mag;
-        n++;
-    }
-    xVec->n = yVec->n = zVec->n = n;
-
-    KapaSendLabel (kapa, "Y", KAPA_LABEL_XM);
-    KapaSendLabel (kapa, "dY", KAPA_LABEL_YM);
-    pmKapaPlotVectorTriple_AutoLimits_OpenGraph (kapa, &graphdata, xVec, yVec, zVec, false);
-
-    section.x = 0.0;
-    section.y = 0.0;
-    section.dx = 0.95;
-    section.dy = 0.95;
-    section.name = NULL;
-    psStringAppend (&section.name, "a5");
-    KapaSetSection (kapa, &section);
-    KapaSendLabel (kapa, title, KAPA_LABEL_XP);
-    psFree (section.name);
-
-
-    // X vs Y plot (different window)
-    if (!psastroVisualInitWindow( &kapa2, "psastro:plots"))
-        return false;
-
-    KapaInitGraph (&graphdata);
-    KapaClearPlots (kapa2);
-
-    graphdata.color = KapaColorByName ("black");
-    graphdata.ptype = 2;
-    graphdata.style = 2;
-
-    psFree (xVec);
-    psFree (yVec);
-    psFree (zVec);
-
-    xVec = psVectorAlloc (rawstars->n, PS_TYPE_F32);
-    yVec = psVectorAlloc (rawstars->n, PS_TYPE_F32);
-    zVec = psVectorAlloc (rawstars->n, PS_TYPE_F32);
-
-    // X vs Y by mag (raw)
-    n = 0;
-    for (int i = 0; i < rawstars->n; i++) {
-        pmAstromObj *raw = rawstars->data[i];
-        if (!isfinite(raw->Mag)) continue;
-        if (raw->Mag < iMagMin) continue;
-        if (raw->Mag > iMagMax) continue;
-
-        xVec->data.F32[n] = raw->chip->x;
-        yVec->data.F32[n] = raw->chip->y;
-        zVec->data.F32[n] = raw->Mag;
-        n++;
-    }
-    xVec->n = yVec->n = zVec->n = n;
-
-    KapaSendLabel (kapa2, "X", KAPA_LABEL_XM);
-    KapaSendLabel (kapa2, "Y", KAPA_LABEL_YM);
-    KapaSendLabel (kapa2,
-                   "Chip Coordinates. Black = Raw Stars. Red = Ref Stars. Blue = Matched Stars"
-                   , KAPA_LABEL_XP);
-    psastroVisualTriplePlot (kapa2, &graphdata, xVec, yVec, zVec, false);
-
-    // X vs Y by mag (ref)
-    psFree (xVec);
-    psFree (yVec);
-    psFree (zVec);
-
-    xVec = psVectorAlloc (refstars->n, PS_TYPE_F32);
-    yVec = psVectorAlloc (refstars->n, PS_TYPE_F32);
-    zVec = psVectorAlloc (refstars->n, PS_TYPE_F32);
-
-    graphdata.color = KapaColorByName ("red");
-    graphdata.ptype = 7;
-    graphdata.style = 2;
-
-    n = 0;
-    for (int i = 0; i < refstars->n; i++) {
-        pmAstromObj *ref = refstars->data[i];
-        if (!isfinite(ref->Mag)) continue;
-        if (ref->Mag < rMagMin) continue;
-        if (ref->Mag > rMagMax) continue;
-
-        xVec->data.F32[n] = ref->chip->x;
-        yVec->data.F32[n] = ref->chip->y;
-        zVec->data.F32[n] = ref->Mag;
-        n++;
-    }
-    xVec->n = yVec->n = zVec->n = n;
-    psastroVisualTripleOverplot (kapa2, &graphdata, xVec, yVec, zVec, false);
-
-    //rescale the graph to include all points
-    float xmin = graphdata.xmin;
-    float ymin = graphdata.ymin;
-    float xmax = graphdata.xmax;
-    float ymax = graphdata.ymax;
-    psastroVisualScaleGraphdata(&graphdata, xVec, yVec, true);
-    graphdata.xmin = PS_MIN(xmin, graphdata.xmin);
-    graphdata.ymin = PS_MIN(ymin, graphdata.ymin);
-    graphdata.xmax = PS_MAX(xmax, graphdata.xmax);
-    graphdata.ymax = PS_MAX(ymax, graphdata.ymax);
-    KapaSetLimits (kapa2, &graphdata);
-
-    //overplot matched stars in blue
-    psFree (xVec);
-    psFree (yVec);
-    psFree (zVec);
-
-    xVec = psVectorAlloc (match->n, PS_TYPE_F32);
-    yVec = psVectorAlloc (match->n, PS_TYPE_F32);
-    zVec = psVectorAlloc (match->n, PS_TYPE_F32);
-
-    graphdata.color = KapaColorByName ("blue");
-    n = 0;
-    for (int i = 0; i < match->n; i++) {
-        pmAstromMatch *pair = match->data[i];
-        pmAstromObj *raw = rawstars->data[pair->raw];
-        pmAstromObj *ref = refstars->data[pair->ref];
-        if (raw->Mag < iMagMin) continue;
-        if (raw->Mag > iMagMax) continue;
-        if (ref->Mag < rMagMin) continue;
-        if (ref->Mag > rMagMax) continue;
-
-        xVec->data.F32[n] = raw->chip->x;
-        yVec->data.F32[n] = raw->chip->y;
-        zVec->data.F32[n] = iMagMin;
-        n++;
-    }
-    xVec->n = yVec->n = zVec->n = n;
-    psastroVisualTripleOverplot (kapa2, &graphdata, xVec, yVec, zVec, false);
-
-    psFree (xVec);
-    psFree (yVec);
-    psFree (zVec);
-    return true;
-}
-
-// END OF PROGRAM
-#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
-
Index: /trunk/psphot/src/psphot.h
===================================================================
--- /trunk/psphot/src/psphot.h	(revision 23241)
+++ /trunk/psphot/src/psphot.h	(revision 23242)
@@ -171,5 +171,4 @@
 
 // psphotVisual functions
-bool psphotSetVisual (bool mode);
 bool psphotVisualShowImage (pmReadout *readout);
 bool psphotVisualShowBackground (pmConfig *config, const pmFPAview *view, pmReadout *readout);
Index: /trunk/psphot/src/psphotArguments.c
===================================================================
--- /trunk/psphot/src/psphotArguments.c	(revision 23241)
+++ /trunk/psphot/src/psphotArguments.c	(revision 23242)
@@ -82,6 +82,5 @@
     if ((N = psArgumentGet (argc, argv, "-visual"))) {
         psArgumentRemove (N, &argc, argv);
-        psphotSetVisual (true);
-        // pmSourceSetVisual (true);
+        pmVisualSetVisual(true);
     }
 
Index: /trunk/psphot/src/psphotVisual.c
===================================================================
--- /trunk/psphot/src/psphotVisual.c	(revision 23241)
+++ /trunk/psphot/src/psphotVisual.c	(revision 23242)
@@ -18,14 +18,8 @@
 // these are invoked by the -visual options
 
-static bool isVisual = false;
 static int kapa = -1;
 static int kapa2 = -1;
 static int kapa3 = -1;
 
-bool psphotSetVisual (bool mode) {
-
-    isVisual = mode;
-    return true;
-}
 
 bool psphotVisualShowMask (int kapaFD, psImage *inImage, const char *name, int channel) {
@@ -135,5 +129,5 @@
 bool psphotVisualShowImage (pmReadout *readout) {
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa == -1) {
@@ -141,5 +135,5 @@
         if (kapa == -1) {
             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
+            pmVisualSetVisual(false);
             return false;
         }
@@ -164,5 +158,5 @@
     pmReadout *backgnd;
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa == -1) {
@@ -170,5 +164,5 @@
         if (kapa == -1) {
             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
+            pmVisualSetVisual(false);
             return false;
         }
@@ -199,5 +193,5 @@
 bool psphotVisualShowSignificance (psImage *image) {
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa == -1) {
@@ -205,5 +199,5 @@
         if (kapa == -1) {
             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
+            pmVisualSetVisual(false);
             return false;
         }
@@ -228,5 +222,5 @@
     KiiOverlay *overlay;
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa == -1) {
@@ -306,5 +300,5 @@
     KiiOverlay *overlay;
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa == -1) {
@@ -423,5 +417,5 @@
     psEllipseAxes axes;
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa == -1) {
@@ -478,5 +472,5 @@
     Graphdata graphdata;
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa3 == -1) {
@@ -484,5 +478,5 @@
         if (kapa3 == -1) {
             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
+            pmVisualSetVisual(false);
             return false;
         }
@@ -694,5 +688,5 @@
 bool psphotVisualShowRoughClass (psArray *sources) {
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa == -1) {
@@ -723,5 +717,5 @@
 bool psphotVisualShowPSFModel (pmReadout *readout, pmPSF *psf) {
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa2 == -1) {
@@ -729,5 +723,5 @@
         if (kapa2 == -1) {
             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
+            pmVisualSetVisual(false);
             return false;
         }
@@ -801,5 +795,5 @@
     bool status;
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa2 == -1) {
@@ -807,5 +801,5 @@
         if (kapa2 == -1) {
             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
+            pmVisualSetVisual(false);
             return false;
         }
@@ -961,5 +955,5 @@
     bool status;
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa2 == -1) {
@@ -967,5 +961,5 @@
         if (kapa2 == -1) {
             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
+            pmVisualSetVisual(false);
             return false;
         }
@@ -1214,5 +1208,5 @@
     KapaSection section;  // put the positive profile in one and the residuals in another?
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa3 == -1) {
@@ -1220,5 +1214,5 @@
         if (kapa3 == -1) {
             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
+            pmVisualSetVisual(false);
             return false;
         }
@@ -1286,5 +1280,5 @@
     psEllipseAxes axes;
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa == -1) {
@@ -1387,5 +1381,5 @@
     KiiOverlay *overlay;
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa == -1) {
@@ -1464,5 +1458,5 @@
     KapaSection section;
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa3 == -1) {
@@ -1470,5 +1464,5 @@
         if (kapa3 == -1) {
             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
+            pmVisualSetVisual(false);
             return false;
         }
@@ -1604,5 +1598,5 @@
 bool psphotVisualShowResidualImage (pmReadout *readout) {
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa == -1) {
@@ -1610,5 +1604,5 @@
         if (kapa == -1) {
             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
+            pmVisualSetVisual(false);
             return false;
         }
@@ -1631,5 +1625,5 @@
     Graphdata graphdata;
 
-    if (!isVisual) return true;
+    if (!pmVisualIsVisual()) return true;
 
     if (kapa3 == -1) {
@@ -1637,5 +1631,5 @@
         if (kapa3 == -1) {
             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
-            isVisual = false;
+            pmVisualSetVisual(false);
             return false;
         }
@@ -1712,5 +1706,4 @@
 # else
 
-bool psphotSetVisual (bool mode){}
 bool psphotVisualShowImage (pmConfig *config, pmReadout *readout) { return true; }
 bool psphotVisualShowBackground (pmConfig *config, const pmFPAview *view, pmReadout *readout) { return true; }
Index: /trunk/pswarp/src/pswarpArguments.c
===================================================================
--- /trunk/pswarp/src/pswarpArguments.c	(revision 23241)
+++ /trunk/pswarp/src/pswarpArguments.c	(revision 23242)
@@ -41,5 +41,5 @@
         if ((arg = psArgumentGet(argc, argv, "-psphot-visual"))) {
             psArgumentRemove(arg, &argc, argv);
-            psphotSetVisual(true);
+            pmVisualSetVisual(true);
         }
     }
