Index: /trunk/psastro/src/psastroMosaicGetRefstars.c
===================================================================
--- /trunk/psastro/src/psastroMosaicGetRefstars.c	(revision 7636)
+++ /trunk/psastro/src/psastroMosaicGetRefstars.c	(revision 7637)
@@ -52,9 +52,7 @@
 		float minY = -fieldExtra*Ny;
 		float maxY = (1+fieldExtra)*Ny;
-		
+
 		// the refstars is a subset within range of this chip
 		psArray *refstars = psArrayAlloc (100);
-
-		int Nst = 0;
 
 		// select the reference objects within range of this readout
@@ -68,47 +66,15 @@
 
 		    // limit the X,Y range of the refs to the selected chip
-		    if (ref->chip->x < minX) continue;
-		    if (ref->chip->x > maxX) continue;
-		    if (ref->chip->y < minY) continue;
-		    if (ref->chip->y > maxY) continue;
-		    
-		    if (Nst < 0) {
-			fprintf (stderr, "dn: %f,%f <- %f,%f <- %f,%f <- %f,%f\n", 
-				 ref->chip->x, ref->chip->y, 
-				 ref->FP->x, ref->FP->y, 
-				 ref->TP->x, ref->TP->y, 
-				 ref->sky->r, ref->sky->d);
-
-			psSphere *sk = psSphereAlloc();
-			psPlane *fp = psPlaneAlloc();
-			psPlane *tp = psPlaneAlloc();
-
-			psPlaneTransformApply (fp, chip->toFPA, ref->chip);
-			psPlaneDistortApply (tp, fpa->toTangentPlane, fp, 0.0, 0.0);
-			p_psDeproject (sk, tp, fpa->projection);
-
-			fprintf (stderr, "up: %f,%f -> %f,%f -> %f,%f -> %f,%f\n", 
-				 ref->chip->x, ref->chip->y, 
-				 fp->x, fp->y, 
-				 tp->x, tp->y, 
-				 sk->r, sk->d);
-		    }
-		    Nst ++;
+		    if (ref->chip->x < minX) goto skip;
+		    if (ref->chip->x > maxX) goto skip;
+		    if (ref->chip->y < minY) goto skip;
+		    if (ref->chip->y > maxY) goto skip;
 
 		    psArrayAdd (refstars, 100, ref);
+		skip:
+		    psFree (ref);
 		}
 		psTrace (__func__, 4, "Added %d refstars\n", refstars->n);
-
 		psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS", PS_DATA_ARRAY, "astrometry matches", refstars);
-
-		// XXX test point
-		if (0) { 
-		    pmChip *chip1 = fpa->chips->data[10];
-		    pmCell *cell1 = chip1->cells->data[0];
-		    pmReadout *readout1 = cell1->readouts->data[0];
-		    psArray *refstars1 = psMetadataLookupPtr (NULL, readout1->analysis, "PSASTRO.REFSTARS");
-		    pmAstromObj *ref1 = refstars1->data[0];
-		    fprintf (stderr, "test 3: %f %f  %f %f  %f %f\n", ref1->chip->x, ref1->chip->y, ref1->FP->x, ref1->FP->y, ref1->sky->r, ref1->sky->d);
-		}
 
 		psFree (refstars);
