Index: trunk/psastro/src/pmAstrom.c
===================================================================
--- trunk/psastro/src/pmAstrom.c	(revision 5495)
+++ trunk/psastro/src/pmAstrom.c	(revision 5510)
@@ -54,5 +54,17 @@
 }
 
-pmAstromMatchedListFit (pmFPA *fpa, psArray *st1, psArray *st2, psArray *match, psMetadata *config) {
+// take two matched star lists and fit a psPlaneTransform between them
+// 
+psPlaneTransform *pmAstromMatchedListFit (psPlaneTransform *map, psArray *st1, psArray *st2, psArray *match, psMetadata *config) {
+
+    if (map == NULL) {
+	// int nX = psMetadataLookupS32 (&status, myHeader, "CHIP.NX");
+	// int nY = psMetadataLookupS32 (&status, myHeader, "CHIP.NY");
+	map = psPlaneTransform (2, 2);
+    }
+
+    psStats *stats = psStatsAlloc (CLIPPED_MEAN);
+    stats->nSigma = psMetadataLookupS32 (&status, myHeader, "CHIP.NITER");
+    stats->nSigma = psMetadataLookupS32 (&status, myHeader, "CHIP.NSIGMA");
 
     psVector *X = psVectorAlloc (match->n);
@@ -62,5 +74,5 @@
   
     // take the matched stars, first fit 
-    for (i = 0; i < match->n; i++) {
+    for (int i = 0; i < match->n; i++) {
 
 	pair = match->data[i];
@@ -68,19 +80,21 @@
 	ob2 = st2->data[pair->i2];
 
-	X->data.F64[i] = ob1->P;
-	Y->data.F64[i] = ob1->Q;
+	X->data.F64[i] = ob1->chip.x;
+	Y->data.F64[i] = ob1->chip.y;
 
-	x->data.F64[i] = ob2->P;
-	y->data.F64[i] = ob2->Q;
-
-	// use one or the other...
-	psPolynomial2D *xt = psVectorFitPolynomial2D (NULL, stats, NULL, 0, X, NULL, x, y);
-	psPolynomial2D *xt = psVectorClipFitPolynomial2D (NULL, stats, NULL, 0, X, NULL, x, y);
-
-	psPolynomial2D *yt = psVectorFitPolynomial2D (NULL, stats, NULL, 0, Y, NULL, x, y);
-	psPolynomial2D *yt = psVectorClipFitPolynomial2D (NULL, stats, NULL, 0, Y, NULL, x, y);
+	x->data.F64[i] = ob2->FP.x;
+	y->data.F64[i] = ob2->FP.y;
     }
 
-    // apply fitted polynomials to fpa
+    // no masking, no errors
+    psVectorClipFitPolynomial2D (map->x, stats, NULL, 0, X, NULL, x, y);
+    psVectorClipFitPolynomial2D (map->y, stats, NULL, 0, Y, NULL, x, y);
+    psFree (x);
+    psFree (y);
+    psFree (X);
+    psFree (Y);
+    psFree (stats);
+
+    return (map);
 }
 
@@ -103,9 +117,9 @@
 	newObj = pmAstromObjCopy (oldObj);
 
-	P = oldObj->FP.x - xCenter;
-	Q = oldObj->FP.y - yCenter;
+	X = oldObj->FP.x - xCenter;
+	Y = oldObj->FP.y - yCenter;
 	
-	newObj->FP.x = P*cs + Q*sn;
-	newObj->FP.y = Q*cs - P*sn;
+	newObj->FP.x = X*cs + Y*sn;
+	newObj->FP.y = Y*cs - X*sn;
 	
 	new->data[i] = newObj;
