Index: /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/Makefile
===================================================================
--- /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/Makefile	(revision 22723)
+++ /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/Makefile	(revision 22724)
@@ -55,5 +55,6 @@
 $(SRC)/relastro_objects.$(ARCH).o    \
 $(SRC)/save_catalogs.$(ARCH).o       \
-$(SRC)/write_coords.$(ARCH).o
+$(SRC)/write_coords.$(ARCH).o        \
+$(SRC)/relastroVisual.$(ARCH).o
 
 $(RELASTRO): $(INC)/relastro.h $(KAPA_INCS)
Index: /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/include/relastro.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/include/relastro.h	(revision 22723)
+++ /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/include/relastro.h	(revision 22724)
@@ -44,5 +44,5 @@
   double Ro, dRo;
   double Do, dDo;
-  
+
   double uR, duR;
   double uD, duD;
@@ -63,5 +63,5 @@
   char flags;
   Coords coords;
-} Mosaic; 
+} Mosaic;
 
 typedef struct {
@@ -87,4 +87,5 @@
 
 double SIGMA_LIM;
+int MIN_SRC_FIT;
 double MIN_ERROR;
 
@@ -145,5 +146,5 @@
 int           corner_check        PROTO((double *x1, double *y1, double *x2, double *y2));
 void          dumpGrid            PROTO((void));
-void          dump_grid           PROTO((void)); 
+void          dump_grid           PROTO((void));
 int           edge_check          PROTO((double *x1, double *y1, double *x2, double *y2));
 void          findImages          PROTO((Catalog *catalog, int Ncatalog));
@@ -220,5 +221,5 @@
 int           setMrelOutput       PROTO((Catalog *catalog, int Ncatalog, int mark));
 void          set_ZP              PROTO((double ZERO));
-int           setrefcode          PROTO((Image *image, int Nimage)); 
+int           setrefcode          PROTO((Image *image, int Nimage));
 void          skip_measurements   PROTO((Catalog *catalog, int pass));
 void          sortA               PROTO((double *X, int N));
Index: /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/ConfigInit.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/ConfigInit.c	(revision 22723)
+++ /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/ConfigInit.c	(revision 22724)
@@ -20,4 +20,5 @@
 
   GetConfig (config, "RELASTRO_SIGMA_LIM",     "%lf", 0, &SIGMA_LIM);
+  GetConfig (config, "RELASTRO_MIN_SRC_FIT",   "%d",  0, &MIN_SRC_FIT);
 
   // XXX these are used in relphot to identify poor stars / images -- define
@@ -55,5 +56,5 @@
     fprintf (stderr, "directory %s does not exist, giving up\n", CATDIR);
     exit (1);
-  } 
+  }
 
   /* update master photcode table if not defined */
Index: /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/FitChip.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/FitChip.c	(revision 22723)
+++ /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/FitChip.c	(revision 22724)
@@ -1,3 +1,4 @@
 # include "relastro.h"
+# include "relastroVisual.h"
 
 // XXX make these user parameters
@@ -22,5 +23,4 @@
 
   ALLOCATE (values, double, Nmatch);
-
   for (Niter = 0; Niter < FIT_CHIP_NITER; Niter ++) {
 
@@ -33,5 +33,5 @@
       dM = raw[i].M - ref[i].M;
       dR = hypot (dL, dM);
-    
+
       values[Nscatter] = dR;
       Nscatter++;
@@ -41,4 +41,5 @@
     dsort (values, Nscatter);
     dRmax = FIT_CHIP_NSIGMA*values[(int)(0.40*Nscatter)];
+    relastroVisualPlotRawRef(raw, ref, dRmax, Nmatch);
 
     // fit the requested order polynomial
@@ -57,5 +58,5 @@
       dR = hypot (dL, dM);
       if (dR > dRmax) continue;
-    
+
       fit_add (fit, raw[i].X, raw[i].Y, ref[i].L, ref[i].M, raw[i].dPos);
     }
@@ -66,15 +67,15 @@
       case 0:
       case 1:
-	skip = (fit[0].Npts < 8);
-	break;
+        skip = (fit[0].Npts < 8);
+        break;
       case 2:
-	skip = (fit[0].Npts < 11);
-	break;
+        skip = (fit[0].Npts < 11);
+        break;
       case 3:
-	skip = (fit[0].Npts < 15);
-	break;
+        skip = (fit[0].Npts < 15);
+        break;
       default:
-	fprintf (stderr, "invalid chip order %d\n", coords[0].Npolyterms);
-	abort ();
+        fprintf (stderr, "invalid chip order %d\n", coords[0].Npolyterms);
+        abort ();
     }
     if (skip) {
@@ -95,4 +96,7 @@
       XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, coords);
     }
+
+    relastroVisualPlotRawRef(fit, coords, dRmax, Nmatch);
+
   }
 
Index: /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/ImageOps.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/ImageOps.c	(revision 22723)
+++ /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/ImageOps.c	(revision 22724)
@@ -91,7 +91,7 @@
   for (i = 0; VERBOSE && (i < Nimage); i++) {
     name = GetPhotcodeNamebyCode (image[i].photcode);
-    fprintf (stderr, "image %d has %d measures (%s, %s)\n", i, Nlist[i], 
-	     ohana_sec_to_date(image[i].tzero), name);
-  } 
+    fprintf (stderr, "image %d has %d measures (%s, %s)\n", i, Nlist[i],
+             ohana_sec_to_date(image[i].tzero), name);
+  }
 }
 
@@ -101,5 +101,5 @@
   int i;
   Measure *measure;
-  
+
   measure = &catalog[cat].measure[meas];
 
@@ -110,5 +110,5 @@
     if (measure[0].t < start[i]) continue;
     if (measure[0].t > stop[i]) continue;
-    
+
     // index for (catalog, measure) -> image
     bin[cat][meas] = i;
@@ -125,5 +125,5 @@
       REALLOCATE (clist[i], int, NLIST[i]);
       REALLOCATE (mlist[i], int, NLIST[i]);
-    }	
+    }
     return;
   }
@@ -157,5 +157,5 @@
 
   plot_defaults (&graphdata);
-  graphdata.ymin = PlotdMmin; 
+  graphdata.ymin = PlotdMmin;
   graphdata.ymax = PlotdMmax;
   plot_list (&graphdata, xlist, Mlist, Nimage, "airmass vs Mcal", "airmass.png");
@@ -191,8 +191,8 @@
   int i, m, c, n;
   double X, Y, L, M, P, Q, R, D, dR, dD;
-  
+
   Mosaic *mosaic;
   Coords *moscoords, *imcoords;
-  
+
   moscoords = NULL;
   mosaic = getMosaicForImage (im);
@@ -224,5 +224,5 @@
     dR = 3600.0*(catalog[c].average[n].R - R);
     dD = 3600.0*(catalog[c].average[n].D - D);
-    
+
     if (fabs(catalog[c].measure[m].dR - dR) > 10.0) {
       // XXXXX running into this still for last megacam exposure: wrong mosaic?
@@ -249,5 +249,5 @@
       catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R);
     }
-  }  
+  }
   return;
 }
@@ -259,9 +259,9 @@
 
   int i, m, c, n;
-  
+
   Mosaic *mosaic;
   Coords *moscoords;
   StarData *raw;
-  
+
   ALLOCATE (raw, StarData, Nlist[im]);
 
@@ -271,6 +271,6 @@
       mosaic = getMosaicForImage (im);
       if (mosaic == NULL) {
-	fprintf (stderr, "mosaic not found for image %s\n", image[im].name);
-	exit (1);
+        fprintf (stderr, "mosaic not found for image %s\n", image[im].name);
+        exit (1);
       }
       moscoords = &mosaic[0].coords;
@@ -284,5 +284,5 @@
     raw[i].X = catalog[c].measure[m].Xccd;
     raw[i].Y = catalog[c].measure[m].Yccd;
-    
+
     raw[i].Mag  = catalog[c].measure[m].M;
     raw[i].dMag = catalog[c].measure[m].dM;
@@ -293,5 +293,5 @@
     // an object with only one detection provides no information about the image calibration
     raw[i].mask = FALSE;
-    if (catalog[c].average[n].Nmeasure < 2) {
+    if (catalog[c].average[n].Nmeasure < MIN_SRC_FIT) {
       raw[i].mask = TRUE;
     }
@@ -299,20 +299,20 @@
     switch (mode) {
       case MODE_SIMPLE:
-	/* note that for a Simple image, L,M = P,Q */
-	XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[im].coords);
-	raw[i].P = raw[i].L;
-	raw[i].Q = raw[i].M;
-	LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, &image[im].coords);
-	break;
+        /* note that for a Simple image, L,M = P,Q */
+        XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[im].coords);
+        raw[i].P = raw[i].L;
+        raw[i].Q = raw[i].M;
+        LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, &image[im].coords);
+        break;
       case MODE_MOSAIC:
-	XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[im].coords);
-	XY_to_LM (&raw[i].P, &raw[i].Q, raw[i].L, raw[i].M, moscoords);
-	LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, moscoords);
-	break;
+        XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[im].coords);
+        XY_to_LM (&raw[i].P, &raw[i].Q, raw[i].L, raw[i].M, moscoords);
+        LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, moscoords);
+        break;
     default:
       fprintf (stderr, "error: invalid mode in getImageRaw");
       abort ();
     }
-  }  
+  }
 
   *Nstars = Nlist[im];
@@ -330,5 +330,5 @@
   Coords *moscoords;
   StarData *ref;
-  
+
   ALLOCATE (ref, StarData, Nlist[im]);
 
@@ -352,5 +352,5 @@
     ref[i].R = catalog[c].average[n].R;
     ref[i].D = catalog[c].average[n].D;
-    
+
     ref[i].Mag  = catalog[c].measure[m].M;
     ref[i].dMag = catalog[c].measure[m].dM;
@@ -373,9 +373,9 @@
       break;
       default:
-	fprintf (stderr, "invalid case");
-	abort();
-    }
-  }
-  
+        fprintf (stderr, "invalid case");
+        abort();
+    }
+  }
+
   *Nstars = Nlist[im];
   return (ref);
Index: /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/initialize.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/initialize.c	(revision 22723)
+++ /branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/initialize.c	(revision 22724)
@@ -25,6 +25,6 @@
       fprintf (stderr, "codename: %s\n", codename);
       if ((photcodesKeep[NphotcodesKeep] = GetPhotcodebyName (codename)) == NULL) {
-	fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename);
-	exit (1);
+        fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename);
+        exit (1);
       }
       NphotcodesKeep ++;
@@ -46,6 +46,6 @@
       fprintf (stderr, "codename: %s\n", codename);
       if ((photcodesSkip[NphotcodesSkip] = GetPhotcodebyName (codename)) == NULL) {
-	fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename);
-	exit (1);
+        fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename);
+        exit (1);
       }
       NphotcodesSkip ++;
