Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapUtils.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapUtils.c	(revision 37447)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapUtils.c	(revision 37447)
@@ -0,0 +1,92 @@
+# include <dvo.h>
+
+int AstromOffsetTableMatchChips (Image *images, off_t Nimages, AstromOffsetTable *table) {
+
+  // we have a table of astrometry offset maps.  we want to find the chips that match to
+  // each of the maps so we can assign the map to the image.coords.offsetMap entry
+
+  // we have the lookup table of table->IDtoSeq to find the match by imageID
+  
+  // we are just going to assume that table->IDtoSeq is correct and complete
+  off_t i;
+  for (i = 0; i < Nimages; i++) {
+    int imageID = images[i].imageID;
+    if (imageID < 0) continue;
+    if (imageID > table->MaxImageID) continue;
+    
+    int seq = table->IDtoSeq[imageID];
+    if (seq < 0) continue;
+    if (seq >= table->Nmap) continue; // this one is probably not valid, right?
+
+    images[i].coords.offsetMap = table->map[seq];    
+  }
+  return (TRUE);
+}
+
+int AstromOffsetTableNewMap (AstromOffsetTable *table, int order, Image *image) {
+
+  int Nmap = table->Nmap;
+
+  table->Nmap++;
+  REALLOCATE (table->map, AstromOffsetMap *, table->Nmap);
+
+  int Nx = order;
+  int Ny = order;
+
+  off_t i;
+  if (image->imageID > table->MaxImageID) {
+    int oldMaxID = table->MaxImageID;
+    table->MaxImageID = image->imageID;
+    REALLOCATE (table->IDtoSeq, int, table->MaxImageID + 1);
+    for (i = oldMaxID + 1; i < table->MaxImageID + 1; i++) {
+      table->IDtoSeq[i] = -1;
+    }
+  }
+  myAssert (table->IDtoSeq[image->imageID] == -1, "table IDtoSeq not initiazed or image collision");
+  table->IDtoSeq[image->imageID] = Nmap;
+  
+  ALLOCATE (table->map[Nmap], AstromOffsetMap, 1);
+  table->map[Nmap][0].Nx      = Nx;
+  table->map[Nmap][0].Ny      = Ny;
+
+  table->MaxTableID ++;
+  table->map[Nmap][0].tableID = table->MaxTableID;
+  table->map[Nmap][0].imageID = image->imageID;
+  
+  table->map[Nmap][0].dX = Nx / (float) image->NX;
+  table->map[Nmap][0].dY = Ny / (float) image->NY;
+
+  ALLOCATE (table->map[Nmap][0].dXv, float *, Nx);
+  ALLOCATE (table->map[Nmap][0].dYv, float *, Nx);
+
+  int j, k;
+  for (j = 0; j < Nx; j++) {
+    ALLOCATE (table->map[Nmap][0].dXv[j], float, Ny);
+    ALLOCATE (table->map[Nmap][0].dYv[j], float, Ny);
+
+    for (k = 0; k < Ny; k++) {
+      table->map[Nmap][0].dXv[j][k] = 0.0;
+      table->map[Nmap][0].dYv[j][k] = 0.0;
+    }
+  }
+  image[0].coords.offsetMap = table->map[Nmap];
+  return TRUE;    
+}
+
+AstromOffsetTable *AstromOffsetTableInit() {
+
+  AstromOffsetTable *table = NULL;
+  ALLOCATE (table, AstromOffsetTable, 1);
+
+  table->Nmap = 0;
+  ALLOCATE (table->map, AstromOffsetMap *, 1);
+
+  table->MaxTableID = 0;
+  table->MaxImageID = 0;
+
+  // generate the index and init values to -1
+  ALLOCATE (table->IDtoSeq, int, 1);
+  table->IDtoSeq[0] = -1;
+
+  return table;
+}
