Index: /branches/eam_branch_20070830/psLib/test/imageops/tap_psImageMapFit.c
===================================================================
--- /branches/eam_branch_20070830/psLib/test/imageops/tap_psImageMapFit.c	(revision 14859)
+++ /branches/eam_branch_20070830/psLib/test/imageops/tap_psImageMapFit.c	(revision 14860)
@@ -19,9 +19,9 @@
 # define TEST_4PT_3 0
 
+# define TEST_6PT_0 0
+
 # define TEST_9PT_0 0
 # define TEST_9PT_1 0
-# define TEST_9PT_2 0
-
-# define TEST_6PT_0 1
+# define TEST_9PT_2 1
 
 # define TEST1 0
@@ -58,12 +58,81 @@
 	int n = 0;
 	for (float ix = 0.5; ix < 3.0; ix += 1.0) {
-	    for (int iy = 0.5; iy < 2.0; iy += 1.0) {
-		x->data.F32[n] = ix;
-		y->data.F32[n] = iy;
-		# if (0)
+	    for (float iy = 0.5; iy < 2.0; iy += 1.0) {
+		// x->data.F32[n] = ix;
+		// y->data.F32[n] = iy;
+		if ((ix == 0.5) && (iy == 0.5)) {
+		    x->data.F32[n] = ix + 0.0;
+		    y->data.F32[n] = iy + 0.1; // add in both points.  
+		    // f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
+		    // n++;
+		    // x->data.F32[n] = ix + 0.0;
+		    // y->data.F32[n] = iy - 0.1;
+		} else {
+		    x->data.F32[n] = ix;
+		    y->data.F32[n] = iy;
+		}
+		f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
+		n++;
+	    }
+	}
+	x->n = n;
+	y->n = n;
+	f->n = n;
+
+	psImage *field = psImageAlloc(3, 2, PS_TYPE_F32);
+	for (int ix = 0; ix < 3; ix++) {
+	    for (int iy = 0; iy < 2; iy++) {
+		field->data.F32[iy][ix] = (ix + 0.5) + (iy + 0.5);
+	    }
+	}
+
+	psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
+
+	// scale defines both field and map image sizes (nXfine, nXruff)
+	psImageMap *map = psImageMapAlloc (NULL, binning, stats);
+
+	// fit the data to the map
+	psImageMapFit (map, x, y, f, NULL);
+	psFree (binning);
+
+	SaveImage (NULL, map->map, "map.fits");
+	
+	SaveImage (NULL, field, "field.fits");
+
+	psImage *model = psImageAlloc(field->numCols, field->numRows, PS_TYPE_F32);
+	for (int ix = 0; ix < model->numCols; ix++) {
+	    for (int iy = 0; iy < model->numRows; iy++) {
+		model->data.F32[iy][ix] = psImageUnbinPixel_V2 (ix + 0.5, iy + 0.5, map->map, map->binning);
+		is_float_tol (model->data.F32[iy][ix], field->data.F32[iy][ix], FLT_EPSILON, "model matches inputs");
+	    }
+	}
+	SaveImage (NULL, model, "model.fits");
+        // ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+    # endif
+
+    // test for more points: 3x3 grid fitted to 9 points with simple slope and scale difference
+    # if (TEST_9PT_2)
+    {
+	psImageBinning *binning = psImageBinningAlloc();
+	binning->nXfine = 6;
+	binning->nYfine = 6;
+	binning->nXruff = 3;
+	binning->nYruff = 3;
+
+	// generate a grid of test data points
+	psVector *x = psVectorAlloc (50, PS_TYPE_F32);
+	psVector *y = psVectorAlloc (50, PS_TYPE_F32);
+	psVector *f = psVectorAlloc (50, PS_TYPE_F32);
+
+	// the underlying field is f = ix + iy, where ix,iy are fine pixel coordinates
+	// place the measurement points exactly on the ruff reference pixel centers
+	int n = 0;
+	for (float ix = 1.0; ix < 6; ix += 2.0) {
+	    for (float iy = 1.0; iy < 6; iy += 2.0) {
 		if ((ix == 3.0) && (iy == 1.0)) {
 		    x->data.F32[n] = ix + 0.0;
 		    y->data.F32[n] = iy + 0.1; // add in both points.  
-		    f->data.F32[n] = ix + iy;
+		    f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
 		    n++;
 		    x->data.F32[n] = ix + 0.0;
@@ -73,6 +142,5 @@
 		    y->data.F32[n] = iy;
 		}
-		# endif
-		f->data.F32[n] = ix + iy;
+		f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
 		n++;
 	    }
@@ -82,7 +150,7 @@
 	f->n = n;
 
-	psImage *field = psImageAlloc(3, 2, PS_TYPE_F32);
-	for (int ix = 0; ix < 3; ix++) {
-	    for (int iy = 0; iy < 2; iy++) {
+	psImage *field = psImageAlloc(6, 6, PS_TYPE_F32);
+	for (int ix = 0; ix < 6; ix++) {
+	    for (int iy = 0; iy < 6; iy++) {
 		field->data.F32[iy][ix] = (ix + 0.5) + (iy + 0.5);
 	    }
@@ -114,6 +182,6 @@
     # endif
 
-    // test for more points: 3x3 grid fitted to 9 points with simple slope and scale difference
-    # if (TEST_9PT_2)
+    // still a simple test: 3x3 grid fitted to 9 points with simple slope and scale difference
+    # if (TEST_9PT_1)
     {
 	psImageBinning *binning = psImageBinningAlloc();
@@ -124,74 +192,4 @@
 
 	// generate a grid of test data points
-	psVector *x = psVectorAlloc (50, PS_TYPE_F32);
-	psVector *y = psVectorAlloc (50, PS_TYPE_F32);
-	psVector *f = psVectorAlloc (50, PS_TYPE_F32);
-
-	// the underlying field is f = ix + iy, where ix,iy are fine pixel coordinates
-	// place the measurement points exactly on the ruff reference pixel centers
-	int n = 0;
-	for (float ix = 1.0; ix < 6; ix += 2.0) {
-	    for (int iy = 1.0; iy < 6; iy += 2.0) {
-		if ((ix == 3.0) && (iy == 1.0)) {
-		    x->data.F32[n] = ix + 0.0;
-		    y->data.F32[n] = iy + 0.1; // add in both points.  
-		    f->data.F32[n] = ix + iy;
-		    n++;
-		    x->data.F32[n] = ix + 0.0;
-		    y->data.F32[n] = iy - 0.1;
-		} else {
-		    x->data.F32[n] = ix;
-		    y->data.F32[n] = iy;
-		}
-		f->data.F32[n] = ix + iy;
-		n++;
-	    }
-	}
-	x->n = n;
-	y->n = n;
-	f->n = n;
-
-	psImage *field = psImageAlloc(6, 6, PS_TYPE_F32);
-	for (int ix = 0; ix < 6; ix++) {
-	    for (int iy = 0; iy < 6; iy++) {
-		field->data.F32[iy][ix] = (ix + 0.5) + (iy + 0.5);
-	    }
-	}
-
-	psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
-
-	// scale defines both field and map image sizes (nXfine, nXruff)
-	psImageMap *map = psImageMapAlloc (NULL, binning, stats);
-
-	// fit the data to the map
-	psImageMapFit (map, x, y, f, NULL);
-	psFree (binning);
-
-	SaveImage (NULL, map->map, "map.fits");
-	
-	SaveImage (NULL, field, "field.fits");
-
-	psImage *model = psImageAlloc(field->numCols, field->numRows, PS_TYPE_F32);
-	for (int ix = 0; ix < model->numCols; ix++) {
-	    for (int iy = 0; iy < model->numRows; iy++) {
-		model->data.F32[iy][ix] = psImageUnbinPixel_V2 (ix + 0.5, iy + 0.5, map->map, map->binning);
-		is_float_tol (model->data.F32[iy][ix], field->data.F32[iy][ix], FLT_EPSILON, "model matches inputs");
-	    }
-	}
-	SaveImage (NULL, model, "model.fits");
-        // ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
-    }
-    # endif
-
-    // still a simple test: 3x3 grid fitted to 9 points with simple slope and scale difference
-    # if (TEST_9PT_1)
-    {
-	psImageBinning *binning = psImageBinningAlloc();
-	binning->nXfine = 6;
-	binning->nYfine = 6;
-	binning->nXruff = 3;
-	binning->nYruff = 3;
-
-	// generate a grid of test data points
 	psVector *x = psVectorAlloc (9, PS_TYPE_F32);
 	psVector *y = psVectorAlloc (9, PS_TYPE_F32);
@@ -205,5 +203,5 @@
 		x->data.F32[n] = ix;
 		y->data.F32[n] = iy;
-		f->data.F32[n] = ix + iy;
+		f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
 		n++;
 	    }
@@ -263,5 +261,5 @@
 		x->data.F32[n] = ix + 0.5;
 		y->data.F32[n] = iy + 0.5;
-		f->data.F32[n] = ix + iy;
+		f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
 		field->data.F32[iy][ix] = f->data.F32[n];
 		n++;
@@ -377,4 +375,12 @@
 	    for (int iy = 0; iy < 2; iy++) {
 		// add in one extra point on the surface
+		if (!ix && !iy) {
+		    x->data.F32[n] = ix + 0.5;
+		    y->data.F32[n] = iy + 0.5 + 0.1;
+		} else {
+		    x->data.F32[n] = ix + 0.5;
+		    y->data.F32[n] = iy + 0.5;
+		}
+		# if (0)
 		if (ix) {
 		    x->data.F32[n] = ix + 0.5 - 0.1;
@@ -387,4 +393,5 @@
 		    y->data.F32[n] = iy + 0.5 + 0.1;
 		}
+		# endif
 		f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
 		field->data.F32[iy][ix] = ix + 0.5 + iy + 0.5;
@@ -439,5 +446,5 @@
 		x->data.F32[n] = ix;
 		y->data.F32[n] = iy;
-		f->data.F32[n] = ix + iy;
+		f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
 		n++;
 	    }
