Index: trunk/psastro/src/psastroMosaicOneChip.c
===================================================================
--- trunk/psastro/src/psastroMosaicOneChip.c	(revision 24036)
+++ trunk/psastro/src/psastroMosaicOneChip.c	(revision 24037)
@@ -58,8 +58,13 @@
 
     // modify the order to correspond to the actual number of matched stars:
-    if ((match->n < 17) && (order >= 3)) order = 2;
-    if ((match->n < 13) && (order >= 2)) order = 1;
-    if ((match->n <  9) && (order >= 1)) order = 0;
-    if ((match->n <  3) || (order < 0) || (order > 3)) {
+    int Ndof_min = 3;
+    int order_max = 0.5*(sqrt(4*match->n - 4*Ndof_min + 1) - 3);
+    order = PS_MIN (order, order_max);
+
+    // if ((match->n < 17) && (order >= 3)) order = 2;
+    // if ((match->n < 13) && (order >= 2)) order = 1;
+    // if ((match->n <  9) && (order >= 1)) order = 0;
+
+    if (order < 0) {
         psLogMsg ("psastro", 3, "insufficient stars (%ld) or invalid order (%d)", match->n, order);
         return false;
