Index: /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fit_fake_stars.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fit_fake_stars.c	(revision 37574)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fit_fake_stars.c	(revision 37575)
@@ -33,4 +33,5 @@
     return FALSE;
   }
+  order_use = 1; // hard-wire linear solutions (nothing higher is needed for now)
 
   // I have Nstars with "reference" positions stars[].Rref,Dref and 
@@ -40,11 +41,16 @@
 
   int CHIPMAP = (image[0].coords.Npolyterms == -1);
-  image[0].coords.Npolyterms = CHIPMAP ? 1 : order_use;
 
-  CoordFit *fit = fit_init (image[0].coords.Npolyterms);
+  // XX1 image[0].coords.Npolyterms = CHIPMAP ? 1 : order_use;
+  CoordFit *fit = CHIPMAP ? fit_init (1) : fit_init (order_use);
 
   double *L, *M;
   ALLOCATE (L, double, Nstars);
   ALLOCATE (M, double, Nstars);
+
+  // static int Ntest = 0;
+  // char name[64];
+  // snprintf (name, 64, "test.%03d.dat", Ntest); Ntest ++;
+  // FILE *f = fopen (name, "w");
 
   // generate the fit matches
@@ -53,5 +59,11 @@
     RD_to_XY (&L[i], &M[i], stars[i].Rref, stars[i].Dref, image[0].coords.mosaic);
     fit_add (fit, stars[i].measure.Xccd, stars[i].measure.Yccd, L[i], M[i], 0.05);
+
+    // double Lo, Mo, Xo, Yo;
+    // RD_to_XY (&Lo, &Mo, stars[i].average.R, stars[i].average.D, image[0].coords.mosaic);
+    // RD_to_XY (&Xo, &Yo, stars[i].average.R, stars[i].average.D, &image[0].coords);
+    // fprintf (f, "%d : %f %f : %f %f : %f %f : %f %f : %f %f : %f %f\n", i, stars[i].Rref, stars[i].Dref, stars[i].average.R, stars[i].average.D, stars[i].measure.Xccd, stars[i].measure.Yccd, L[i], M[i], Lo, Mo, Xo, Yo);
   }
+  // fclose (f);
 
   // measure the fit, update the coords & object coordinates
@@ -66,4 +78,5 @@
   }
 
+  image[0].coords.Npolyterms = CHIPMAP ? 1 : order_use;
   if (!fit_apply_coords (fit, &image[0].coords, FALSE)) {
     fprintf (stderr, "failed to fit new model\n");
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapIO.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapIO.c	(revision 37574)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapIO.c	(revision 37575)
@@ -48,5 +48,4 @@
   // Convert the disk array of maps to then internal format in a rich structure:
   AstromOffsetTable *table = AstromOffsetMapToTable (map_disk, Nmap);
-  free (map_disk);
 
   gfits_free_header (&theader);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapUtils.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapUtils.c	(revision 37574)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapUtils.c	(revision 37575)
@@ -76,13 +76,13 @@
   for (i = 0; i < table->Nmap; i++) {
     for (j = 0; j < table->map[i][0].Nx; j++) {
-      free (table->map[i][0].dXv);
-      free (table->map[i][0].dYv);
+      free (table->map[i][0].dXv[j]);
+      free (table->map[i][0].dYv[j]);
     }
-    free (table->map[i]);
-    free (table->map[i][0].dXv[j]);
-    free (table->map[i][0].dYv[j]);
+    FREE (table->map[i]);
+    FREE (table->map[i][0].dXv);
+    FREE (table->map[i][0].dYv);
   }
-  free (table->IDtoSeq);
-  free (table->map);
+  FREE (table->IDtoSeq);
+  FREE (table->map);
 }
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/coordops.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/coordops.c	(revision 37574)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/coordops.c	(revision 37575)
@@ -47,4 +47,6 @@
     float dX = AstromOffsetMapValue (coords->offsetMap, x, y, TRUE);
     float dY = AstromOffsetMapValue (coords->offsetMap, x, y, FALSE);
+    if (isnan(dX)) dX = 0.0;
+    if (isnan(dY)) dY = 0.0;
     x += dX;
     y += dY;
@@ -426,4 +428,7 @@
       double dY = AstromOffsetMapValue (coords->offsetMap, xraw, yraw, FALSE);
 
+      if (isnan(dX)) dX = 0.0;
+      if (isnan(dY)) dY = 0.0;
+
       dX -= dXo;
       dY -= dYo;
