Index: trunk/psastro/src/psastroMosaicSetMatch.c
===================================================================
--- trunk/psastro/src/psastroMosaicSetMatch.c	(revision 7154)
+++ trunk/psastro/src/psastroMosaicSetMatch.c	(revision 7332)
@@ -7,4 +7,10 @@
     pmReadout *readout = NULL;
     pmFPAview *view = pmFPAviewAlloc (0);
+
+    FILE *f;
+    char name[128];
+
+    FILE *g1 = fopen ("raw.ps.dat", "w");
+    FILE *g2 = fopen ("ref.ps.dat", "w");
 
     // this loop selects the matched stars for all chips
@@ -23,5 +29,5 @@
 
 		// select the raw objects for this readout
-		psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.OBJECTS");
+		psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS");
 		if (rawstars == NULL) { continue; }
 
@@ -29,14 +35,52 @@
 		psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS");
 		if (refstars == NULL) { continue; }
+		psTrace (__func__, 4, "Trying %d refstars\n", refstars->n);
 
 		// use small radius to match stars (assume starting astrometry is good)
 		// XXX should this take a (double radius)?
-		psArray *matches = pmAstromRadiusMatch (rawstars, refstars, recipe);
+		psArray *matches = pmAstromRadiusMatchChip (rawstars, refstars, recipe);
+		psTrace (__func__, 4, "Matched %d 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++) {
+		    pmAstromMatch *match = matches->data[i];
+
+		    pmAstromObj *raw = rawstars->data[match->raw];
+		    fprintf (g1, "%d %f %f  %f %f  %f %f  %f %f\n", i, 
+			     DEG_RAD*raw->sky->r, DEG_RAD*raw->sky->d, 
+			     raw->TP->x, raw->TP->y, 
+			     raw->FP->x, raw->FP->y, 
+			     raw->chip->x, raw->chip->y);
+
+		    pmAstromObj *ref = refstars->data[match->ref];
+		    fprintf (g2, "%d %f %f  %f %f  %f %f  %f %f\n", i, 
+			     DEG_RAD*ref->sky->r, DEG_RAD*ref->sky->d, 
+			     ref->TP->x, ref->TP->y, 
+			     ref->FP->x, ref->FP->y, 
+			     ref->chip->x, ref->chip->y);
+		}
 
 		// XXX drop the old one
-		psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.MATCH", PS_DATA_ARRAY, "astrometry matches", matches);
+		psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.MATCH", PS_DATA_ARRAY | PS_META_REPLACE, "astrometry matches", matches);
 	    }
 	}
     }
+    fclose (g1);
+    fclose (g2);
     return true;
 }
