Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/include/relastro.h
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/include/relastro.h	(revision 35668)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/include/relastro.h	(revision 35669)
@@ -194,4 +194,7 @@
 
 int PhotFlagSelect, PhotFlagPoor, PhotFlagBad;
+
+float MinBadQF;
+float MaxMeanOffset;
 
 int TimeSelect;
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/ImageOps.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/ImageOps.c	(revision 35668)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/ImageOps.c	(revision 35669)
@@ -1019,4 +1019,8 @@
   }  
   
+  // if (MinBadQF > 0.0) {
+  //   if (measure[0].psfQF < MinBadQF) return FALSE;
+  // }
+
   /* select measurements by time */
   if (TimeSelect) {
@@ -1081,4 +1085,8 @@
   }  
   
+  if (MinBadQF > 0.0) {
+    if (measure[0].psfQF < MinBadQF) return FALSE;
+  }
+
   /* select measurements by time */
   if (TimeSelect) {
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateObjectOffsets.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateObjectOffsets.c	(revision 35668)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateObjectOffsets.c	(revision 35669)
@@ -128,4 +128,7 @@
     // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
 
+    if (MinBadQF > 0.0)    { snprintf (tmpline, 1024, "%s -min-bad-psfqf %f",        command, MinBadQF);      strcpy (command, tmpline); }
+    if (MaxMeanOffset != 10.0) { snprintf (tmpline, 1024, "%s -max-mean-offset  %f", command, MaxMeanOffset); strcpy (command, tmpline); }
+
     if (TimeSelect) { 
       char *tstart = ohana_sec_to_date (TSTART);
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateObjects.c	(revision 35668)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/UpdateObjects.c	(revision 35669)
@@ -48,6 +48,6 @@
   PMFit fitAve, fitPM, fitPAR, fit;
   time_t T2000;
-  off_t Nave, Npm, Npar, Nskip;
-  off_t NaveSum, NpmSum, NparSum, NskipSum;
+  off_t Nave, Npm, Npar, Nskip, Noffset;
+  off_t NaveSum, NpmSum, NparSum, NskipSum, NoffSum;
   double Tmin, Tmax, Tmean, Trange;
 
@@ -80,10 +80,10 @@
   }
 
-  NaveSum = NparSum = NpmSum = NskipSum = 0;
+  NaveSum = NparSum = NpmSum = NoffSum = NskipSum = 0;
   for (i = 0; i < Ncatalog; i++) {
 
     if (VERBOSE2) fprintf (stderr, "astrometrize catalog %d : "OFF_T_FMT" ave, "OFF_T_FMT" meas\n", i,  catalog[i].Naverage,  catalog[i].Nmeasure);
 
-    Nave = Npar = Npm = Nskip = 0;
+    Nave = Npar = Npm = Nskip = Noffset = 0;
     for (j = 0; j < catalog[i].Naverage; j++) {
       /* calculate the average value of R,D for a single star */
@@ -121,5 +121,7 @@
 
 	// does the measurement pass the supplied filtering constraints?
-	if (!MeasFilterTestTiny(&measure[k], FALSE)) {
+	// MeasFilterTestTiny does not test psfQF
+	int keepMeasure = measureBig ? MeasFilterTest(&measureBig[k], FALSE) : MeasFilterTestTiny(&measure[k], FALSE);
+	if (!keepMeasure) {
 	  measure[k].dbFlags &= ~ID_MEAS_USED_OBJ;
 	  if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; }
@@ -345,4 +347,17 @@
 	continue;
       }
+
+      // what is the offset relative to the mean fit position?
+      coords.crval1 = catalog[i].average[j].R;
+      coords.crval2 = catalog[i].average[j].D;
+
+      double dXoff, dYoff;
+      RD_to_XY (&dXoff, &dYoff, fit.Ro, fit.Do, &coords);
+      float dPos = hypot (dXoff, dYoff);
+      if (dPos > MaxMeanOffset) {
+	Noffset ++;
+	continue;
+      }
+
 
       // the measure fields must be updated before the average fields
@@ -390,8 +405,9 @@
     NparSum += Npar;
     NskipSum += Nskip;
-    if (VERBOSE) fprintf (stderr, "catalog %d : "OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par : Nskip "OFF_T_FMT"\n",  i,  Nave,  Npm,  Npar,  Nskip);
+    NoffSum += Noffset;
+    if (VERBOSE) fprintf (stderr, "catalog %d : "OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par : Nskip "OFF_T_FMT", Noffset "OFF_T_FMT"\n",  i,  Nave,  Npm,  Npar,  Nskip, Noffset);
   }
 
-  if (VERBOSE) fprintf (stderr, "fitted "OFF_T_FMT" objects ("OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par), skipped "OFF_T_FMT"\n",  (NaveSum + NpmSum + NparSum),  NaveSum,  NpmSum,  NparSum,  NskipSum);
+  if (VERBOSE) fprintf (stderr, "fitted "OFF_T_FMT" objects ("OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par), skipped "OFF_T_FMT", "OFF_T_FMT" have too large an offset\n",  (NaveSum + NpmSum + NparSum),  NaveSum,  NpmSum,  NparSum,  NskipSum, NoffSum);
   return (TRUE);
 }
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/args.c	(revision 35668)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/args.c	(revision 35669)
@@ -382,4 +382,18 @@
   }
 
+  MinBadQF = 0.0;
+  if ((N = get_argument (argc, argv, "-min-bad-psfqf"))) {
+    remove_argument (N, &argc, argv);
+    MinBadQF = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  MaxMeanOffset = 10.0;
+  if ((N = get_argument (argc, argv, "-max-mean-offset"))) {
+    remove_argument (N, &argc, argv);
+    MaxMeanOffset = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
   NLOOP = 4;
   if ((N = get_argument (argc, argv, "-nloop"))) {
@@ -675,4 +689,18 @@
     remove_argument (N, &argc, argv);
     PhotFlagPoor = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  MinBadQF = 0.0;
+  if ((N = get_argument (argc, argv, "-min-bad-psfqf"))) {
+    remove_argument (N, &argc, argv);
+    MinBadQF = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  MaxMeanOffset = 10.0;
+  if ((N = get_argument (argc, argv, "-max-mean-offset"))) {
+    remove_argument (N, &argc, argv);
+    MaxMeanOffset = atof (argv[N]);
     remove_argument (N, &argc, argv);
   }
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/high_speed_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/high_speed_catalogs.c	(revision 35668)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/high_speed_catalogs.c	(revision 35669)
@@ -162,4 +162,7 @@
     if (PhotFlagPoor)      { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor);    strcpy (command, tmpline); }
     // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
+
+    if (MinBadQF > 0.0)    { snprintf (tmpline, 1024, "%s -min-bad-psfqf %f",        command, MinBadQF);      strcpy (command, tmpline); }
+    if (MaxMeanOffset != 10.0) { snprintf (tmpline, 1024, "%s -max-mean-offset  %f", command, MaxMeanOffset); strcpy (command, tmpline); }
 
     if (WHERE_A[0]) { snprintf (tmpline, 1024, "%s -D WHERE_A \"%s\"", command, WHERE_A);               strcpy (command, tmpline); }
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/hpm_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/hpm_catalogs.c	(revision 35668)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/hpm_catalogs.c	(revision 35669)
@@ -160,4 +160,7 @@
     if (PhotFlagPoor)      { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor);    strcpy (command, tmpline); }
     // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
+
+    if (MinBadQF > 0.0)    { snprintf (tmpline, 1024, "%s -min-bad-psfqf %f",        command, MinBadQF);      strcpy (command, tmpline); }
+    if (MaxMeanOffset != 10.0) { snprintf (tmpline, 1024, "%s -max-mean-offset  %f", command, MaxMeanOffset); strcpy (command, tmpline); }
 
     if (TimeSelect) { 
Index: /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro_objects.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro_objects.c	(revision 35668)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/relastro/src/relastro_objects.c	(revision 35669)
@@ -154,8 +154,11 @@
     if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, 1024, "%s +photcode %s", command, PHOTCODE_KEEP_LIST); strcpy (command, tmpline); }
     if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, 1024, "%s -photcode %s", command, PHOTCODE_SKIP_LIST); strcpy (command, tmpline); }
-    if (PhotFlagSelect)    { snprintf (tmpline, 1024, "%s +photflags",   command);                     strcpy (command, tmpline); }
-    if (PhotFlagBad)       { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad);     strcpy (command, tmpline); }
-    if (PhotFlagPoor)      { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor);   strcpy (command, tmpline); }
+    if (PhotFlagSelect)    { snprintf (tmpline, 1024, "%s +photflags",   command);                     	strcpy (command, tmpline); }
+    if (PhotFlagBad)       { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad);     	strcpy (command, tmpline); }
+    if (PhotFlagPoor)      { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor);   	strcpy (command, tmpline); }
     // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
+
+    if (MinBadQF > 0.0)    { snprintf (tmpline, 1024, "%s -min-bad-psfqf %f",        command, MinBadQF);      strcpy (command, tmpline); }
+    if (MaxMeanOffset != 10.0) { snprintf (tmpline, 1024, "%s -max-mean-offset  %f", command, MaxMeanOffset); strcpy (command, tmpline); }
 
     if (TimeSelect) { 
