Index: /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/ImagePosIO.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/ImagePosIO.c	(revision 36616)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/ImagePosIO.c	(revision 36617)
@@ -53,6 +53,6 @@
   fclose (f);
 
-  // a bit annoying : we read the entire block of data, then extract the columns, then set the image structure values.
-  // this means I need 3 copies in memory at some point.  ugh.
+  // we read the entire block of data, then extract the columns, then set the image structure values.
+  // I free the FITS table data after extracting the colums to avoid having 3 copies in memory.
 
   char type[16];
@@ -77,4 +77,10 @@
   GET_COLUMN (flags,            "FLAGS",             int);
 
+  // free the memory associated with the FITS files
+  gfits_free_header (&header);
+  gfits_free_matrix (&matrix);
+  gfits_free_header (&theader);
+  gfits_free_table  (&ftable);
+
   ALLOCATE (image_pos, ImagePos, Nrow);
   for (i = 0; i < Nrow; i++) {
@@ -120,9 +126,4 @@
   free (nFitAstrom);
   free (flags     );
-
-  gfits_free_header (&header);
-  gfits_free_matrix (&matrix);
-  gfits_free_header (&theader);
-  gfits_free_table  (&ftable);
 
   *nimage_pos = Nrow;
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/MosaicOps.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/MosaicOps.c	(revision 36616)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/MosaicOps.c	(revision 36617)
@@ -136,4 +136,8 @@
   ALLOCATE (mosaic_for_images, off_t, Nmosaic_for_images);
 
+  // emit an error if we miss mosaics, but stop if we miss too many
+  int NmissMosaic = 0;
+  int NtestMosaic = 0;
+
   /* now assign the WRP images to these mosaics */
   for (i = 0; i < Nimage; i++) {
@@ -141,4 +145,5 @@
 
     if (strcmp(&image[i].coords.ctype[4], "-WRP")) continue;
+    NtestMosaic ++;
 
     /* set image time range */
@@ -148,5 +153,8 @@
     Nmos = getMosaicByTimes (start, stop, startMos, stopMos, indexMos);
     if (Nmos == -1) {
-      fprintf (stderr, "cannot match mosaic for %s\n", image[i].name);
+      if (NmissMosaic < 1000) {
+	fprintf (stderr, "cannot match mosaic for %s\n", image[i].name);
+      }
+      NmissMosaic ++;
       continue;
     }
@@ -165,4 +173,10 @@
   }
 
+  fprintf (stderr, "mosaic matching : %d of possible %d failed to match\n", NmissMosaic, NtestMosaic);
+  if (NmissMosaic > 0.5*NtestMosaic) {
+    fprintf (stderr, "serious problem with mosaic matching\n");
+    exit (5);
+  }
+
   free (startMos);
   free (stopMos);
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/UpdateObjects.c	(revision 36616)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/UpdateObjects.c	(revision 36617)
@@ -1,5 +1,5 @@
 # include "relastro.h"
 
-static off_t   Nmax;
+static off_t Nmax;
 static double *X, *dX;
 static double *Y, *dY;
@@ -36,4 +36,22 @@
   ALLOCATE (pX, double, MAX (1, Nmax));
   ALLOCATE (pY, double, MAX (1, Nmax));
+}  
+
+void freeObjectData () {
+
+  free (R);
+  free (D);
+  free (T);
+  free (X);
+  free (Y);
+
+  free (dR);
+  free (dD);
+  free (dT);
+  free (dX);
+  free (dY);
+
+  free (pX);
+  free (pY);
 }  
 
@@ -412,4 +430,6 @@
   }
 
+  freeObjectData ();
+
   if (VERBOSE) fprintf (stderr, "fitted "OFF_T_FMT" objects ("OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par), skipped "OFF_T_FMT", "OFF_T_FMT" have too large an offset\n",  (NaveSum + NpmSum + NparSum),  NaveSum,  NpmSum,  NparSum,  NskipSum, NoffSum);
   return (TRUE);
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/relastro_client.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/relastro_client.c	(revision 36616)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/relastro_client.c	(revision 36617)
@@ -35,11 +35,11 @@
       Catalog *catalog = load_catalogs (skylist, &Ncatalog, TRUE, HOST_ID, HOSTDIR);
       if (!catalog) {
-	  fprintf (stderr, "ERROR loading catalogs from %s\n", CATDIR);
-	  exit (2);
+	fprintf (stderr, "ERROR loading catalogs from %s\n", CATDIR);
+	exit (2);
       }
       BrightCatalog *bcatalog = BrightCatalogMerge (catalog, Ncatalog);
       if (!BrightCatalogSave (BCATALOG, bcatalog)) {
-	  fprintf (stderr, "ERROR saving bright catalog from %s\n", CATDIR);
-	  exit (2);
+	fprintf (stderr, "ERROR saving bright catalog from %s\n", CATDIR);
+	exit (2);
       }
       break;
@@ -64,5 +64,5 @@
     }
 
-      // XXX loading the images is fairly costly -- see if we can do an image subset
+      // XXX loading the images is fairly costly -- see if we can do an image subset?
     case OP_UPDATE_OFFSETS: {
       FITS_DB db;
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/select_images.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/select_images.c	(revision 36616)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relastro/src/select_images.c	(revision 36617)
@@ -125,5 +125,6 @@
     if (NphotcodesKeep > 0) {
       found = FALSE;
-      // XXX this bit of code excludes DIS mosaics and should be fixed
+      // we have to keep DIS mosaics explicitly (photcode = 0)
+      if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) found = TRUE;
       for (k = 0; (k < NphotcodesKeep) && !found; k++) {
 	if (photcodesKeep[k][0].code == timage[i].photcode) found = TRUE;
