Index: trunk/psastro/src/psastroMosaicOneChip.c
===================================================================
--- trunk/psastro/src/psastroMosaicOneChip.c	(revision 10880)
+++ trunk/psastro/src/psastroMosaicOneChip.c	(revision 12718)
@@ -7,7 +7,8 @@
    return false; } 
 
-bool psastroMosaicOneChip (pmChip *chip, pmReadout *readout, psMetadata *recipe, psMetadata *updates, bool nonlinear) {
+bool psastroMosaicOneChip (pmChip *chip, pmReadout *readout, psMetadata *recipe, psMetadata *updates, int iteration) {
 
     bool status;
+    char errorWord[64];
 
     PS_ASSERT_PTR_NON_NULL(chip,    false);
@@ -30,17 +31,18 @@
 
     // allowed limits for valid solutions
-    REQUIRED_RECIPE_VALUE (float maxError, "PSASTRO.MOSAIC.MAX.ERROR", F32, "failed to find single-chip max allowed error\n");
+    sprintf (errorWord, "PSASTRO.MOSAIC.MAX.ERROR.N%d", iteration);
+    REQUIRED_RECIPE_VALUE (float maxError, errorWord, F32, "failed to find single-chip max allowed error\n");
     REQUIRED_RECIPE_VALUE (int minNstar, "PSASTRO.MOSAIC.MIN.NSTAR", S32, "failed to find single-chip min allowed stars\n");
 
-    // set the order of the per-chip fit (higher order only if nonlinear == true)
+    // set the order of the per-chip fit (higher order only if iteration > 0)
     int order = 1;
-    if (nonlinear) {
+    if (iteration > 0) {
 	// select the desired chip order
 	REQUIRED_RECIPE_VALUE (order, "PSASTRO.MOSAIC.CHIP.ORDER", S32, "failed to find mosaic chip-level fit order\n");
 
 	// 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;
+	if ((match->n < 15) && (order >= 3)) order = 2;
+	if ((match->n < 11) && (order >= 2)) order = 1;
+	if ((match->n <  8) && (order >= 1)) order = 0;
 	if (order < 1) {
 	    psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n); 
@@ -84,4 +86,9 @@
     int astNstar = results->yStats->clippedNvalues;
 
+    // if we clip away too many stars, the order may be invalid
+    if (order == 3) { minNstar = PS_MAX (15, minNstar); }
+    if (order == 2) { minNstar = PS_MAX (11, minNstar); }
+    if (order == 1) { minNstar = PS_MAX ( 8, minNstar); }
+
     bool validSolution = true;
 
@@ -114,4 +121,4 @@
     psFree (fitStats);
     psFree (results);
-    return true;
+    return validSolution;
 }
