Index: /trunk/psModules/src/astrom/pmAstrometryWCS.c
===================================================================
--- /trunk/psModules/src/astrom/pmAstrometryWCS.c	(revision 25875)
+++ /trunk/psModules/src/astrom/pmAstrometryWCS.c	(revision 25876)
@@ -670,6 +670,13 @@
     wcs->crval2 = fpa->toSky->D*PS_DEG_RAD;
 
+    // generate a transform that has 0.0 rotation:
+    // get the current posangle of the ref chip
+    // XXX average angles for x and y...
+    float angle = atan2 (toTPA->y->coeff[1][0], toTPA->x->coeff[1][0]);
+    // fprintf (stderr, "angle: %f\n", angle*PS_DEG_RAD);
+    psPlaneTransform *tpa1 = psPlaneTransformRotate (NULL, toTPA, angle);
+
     // given transformation, solve for coordinates which yields output coordinates of 0,0
-    psPlane *center = psPlaneTransformGetCenter (toTPA, tol);
+    psPlane *center = psPlaneTransformGetCenter (tpa1, tol);
     if (!center) {
         psError(PS_ERR_UNKNOWN, false, "Unable to solve for TPA center.");
@@ -679,7 +686,20 @@
     }
 
+    // generate transform with the original orientation (does this rotate about 'center'?) 
+    psPlaneTransform *tpa2 = psPlaneTransformRotate (NULL, tpa1, -1.0*angle);
+
+    // prove that the center coordinates give 0,0:
+    // float Xo = psPolynomial2DEval (tpa1->x, center->x, center->y);
+    // float Yo = psPolynomial2DEval (tpa1->x, center->x, center->y);
+    // fprintf (stderr, "tpa1: Xo, Yo: %f, %f\n", Xo, Yo);
+
+    // prove that the center coordinates give 0,0:
+    // Xo = psPolynomial2DEval (tpa2->x, center->x, center->y);
+    // Yo = psPolynomial2DEval (tpa2->x, center->x, center->y);
+    // fprintf (stderr, "tpa2: Xo, Yo: %f, %f\n", Xo, Yo);
+
     // create wcs transform from toFPA, resulting transformation has units of microns/pixel
     // adjust wcs transform to use center as reference coordinate
-    psPlaneTransformSetCenter (wcs->trans, toTPA, center->x, center->y);
+    psPlaneTransformSetCenter (wcs->trans, tpa2, center->x, center->y);
 
     // calculated center is crpix1,2
@@ -687,4 +707,6 @@
     wcs->crpix2 = center->y;
     psFree (center);
+    psFree (tpa1);
+    psFree (tpa2);
 
     // pdelt1,2 has units of degrees/micron
