Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/include/libdvo_astro.h
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/include/libdvo_astro.h	(revision 37682)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/include/libdvo_astro.h	(revision 37683)
@@ -59,4 +59,5 @@
   unsigned int tableID;
   unsigned int imageID;
+  int keep;
 } AstromOffsetMap;
 
@@ -140,4 +141,6 @@
 /* in coords.c */
 void InitCoords (Coords *coords, char *projection);
+void CopyCoords (Coords *tgt, Coords *src);
+
 int  XY_to_LM (double *L, double *M, double x,  double y,   Coords *coords);
 int  LM_to_XY (double *x,  double *y,   double L, double M, Coords *coords);
@@ -169,5 +172,5 @@
 void AstromOffsetMapFree (AstromOffsetMap *map);
 
-int AstromOffsetTableNewMap (AstromOffsetTable *table, int order, Image *image);
+int AstromOffsetTableNewMap (AstromOffsetTable *table, int Nx, int Ny, Image *image);
 int AstromOffsetTableMatchChips (Image *images, off_t Nimages, AstromOffsetTable *table);
 AstromOffsetTable *AstromOffsetTableInit();
@@ -176,4 +179,7 @@
 void AstromOffsetMapPrint (AstromOffsetMap *map, char *filename);
 int AstromOffsetMapRepair (AstromOffsetMap *map, int xdir);
+AstromOffsetMap *AstromOffsetMapCopy (AstromOffsetMap *map);
+void AstromOffsetMapCopyData (AstromOffsetMap *tgt, AstromOffsetMap *src);
+void AstromOffsetMapSetOrder (AstromOffsetMap *map, int Nx, int Ny, Image *image);
 
 # endif
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapIO.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapIO.c	(revision 37682)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapIO.c	(revision 37683)
@@ -142,4 +142,7 @@
     table->map[i][0].dX 	  = map_disk[i].dY;
 
+    // since this was on disk, we obviously keep it
+    table->map[i][0].keep 	  = TRUE;
+
     ALLOCATE (table->map[i][0].dXv, float *, map_disk[i].Nx);
     ALLOCATE (table->map[i][0].dYv, float *, map_disk[i].Nx);
@@ -167,21 +170,25 @@
   // assign the map values (this allocates just the area needed for each image, not the
   // full 6x6, saving some memory while doing the analysis)
+  // some maps in the table should be skipped because their image no longer uses them
+  int Ndisk = 0;
   for (i = 0; i < table->Nmap; i++) {
-    map_disk[i].Nx 	 = table->map[i][0].Nx;
-    map_disk[i].Ny 	 = table->map[i][0].Ny;
-    map_disk[i].tableID	 = table->map[i][0].tableID;
-    map_disk[i].imageID  = table->map[i][0].imageID;
+    if (!table->map[i][0].keep) continue;
+    map_disk[Ndisk].Nx 	    = table->map[i][0].Nx;
+    map_disk[Ndisk].Ny 	    = table->map[i][0].Ny;
+    map_disk[Ndisk].tableID = table->map[i][0].tableID;
+    map_disk[Ndisk].imageID = table->map[i][0].imageID;
     
-    map_disk[i].dX 	 = table->map[i][0].dX;
-    map_disk[i].dY 	 = table->map[i][0].dY;
+    map_disk[Ndisk].dX 	    = table->map[i][0].dX;
+    map_disk[Ndisk].dY 	    = table->map[i][0].dY;
 
-    for (j = 0; j < map_disk[i].Nx; j++) {
-      for (k = 0; k < map_disk[i].Ny; k++) {
-	map_disk[i].dXv[j][k] = table->map[i][0].dXv[j][k];
-	map_disk[i].dYv[j][k] = table->map[i][0].dYv[j][k];
+    for (j = 0; j < map_disk[Ndisk].Nx; j++) {
+      for (k = 0; k < map_disk[Ndisk].Ny; k++) {
+	map_disk[Ndisk].dXv[j][k] = table->map[i][0].dXv[j][k];
+	map_disk[Ndisk].dYv[j][k] = table->map[i][0].dYv[j][k];
       }
     }
+    Ndisk ++;
   }
-  *Nmap = table->Nmap;
+  *Nmap = Ndisk;
   return map_disk;
 }
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapUtils.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapUtils.c	(revision 37682)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapUtils.c	(revision 37683)
@@ -34,4 +34,6 @@
   map->Ny = Ny; // output map size
  
+  map->keep = TRUE; // output map size
+
   ALLOCATE (map->dXv, float *, map->Nx);
   ALLOCATE (map->dYv, float *, map->Nx);
@@ -69,12 +71,48 @@
 }
 
-void AstromOffsetMapCopy (AstromOffsetMap *map) {
-
-  if (!map) return;
-
-  AstromOffsetMap *tgt = AstromOffsetMInit (map->Nx, map->Ny);
+void AstromOffsetMapSetOrder (AstromOffsetMap *map, int Nx, int Ny, Image *image) {
+
+  int j, k;
+
+  // rather than try to figure out how to resize, and free/allocate, lets just free the old arrays and make new ones
+  for (j = 0; j < map->Nx; j++) {
+    if (map->dXv) free (map->dXv[j]);
+    if (map->dYv) free (map->dYv[j]);
+  }
+  free (map->dXv);
+  free (map->dYv);
+
+  map->Nx = Nx; // output map size
+  map->Ny = Ny; // output map size
+  map->dX = Nx / (float) image->NX;
+  map->dY = Ny / (float) image->NY;
+ 
+  map->keep = TRUE; // output map size
+
+  ALLOCATE (map->dXv, float *, map->Nx);
+  ALLOCATE (map->dYv, float *, map->Nx);
+
+  for (j = 0; j < map->Nx; j++) {
+    ALLOCATE (map->dXv[j], float, map->Ny);
+    ALLOCATE (map->dYv[j], float, map->Ny);
+
+    for (k = 0; k < map->Ny; k++) {
+      map->dXv[j][k] = 0.0;
+      map->dYv[j][k] = 0.0;
+    }
+  }
+  return;
+}
+
+AstromOffsetMap *AstromOffsetMapCopy (AstromOffsetMap *map) {
+
+  if (!map) return NULL;
+
+  AstromOffsetMap *tgt = AstromOffsetMapInit (map->Nx, map->Ny);
 
   tgt->dX = map->dX; 
   tgt->dY = map->dY; 
+  tgt->imageID = map->imageID; 
+  tgt->tableID = map->tableID; 
 
   int j, k;
@@ -85,16 +123,27 @@
     }
   }
-
-  int j;
-  for (j = 0; j < map->Nx; j++) {
-    if (map->dXv) free (map->dXv[j]);
-    if (map->dYv) free (map->dYv[j]);
-  }
-
-  free (map->dXv);
-  free (map->dYv);
-
-  free (map);
-
+  return tgt;
+}
+
+// copy the data from one to another, assuming a pre-allocated structure
+void AstromOffsetMapCopyData (AstromOffsetMap *tgt, AstromOffsetMap *src) {
+
+  myAssert (tgt->Nx == src->Nx, "programming error");
+  myAssert (tgt->Ny == src->Ny, "programming error");
+
+  tgt->dX = src->dX; 
+  tgt->dY = src->dY; 
+  tgt->imageID = src->imageID; 
+  tgt->tableID = src->tableID; 
+
+  tgt->keep = src->keep; 
+
+  int j, k;
+  for (j = 0; j < tgt->Nx; j++) {
+    for (k = 0; k < src->Ny; k++) {
+      tgt->dXv[j][k] = src->dXv[j][k];
+      tgt->dYv[j][k] = src->dYv[j][k];
+    }
+  }
   return;
 }
@@ -118,5 +167,5 @@
 }
 
-int AstromOffsetTableNewMap (AstromOffsetTable *table, int order, Image *image) {
+int AstromOffsetTableNewMap (AstromOffsetTable *table, int Nx, int Ny, Image *image) {
 
   int Nmap = table->Nmap;
@@ -124,7 +173,4 @@
   table->Nmap++;
   REALLOCATE (table->map, AstromOffsetMap *, table->Nmap);
-
-  int Nx = order;
-  int Ny = order;
 
   off_t i;
@@ -213,5 +259,5 @@
   }
 
-  fprintf (f, "imageID: %d, tableID: %d (dX: %f, dY: %f)\n", map->imageID, map->tableID, map->dX, map->dY);
+  fprintf (f, "imageID: %d, tableID: %d (dX: %f, dY: %f), keep: %d\n", map->imageID, map->tableID, map->dX, map->dY, map->keep);
   int ix, iy;
   fprintf (f, "dXv map:\n");
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/coordops.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/coordops.c	(revision 37682)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/coordops.c	(revision 37683)
@@ -29,4 +29,24 @@
     strcpy (coords->ctype, "NONE");
   }
+} 
+
+// default coordinates have unit scale and no rotation
+void CopyCoords (Coords *tgt, Coords *src) {
+  tgt->crval1     = src->crval1;
+  tgt->crval2     = src->crval2;
+  tgt->crpix1     = src->crpix1;
+  tgt->crpix2     = src->crpix2;
+  tgt->cdelt1     = src->cdelt1;
+  tgt->cdelt2     = src->cdelt2;
+  tgt->pc1_1      = src->pc1_1;
+  tgt->pc2_2      = src->pc2_2;
+  tgt->pc2_1      = src->pc2_1;
+  tgt->pc1_2      = src->pc1_2;
+  tgt->Npolyterms = src->Npolyterms;
+  tgt->mosaic     = src->mosaic;      // pointer to another structure
+  tgt->offsetMap  = src->offsetMap;   // pointer to another structure
+
+  memcpy (tgt->polyterms, src->polyterms, 7*2*sizeof(float));
+  strcpy (tgt->ctype,     src->ctype);
 } 
 
