Index: trunk/Ohana/src/addstar/Makefile
===================================================================
--- trunk/Ohana/src/addstar/Makefile	(revision 8328)
+++ trunk/Ohana/src/addstar/Makefile	(revision 8342)
@@ -35,5 +35,4 @@
 $(SRC)/find_subset.$(ARCH).o \
 $(SRC)/fakeimage.$(ARCH).o \
-$(SRC)/gcatalog.$(ARCH).o \
 $(SRC)/get2mass.$(ARCH).o \
 $(SRC)/get2mass_as.$(ARCH).o \
@@ -49,9 +48,6 @@
 $(SRC)/gimages.$(ARCH).o \
 $(SRC)/gstars.$(ARCH).o \
-$(SRC)/image-db.$(ARCH).o \
 $(SRC)/in_image.$(ARCH).o \
-$(SRC)/load_pt_catalog.$(ARCH).o \
 $(SRC)/load_subpix.$(ARCH).o \
-$(SRC)/mkcatalog.$(ARCH).o \
 $(SRC)/opening_angle.$(ARCH).o \
 $(SRC)/parse_time.$(ARCH).o \
@@ -61,5 +57,4 @@
 $(SRC)/sort_lists.$(ARCH).o \
 $(SRC)/update_coords.$(ARCH).o \
-$(SRC)/wcatalog.$(ARCH).o \
 $(SRC)/Shutdown.$(ARCH).o \
 $(SRC)/SkyTableFromTychoIndex.$(ARCH).o \
Index: trunk/Ohana/src/addstar/src/addstar.c
===================================================================
--- trunk/Ohana/src/addstar/src/addstar.c	(revision 8328)
+++ trunk/Ohana/src/addstar/src/addstar.c	(revision 8342)
@@ -30,11 +30,8 @@
   overlap = NULL;
   set_db (&db);
-  if (options.update) {
-    catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
-  } else {
-    catalog.catflags = LOAD_AVES | LOAD_MEAS      | LOAD_MISS | LOAD_SECF;
-  }
 
   /* we use the image table to lock db access -- perhaps this is not necessary? */
+  db.mode = dvo_catalog_catmode (CATMODE);
+  db.format = dvo_catalog_catformat (CATFORMAT);
   status = dvo_image_lock (&db, ImageCat, 3600.0, LCK_XCLD);
   if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
@@ -61,5 +58,5 @@
 
       if (db.dbstate == LCK_EMPTY) {
-	create_image_db (&db);
+	dvo_image_create (&db, ZeroPt);
       } else {
 	if (!dvo_image_load (&db, VERBOSE, FORCE_READ)) {
@@ -94,14 +91,22 @@
   for (i = 0; i < skylist[0].Nregions; i++) {
 
+    // set the parameters which guide catalog open/load/create
+    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.filename = skylist[0].filename[i];
-    catalog.catformat = dvo_catalog_format (CATFORMAT);  // set the default catformat from config data
-    catalog.catmode   = dvo_catalog_mode (CATMODE);      // set the default catmode from config data
-    catalog.lockmode  = LCK_XCLD;
-    dvo_catalog_open (&catalog, skylist[0].regions[i], Nsecfilt, "w");
+    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+    catalog.catflags = LOAD_AVES | LOAD_MEAS      | LOAD_MISS | LOAD_SECF;
+    if (options.update) catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
 
-    /* for only_match, skip empty catalogs XXX EAM : this leaves behind empty files */
+    // an error exit status here is a significant error
+    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
+      fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
+      exit (2);
+    }
+
+    // Nave_disk == 0 implies an empty catalog file
+    // for only_match, skip empty catalogs
     if ((catalog.Nave_disk == 0) && options.only_match) {
       dvo_catalog_unlock (&catalog);
-      free (catalog.filename);  // can this be done within the dvo_catalog_free function?? 
       dvo_catalog_free (&catalog);
       continue;
@@ -138,23 +143,22 @@
     }
 
-    if (Nsubset == 0) {
-      // XXX remove empty catalogs
-      unlock_catalog (&catalog);
-    } else {
+    // write out catalog, if appropriate
+    if (Nsubset && !options.only_images) {
       SetProtect (TRUE);
-      if (!options.only_images) dvo_catalog_save (&catalog);
+      dvo_catalog_save (&catalog, VERBOSE);
       SetProtect (FALSE);
-      dvo_catalog_unlock (&catalog);
     }
+    dvo_catalog_unlock (&catalog);
     dvo_catalog_free (&catalog);
-    free (catalog.filename); // XXX ????
 
     if (options.mode == M_REFCAT) free (stars);
   }
 
+  // XXX is it necessary to lock the image catalog during this entire process?
   if (options.calibrate) { FindCalibration (&image); }
 
   if (db.dbstate == LCK_EMPTY) {
-    create_image_db (&db);
+    if (VERBOSE) fprintf (stderr, "can't find %s, creating a new one\n", ImageCat);
+    dvo_image_create (&db, ZeroPt);
   }
   
@@ -173,5 +177,5 @@
   gettimeofday (&stop, NULL);
   dtime = DTIME (stop, start);
-  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for %5d stars, %6d average, %7d measure\n", dtime, Nstars, Naverage, Nmeasure);
+  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for %5d stars, %6lld average, %7lld measure\n", dtime, Nstars, Naverage, Nmeasure);
   exit (0);
 }
Index: trunk/Ohana/src/addstar/src/wcatalog.c
===================================================================
--- trunk/Ohana/src/addstar/src/wcatalog.c	(revision 8328)
+++ trunk/Ohana/src/addstar/src/wcatalog.c	(revision 8342)
@@ -5,7 +5,4 @@
   /* output CATMODE and CATFORMAT are set by mkcatalog 
      or by mode and format of existing data */
-
-  /* should this be moved into save_catalog?? */
-  gfits_modify (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
 
   /* if partial load, must use update */
@@ -23,23 +20,2 @@
 }
 
-void free_catalog (Catalog *catalog) {
-
-  /* free, initialize data structures */
-  if (catalog[0].average != NULL) {
-    free (catalog[0].average); 
-    catalog[0].Naverage = 0;
-  }
-  if (catalog[0].measure != NULL) {
-    free (catalog[0].measure); 
-    catalog[0].Nmeasure = 0;
-  }
-  if (catalog[0].missing != NULL) {
-    free (catalog[0].missing); 
-    catalog[0].Nmissing = 0;
-  }
-  if (catalog[0].secfilt != NULL) {
-    free (catalog[0].secfilt); 
-    catalog[0].Nsecfilt = 0;
-  }
-  gfits_free_header (&catalog[0].header);
-}
