Index: branches/pap/psastro/src/psastroOneChipFit.c
===================================================================
--- branches/pap/psastro/src/psastroOneChipFit.c	(revision 23948)
+++ branches/pap/psastro/src/psastroOneChipFit.c	(revision 25027)
@@ -64,6 +64,18 @@
         // modify the order to correspond to the actual number of matched stars:
         int Ndof_min = 3;
-        int order_max = 0.5*(3 + sqrt(4*match->n - 4*Ndof_min + 1));
+        int order_max = 0.5*(sqrt(4*match->n - 4*Ndof_min + 1) - 3);
         order = PS_MIN (order, order_max);
+
+	// order 0 : Ro -> nterms = 1 * 2;
+	// order 1 : Ro, Rx, Ry -> nterms = 3 * 2;
+	// order 2 : Ro, Rx, Ry, Rxx, Rxy, Ryy -> nterms = 6 * 2;
+	// order 3 : Ro, Rx, Ry, Rxx, Rxy, Ryy, Rxxx, Rxxy, Rxyy, Ryyy -> nterms = 10 * 2
+	// 2*(N+1)*(N+2)/2 = (N+1)*(N+2) = nterms;
+	// (order+1)(order+2) + ndof = nvalues
+	// order^2 + 3*order + 2 + ndof = nvalue;
+	// order^2 + 3*order + 2 + ndof - nvalue = 0;
+	// 2*order = -3 +/- sqrt (9 - 4*(2 - nvalue + ndof));
+	// 2*order = -3 +/- sqrt (9 - 8 + 4*nvalue - 4*ndof);
+	// 2*order = (sqrt (1 + 4*nvalue - 4*ndof) - 3);
 
         // if ((match->n < 11) && (order >= 3)) order = 2;
