Index: /trunk/Ohana/src/gastro2/src/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/gastro2/src/ConfigInit.c	(revision 3389)
+++ /trunk/Ohana/src/gastro2/src/ConfigInit.c	(revision 3390)
@@ -19,5 +19,4 @@
   ScanConfig (config, "DEFAULT_RADIUS",    "%lf", 0, &DEFAULT_RADIUS);
   ScanConfig (config, "MINIMUM_RADIUS",    "%lf", 0, &MINIMUM_RADIUS);
-  ScanConfig (config, "MAX_ERROR",         "%lf", 0, &MAX_ERROR);
   ScanConfig (config, "MAX_NONLINEAR",     "%lf", 0, &MAX_NONLINEAR);
   ScanConfig (config, "MAX_PRECISE",       "%lf", 0, &MIN_PRECISE);
@@ -47,4 +46,5 @@
   ScanConfig (config, "PHOTCODE_FILE",     "%s",  0, PhotCodeFile);
   ScanConfig (config, "GASTRO_MAX_NSTARS", "%d",  0, &GASTRO_MAX_NSTARS);
+  ScanConfig (config, "GASTRO_MAX_MAG_ERROR", "%lf", 0, &MAX_ERROR);
 
   if (strcasecmp (ROUGH_ASTROMETRY, "header") && 
Index: /trunk/Ohana/src/gastro2/src/gastro2.c
===================================================================
--- /trunk/Ohana/src/gastro2/src/gastro2.c	(revision 3389)
+++ /trunk/Ohana/src/gastro2/src/gastro2.c	(revision 3390)
@@ -31,5 +31,5 @@
 
   for (i = 0; i < 3; i++) {
-    gfit (&Target, &Ref, 1);
+    gfit (&Target, &Ref, MIN (MAX (1, NPOLYTERMS), 3));
     fprintf (stderr, "precision: %f\n", Target.answer.dR / sqrt(Target.answer.N));
   }
Index: /trunk/Ohana/src/gastro2/src/gproject2.c
===================================================================
--- /trunk/Ohana/src/gastro2/src/gproject2.c	(revision 3389)
+++ /trunk/Ohana/src/gastro2/src/gproject2.c	(revision 3390)
@@ -61,4 +61,11 @@
     
   Subset[0].N = N;
+  sort_stars_mag (Subset[0].stars, N);
+  if (GASTRO_MAX_NSTARS && (GASTRO_MAX_NSTARS < Subset[0].N)) {
+    Subset[0].N = GASTRO_MAX_NSTARS;
+    REALLOCATE (Subset[0].stars, StarData, Subset[0].N);
+  }
+  if (VERBOSE) fprintf (stderr, "using %d stars from ref catalog\n", Subset[0].N);
+
   REALLOCATE (Subset[0].stars, StarData, MAX (1, Subset[0].N));
 
Index: /trunk/Ohana/src/gastro2/src/gstars2.c
===================================================================
--- /trunk/Ohana/src/gastro2/src/gstars2.c	(revision 3389)
+++ /trunk/Ohana/src/gastro2/src/gstars2.c	(revision 3390)
@@ -153,5 +153,5 @@
       /* hardwired dophot exclusions should eventually be encapsulated elsewhere */
       if ((type == 4) || (type == 6) || (type == 5) || (type == 9)) continue;
-      if (dmag > 100) continue;
+      if (dmag > 1000*MAX_ERROR) continue;
       stars[N].dM   = 0.001 * dmag;
       stars[N].type = type;
