Index: trunk/pswarp/src/pswarpMatchRange.c
===================================================================
--- trunk/pswarp/src/pswarpMatchRange.c	(revision 10958)
+++ trunk/pswarp/src/pswarpMatchRange.c	(revision 12523)
@@ -2,17 +2,20 @@
 
 # define TEST_MINMAX \
-    psPlaneTransformApply(FP, chipDest->toFPA, destPix); \
-    psPlaneTransformApply (TP, fpaDest->toTPA, FP); \
-    psDeproject (sky, TP, fpaDest->toSky); \
-    psProject (TP, sky, fpaSrc->toSky); \
-    psPlaneTransformApply (FP, fpaSrc->fromTPA, TP); \
-    psPlaneTransformApply (srcPix, chipSrc->fromFPA, FP); \
+    psPlaneTransformApply(destFP, chipDest->toFPA, destPix); \
+    psPlaneTransformApply (destTP, fpaDest->toTPA, destFP); \
+    psDeproject (sky, destTP, fpaDest->toSky); \
+    psProject (srcTP, sky, fpaSrc->toSky); \
+    psPlaneTransformApply (srcFP, fpaSrc->fromTPA, srcTP); \
+    psPlaneTransformApply (srcPix, chipSrc->fromFPA, srcFP); \
+    fprintf (stderr, "%6.1f,%6.1f -> ", srcPix->x, srcPix->y); \
     *minX = PS_MIN (*minX, srcPix->x); \
     *minY = PS_MIN (*minY, srcPix->y); \
     *maxX = PS_MAX (*maxX, srcPix->x); \
-    *maxY = PS_MAX (*maxY, srcPix->y);
+    *maxY = PS_MAX (*maxY, srcPix->y); \
+    fprintf (stderr, "%4d,%4d - %4d,%4d\n", *minX, *minY, *maxX, *maxY);
 
 // we are warping from src to dest.  find the max overlapping pixels in the INPUT (src)
-// coordinate frame
+// coordinate frame.  NOTE: these are in the parent pixel frame since the astrometric
+// transformation refers to the parent frame
 bool pswarpMatchRange (int *minX, int *minY, int *maxX, int *maxY, pmReadout *dest, pmReadout *src) {
 
@@ -30,58 +33,87 @@
     pmFPA *fpaDest = chipDest->parent;
 
-    *minX = src->image->numCols;
-    *minY = src->image->numRows;
-    *maxX = 0;
-    *maxY = 0;
+    *minX = src->image->numCols + src->image->col0 - 1;
+    *minY = src->image->numRows + src->image->row0 - 1;
+    *maxX = src->image->col0;
+    *maxY = src->image->row0;
+    fprintf (stderr, "%4d,%4d - %4d,%4d\n", *minX, *minY, *maxX, *maxY);
 
     // XXX save these as static for speed?
     psPlane *srcPix = psPlaneAlloc();
+    psPlane *srcFP  = psPlaneAlloc();
+    psPlane *srcTP  = psPlaneAlloc();
+
     psPlane *destPix = psPlaneAlloc();
+    psPlane *destFP  = psPlaneAlloc();
+    psPlane *destTP  = psPlaneAlloc();
 
-    psPlane *FP = psPlaneAlloc();
-    psPlane *TP = psPlaneAlloc();
     psSphere *sky = psSphereAlloc();
 
-    destPix->x = 0;
-    destPix->y = 0;
+    destPix->x = dest->image->col0;
+    destPix->y = dest->image->row0;
     TEST_MINMAX;
     
-    destPix->x = dest->image->numCols;
-    destPix->y = 0;
+    destPix->x = dest->image->col0 + dest->image->numCols;
+    destPix->y = dest->image->row0;
     TEST_MINMAX;
     
-    destPix->x = dest->image->numCols;
-    destPix->y = dest->image->numRows;
+    destPix->x = dest->image->col0 + dest->image->numCols;
+    destPix->y = dest->image->row0 + dest->image->numRows;
     TEST_MINMAX;
     
-    destPix->x = 0;
-    destPix->y = dest->image->numRows;
+    destPix->x = dest->image->col0;
+    destPix->y = dest->image->row0 + dest->image->numRows;
     TEST_MINMAX;
     
-    destPix->x = 0.5*dest->image->numCols;
-    destPix->y = 0.0;
+    destPix->x = dest->image->col0 + 0.5*dest->image->numCols;
+    destPix->y = dest->image->row0;
     TEST_MINMAX;
     
-    destPix->x = 0.0;
-    destPix->y = 0.5*dest->image->numRows;
+    destPix->x = dest->image->col0;
+    destPix->y = dest->image->row0 + 0.5*dest->image->numRows;
     TEST_MINMAX;
     
-    destPix->x = 0.5*dest->image->numCols;
-    destPix->y = dest->image->numRows;
+    destPix->x = dest->image->col0 + 0.5*dest->image->numCols;
+    destPix->y = dest->image->row0;
     TEST_MINMAX;
 
-    destPix->x = dest->image->numCols;
-    destPix->y = 0.5*dest->image->numRows;
+    destPix->x = dest->image->col0;
+    destPix->y = dest->image->row0 + 0.5*dest->image->numRows;
     TEST_MINMAX;
 
-    *minX = PS_MAX (*minX, 0);
-    *minY = PS_MAX (*minY, 0);
-    *maxX = PS_MIN (*maxX, src->image->numCols);
-    *maxY = PS_MIN (*maxY, src->image->numRows);
+    *minX = PS_MAX (*minX, src->image->col0);
+    *minY = PS_MAX (*minY, src->image->row0);
+    *maxX = PS_MIN (*maxX, src->image->numCols + src->image->col0);
+    *maxY = PS_MIN (*maxY, src->image->numRows + src->image->row0);
+
+    // demo forward and backward transformation
+    srcPix->x = *minX;
+    srcPix->y = *minY;
+    psPlaneTransformApply(srcFP, chipSrc->toFPA, srcPix); 
+    psPlaneTransformApply (srcTP, fpaSrc->toTPA, srcFP); 
+    psDeproject (sky, srcTP, fpaSrc->toSky); 
+    psProject (destTP, sky, fpaDest->toSky); 
+    psPlaneTransformApply (destFP, fpaDest->fromTPA, destTP); 
+    psPlaneTransformApply (destPix, chipDest->fromFPA, destFP); 
+
+    fprintf (stderr, "%f,%f -> %f,%f ", srcPix->x, srcPix->y, destPix->x, destPix->y);
+
+    psPlaneTransformApply(destFP, chipDest->toFPA, destPix); 
+    psPlaneTransformApply (destTP, fpaDest->toTPA, destFP); 
+    psDeproject (sky, destTP, fpaDest->toSky); 
+    psProject (srcTP, sky, fpaSrc->toSky); 
+    psPlaneTransformApply (srcFP, fpaSrc->fromTPA, srcTP); 
+    psPlaneTransformApply (srcPix, chipSrc->fromFPA, srcFP); 
+
+    fprintf (stderr, "-> %f,%f ", srcPix->x, srcPix->y);
 
     psFree (srcPix);
+    psFree (srcFP);
+    psFree (srcTP);
+
     psFree (destPix);
-    psFree (FP);
-    psFree (TP);
+    psFree (destFP);
+    psFree (destTP);
+
     psFree (sky);
 
