Index: /branches/eam_branches/ipp-20130307/psModules/src/astrom/pmAstrometryUtils.c
===================================================================
--- /branches/eam_branches/ipp-20130307/psModules/src/astrom/pmAstrometryUtils.c	(revision 35340)
+++ /branches/eam_branches/ipp-20130307/psModules/src/astrom/pmAstrometryUtils.c	(revision 35341)
@@ -23,4 +23,7 @@
 #include "pmAstrometryUtils.h"
 
+// this is used by the test output block
+static int Nout = 0;
+
 // given a 2D transformation -- L(x,y),M(x,y) -- find the coordinates x,y
 // for which L,M = 0,0. tol is the allowed error on x,y.
@@ -33,4 +36,20 @@
     double Xo = (trans->y->coeff[0][0]*trans->x->coeff[0][1] - trans->x->coeff[0][0]*trans->y->coeff[0][1])/R;
     double Yo = (trans->x->coeff[0][0]*trans->y->coeff[1][0] - trans->y->coeff[0][0]*trans->x->coeff[1][0])/R;
+
+    if (0) {
+      // this is a test output block, not used in normal operations
+      char filename[64];
+      snprintf (filename, 64, "trans.%03d.md", Nout);
+      FILE *f = fopen (filename, "w");
+
+      psMetadata *md = psMetadataAlloc();
+
+      psPolynomial2DtoMetadata (md, trans->x, "X");
+      psPolynomial2DtoMetadata (md, trans->y, "Y");
+      psMetadataConfigPrint (f, md);
+      psFree (md);
+      fclose (f);
+      Nout ++;
+    }
 
     // iterate to actual solution: requires small non-linear terms
@@ -53,10 +72,10 @@
             // NOTE: order for Alpha is: [y][x]
             Alpha->data.F32[0][0] = psPolynomial2DEval (XdX, Xo, Yo);
-            Alpha->data.F32[1][0] = psPolynomial2DEval (XdY, Xo, Yo);
-            Alpha->data.F32[0][1] = psPolynomial2DEval (YdX, Xo, Yo);
+            Alpha->data.F32[0][1] = psPolynomial2DEval (XdY, Xo, Yo);
+            Alpha->data.F32[1][0] = psPolynomial2DEval (YdX, Xo, Yo);
             Alpha->data.F32[1][1] = psPolynomial2DEval (YdY, Xo, Yo);
 
-            Beta->data.F32[0] = psPolynomial2DEval (trans->x, Xo, Yo);
-            Beta->data.F32[1] = psPolynomial2DEval (trans->y, Xo, Yo);
+            Beta->data.F32[0] = -1.0 * psPolynomial2DEval (trans->x, Xo, Yo);
+            Beta->data.F32[1] = -1.0 * psPolynomial2DEval (trans->y, Xo, Yo);
 
             if (!psMatrixGJSolve (Alpha, Beta)) {
@@ -71,8 +90,8 @@
 	    }
 
-            Xo -= Beta->data.F32[0];
-            Yo -= Beta->data.F32[1];
+            Xo += Beta->data.F32[0];
+            Yo += Beta->data.F32[1];
             dPos = hypot(Beta->data.F32[0], Beta->data.F32[1]);
-
+	    psTrace ("psastro", 5, "i: %d, Xo,Yo : %f %f  dX, dY: %f %f dPos: %f\n", i, Xo, Yo, Beta->data.F32[0], Beta->data.F32[1], dPos);
         }
         psFree (Alpha);
Index: /branches/eam_branches/ipp-20130307/psastro/src/psastroChipAstrom.c
===================================================================
--- /branches/eam_branches/ipp-20130307/psastro/src/psastroChipAstrom.c	(revision 35340)
+++ /branches/eam_branches/ipp-20130307/psastro/src/psastroChipAstrom.c	(revision 35341)
@@ -75,4 +75,41 @@
                 if (refstars == NULL) { continue; }
 
+# if (0)
+		static int Nchip = 0;
+		if (1) {
+		  // XXX test
+		  char filename[64];
+		  snprintf (filename, 64, "refstars.%02d.dat", Nchip);
+		  FILE *outfile = fopen (filename, "w");
+		  assert (outfile);
+		  for (int nn = 0; nn < refstars->n; nn++) {
+		    pmAstromObj *ref = refstars->data[nn];
+		    fprintf (outfile, "%lf %lf  %lf %lf  %lf %lf  %lf %lf\n", 
+			     ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD,
+			     ref->TP->x, ref->TP->y, 
+			     ref->FP->x, ref->FP->y, 
+			     ref->chip->x, ref->chip->y);
+		  }
+		  fclose (outfile);
+		}
+		if (1) {
+		  // XXX test
+		  char filename[64];
+		  snprintf (filename, 64, "rawstars.%02d.dat", Nchip);
+		  FILE *outfile = fopen (filename, "w");
+		  assert (outfile);
+		  for (int nn = 0; nn < gridrawstars->n; nn++) {
+		    pmAstromObj *ref = gridrawstars->data[nn];
+		    fprintf (outfile, "%lf %lf  %lf %lf  %lf %lf  %lf %lf\n", 
+			     ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD,
+			     ref->TP->x, ref->TP->y, 
+			     ref->FP->x, ref->FP->y, 
+			     ref->chip->x, ref->chip->y);
+		  }
+		  fclose (outfile);
+		  Nchip ++;
+		}
+# endif
+
                 // the absolute minimum number of stars is 4 (for order = 1)
                 if ((rawstars->n < 4) || (refstars->n < 4)) {
Index: /branches/eam_branches/ipp-20130307/psastro/src/psastroChooseRefstars.c
===================================================================
--- /branches/eam_branches/ipp-20130307/psastro/src/psastroChooseRefstars.c	(revision 35340)
+++ /branches/eam_branches/ipp-20130307/psastro/src/psastroChooseRefstars.c	(revision 35341)
@@ -107,5 +107,5 @@
 
                     if (ref->Mag < clampMagMin) {
-                        psWarning("Skipping refstar with abusrd magnintude %f ra: %f dec: %f\n",
+                        psWarning("Skipping refstar with abusrd magnitude %f ra: %f dec: %f\n",
                             ref->Mag, RAD_TO_DEG(ref->sky->r), RAD_TO_DEG(ref->sky->d));
                         goto skip;
@@ -131,12 +131,28 @@
 
 # if (0)
-		// XXX test
-		FILE *outfile = fopen ("refstars.dat", "w");
-		assert (outfile);
-		for (int nn = 0; nn < refstars->n; nn++) {
-			  pmAstromObj *ref = refstars->data[nn];
-			  fprintf (outfile, "%lf %lf\n", ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD);
+		if (1) {
+		  // test output block, not used in normal ops
+		  char filename[64];
+		  snprintf (filename, 64, "refstars.%02d.dat", Nchip);
+		  FILE *outfile = fopen (filename, "w");
+		  assert (outfile);
+		  for (int nn = 0; nn < refstars->n; nn++) {
+		    pmAstromObj *ref = refstars->data[nn];
+		    fprintf (outfile, "%lf %lf\n", ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD);
+		  }
+		  fclose (outfile);
 		}
-		fclose (outfile);
+		if (1) {
+		  // test output block, not used in normal ops
+		  char filename[64];
+		  snprintf (filename, 64, "refstars.%02d.dat", Nchip);
+		  FILE *outfile = fopen (filename, "w");
+		  assert (outfile);
+		  for (int nn = 0; nn < refstars->n; nn++) {
+		    pmAstromObj *ref = refstars->data[nn];
+		    fprintf (outfile, "%lf %lf  %lf %lf  %lf %lf\n", ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD, );
+		  }
+		  fclose (outfile);
+		}
 # endif
 
