Index: trunk/psastro/src/psastroAstromGuess.c
===================================================================
--- trunk/psastro/src/psastroAstromGuess.c	(revision 7014)
+++ trunk/psastro/src/psastroAstromGuess.c	(revision 7332)
@@ -3,8 +3,11 @@
 // XXX this function assumes the initial astrometry arrives in the form of
 // XXX WCS keywords in the headers corresponding to the chips.
+// XXX this function is both converting the header WCS astrometry terms to the fpa terms
+//     and applying the astrometry to the detected objects.  
 bool psastroAstromGuess (pmConfig *config) {
 
     bool newFPA = true;
     bool status = false;
+    bool isMosaic = false;
     double RAmin, RAmax, RAminSky, RAmaxSky;
     double DECmin, DECmax;
@@ -13,4 +16,7 @@
     pmCell *cell = NULL;
     pmReadout *readout = NULL;
+
+    // is this a mosaic astrometry analysis?
+    psMetadataLookupStr (&isMosaic, config->arguments, "MOSASTRO");
 
     // select the current recipe
@@ -30,4 +36,5 @@
     double plateScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLATE.SCALE");
     if (!status) plateScale = 1.0;
+    plateScale = 1.0;
 
     pmFPAview *view = pmFPAviewAlloc (0);
@@ -41,5 +48,5 @@
         pmHDU *hdu = pmFPAviewThisHDU (view, fpa);
 
-	pmAstromReadWCS (&fpa->projection, &fpa->toTangentPlane, &chip->toFPA, hdu->header, plateScale);
+	pmAstromReadWCS (fpa, chip, hdu->header, plateScale, isMosaic);
 	if (newFPA) {
 	    newFPA = false;
@@ -49,10 +56,4 @@
 	    DECmin = DECmax = fpa->projection->D;
 	}
-
-	// build projection inversions
-	// XXX region should be set from image data
-	psRegion region = {0, 0, 2000, 4500};
-	fpa->fromTangentPlane = psPlaneDistortIdentity ();
-	chip->fromFPA = psPlaneTransformInvert (NULL, chip->toFPA, region, 20);
 
 	// apply the new WCS guess data to all of the data in the readouts
@@ -66,23 +67,45 @@
 		if (! readout->data_exists) { continue; }
 
-		psArray *objects = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.OBJECTS");
-		if (objects == NULL) { continue; }
+		psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS");
+		if (rawstars == NULL) { continue; }
 
-		for (int i = 0; i < objects->n; i++) {
-		    pmAstromObj *object = objects->data[i];
+		for (int i = 0; i < rawstars->n; i++) {
+		    pmAstromObj *raw = rawstars->data[i];
 	
-		    psPlaneTransformApply (object->FP, chip->toFPA, object->chip);
-		    psPlaneDistortApply (object->TP, fpa->toTangentPlane, object->FP, 0.0, 0.0);
-		    p_psDeproject (object->sky, object->TP, fpa->projection);
+		    psPlaneTransformApply (raw->FP, chip->toFPA, raw->chip);
+		    psPlaneDistortApply (raw->TP, fpa->toTangentPlane, raw->FP, 0.0, 0.0);
+		    p_psDeproject (raw->sky, raw->TP, fpa->projection);
+
+		    if (i < 0) {
+			fprintf (stderr, "up: %f,%f -> %f,%f -> %f,%f -> %f,%f\n", 
+				 raw->chip->x, raw->chip->y, 
+				 raw->FP->x, raw->FP->y, 
+				 raw->TP->x, raw->TP->y, 
+				 raw->sky->r, raw->sky->d);
+
+			psPlane *fp = psPlaneAlloc();
+			psPlane *tp = psPlaneAlloc();
+			psPlane *ch = psPlaneAlloc();
+
+			p_psProject (tp, raw->sky, fpa->projection);
+			psPlaneDistortApply (fp, fpa->fromTangentPlane, tp, 0.0, 0.0);
+			psPlaneTransformApply (ch, chip->fromFPA, fp);
+
+			fprintf (stderr, "dn: %f,%f <- %f,%f <- %f,%f <- %f,%f\n", 
+				 ch->x, ch->y, 
+				 fp->x, fp->y, 
+				 tp->x, tp->y, 
+				 raw->sky->r, raw->sky->d);
+		    }
 
 		    // rationalize ra to sky range centered on boresite
-		    while (object->sky->r < RAminSky) object->sky->r += M_PI;
-		    while (object->sky->r > RAmaxSky) object->sky->r -= M_PI;
+		    while (raw->sky->r < RAminSky) raw->sky->r += M_PI;
+		    while (raw->sky->r > RAmaxSky) raw->sky->r -= M_PI;
 
-		    RAmin = PS_MIN (object->sky->r, RAmin);
-		    RAmax = PS_MAX (object->sky->r, RAmax);
+		    RAmin = PS_MIN (raw->sky->r, RAmin);
+		    RAmax = PS_MAX (raw->sky->r, RAmax);
 
-		    DECmin = PS_MIN (object->sky->d, DECmin);
-		    DECmax = PS_MAX (object->sky->d, DECmax);
+		    DECmin = PS_MIN (raw->sky->d, DECmin);
+		    DECmax = PS_MAX (raw->sky->d, DECmax);
 		}
 	    }
