Index: /trunk/psastro/src/psastroOneChipFit.c
===================================================================
--- /trunk/psastro/src/psastroOneChipFit.c	(revision 20793)
+++ /trunk/psastro/src/psastroOneChipFit.c	(revision 20794)
@@ -51,7 +51,12 @@
 
 	// modify the order to correspond to the actual number of matched stars:
-	if ((match->n < 11) && (order >= 3)) order = 2;
-	if ((match->n <  7) && (order >= 2)) order = 1;
-	if ((match->n <  4) && (order >= 1)) order = 0;
+	int Ndof_min = 3;
+	int order_max = 0.5*(3 + sqrt(4*match->n - 4*Ndof_min + 1));
+	order = PS_MIN (order, order_max);
+
+	// if ((match->n < 11) && (order >= 3)) order = 2;
+	// if ((match->n <  7) && (order >= 2)) order = 1;
+	// if ((match->n <  4) && (order >= 1)) order = 0;
+
 	if (order < 1) {
 	    psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n); 
