Index: trunk/pswarp/src/pswarpMapGrid.c
===================================================================
--- trunk/pswarp/src/pswarpMapGrid.c	(revision 31878)
+++ trunk/pswarp/src/pswarpMapGrid.c	(revision 41538)
@@ -13,4 +13,6 @@
 # include "pswarp.h"
 
+FILE *fout = NULL;
+
 /**
  * pswarpMapGridFromImage builds a set (a grid) of locally-linear maps which convert the source
@@ -46,4 +48,58 @@
     }
 
+    if (0) {
+	// test the transformation sky<->chip for chip in smf:
+	if (fout == NULL) { fout = fopen ("map.grid.txt", "w");	}
+
+	pmCell *cell = dest->parent;
+	pmChip *chip = cell->parent;
+	pmFPA *fpa = chip->parent;
+
+	int NxChip = dest->image->numCols;
+	int NyChip = dest->image->numRows;
+
+	// XXX save these as static for speed?
+	psPlane *CH0 = psPlaneAlloc();
+	psPlane *CH1 = psPlaneAlloc();
+	
+	psPlane *FP0 = psPlaneAlloc();
+	psPlane *TP0 = psPlaneAlloc();
+
+	psPlane *FP1 = psPlaneAlloc();
+	psPlane *TP1 = psPlaneAlloc();
+
+	psSphere *sky = psSphereAlloc();
+
+	// measure the map for the center of each superpixel
+	for (i = 0; i < NxChip; i += 100) {
+	    for (j = 0; j < NyChip; j += 100) {
+		
+		CH0->x = i;
+		CH0->y = j;
+		psPlaneTransformApply(FP0, chip->toFPA, CH0);
+		psPlaneTransformApply (TP0, fpa->toTPA, FP0);
+		psDeproject (sky, TP0, fpa->toSky);
+		psProject (TP1, sky, fpa->toSky);
+		psPlaneTransformApply (FP1, fpa->fromTPA, TP1);
+		psPlaneTransformApply (CH1, chip->fromFPA, FP1);
+
+		fprintf (fout, "%f %f > %f %f > %f %f > %f %f | ", CH0->x, CH0->y, FP0->x, FP0->y, TP0->x, TP0->y, sky->r*180/M_PI, sky->d*180/M_PI);
+		fprintf (fout, "%f %f < %f %f < %f %f \n", TP1->x, TP1->y, FP1->x, FP1->y, CH1->x, CH1->y);
+
+	    }
+	}
+	fclose (fout);
+
+	psFree (CH0);
+	psFree (FP0);
+	psFree (TP0);
+
+	psFree (CH1);
+	psFree (FP1);
+	psFree (TP1);
+
+	psFree (sky);
+    }
+
     grid->nXpix = nXpix;
     grid->nYpix = nYpix;
@@ -164,4 +220,6 @@
 
     // XXX need to include readout->cell->chip offsets
+    // XXX note that 'dest' is the SMF and 'src' is the skycell CMF
+    // this is the lower accuracy direction...
 
     /** V(0,0) position */
@@ -205,5 +263,5 @@
     map->xo = ix;
     map->yo = iy;
-
+    
     psFree (offset);
     psFree (FP);
