Index: trunk/pswarp/src/pswarpDefineBackground.c
===================================================================
--- trunk/pswarp/src/pswarpDefineBackground.c	(revision 41537)
+++ trunk/pswarp/src/pswarpDefineBackground.c	(revision 41538)
@@ -145,10 +145,8 @@
         }
     }
-
     
     view->chip = view->cell = view->readout = -1;
     pmFPAAddSourceFromView(output->fpa, view, output->format);
 
-
     psFree (view);
     return true;
Index: trunk/pswarp/src/pswarpLoopSkycell.c
===================================================================
--- trunk/pswarp/src/pswarpLoopSkycell.c	(revision 41537)
+++ trunk/pswarp/src/pswarpLoopSkycell.c	(revision 41538)
@@ -1,4 +1,5 @@
 /** @file pswarpLoop.c
  *
+ *  ** this function is not used... **
  *  @brief mail processing loop for pswarp
  *  @ingroup pswarp
@@ -63,15 +64,15 @@
 
     // select the output readout
-    pmFPAview *view = pmFPAviewAlloc(0);
-    view->chip = 0;
-    view->cell = 0;
-    view->readout = 0;
-    pmReadout *output = pmFPAfileThisReadout(config->files, view, "PSWARP.OUTPUT");
+    pmFPAview *viewT0 = pmFPAviewAlloc(0);
+    viewT0->chip = 0;
+    viewT0->cell = 0;
+    viewT0->readout = 0;
+    pmReadout *output = pmFPAfileThisReadout(config->files, viewT0, "PSWARP.OUTPUT");
     if (!output) {
         psError(PSWARP_ERR_CONFIG, true, "Can't find output data!\n");
+	psFree (viewT0);
         return false;
     }
-    psFree (view);
-
+    psFree (viewT0);
 
     // Turn all skycell files on to generate them, and then turn them off for the loop over the input images
@@ -97,36 +98,41 @@
 
         pmChip *chip;
-        pmFPAview *view = pmFPAviewAlloc(0);
-        if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
+        pmFPAview *viewT1 = pmFPAviewAlloc(0);
+        if (!pmFPAfileIOChecks(config, viewT1, PM_FPA_BEFORE)) {
             psError(psErrorCodeLast(), false, "Unable to read files.");
-            goto DONE;
-        }
-        while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
-            psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+	    psFree(viewT1);
+            goto DONE;
+        }
+        while ((chip = pmFPAviewNextChip (viewT1, input->fpa, 1)) != NULL) {
+            psTrace ("pswarp", 4, "Chip %d: %x %x\n", viewT1->chip, chip->file_exists, chip->process);
             if (!chip->process || !chip->file_exists) { continue; }
-            if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
+            if (!pmFPAfileIOChecks(config, viewT1, PM_FPA_BEFORE)) {
                 psError(psErrorCodeLast(), false, "Unable to read files.");
+		psFree(viewT1);
                 goto DONE;
             }
             pmCell *cell;
-            while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
-                psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            while ((cell = pmFPAviewNextCell (viewT1, input->fpa, 1)) != NULL) {
+                psTrace ("pswarp", 4, "Cell %d: %x %x\n", viewT1->cell, cell->file_exists, cell->process);
                 if (!cell->process || !cell->file_exists) { continue; }
-                if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE) ||
-                    !pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
+                if (!pmFPAfileIOChecks (config, viewT1, PM_FPA_BEFORE) ||
+                    !pmFPAfileIOChecks (config, viewT1, PM_FPA_AFTER)) {
                     psError(psErrorCodeLast(), false, "Unable to read files.");
+		    psFree(viewT1);
                     goto DONE;
                 }
             }
-            if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
+            if (!pmFPAfileIOChecks (config, viewT1, PM_FPA_AFTER)) {
                 psError(psErrorCodeLast(), false, "Unable to write files.");
-                goto DONE;
-            }
-        }
-        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
+		psFree(viewT1);
+                goto DONE;
+            }
+        }
+        if (!pmFPAfileIOChecks (config, viewT1, PM_FPA_AFTER)) {
             psError(psErrorCodeLast(), false, "Unable to write files.");
-            goto DONE;
-        }
-        psFree(view);
+	    psFree(viewT1);
+            goto DONE;
+        }
+        psFree(viewT1);
 
         pswarpFileActivation(config, detectorFiles, true);
@@ -139,9 +145,9 @@
     // Don't care about the skycell anymore --- we've read it, and that's all we need to do.
     pmFPAfileActivate(config->files, false, "PSWARP.SKYCELL");
-    view = pmFPAviewAlloc(0);
+    pmFPAview *viewT2 = pmFPAviewAlloc(0);
 
     // find the FPA phu
     bool bilevelAstrometry = false;
-    pmHDU *phu = pmFPAviewThisPHU(view, astrom->fpa);
+    pmHDU *phu = pmFPAviewThisPHU(viewT2, astrom->fpa);
     if (phu) {
         char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1");
@@ -153,5 +159,5 @@
         if (!pmAstromReadBilevelMosaic(input->fpa, phu->header)) {
             psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for input FPA.");
-            psFree(view);
+            psFree(viewT2);
             goto DONE;
         }
@@ -161,6 +167,7 @@
 
     // files associated with the science image
-    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
+    if (!pmFPAfileIOChecks (config, viewT2, PM_FPA_BEFORE)) {
         psError(psErrorCodeLast(), false, "Unable to read files.");
+            psFree(viewT2);
         goto DONE;
     }
@@ -168,14 +175,15 @@
     // *** main transformation block
     pmChip *chip;
-    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
-        psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+    while ((chip = pmFPAviewNextChip (viewT2, input->fpa, 1)) != NULL) {
+        psTrace ("pswarp", 4, "Chip %d: %x %x\n", viewT2->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
-        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
+        if (!pmFPAfileIOChecks (config, viewT2, PM_FPA_BEFORE)) {
             psError(psErrorCodeLast(), false, "Unable to read files.");
+            psFree(viewT2);
             goto DONE;
         }
 
         // read WCS data from the corresponding header
-        pmHDU *hdu = pmFPAviewThisHDU (view, astrom->fpa);
+        pmHDU *hdu = pmFPAviewThisHDU (viewT2, astrom->fpa);
 
 	
@@ -183,5 +191,5 @@
             if (!pmAstromReadBilevelChip (chip, hdu->header)) {
                 psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for input FPA.");
-                psFree(view);
+                psFree(viewT2);
                 goto DONE;
             }
@@ -190,5 +198,5 @@
             if (!pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0)) {
                 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA.");
-                psFree(view);
+                psFree(viewT2);
                 goto DONE;
             }
@@ -196,9 +204,10 @@
 	
         pmCell *cell;
-        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
-            psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+        while ((cell = pmFPAviewNextCell (viewT2, input->fpa, 1)) != NULL) {
+            psTrace ("pswarp", 4, "Cell %d: %x %x\n", viewT2->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
             if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
                 psError(psErrorCodeLast(), false, "Unable to read files.");
+            psFree(viewT2);
                 goto DONE;
             }
@@ -211,4 +220,5 @@
                 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
                     psError(psErrorCodeLast(), false, "Unable to read files.");
+            psFree(viewT2);
                     goto DONE;
                 }
@@ -229,4 +239,5 @@
                 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
                     psError(psErrorCodeLast(), false, "Unable to write files.");
+            psFree(viewT2);
                     goto DONE;
                 }
@@ -234,4 +245,5 @@
             if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
                 psError(psErrorCodeLast(), false, "Unable to write files.");
+            psFree(viewT2);
                 goto DONE;
             }
@@ -239,4 +251,5 @@
         if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
             psError(psErrorCodeLast(), false, "Unable to write files.");
+            psFree(viewT2);
             goto DONE;
         }
@@ -251,5 +264,5 @@
         psphotFilesActivate(config, false);
         psFree(cells);
-        psFree(view);
+        psFree(viewT2);
         goto DONE;
     }
@@ -262,5 +275,5 @@
         psError(psErrorCodeLast(), false, "Unable to calculate pixel regions.");
         psFree(cells);
-        psFree(view);
+        psFree(viewT2);
         goto DONE;
     }
@@ -270,5 +283,5 @@
 	psError(psErrorCodeLast(), false, "Unable to calculate mask stats.");
 	psFree(cells);
-	psFree(view);
+	psFree(viewT2);
 	goto DONE;
       }
@@ -299,5 +312,5 @@
         psError(psErrorCodeLast(), false, "Unable to average cell concepts.");
         psFree(cells);
-        psFree(view);
+        psFree(viewT2);
         goto DONE;
     }
@@ -309,5 +322,5 @@
     if (!psMetadataCopy(outFPA->concepts, input->fpa->concepts)) {
         psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output.");
-        psFree(view);
+        psFree(viewT2);
         goto DONE;
     }
@@ -330,5 +343,5 @@
         if (!skyHDU) {
             psError(PSWARP_ERR_DATA, false, "Unable to find skycell HDU.");
-            psFree(view);
+            psFree(viewT2);
             goto DONE;
         }
@@ -340,9 +353,11 @@
     if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) {
         psError(psErrorCodeLast(), false, "Unable to generate WCS header.");
-        goto DONE;
-    }
-
-    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
+            psFree(viewT2);
+        goto DONE;
+    }
+
+    if (!pmFPAfileIOChecks(config, viewT2, PM_FPA_AFTER)) {
         psError(psErrorCodeLast(), false, "Unable to write files.");
+            psFree(viewT2);
         goto DONE;
     }
@@ -360,4 +375,5 @@
         if (!pswarpIOChecksBefore(config)) {
             psError(psErrorCodeLast(), false, "Unable to read files.");
+            psFree(viewT2);
             goto DONE;
         }
@@ -367,6 +383,6 @@
         pmFPACopy(photFile->fpa, outFPA);
 
-        pmFPAview *view = pmFPAviewAlloc(0); ///< View into skycell
-        view->chip = view->cell = view->readout = 0;
+        pmFPAview *viewT3 = pmFPAviewAlloc(0); ///< View into skycell
+        viewT3->chip = viewT3->cell = viewT3->readout = 0;
 
         // grab the sources of interest from the storage location (pmFPAfile PSPHOT.INPUT.CMF)
@@ -374,4 +390,5 @@
         if (!sources) {
             psError(psErrorCodeLast(), false, "No sources supplied to measure PSF");
+            psFree(viewT2);
             goto DONE;
         }
@@ -432,5 +449,5 @@
     const char *cellName = psMetadataLookupStr(NULL, output->parent->concepts, "CELL.NAME");
     psString headerName = NULL; ///< Header name for MD5
-    psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout);
+    psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, viewT2->readout);
     psVector *md5 = psImageMD5(output->image); ///< md5 hash
     psString md5string = psMD5toString(md5); ///< String
@@ -440,5 +457,5 @@
     psFree(md5string);
     psFree(headerName);
-    psFree(view);
+    psFree(viewT2);
 
  DONE:
Index: trunk/pswarp/src/pswarpMapGrid.c
===================================================================
--- trunk/pswarp/src/pswarpMapGrid.c	(revision 41537)
+++ 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);
