Index: trunk/psastro/src/psastroMosaicSetMatch.c
===================================================================
--- trunk/psastro/src/psastroMosaicSetMatch.c	(revision 9574)
+++ trunk/psastro/src/psastroMosaicSetMatch.c	(revision 10830)
@@ -1,5 +1,5 @@
 # include "psastro.h"
 
-bool psastroMosaicSetMatch (pmFPA *fpa, psMetadata *recipe) {
+bool psastroMosaicSetMatch (pmFPA *fpa, psMetadata *recipe, int iteration) {
 
     pmChip *chip = NULL;
@@ -7,10 +7,17 @@
     pmReadout *readout = NULL;
     pmFPAview *view = pmFPAviewAlloc (0);
-
-    FILE *f;
-    char name[128];
+    char radiusWord[64];
 
     FILE *g1 = fopen ("raw.ps.dat", "w");
     FILE *g2 = fopen ("ref.ps.dat", "w");
+
+    // use small radius to match stars (assume starting astrometry is good)
+    bool status = false; 
+    sprintf (radiusWord, "PSASTRO.MOSAIC.RADIUS.N%d", iteration);
+    double RADIUS = psMetadataLookupF32 (&status, recipe, radiusWord); 
+    if (!status) { 
+	psError(PS_ERR_IO, false, "Failed to lookup matching radius: %s", radiusWord); 
+	return NULL; 
+    } 
 
     // this loop selects the matched stars for all chips
@@ -37,24 +44,6 @@
 		psTrace ("psastro", 4, "Trying %ld refstars\n", refstars->n);
 
-		// use small radius to match stars (assume starting astrometry is good)
-		// XXX should this take a (double radius)?
-		psArray *matches = pmAstromRadiusMatchChip (rawstars, refstars, recipe);
+		psArray *matches = pmAstromRadiusMatchChip (rawstars, refstars, RADIUS);
 		psTrace ("psastro", 4, "Matched %ld refstars\n", matches->n);
-
-		sprintf (name, "raw.%02d.dat", view->chip);
-		f = fopen (name, "w");
-		for (int i = 0; i < rawstars->n; i++) {
-		    pmAstromObj *raw = rawstars->data[i];
-		    fprintf (f, "%f %f  %f %f  %f %f\n", raw->chip->x, raw->chip->y, raw->FP->x, raw->FP->y, raw->sky->r, raw->sky->d);
-		}
-		fclose (f);
-
-		sprintf (name, "ref.%02d.dat", view->chip);
-		f = fopen (name, "w");
-		for (int i = 0; i < refstars->n; i++) {
-		    pmAstromObj *ref = refstars->data[i];
-		    fprintf (f, "%f %f  %f %f  %f %f\n", ref->chip->x, ref->chip->y, ref->FP->x, ref->FP->y, ref->sky->r, ref->sky->d);
-		}
-		fclose (f);
 
 		for (int i = 0; i < matches->n; i++) {
