Index: trunk/Ohana/src/getstar/Makefile
===================================================================
--- trunk/Ohana/src/getstar/Makefile	(revision 7965)
+++ trunk/Ohana/src/getstar/Makefile	(revision 8392)
@@ -24,10 +24,5 @@
 $(SRC)/Shutdown.$(ARCH).o	 \
 $(SRC)/SetSignals.$(ARCH).o	 \
-$(SRC)/gcatalog.$(ARCH).o 	 \
-$(SRC)/load_pt_catalog.$(ARCH).o \
-$(SRC)/select_by_region.$(ARCH).o \
-$(SRC)/wcatalog.$(ARCH).o        \
-$(SRC)/init_catalog.$(ARCH).o    \
-$(SRC)/mkcatalog.$(ARCH).o
+$(SRC)/select_by_region.$(ARCH).o
 
 OBJ = $(GETSTAR)
Index: trunk/Ohana/src/getstar/src/gcatalog.c
===================================================================
--- trunk/Ohana/src/getstar/src/gcatalog.c	(revision 7965)
+++ 	(revision )
@@ -1,44 +1,0 @@
-# include "getstar.h"
-
-int gcatalog (Catalog *catalog) {
-  
-  int Nsecfilt;
-  int i, j, Nextra, in, out;
-  SecFilt *insec, *outsec;
-
-  /* read catalog header */
-  if (!load_catalog (catalog, VERBOSE)) {
-    fprintf (stderr, "ERROR: failure loading catalog\n");
-    exit (1);
-  }
-
-  /* check Nsecfile value, update if needed */
-  Nsecfilt = GetPhotcodeNsecfilt ();
-  if (catalog[0].Nsecfilt < Nsecfilt) {
-
-    Nextra = Nsecfilt - catalog[0].Nsecfilt;
-    insec = catalog[0].secfilt;
-    ALLOCATE (outsec, SecFilt, catalog[0].Naverage * Nsecfilt);
-    for (in = out = i = 0; i < catalog[0].Naverage; i++) {
-      for (j = 0; j < catalog[0].Nsecfilt; j++, in++, out++) {
-	outsec[out].M_PS  = insec[in].M_PS;
-	outsec[out].dM_PS = insec[in].dM_PS;
-	outsec[out].Xm = insec[in].Xm;
-      }
-      for (j = 0; j < Nextra; j++, out++) {
-	outsec[out].M_PS  = NO_MAG;
-	outsec[out].dM_PS = NO_MAG;
-	outsec[out].Xm    = NO_MAG;
-      }
-    }
-    free (catalog[0].secfilt);
-    catalog[0].secfilt = outsec;
-    catalog[0].Nsecfilt = Nsecfilt;
-  }
-
-  if (catalog[0].Nsecfilt > Nsecfilt) {
-    fprintf (stderr, "ERROR: can't reduce number of secondary filters\n");
-    exit (1);
-  }
-  return (TRUE);
-}
Index: trunk/Ohana/src/getstar/src/getstar.c
===================================================================
--- trunk/Ohana/src/getstar/src/getstar.c	(revision 7965)
+++ trunk/Ohana/src/getstar/src/getstar.c	(revision 8392)
@@ -16,7 +16,10 @@
   SkyTableSetFilenames (sky, CATDIR, "cpt");
 
-  /* choose elements to load based on options */
-  catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
-  init_catalog (&output);
+  // create an output catalog with the desired name and format options
+  output.filename  = OUTPUT;
+  output.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
+  output.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
+  output.Nsecfilt  = GetPhotcodeNsecfilt ();
+  dvo_catalog_open (&output, NULL, VERBOSE, "w");
 
   switch (MODE) {
@@ -28,10 +31,22 @@
       skylist = SkyListByPatch (sky, -1, &REGION);
       for (i = 0; i < skylist[0].Nregions; i++) {
+	// set the parameters which guide catalog open/load/create
 	catalog.filename = skylist[0].filename[i];
-	load_pt_catalog (&catalog, skylist[0].regions[i]);
-	unlock_catalog (&catalog);
+	catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+	catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
+
+	// an error exit status here is a significant error
+	if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "r")) {
+	  fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
+	  exit (2);
+	}
+	if (!catalog.Nave_disk) {
+	  dvo_catalog_unlock (&catalog);
+	  dvo_catalog_free (&catalog);
+	  continue;
+	}
+	dvo_catalog_unlock (&catalog);
 
 	/* skip empty catalogs */
-	if (catalog.Nave_disk == 0) continue;
 	select_by_region (&output, &catalog, &REGION, 0, 0);
       }
@@ -46,11 +61,17 @@
       skylist = SkyListByImage (sky, -1, &image, &Nimage);
       for (i = 0; i < skylist[0].Nregions; i++) {
-	  catalog.filename = skylist[0].filename[i];
-	  load_pt_catalog (&catalog, skylist[0].regions[i]);
-	  unlock_catalog (&catalog);
+	// set the parameters which guide catalog open/load/create
+	catalog.filename = skylist[0].filename[i];
+	catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+	catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
 
-	  /* skip empty catalogs */
-	  if (catalog.Nave_disk == 0) continue;
-	  stars = select_by_image (&catalog, &image, 0, 0, stars, &Nstars);
+	// an error exit status here is a significant error
+	if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "r")) {
+	  fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
+	  exit (2);
+	}
+	/* skip empty catalogs */
+	if (!catalog.Nave_disk) continue;
+	stars = select_by_image (&catalog, &image, 0, 0, stars, &Nstars);
       }
       # endif
@@ -70,7 +91,9 @@
 
   /* write out the selected stars */
-  wcatalog (OUTPUT, &output);
+  // XXX need to set the catalog boundaries by hand? RA0-RA1, DEC0-DEC1
+  dvo_catalog_save (&output, VERBOSE);
+  dvo_catalog_unlock (&output);
+  dvo_catalog_free (&output);
   fprintf (stderr, "SUCCESS\n");
   exit (0);
-
 }
Index: trunk/Ohana/src/getstar/src/init_catalog.c
===================================================================
--- trunk/Ohana/src/getstar/src/init_catalog.c	(revision 7965)
+++ 	(revision )
@@ -1,27 +1,0 @@
-# include "getstar.h"
-
-void init_catalog (Catalog *catalog) {
-  
-  catalog[0].Naverage = 0;
-  ALLOCATE (catalog[0].average, Average, 1);
-
-  catalog[0].Nmeasure = 0;
-  ALLOCATE (catalog[0].measure, Measure, 1);
-
-  catalog[0].Nsecfilt = GetPhotcodeNsecfilt ();
-  ALLOCATE (catalog[0].secfilt, SecFilt, 1);
-
-  catalog[0].Nmissing = 0;
-  ALLOCATE (catalog[0].missing, Missing, 1);
-
-  // there is no data yet on disk:
-  catalog[0].Nave_disk = 0;
-  catalog[0].Nmeas_disk = 0;
-  catalog[0].Nmiss_disk = 0;
-  catalog[0].Nmeas_off = 0;
-}
-
-/* setup secondary filters to match photcodes:
- * Nsecfilt is number of filters.  Number of entries in array is
- * Nsecfilt * Naverage.  At this point, N entries == 0
- */
Index: trunk/Ohana/src/getstar/src/load_pt_catalog.c
===================================================================
--- trunk/Ohana/src/getstar/src/load_pt_catalog.c	(revision 7965)
+++ 	(revision )
@@ -1,27 +1,0 @@
-# include "getstar.h"
-
-int load_pt_catalog (Catalog *catalog, SkyRegion *region) {
-  
-  if (!check_file_access (catalog[0].filename, TRUE, TRUE)) {
-    exit (1);
-  }
-
-  if (VERBOSE) fprintf (stderr, "loading from %s\n", catalog[0].filename);
-    
-  switch (lock_catalog (catalog, LCK_XCLD)) {
-  case 0:
-    fprintf (stderr, "ERROR: can't lock file %s\n", catalog[0].filename);
-    exit (1);
-  case 1:
-    gcatalog (catalog); /* load from disk */
-    break;
-  case 2:
-    /* no data in file */
-    return (FALSE);
-  }
-  return (TRUE);
-}
-
-/* If the catalog file is locked, something weird is happening...  this is an unexpected error
-   because ImageCat was NOT locked so we should be the only locking entity.  However, this logic
-   breaks down for the server design: image and catalog are updated independently... */
Index: trunk/Ohana/src/getstar/src/mkcatalog.c
===================================================================
--- trunk/Ohana/src/getstar/src/mkcatalog.c	(revision 7965)
+++ 	(revision )
@@ -1,121 +1,0 @@
-# include "getstar.h"
-
-void mkcatalog (Catalog *catalog) {
-  
-  int i;
-  double Rmin, Rmax, Dmin, Dmax;
-  int length, status;
-  char *path, *root, *file, *line;
-  time_t now;
-
-  if (VERBOSE) fprintf (stderr, "new catalog file: %s\n", catalog[0].filename);
-
-  /* set the recommended CATFORMAT */
-  catalog[0].catformat = DVO_FORMAT_UNDEF;
-  if (!strcasecmp (CATFORMAT, "INTERNAL"))  catalog[0].catformat = DVO_FORMAT_INTERNAL;
-  if (!strcasecmp (CATFORMAT, "LONEOS"))    catalog[0].catformat = DVO_FORMAT_LONEOS;
-  if (!strcasecmp (CATFORMAT, "ELIXIR"))    catalog[0].catformat = DVO_FORMAT_ELIXIR;
-  if (!strcasecmp (CATFORMAT, "PANSTARRS")) catalog[0].catformat = DVO_FORMAT_PANSTARRS;
-  if (!strcasecmp (CATFORMAT, "PMTEST"))    catalog[0].catformat = DVO_FORMAT_PMTEST;
-  if (catalog[0].catformat == DVO_FORMAT_UNDEF) {
-    fprintf (stderr, "invalid output catalog format\n");
-    exit (1);
-  }
-
-  /* set the recommended CATMODE */
-  catalog[0].catmode = DVO_MODE_UNDEF;
-  if (!strcasecmp (CATMODE, "RAW"))  catalog[0].catmode = DVO_MODE_RAW;
-  if (!strcasecmp (CATMODE, "MEF"))  catalog[0].catmode = DVO_MODE_MEF;
-  if (!strcasecmp (CATMODE, "SPLIT"))  catalog[0].catmode = DVO_MODE_SPLIT;
-  if (catalog[0].catmode == DVO_MODE_UNDEF) {
-    fprintf (stderr, "invalid output catalog mode\n");
-    exit (1);
-  }
-
-  gfits_init_header (&catalog[0].header);
-
-  if (catalog[0].catmode == DVO_MODE_RAW) {
-    /* make header a fake image */
-    catalog[0].header.bitpix   = 16;
-    catalog[0].header.Naxes    = 2;
-    catalog[0].header.Naxis[0] = 1;
-    catalog[0].header.Naxis[1] = 1;
-  }
-
-  gfits_create_header (&catalog[0].header);
-  
-  if (catalog[0].catmode == DVO_MODE_SPLIT) {
-    path = pathname (catalog[0].filename);
-    root = filerootname (catalog[0].filename);
-    length = strlen(path) + strlen(root) + 6;
-
-    /* define measure catalog file */
-    ALLOCATE (catalog[0].measure_catalog, Catalog, 1);
-    gfits_init_header (&catalog[0].measure_catalog[0].header);
-    gfits_create_header (&catalog[0].measure_catalog[0].header);
-    ALLOCATE (catalog[0].measure_catalog[0].filename, char, length);
-    sprintf (catalog[0].measure_catalog[0].filename, "%s/%s.cpm", path, root);
-    status = lock_catalog (catalog[0].measure_catalog, catalog[0].lockmode);
-    if (status != 2) {
-      fprintf (stderr, "error with file lock\n");
-      exit (2);
-    }
-    file = filebasename (catalog[0].measure_catalog[0].filename);
-    gfits_modify (&catalog[0].header, "MEASURE", "%s", 1, file);
-    free (file);
-
-    /* define missing catalog file */
-    ALLOCATE (catalog[0].missing_catalog, Catalog, 1);
-    gfits_init_header (&catalog[0].missing_catalog[0].header);
-    gfits_create_header (&catalog[0].missing_catalog[0].header);
-    ALLOCATE (catalog[0].missing_catalog[0].filename, char, length);
-    sprintf (catalog[0].missing_catalog[0].filename, "%s/%s.cpn", path, root);
-    if (lock_catalog (catalog[0].missing_catalog, catalog[0].lockmode) != 2) {
-      fprintf (stderr, "error with file lock\n");
-      exit (2);
-    }
-    file = filebasename (catalog[0].missing_catalog[0].filename);
-    gfits_modify (&catalog[0].header, "MISSING", "%s", 1, file);
-    free (file);
-
-    /* define secfilt catalog file */
-    ALLOCATE (catalog[0].secfilt_catalog, Catalog, 1);
-    gfits_init_header (&catalog[0].secfilt_catalog[0].header);
-    gfits_create_header (&catalog[0].secfilt_catalog[0].header);
-    ALLOCATE (catalog[0].secfilt_catalog[0].filename, char, length);
-    sprintf (catalog[0].secfilt_catalog[0].filename, "%s/%s.cps", path, root);
-    if (lock_catalog (catalog[0].secfilt_catalog, catalog[0].lockmode) != 2) {
-      fprintf (stderr, "error with file lock\n");
-      exit (2);
-    }
-    file = filebasename (catalog[0].secfilt_catalog[0].filename);
-    gfits_modify (&catalog[0].header, "SECFILT", "%s", 1, file);
-    free (file);
-    free (path);
-    free (root);
-  }    
-
-  /* determine RA,DEC range */
-  Rmin = 360.0;
-  Rmax =   0.0;
-  Dmin = +90.0;
-  Dmax = -90.0;
-  for (i = 0; i < catalog[0].Naverage; i++) {
-    Rmin = MIN (Rmin, catalog[0].average[i].R);
-    Rmax = MAX (Rmax, catalog[0].average[i].R);
-    Dmin = MIN (Dmin, catalog[0].average[i].D);
-    Dmax = MAX (Dmax, catalog[0].average[i].D);
-  }
-
-  /* write RA,DEC range in header */
-  gfits_modify (&catalog[0].header, "RA0",  "%lf", 1, Rmin);
-  gfits_modify (&catalog[0].header, "DEC0", "%lf", 1, Dmin);
-  gfits_modify (&catalog[0].header, "RA1",  "%lf", 1, Rmax);
-  gfits_modify (&catalog[0].header, "DEC1", "%lf", 1, Dmax);
-
-  /* write creation date in header */
-  str_to_time ("now", &now);
-  line = sec_to_date (now);
-  gfits_modify (&catalog[0].header, "DATE", "%s", 1, line);
-  free (line);
-}
Index: trunk/Ohana/src/getstar/src/wcatalog.c
===================================================================
--- trunk/Ohana/src/getstar/src/wcatalog.c	(revision 7965)
+++ 	(revision )
@@ -1,25 +1,0 @@
-# include "getstar.h"
-
-void wcatalog (char *filename, Catalog *catalog) {
-
-  /* CATMODE and CATFORMAT determined from catalog */
-  // XXX 'stdout' and SPLIT are not compatible
-  
-  catalog[0].filename = filename;
-  mkcatalog (catalog);
-
-  /* open file as appropriate */
-  if (!strcasecmp (filename, "stdout")) {
-    catalog[0].f = stdout;
-  } else {
-    catalog[0].f = fopen (filename, "w");
-    if (catalog[0].f == NULL) {
-      fprintf (stderr, "ERROR: failure opening catalog for output\n");
-      exit (1);
-    }
-  }    
-  if (!save_catalog (catalog, VERBOSE)) {
-    fprintf (stderr, "ERROR: failure saving catalog\n");
-    exit (1);
-  }
-}
