Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/astrom_maps.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/astrom_maps.c	(revision 37437)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/astrom_maps.c	(revision 37438)
@@ -24,2 +24,3 @@
 }
 
+int 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/FitChip.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/FitChip.c	(revision 37437)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/FitChip.c	(revision 37438)
@@ -49,4 +49,6 @@
     // use that count to set order_use below
 
+    // 20140925 : the same logic below is used to constrain the dimensions of the image map
+
     // figures to assess the fitting process:
     // x vs dx, x vs dy, y vs dx, y vs dy : 
@@ -65,5 +67,11 @@
       return FALSE;
     }
-    image[0].coords.Npolyterms = order_use;
+
+    // when fitting the map, first fit a linear model (below? change Npolyterms to -1)
+    if (MAP) {
+      image[0].coords.Npolyterms = 1;
+    } else {
+      image[0].coords.Npolyterms = order_use;
+    }
 
     if (fit) fit_free (fit);
@@ -92,7 +100,19 @@
 
     for (i = 0; i < Nmatch; i++) {
+      // we have not yet fitted the map, so image[0].coords.Npolyterms needs to 
+      // be 1 here...
       XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[0].coords);
     }
 
+    // where do we apply the fit all the way b
+
+    if (MAP) {
+      if (image[0].coords.offsetMap == NULL) {
+	AstromOffsetMap *map = AstromOffsetTableNewMap(table, order);
+	image[0].coords.offsetMap = map;
+      }
+      fit_map (image[0].coords.offsetMap, raw, ref);
+      image[0].coords.Npolyterm = -1;
+    }
   }
 
@@ -254,2 +274,14 @@
 */
 
+int fit_map (AstromOffsetMap *map) {
+
+  // we are actually fitting the residual after the linear fit has been taken off
+  
+  // fit the linear terms as above
+  // calculate dX (raw.X - ref.X) and dY 
+  
+  AstromOffsetMapFit (map, x, y, dX, Npts, TRUE);
+  AstromOffsetMapFit (map, x, y, dY, Npts, FALSE);
+
+  return TRUE;
+}
Index: /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/fitpoly.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/fitpoly.c	(revision 37437)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/fitpoly.c	(revision 37438)
@@ -277,4 +277,5 @@
 /* this should only apply to the polynomial, not the projection terms */
 /* compare with psastro supporting code */
+// this code will work for linear (Npolyterm == 0 or 1) and linear + map fits
 int fit_apply_coords (CoordFit *fit, Coords *coords, int keepRef) {
 
