Index: /trunk/psastro/src/psastro.h
===================================================================
--- /trunk/psastro/src/psastro.h	(revision 12717)
+++ /trunk/psastro/src/psastro.h	(revision 12718)
@@ -59,10 +59,10 @@
 bool psastroMosaicCommonScale (pmFPA *fpa, psMetadata *recipe);
 bool psastroMosaicAstrom (pmConfig *config, psArray *refs);
-bool psastroMosaicChipAstrom (pmFPA *fpa, psMetadata *recipe, bool nonlinear);
+bool psastroMosaicChipAstrom (pmFPA *fpa, psMetadata *recipe, int iteration);
 bool psastroMosaicSetMatch (pmFPA *fpa, psMetadata *recipe, int iteration);
 bool psastroMosaicSetAstrom (pmFPA *fpa);
 bool psastroMosaicHeaders (pmConfig *config);
 bool psastroMosaicRescaleChips (pmFPA *fpa);
-bool psastroMosaicOneChip (pmChip *chip, pmReadout *readout, psMetadata *recipe, psMetadata *updates, bool nonlinear);
+bool psastroMosaicOneChip (pmChip *chip, pmReadout *readout, psMetadata *recipe, psMetadata *updates, int iteration);
 
 // Return version strings.
Index: /trunk/psastro/src/psastroChipAstrom.c
===================================================================
--- /trunk/psastro/src/psastroChipAstrom.c	(revision 12717)
+++ /trunk/psastro/src/psastroChipAstrom.c	(revision 12718)
@@ -47,4 +47,5 @@
 		// the absolute minimum number of stars is 4 (for order = 1)
 		if ((rawstars->n < 4) || (refstars->n < 4)) {
+		    readout->data_exists = false;
 		    psLogMsg ("psastro", 3, "insufficient rawstars (%ld) or refstars (%ld)", 
 			    rawstars->n, refstars->n);
@@ -72,4 +73,5 @@
 		// XXX update the header with info to reflect the failure
 		if (!psastroOneChip (fpa, chip, refstars, rawstars, recipe, updates)) {
+		    readout->data_exists = false;
 		    psLogMsg ("psastro", 3, "failed to find a solution\n");
 		    psFree (updates);
Index: /trunk/psastro/src/psastroChooseRefstars.c
===================================================================
--- /trunk/psastro/src/psastroChooseRefstars.c	(revision 12717)
+++ /trunk/psastro/src/psastroChooseRefstars.c	(revision 12718)
@@ -80,4 +80,7 @@
                 psFree (refstars);
 
+		// XXX TEST : skip the luminosity function selection
+		continue;
+
 		// XXX this error means the readout fails, but should probably not kill the entire program
 		// in this case, no PSASTRO.REFSTARS is added to readout->analysis
Index: /trunk/psastro/src/psastroLoadRefstars.c
===================================================================
--- /trunk/psastro/src/psastroLoadRefstars.c	(revision 12717)
+++ /trunk/psastro/src/psastroLoadRefstars.c	(revision 12718)
@@ -19,5 +19,5 @@
     float DECmin = DEG_RAD*psMetadataLookupF32(NULL, recipe, "DEC_MIN");
     float DECmax = DEG_RAD*psMetadataLookupF32(NULL, recipe, "DEC_MAX");
-    float MAGmax = psMetadataLookupF32(NULL, recipe, "MAG_MAX");
+    // float MAGmax = psMetadataLookupF32(NULL, recipe, "MAG_MAX");
 
     // XXX CATDIR needs to look up abstracted name from psastro.config
@@ -53,6 +53,8 @@
 
     // XXX set getstar in config?
+    // XXX TEST : no magnitude limit
     // psStringAppend (&getstarLine, "/home/kiawe/eugene/psconfig/dev.lin64/bin/getstar %s -D CATMODE mef -maglim %f -region %f %f %f %f -o %s", catformat, MAGmax, RAmin, DECmin, RAmax, DECmax, tempFile);
-    psStringAppend (&getstarLine, "/home/kiawe/eugene/psconfig/dev.lin64/bin/getstar %s -D CATMODE mef -maglim %f -region %f %f %f %f -o %s", catformat, MAGmax, RAmin, DECmin, RAmax, DECmax, tempFile);
+    // psStringAppend (&getstarLine, "/home/kiawe/eugene/psconfig/dev.lin64/bin/getstar %s -D CATMODE mef -maglim %f -region %f %f %f %f -o %s", catformat, MAGmax, RAmin, DECmin, RAmax, DECmax, tempFile);
+    psStringAppend (&getstarLine, "/home/kiawe/eugene/psconfig/dev.lin64/bin/getstar %s -D CATMODE mef -region %f %f %f %f -o %s", catformat, RAmin, DECmin, RAmax, DECmax, tempFile);
     psTrace ("psastro", 3, "%s\n", getstarLine);
 
Index: /trunk/psastro/src/psastroMosaicAstrom.c
===================================================================
--- /trunk/psastro/src/psastroMosaicAstrom.c	(revision 12717)
+++ /trunk/psastro/src/psastroMosaicAstrom.c	(revision 12718)
@@ -74,5 +74,5 @@
     if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.4.dat"); }
 
-    if (!psastroMosaicChipAstrom (fpa, recipe, false)) {
+    if (!psastroMosaicChipAstrom (fpa, recipe, 0)) {
 	psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode (2nd pass)");
 	return false;
@@ -82,9 +82,9 @@
     // now fit the chips under the common distortion with higher-order terms
     // first, re-perform the match with a slightly tighter circle
-    if (!psastroMosaicSetMatch (fpa, recipe, 1)) {
+    if (!psastroMosaicSetMatch (fpa, recipe, 2)) {
 	psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic (3rd pass)");
 	return false;
     }
-    if (!psastroMosaicChipAstrom (fpa, recipe, true)) {
+    if (!psastroMosaicChipAstrom (fpa, recipe, 1)) {
 	psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode (3rd pass)");
 	return false;
Index: /trunk/psastro/src/psastroMosaicChipAstrom.c
===================================================================
--- /trunk/psastro/src/psastroMosaicChipAstrom.c	(revision 12717)
+++ /trunk/psastro/src/psastroMosaicChipAstrom.c	(revision 12718)
@@ -2,5 +2,5 @@
 # define NONLIN_TOL 0.001 /* tolerance in pixels */
 
-bool psastroMosaicChipAstrom (pmFPA *fpa, psMetadata *recipe, bool nonlinear) {
+bool psastroMosaicChipAstrom (pmFPA *fpa, psMetadata *recipe, int iteration) {
 
     pmChip *chip = NULL;
@@ -26,5 +26,10 @@
 		psMetadata *updates = psMetadataAlloc();
 
-		psastroMosaicOneChip (chip, readout, recipe, updates, nonlinear);
+		if (!psastroMosaicOneChip (chip, readout, recipe, updates, iteration)) {
+		    readout->data_exists = false;
+		    psLogMsg ("psastro", 3, "failed to find a solution for %d,%d,%d\n", view->chip, view->cell, view->readout);
+		    psFree (updates);
+		    continue;
+		}
 
 		// create the header keywords to descripe the results
Index: /trunk/psastro/src/psastroMosaicOneChip.c
===================================================================
--- /trunk/psastro/src/psastroMosaicOneChip.c	(revision 12717)
+++ /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;
 }
Index: /trunk/psastro/src/psastroOneChip.c
===================================================================
--- /trunk/psastro/src/psastroOneChip.c	(revision 12717)
+++ /trunk/psastro/src/psastroOneChip.c	(revision 12718)
@@ -154,5 +154,5 @@
     psFree (fitStats);
     psFree (gridStats);
-    return true;
+    return validSolution;
 }
 
