Index: /trunk/Ohana/src/relastro/Makefile
===================================================================
--- /trunk/Ohana/src/relastro/Makefile	(revision 17242)
+++ /trunk/Ohana/src/relastro/Makefile	(revision 17243)
@@ -21,36 +21,38 @@
 
 RELASTRO = \
-$(SRC)/ConfigInit.$(ARCH).o	 \
-$(SRC)/FitChip.$(ARCH).o         \
-$(SRC)/FitMosaic.$(ARCH).o       \
-$(SRC)/FitPM.$(ARCH).o           \
-$(SRC)/FitPar.$(ARCH).o          \
-$(SRC)/FitPMandPar.$(ARCH).o     \
-$(SRC)/FitSimple.$(ARCH).o       \
-$(SRC)/ImageOps.$(ARCH).o	 \
-$(SRC)/MosaicOps.$(ARCH).o	 \
-$(SRC)/ParFactor.$(ARCH).o       \
-$(SRC)/SetSignals.$(ARCH).o 	 \
-$(SRC)/Shutdown.$(ARCH).o 	 \
-$(SRC)/UpdateChips.$(ARCH).o     \
-$(SRC)/UpdateMosaic.$(ARCH).o    \
-$(SRC)/UpdateObjects.$(ARCH).o   \
-$(SRC)/UpdateSimple.$(ARCH).o    \
-$(SRC)/UpdateMeasures.$(ARCH).o  \
-$(SRC)/GetAstromError.$(ARCH).o  \
-$(SRC)/args.$(ARCH).o		 \
-$(SRC)/bcatalog.$(ARCH).o	 \
-$(SRC)/dvo_astrom_ops.$(ARCH).o  \
-$(SRC)/fitpoly.$(ARCH).o         \
-$(SRC)/initialize.$(ARCH).o	 \
-$(SRC)/liststats.$(ARCH).o	 \
-$(SRC)/load_catalogs.$(ARCH).o	 \
-$(SRC)/load_images.$(ARCH).o	 \
-$(SRC)/mkpolyterm.$(ARCH).o      \
-$(SRC)/plot_scatter.$(ARCH).o	 \
-$(SRC)/plotstuff.$(ARCH).o	 \
-$(SRC)/select_images.$(ARCH).o	 \
-$(SRC)/relastro.$(ARCH).o	 \
-$(SRC)/save_catalogs.$(ARCH).o   \
+$(SRC)/ConfigInit.$(ARCH).o	     \
+$(SRC)/FitChip.$(ARCH).o             \
+$(SRC)/FitMosaic.$(ARCH).o           \
+$(SRC)/FitPM.$(ARCH).o               \
+$(SRC)/FitPar.$(ARCH).o              \
+$(SRC)/FitPMandPar.$(ARCH).o         \
+$(SRC)/FitSimple.$(ARCH).o           \
+$(SRC)/ImageOps.$(ARCH).o	     \
+$(SRC)/MosaicOps.$(ARCH).o	     \
+$(SRC)/ParFactor.$(ARCH).o           \
+$(SRC)/SetSignals.$(ARCH).o 	     \
+$(SRC)/Shutdown.$(ARCH).o 	     \
+$(SRC)/UpdateChips.$(ARCH).o         \
+$(SRC)/UpdateMosaic.$(ARCH).o        \
+$(SRC)/UpdateObjects.$(ARCH).o       \
+$(SRC)/UpdateObjectOffsets.$(ARCH).o \
+$(SRC)/UpdateSimple.$(ARCH).o        \
+$(SRC)/UpdateMeasures.$(ARCH).o      \
+$(SRC)/GetAstromError.$(ARCH).o      \
+$(SRC)/args.$(ARCH).o		     \
+$(SRC)/bcatalog.$(ARCH).o	     \
+$(SRC)/dvo_astrom_ops.$(ARCH).o      \
+$(SRC)/fitpoly.$(ARCH).o             \
+$(SRC)/initialize.$(ARCH).o	     \
+$(SRC)/liststats.$(ARCH).o	     \
+$(SRC)/load_catalogs.$(ARCH).o	     \
+$(SRC)/load_images.$(ARCH).o	     \
+$(SRC)/mkpolyterm.$(ARCH).o          \
+$(SRC)/plot_scatter.$(ARCH).o	     \
+$(SRC)/plotstuff.$(ARCH).o	     \
+$(SRC)/select_images.$(ARCH).o	     \
+$(SRC)/relastro.$(ARCH).o	     \
+$(SRC)/relastro_objects.$(ARCH).o    \
+$(SRC)/save_catalogs.$(ARCH).o       \
 $(SRC)/write_coords.$(ARCH).o
 
Index: /trunk/Ohana/src/relastro/include/relastro.h
===================================================================
--- /trunk/Ohana/src/relastro/include/relastro.h	(revision 17242)
+++ /trunk/Ohana/src/relastro/include/relastro.h	(revision 17243)
@@ -289,2 +289,4 @@
 
 float GetAstromError (Measure *measure, int mode);
+int relastro_objects ();
+int UpdateObjectOffsets (SkyList *skylist);
Index: /trunk/Ohana/src/relastro/src/ImageOps.c
===================================================================
--- /trunk/Ohana/src/relastro/src/ImageOps.c	(revision 17242)
+++ /trunk/Ohana/src/relastro/src/ImageOps.c	(revision 17243)
@@ -229,9 +229,9 @@
       // ???? inconsistently hitting this????
       fprintf (stderr, "!");
-      abort ();
+      // abort ();
     }
     if (fabs(catalog[c].measure[m].dD - dD) > 10.0) {
       fprintf (stderr, "*");
-      abort ();
+      // abort ();
     }
 
Index: /trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c
===================================================================
--- /trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c	(revision 17243)
+++ /trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c	(revision 17243)
@@ -0,0 +1,43 @@
+# include "relastro.h"
+
+int UpdateObjectOffsets (SkyList *skylist) {
+
+  int i;
+  Catalog catalog;
+
+  // load data from each region file, only use bright stars
+  for (i = 0; i < skylist[0].Nregions; i++) {
+
+    // set up the basic catalog info
+    catalog.filename  = skylist[0].filename[i];
+    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
+    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
+    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+
+    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
+      fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
+      exit (1);
+    }
+    if (!catalog.Naves_disk) {
+      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
+      dvo_catalog_unlock (&catalog);
+      dvo_catalog_free (&catalog);
+      continue;
+    }
+
+    // match measurements with images
+    initImageBins (&catalog, 1);
+    findImages (&catalog, 1);
+
+    // update the detection coordinates using the new image parameters
+    UpdateMeasures (&catalog, 1);
+
+    freeImageBins (1);
+
+    // write the updated detections to disk
+    save_catalogs (&catalog, 1);
+  }
+  
+  return (TRUE);
+}
Index: /trunk/Ohana/src/relastro/src/relastro.c
===================================================================
--- /trunk/Ohana/src/relastro/src/relastro.c	(revision 17242)
+++ /trunk/Ohana/src/relastro/src/relastro.c	(revision 17243)
@@ -12,4 +12,10 @@
   initialize (argc, argv);
 
+  /* the object analysis is a separate process iterating over catalogs */
+  if (FIT_TARGET == TARGET_OBJECTS) {
+    relastro_objects ();
+    exit (0);
+  }
+
   /* register database handle with shutdown procedure */
   set_db (&db);
@@ -21,9 +27,9 @@
   if (!dvo_image_load (&db, VERBOSE, FALSE)) Shutdown ("can't read image catalog %s", db.filename);
 
-  /* load regions and images based on specified sky patch */
+  /* load regions and images based on specified sky patch (default depth) */
   skylist = load_images (&db, &UserPatch);
 
-  /* load catalog data from region files : subselect only if we are not doing the objects */
-  catalog = load_catalogs (skylist, &Ncatalog, (FIT_TARGET != TARGET_OBJECTS));
+  /* load catalog data from region files : subselect high-quality measurements */
+  catalog = load_catalogs (skylist, &Ncatalog, TRUE);
 
   /* match measurements with images */
@@ -38,8 +44,4 @@
   /* major modes */
   switch (FIT_TARGET) {
-    case TARGET_OBJECTS:
-      UpdateObjects (catalog, Ncatalog);
-      break;
-
     case TARGET_SIMPLE:
       UpdateSimple (catalog, Ncatalog);
@@ -61,28 +63,14 @@
   if (!UPDATE) exit (0);
 
-  if (FIT_TARGET == TARGET_OBJECTS) {
-    save_catalogs (catalog, Ncatalog);
-  } else {
-    // XXX for now, reload all catalogs at once; as memory use gets large, reload one-at-a-time
+  // free the image / measurement pointers
+  freeImageBins (1);
 
-    // load catalog data from region files : do not subselect
-    catalog = load_catalogs (skylist, &Ncatalog, FALSE);
-    
-    // match measurements with images
-    initImageBins (catalog, Ncatalog);
-    findImages (catalog, Ncatalog);
+  // iterate over catalogs to make detection coordinates consistant
+  UpdateObjectOffsets (skylist);
 
-    // update the detection coordinates using the new image parameters
-    UpdateMeasures (catalog, Ncatalog);
-
-    // write the updated detections to disk
-    save_catalogs (catalog, Ncatalog);
-
-    // save the updated image parameters
-    dvo_image_update (&db, VERBOSE);
-    dvo_image_unlock (&db); 
-  }
+  // save the updated image parameters
+  dvo_image_update (&db, VERBOSE);
+  dvo_image_unlock (&db); 
 
   exit (0);
 }
-
Index: /trunk/Ohana/src/relastro/src/relastro_objects.c
===================================================================
--- /trunk/Ohana/src/relastro/src/relastro_objects.c	(revision 17243)
+++ /trunk/Ohana/src/relastro/src/relastro_objects.c	(revision 17243)
@@ -0,0 +1,62 @@
+# include "relastro.h"
+
+int relastro_objects () {
+
+  int i, j, k, m;
+
+  SkyTable *sky = NULL;
+  SkyList *skylist = NULL;
+  Catalog catalog;
+
+  // load the current sky table (layout of all SkyRegions) 
+  sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, SKY_DEPTH, VERBOSE);
+  SkyTableSetFilenames (sky, CATDIR, "cpt");
+  
+  // determine the populated SkyRegions overlapping the requested area (default depth)
+  skylist = SkyListByPatch (sky, -1, &UserPatch);
+
+  // load data from each region file, only use bright stars
+  for (i = 0; i < skylist[0].Nregions; i++) {
+
+    // set up the basic catalog info
+    catalog.filename  = skylist[0].filename[i];
+    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
+    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
+    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+
+    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
+      fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
+      exit (1);
+    }
+    if (!catalog.Naves_disk) {
+      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
+      dvo_catalog_unlock (&catalog);
+      dvo_catalog_free (&catalog);
+      continue;
+    }
+
+    // XXX consider what gets reset (only ASTROM flags)
+    if (RESET) {
+      for (j = 0; j < catalog.Naverage; j++) {
+	catalog.average[j].code = 0;
+	m = catalog.average[j].measureOffset;
+	for (k = 0; k < catalog.average[j].Nmeasure; k++) {
+	  catalog.measure[m+k].dbFlags = 0;
+	}
+      }
+    }
+
+    UpdateObjects (&catalog, 1);
+
+    if (!UPDATE) {
+      dvo_catalog_unlock (&catalog);
+      dvo_catalog_free (&catalog);
+      continue;
+    }
+    
+    save_catalogs (&catalog, 1);
+  }
+  
+  return (TRUE);
+}
