Index: /trunk/Ohana/src/addstar/Makefile
===================================================================
--- /trunk/Ohana/src/addstar/Makefile	(revision 8360)
+++ /trunk/Ohana/src/addstar/Makefile	(revision 8361)
@@ -22,4 +22,10 @@
 
 ADDSTAR = \
+$(SRC)/ConfigInit.$(ARCH).o \
+$(SRC)/SetSignals.$(ARCH).o \
+$(SRC)/Shutdown.$(ARCH).o \
+$(SRC)/SkyListForStars.$(ARCH).o \
+$(SRC)/SkyRegionUtils.$(ARCH).o \
+$(SRC)/SkyTableFromTychoIndex.$(ARCH).o \
 $(SRC)/addstar.$(ARCH).o \
 $(SRC)/airmass.$(ARCH).o \
@@ -27,6 +33,55 @@
 $(SRC)/build_links.$(ARCH).o \
 $(SRC)/calibrate.$(ARCH).o \
-$(SRC)/ConfigInit.$(ARCH).o \
 $(SRC)/dump.$(ARCH).o \
+$(SRC)/edge_check.$(ARCH).o \
+$(SRC)/fakeimage.$(ARCH).o \
+$(SRC)/find_matches.$(ARCH).o \
+$(SRC)/find_matches_closest.$(ARCH).o \
+$(SRC)/find_matches_refstars.$(ARCH).o \
+$(SRC)/find_subset.$(ARCH).o \
+$(SRC)/get2mass.$(ARCH).o \
+$(SRC)/get2mass_as.$(ARCH).o \
+$(SRC)/get2mass_as_raw.$(ARCH).o \
+$(SRC)/get2mass_dr2.$(ARCH).o \
+$(SRC)/get2mass_ops.$(ARCH).o \
+$(SRC)/getgsc.$(ARCH).o \
+$(SRC)/gettycho.$(ARCH).o \
+$(SRC)/getusno.$(ARCH).o \
+$(SRC)/getusnob.$(ARCH).o \
+$(SRC)/gimages.$(ARCH).o \
+$(SRC)/greference.$(ARCH).o \
+$(SRC)/grefstars.$(ARCH).o \
+$(SRC)/gstars.$(ARCH).o \
+$(SRC)/in_image.$(ARCH).o \
+$(SRC)/load_subpix.$(ARCH).o \
+$(SRC)/opening_angle.$(ARCH).o \
+$(SRC)/parse_time.$(ARCH).o \
+$(SRC)/replace_match.$(ARCH).o \
+$(SRC)/resort_catalog.$(ARCH).o \
+$(SRC)/rfits.$(ARCH).o \
+$(SRC)/rtext.$(ARCH).o \
+$(SRC)/sort_lists.$(ARCH).o \
+$(SRC)/update_coords.$(ARCH).o
+
+ADDSTARD = \
+$(SRC)/CheckPassword.$(ARCH).o \
+$(SRC)/ConfigInit.$(ARCH).o \
+$(SRC)/NewImage.$(ARCH).o \
+$(SRC)/NewRefcat.$(ARCH).o \
+$(SRC)/NewReflist.$(ARCH).o \
+$(SRC)/SetSignals.$(ARCH).o \
+$(SRC)/Shutdown.$(ARCH).o \
+$(SRC)/SkyListForStars.$(ARCH).o \
+$(SRC)/SkyRegionUtils.$(ARCH).o \
+$(SRC)/SkyTableFromTychoIndex.$(ARCH).o \
+$(SRC)/SocketOps.$(ARCH).o \
+$(SRC)/UpdateDatabase_Image.$(ARCH).o \
+$(SRC)/UpdateDatabase_Refcat.$(ARCH).o \
+$(SRC)/UpdateDatabase_Reflist.$(ARCH).o \
+$(SRC)/addstard.$(ARCH).o \
+$(SRC)/airmass.$(ARCH).o \
+$(SRC)/args_server.$(ARCH).o \
+$(SRC)/build_links.$(ARCH).o \
+$(SRC)/calibrate.$(ARCH).o \
 $(SRC)/edge_check.$(ARCH).o \
 $(SRC)/find_matches.$(ARCH).o \
@@ -34,97 +89,25 @@
 $(SRC)/find_matches_refstars.$(ARCH).o \
 $(SRC)/find_subset.$(ARCH).o \
-$(SRC)/fakeimage.$(ARCH).o \
 $(SRC)/get2mass.$(ARCH).o \
 $(SRC)/get2mass_as.$(ARCH).o \
-$(SRC)/get2mass_ops.$(ARCH).o \
 $(SRC)/get2mass_as_raw.$(ARCH).o \
 $(SRC)/get2mass_dr2.$(ARCH).o \
+$(SRC)/get2mass_ops.$(ARCH).o \
 $(SRC)/getgsc.$(ARCH).o \
+$(SRC)/gettycho.$(ARCH).o \
 $(SRC)/getusno.$(ARCH).o \
 $(SRC)/getusnob.$(ARCH).o \
-$(SRC)/gettycho.$(ARCH).o \
+$(SRC)/gimages.$(ARCH).o \
 $(SRC)/greference.$(ARCH).o \
-$(SRC)/grefstars.$(ARCH).o \
-$(SRC)/gimages.$(ARCH).o \
-$(SRC)/gstars.$(ARCH).o \
 $(SRC)/in_image.$(ARCH).o \
 $(SRC)/load_subpix.$(ARCH).o \
 $(SRC)/opening_angle.$(ARCH).o \
-$(SRC)/parse_time.$(ARCH).o \
-$(SRC)/replace_match.$(ARCH).o \
-$(SRC)/resort_catalog.$(ARCH).o \
-$(SRC)/SetSignals.$(ARCH).o \
-$(SRC)/sort_lists.$(ARCH).o \
-$(SRC)/update_coords.$(ARCH).o \
-$(SRC)/Shutdown.$(ARCH).o \
-$(SRC)/SkyTableFromTychoIndex.$(ARCH).o \
-$(SRC)/SkyRegionUtils.$(ARCH).o \
-$(SRC)/SkyListForStars.$(ARCH).o \
-$(SRC)/rfits.$(ARCH).o \
-$(SRC)/rtext.$(ARCH).o
-
-GSC-OPS = \
-$(SRC)/RegionOps.$(ARCH).o \
-$(SRC)/gregion_image.$(ARCH).o \
-$(SRC)/gregion_match.$(ARCH).o \
-$(SRC)/gregion_patch.$(ARCH).o \
-$(SRC)/gregion_star.$(ARCH).o
-
-MKACC-2MASS = \
-$(SRC)/mkacc-2mass.$(ARCH).o \
-$(SRC)/image-db.$(ARCH).o \
-$(SRC)/ConfigInit.$(ARCH).o \
-$(SRC)/SetSignals.$(ARCH).o \
-$(SRC)/wimage.$(ARCH).o \
-$(SRC)/get2mass_as.$(ARCH).o
-
-SCAN-2MASS = \
-$(SRC)/scan2mass.$(ARCH).o \
-$(SRC)/scan2mass_as_data.$(ARCH).o \
-$(SRC)/get2mass_as.$(ARCH).o \
-$(SRC)/ConfigInit.$(ARCH).o \
-$(SRC)/Shutdown.$(ARCH).o \
-$(SRC)/SetSignals.$(ARCH).o
-
-LOAD-2MASS = \
-$(SRC)/load2mass.$(ARCH).o \
-$(SRC)/load2mass_as_rawdata.$(ARCH).o \
-$(SRC)/load2mass_catalog.$(ARCH).o \
-$(SRC)/get2mass_ops.$(ARCH).o \
-$(SRC)/find_matches_refstars.$(ARCH).o \
-$(SRC)/load_pt_catalog.$(ARCH).o \
-$(SRC)/args_load2mass.$(ARCH).o \
-$(SRC)/sort_lists.$(ARCH).o \
-$(SRC)/replace_match.$(ARCH).o \
-$(SRC)/update_coords.$(ARCH).o \
-$(SRC)/gcatalog.$(ARCH).o \
-$(SRC)/mkcatalog.$(ARCH).o \
-$(SRC)/wcatalog.$(ARCH).o \
-$(SRC)/ConfigInit.$(ARCH).o \
-$(SRC)/Shutdown.$(ARCH).o \
-$(SRC)/SetSignals.$(ARCH).o
-
-SEDSTAR = \
-$(SRC)/sedstar.$(ARCH).o \
-$(SRC)/SEDtableLoad.$(ARCH).o \
-$(SRC)/SEDfit.$(ARCH).o \
-$(SRC)/SEDops.$(ARCH).o \
-$(SRC)/args_sedstar.$(ARCH).o \
-$(SRC)/gcatalog.$(ARCH).o \
-$(SRC)/mkcatalog.$(ARCH).o \
-$(SRC)/wcatalog.$(ARCH).o \
-$(SRC)/ConfigInit.$(ARCH).o \
-$(SRC)/Shutdown.$(ARCH).o \
-$(SRC)/SetSignals.$(ARCH).o
-
-EXTRA = \
-$(SRC)/bracket.$(ARCH).o \
-$(SRC)/find_proper.$(ARCH).o \
-$(SRC)/gregion_match_glob.$(ARCH).o \
-$(SRC)/gregions.$(ARCH).o \
-$(SRC)/match_refstars.$(ARCH).o \
-
-ADDSTARD = \
-$(SRC)/addstard.$(ARCH).o \
+$(SRC)/replace_match.$(ARCH).o \
+$(SRC)/sort_lists.$(ARCH).o \
+$(SRC)/update_coords.$(ARCH).o
+
+ADDSTART = \
+$(SRC)/addstart.$(ARCH).o \
+$(SRC)/DatasetOps.$(ARCH).o \
 $(SRC)/SocketOps.$(ARCH).o \
 $(SRC)/ConfigInit.$(ARCH).o \
@@ -143,5 +126,7 @@
 $(SRC)/get2mass.$(ARCH).o \
 $(SRC)/get2mass_as.$(ARCH).o \
+$(SRC)/get2mass_as_raw.$(ARCH).o \
 $(SRC)/get2mass_dr2.$(ARCH).o \
+$(SRC)/get2mass_ops.$(ARCH).o \
 $(SRC)/getgsc.$(ARCH).o \
 $(SRC)/getusno.$(ARCH).o \
@@ -149,11 +134,7 @@
 $(SRC)/gettycho.$(ARCH).o \
 $(SRC)/greference.$(ARCH).o \
-$(SRC)/gcatalog.$(ARCH).o \
 $(SRC)/gimages.$(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)/load_subpix.$(ARCH).o \
 $(SRC)/replace_match.$(ARCH).o \
 $(SRC)/SetSignals.$(ARCH).o \
@@ -162,52 +143,4 @@
 $(SRC)/sort_lists.$(ARCH).o \
 $(SRC)/update_coords.$(ARCH).o \
-$(SRC)/wcatalog.$(ARCH).o \
-$(SRC)/Shutdown.$(ARCH).o \
-$(SRC)/edge_check.$(ARCH).o \
-$(SRC)/opening_angle.$(ARCH).o \
-$(SRC)/NewImage.$(ARCH).o \
-$(SRC)/NewReflist.$(ARCH).o \
-$(SRC)/SkyTableFromTychoIndex.$(ARCH).o \
-$(SRC)/NewRefcat.$(ARCH).o 
-
-ADDSTART = \
-$(SRC)/addstart.$(ARCH).o \
-$(SRC)/DatasetOps.$(ARCH).o \
-$(SRC)/SocketOps.$(ARCH).o \
-$(SRC)/ConfigInit.$(ARCH).o \
-$(SRC)/args_server.$(ARCH).o \
-$(SRC)/CheckPassword.$(ARCH).o \
-$(SRC)/UpdateDatabase_Image.$(ARCH).o \
-$(SRC)/UpdateDatabase_Reflist.$(ARCH).o \
-$(SRC)/UpdateDatabase_Refcat.$(ARCH).o \
-$(SRC)/airmass.$(ARCH).o \
-$(SRC)/build_links.$(ARCH).o \
-$(SRC)/calibrate.$(ARCH).o \
-$(SRC)/find_matches.$(ARCH).o \
-$(SRC)/find_matches_closest.$(ARCH).o \
-$(SRC)/find_matches_refstars.$(ARCH).o \
-$(SRC)/find_subset.$(ARCH).o \
-$(SRC)/get2mass.$(ARCH).o \
-$(SRC)/get2mass_as.$(ARCH).o \
-$(SRC)/get2mass_dr2.$(ARCH).o \
-$(SRC)/getgsc.$(ARCH).o \
-$(SRC)/getusno.$(ARCH).o \
-$(SRC)/getusnob.$(ARCH).o \
-$(SRC)/gettycho.$(ARCH).o \
-$(SRC)/greference.$(ARCH).o \
-$(SRC)/gcatalog.$(ARCH).o \
-$(SRC)/gimages.$(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)/replace_match.$(ARCH).o \
-$(SRC)/SetSignals.$(ARCH).o \
-$(SRC)/SkyRegionUtils.$(ARCH).o \
-$(SRC)/SkyListForStars.$(ARCH).o \
-$(SRC)/sort_lists.$(ARCH).o \
-$(SRC)/update_coords.$(ARCH).o \
-$(SRC)/wcatalog.$(ARCH).o \
 $(SRC)/Shutdown.$(ARCH).o \
 $(SRC)/edge_check.$(ARCH).o \
@@ -233,4 +166,35 @@
 $(SRC)/args_client.$(ARCH).o
 
+### this program may need to be repaired (EAM 2006.08)
+MKACC-2MASS = \
+$(SRC)/mkacc-2mass.$(ARCH).o \
+$(SRC)/ConfigInit.$(ARCH).o \
+$(SRC)/SetSignals.$(ARCH).o \
+$(SRC)/get2mass_as.$(ARCH).o
+
+LOAD-2MASS = \
+$(SRC)/load2mass.$(ARCH).o \
+$(SRC)/load2mass_as_rawdata.$(ARCH).o \
+$(SRC)/load2mass_catalog.$(ARCH).o \
+$(SRC)/get2mass_ops.$(ARCH).o \
+$(SRC)/find_matches_refstars.$(ARCH).o \
+$(SRC)/args_load2mass.$(ARCH).o \
+$(SRC)/sort_lists.$(ARCH).o \
+$(SRC)/replace_match.$(ARCH).o \
+$(SRC)/update_coords.$(ARCH).o \
+$(SRC)/ConfigInit.$(ARCH).o \
+$(SRC)/Shutdown.$(ARCH).o \
+$(SRC)/SetSignals.$(ARCH).o
+
+SEDSTAR = \
+$(SRC)/sedstar.$(ARCH).o \
+$(SRC)/SEDtableLoad.$(ARCH).o \
+$(SRC)/SEDfit.$(ARCH).o \
+$(SRC)/SEDops.$(ARCH).o \
+$(SRC)/args_sedstar.$(ARCH).o \
+$(SRC)/ConfigInit.$(ARCH).o \
+$(SRC)/Shutdown.$(ARCH).o \
+$(SRC)/SetSignals.$(ARCH).o
+
 $(ADDSTARC) : $(INC)/addstar.h
 $(ADDSTARD) : $(INC)/addstar.h
@@ -252,13 +216,11 @@
 $(BIN)/addstarc.$(ARCH) : $(ADDSTARC)
 
-gztest                  : $(BIN)/gztest.$(ARCH)
-
 mkacc-2mass                : $(BIN)/mkacc-2mass.$(ARCH)
 $(BIN)/mkacc-2mass.$(ARCH) : $(MKACC-2MASS)
 mkacc-2mass.install        : $(DESTBIN)/mkacc-2mass
 
-scan2mass                : $(BIN)/scan2mass.$(ARCH)
-$(BIN)/scan2mass.$(ARCH) : $(SCAN-2MASS)
-scan2mass.install        : $(DESTBIN)/scan2mass
+sedstar                  : $(BIN)/sedstar.$(ARCH)
+$(BIN)/sedstar.$(ARCH)   : $(SEDSTAR)
+sedstar.install          : $(DESTBIN)/sedstar
 
 load2mass                : $(BIN)/load2mass.$(ARCH)
@@ -266,9 +228,7 @@
 load2mass.install        : $(DESTBIN)/load2mass
 
-sedstar                  : $(BIN)/sedstar.$(ARCH)
-$(BIN)/sedstar.$(ARCH)   : $(SEDSTAR)
-sedstar.install          : $(DESTBIN)/sedstar
-
-all: addstar addstarc addstard addstart 
+gztest                  : $(BIN)/gztest.$(ARCH)
+
+all: addstar addstarc addstard addstart sedstar load2mass
 
 INSTALL = addstar
Index: /trunk/Ohana/src/addstar/include/2mass.h
===================================================================
--- /trunk/Ohana/src/addstar/include/2mass.h	(revision 8360)
+++ /trunk/Ohana/src/addstar/include/2mass.h	(revision 8361)
@@ -22,19 +22,22 @@
 
 SkyTable *get2mass_acc (SkyRegion *patch, char *path, char *accel);
-Stars *get2mass_2DR_data (SkyRegion *region, char *filename, SkyRegion *patch, int photcode, int *nstars);
-Stars *get2mass_AS_data (SkyRegion *region, char *filename, SkyRegion *patch, int phocode, int *nstars);
-Stars *get2mass_AS_rawdata (SkyRegion *region, char *filename, SkyRegion *patch, int phocode, int *nstars);
+Stars    *get2mass_2DR_data (SkyRegion *region, char *filename, SkyRegion *patch, int photcode, int *nstars);
+Stars    *get2mass_AS_data (SkyRegion *region, char *filename, SkyRegion *patch, int phocode, int *nstars);
+Stars    *get2mass_AS_rawdata (SkyRegion *region, char *filename, SkyRegion *patch, int phocode, int *nstars);
 
 SkyTable *scan2mass_acc (char *path, char *accel);
-int scan2mass_as_data (char *filename);
+int       scan2mass_as_data (char *filename);
 
-char *skipNbounds (char *line, char bound, int Nbound, int Nbyte);
-e_time get2mass_time (char *ptr, int Nbound, int Nbyte);
+char     *skipNbounds (char *line, char bound, int Nbound, int Nbyte);
+e_time    get2mass_time (char *ptr, int Nbound, int Nbyte);
+e_time    get2mass_date (char *ptr, int Nbound, int Nmax);
 
-int load2mass_as_rawdata (SkyTable *skytable, char *filename, AddstarClientOptions options);
+int       load2mass_as_rawdata (SkyTable *skytable, char *filename, AddstarClientOptions options);
 SkyTable *load2mass_acc (char *path, char *accel);
-int get2mass_3star (Stars *star, char *line, int Nmax);
-int load2mass_catalog (Catalog *catalog, Stars *stars, int Nstars);
+int       get2mass_3star (Stars *star, char *line, int Nmax);
+int       load2mass_catalog (Catalog *catalog, Stars *stars, int Nstars);
 
-int get2mass_setup (int photcode);
-int get2mass_coords (char *line, double *R, double *D, int Nmax);
+int       get2mass_setup (int photcode);
+int       get2mass_coords (char *line, double *R, double *D, int Nmax);
+int       get2mass_star (Stars *star, char *line, int Nmax);
+int       get2mass_3star (Stars *star, char *line, int Nmax);
Index: /trunk/Ohana/src/addstar/include/sedstar.h
===================================================================
--- /trunk/Ohana/src/addstar/include/sedstar.h	(revision 8360)
+++ /trunk/Ohana/src/addstar/include/sedstar.h	(revision 8361)
@@ -38,7 +38,8 @@
 SEDfit SEDchisq (SEDtableRow *ref, SEDtableRow *data, SEDtableRow *error, int Nfilter);
 SEDtable *SEDtableLoad (char *filename);
-int SEDcolorBracket (SEDtable *table, float color);
+int SEDcolorBracket (SEDtable *table, float color, float delta);
 int SEDfitInit (SEDtable *table);
 int SEDfitPlot (SEDtable *table, double R, double D, SEDfit *minFit, SEDtableRow *sourceValue, SEDtableRow *sourceError);
+int SEDfitClear ();
 int SEDfitCatalog (Catalog *outcat, Catalog *incat, SEDtable *table);
 void SetLimitsRaw (float *xvec, float *yvec, int Nelements, Graphdata *graphmode);
Index: unk/Ohana/src/addstar/src/ConvertStars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ConvertStars.c	(revision 8360)
+++ 	(revision )
@@ -1,58 +1,0 @@
-# include "addstar.h"
-
-# define SWAP_BYTE(X) \
-  tmp = byte[X+0]; byte[X+0] = byte[X+1]; byte[X+1] = tmp;
-# define SWAP_WORD(X) \
-  tmp = byte[X+0]; byte[X+0] = byte[X+3]; byte[X+3] = tmp; \
-  tmp = byte[X+1]; byte[X+1] = byte[X+2]; byte[X+2] = tmp;
-# define SWAP_DBLE(X) \
-  tmp = byte[X+0]; byte[X+0] = byte[X+7]; byte[X+7] = tmp; \
-  tmp = byte[X+1]; byte[X+1] = byte[X+6]; byte[X+6] = tmp; \
-  tmp = byte[X+2]; byte[X+2] = byte[X+5]; byte[X+5] = tmp; \
-  tmp = byte[X+3]; byte[X+3] = byte[X+4]; byte[X+4] = tmp;
-
-# ifdef linux
-# define BYTE_SWAP
-# endif
-
-# ifdef sid
-# define BYTE_SWAP
-# endif
-
-# ifdef dec
-# define BYTE_SWAP
-# endif
-
-# define STARS_SIZE 44
-
-int ConvertStars (StarData *data, int size, int nitems) {
-
-  int i;
-  unsigned char *byte, tmp;
-
-# ifdef BYTE_SWAP
-
-  if (size != STARS_SIZE) {
-    fprintf (stderr, "mismatch in type sizes (StarData) %d vs %d\n", size, STARS_SIZE);
-    return (FALSE);
-  }
-
-  byte = (char *) data;
-  for (i = 0; i < nitems; i++, byte += size) {
-    SWAP_WORD (0);   /* R */
-    SWAP_WORD (4);   /* Y */
-    SWAP_WORD (8);   /* M */
-    SWAP_WORD (12);  /* dM */
-    SWAP_WORD (16);  /* Mgal */
-    SWAP_WORD (20);  /* Map */
-    SWAP_WORD (24);  /* sky */
-    SWAP_WORD (28);  /* fx */
-    SWAP_WORD (32);  /* fy */
-    SWAP_WORD (36);  /* df */
-  }
-  return (TRUE);
-
-# else
-  return (TRUE);
-# endif  
-} 
Index: unk/Ohana/src/addstar/src/RegionOps.c
===================================================================
--- /trunk/Ohana/src/addstar/src/RegionOps.c	(revision 8360)
+++ 	(revision )
@@ -1,211 +1,0 @@
-# include "addstar.h"
-
-# define NBANDS 24
-
-double DecBands[] = {
-  -90.0, -82.5, -75.0, -67.5, -60.0, 
-  -52.5, -45.0, -37.5, -30.0, -22.5, 
-  -15.0, -07.5, +00.0, +07.5, +15.0, 
-  +22.5, +30.0, +37.5, +45.0, +52.5, 
-  +60.0, +67.5, +75.0, +82.5, +90.0
-};
-
-char *DecNames[] = {
-  "s8230", "s7500", "s6730", "s6000", "s5230",
-  "s4500", "s3730", "s3000", "s2230", "s1500", 
-  "s0730", "s0000", "n0000", "n0730", "n1500", 
-  "n2230", "n3000", "n3730", "n4500", "n5230", 
-  "n6000", "n6730", "n7500", "n8230", 
-};
-
-GSCRegion *LoadRegions (int *nregions) {
-  
-  int Nregions, i, NDec, Nx, Ny;
-  char temp[50], file[256];
-  double RA0, RA1, DEC0, DEC1, D0, D1;
-  FILE *f;
-  GSCRegion *regions;
-  Header header;
-  Header theader;
-  Matrix matrix;
-  FTable table;
-  
-  f = fopen (GSCFILE, "r");
-  if (f == NULL) {
-    fprintf (stderr, "ERROR: can't find GSC region file %s\n", GSCFILE);
-    exit (1);
-  }
-
-  /* init & load in table data */
-  table.header = &theader;
-  if (!gfits_fread_header (f, &header))           Shutdown ("can't read primary header for GSC Region table"); 
-  if (!gfits_fread_matrix (f, &matrix, &header))  Shutdown ("can't read primary matrix for GSC Region table");
-  if (!gfits_fread_ftable (f, &table, "REGIONS")) Shutdown ("can't read GSC Region table");
-
-  gfits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
-  gfits_scan (table.header, "NAXIS2", "%d", 1, &Ny);
-
-  Nregions = 0;
-  ALLOCATE (regions, GSCRegion, Ny + 2);  /* allow room for N & S poles */
-
-  /* pole region is artificial - not in table */
-  sprintf (file, "%s/n8230/pole.cpt", CATDIR);
-  regions[Nregions].DEC[0] = 86.25;
-  regions[Nregions].DEC[1] = 93.75;
-  regions[Nregions].RA[0] =  0.0;
-  regions[Nregions].RA[1] =  360.0;
-  strcpy (regions[Nregions].filename, file);
-  Nregions ++;
-
-  /* fill out GSCRegion structure */
-  for (i = 0; i < Ny; i++) {
-    strncpy (temp, &table.buffer[i*48], 48);
-    temp[49] = 0;
-    hstgsc_hms_to_deg (&RA0, &RA1, &DEC0, &DEC1, &temp[7]);
-    if (RA1 < RA0) RA1 += 360.0;
-
-    if (DEC0 < DEC1) {
-      regions[Nregions].DEC[0] = DEC0;
-      regions[Nregions].DEC[1] = DEC1;
-    } else {
-      regions[Nregions].DEC[0] = DEC1;
-      regions[Nregions].DEC[1] = DEC0;
-    }     
-    /* skip the pole entries */
-    if (regions[Nregions].DEC[1] > 86.25) continue;
-
-    regions[Nregions].RA[0] = RA0;
-    regions[Nregions].RA[1] = RA1;
-
-    /** convert DEC0, DEC1 to NBigDec **/
-    NDec = FindDecBand (0.5*(DEC0 + DEC1), &D0, &D1);
-    if (NDec == -1) Shutdown ("programming / table error");
-
-    temp[5] = 0;
-    sprintf (file, "%s/%s/%s.cpt", CATDIR, DecNames[NDec], &temp[1]);
-
-    strcpy (regions[Nregions].filename, file);
-    Nregions ++;
-  }
-  if (Nregions > Ny + 2) {
-    fprintf (stderr, "ERROR: too many regions\n");
-    exit (2);
-  }
-
-  sort_regions (regions, Nregions);
-  *nregions = Nregions;
-  return (regions);
-}
-
-/* given dec value, find upper and lower bounds of enclosing dec band */
-int FindDecBand (double dec, double *DEC0, double *DEC1) {
-
-  int i;
-
-  for (i = 0; i < NBANDS; i++) {
-    if (DecBands[i + 0] >  dec) continue;
-    if (DecBands[i + 1] <= dec) continue;
-    *DEC0 = DecBands[i+0];
-    *DEC1 = DecBands[i+1];
-    return (i);
-  }
-  return (-1);
-}
-
-/* note that region.DEC[0] is sorted, but not necessarily DEC[1] */
-int FindRegionDecBandStart (GSCRegion *region, int Nregion, double dec) {
-
-  int N, Nlo, Nhi;
-  double D0, D1;
-
-  if (dec <= 90) return (0);
-
-  /* D0, D1 are upper lower band boundaries */
-  /* all regions in this band have DEC[0] >= D0 */
-  N = FindDecBand (dec, &D0, &D1);
-  if (N == -1) Shutdown ("programming / table error");
-
-  /* bracket value of interest */
-  Nlo = 0; Nhi = Nregion;
-  while (Nhi - Nlo > 10) {
-    N = 0.5*(Nlo + Nhi);
-    if (region[N].DEC[0] < D0) {
-      Nlo = N;
-    } else {
-      Nhi = N;
-    }
-  }
-  /* Nlo - Nhi bracket the transition across dec */
-  /* v[Nlo] < v <= v[Nhi] */ 
-
-  /* find the last entry < dec */
-  for (N = Nhi; N >= Nlo; N--) {
-    if (region[N].DEC[0] < D0) return (N);
-  }
-  return (-1);
-  /* this will fail if transition value is not in the data range */
-}
-
-/* note that region.DEC[0] is sorted, but not necessarily DEC[1] */
-int FindRegionDecBandStop (GSCRegion *region, int Nregion, double dec) {
-
-  int N, Nlo, Nhi;
-  double D0, D1;
-
-  if (dec >= 90) return (Nregion - 1);
-
-  /* D0, D1 are upper lower band boundaries */
-  /* all regions in this band have DEC[0] < D1 */
-  N = FindDecBand (dec, &D0, &D1);
-  if (N == -1) Shutdown ("programming / table error");
-
-  /* bracket value of interest */
-  Nlo = 0; Nhi = Nregion;
-  while (Nhi - Nlo > 10) {
-    N = 0.5*(Nlo + Nhi);
-    if (region[N].DEC[0] > D1) {
-      Nhi = N;
-    } else {
-      Nlo = N;
-    }
-  }
-  /* Nlo - Nhi bracket the transition across dec */
-  /* v[Nlo] <= v < v[Nhi] */ 
-
-  /* find the last entry < dec */
-  for (N = Nlo; N < Nhi; N++) {
-    if (region[N].DEC[0] > D1) return (N);
-  }
-  return (-1);
-  /* this will fail if transition value is not in the data range */
-}
-
-int FindRegionByPoint (GSCRegion *region, double ra, double dec, GSCRegion *gsc, int Ngsc) {
-
-  int i, Ns;
-
-  Ns = FindRegionDecBandStart (gsc, Ngsc, dec);
-  if (Ns < 0) return (FALSE);
-
-  for (i = Ns; i < Ngsc; i++) {
-    if (gsc[i].RA[0]  >= ra) continue;
-    if (gsc[i].RA[1]  <  ra) continue;
-    if (gsc[i].DEC[0] >= dec) continue;
-    if (gsc[i].DEC[1] <  dec) continue;
-    region[0] = gsc[i];
-    return (TRUE);
-  }
-  return (FALSE);
-}
-
-/* bracket search:
-
-   Nlo            T      N                   Nhi
-   X X X X X X X V X X X X X X X X X X X X X X
-                         Nhi
-
-   Nlo                   N      T            Nhi
-   X X X X X X X X X X X X X X X V X X X X X X
-                         Nlo 
-
-*/
Index: /trunk/Ohana/src/addstar/src/SEDfit.c
===================================================================
--- /trunk/Ohana/src/addstar/src/SEDfit.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/SEDfit.c	(revision 8361)
@@ -5,6 +5,6 @@
 int SEDfitCatalog (Catalog *outcat, Catalog *incat, SEDtable *table) {
   
-  int i, j, m, idx, start, done, row, Nsec, Nfit, Nphot, fd;
-  int Nave, Nmeas, NAVE, NMEAS;
+  int i, j, m, n, idx, start, done, row, Nsec, Nfit, Nphot;
+  int Nave, Nmeas, NAVE, NMEAS, Nmodel, Nreq;
   unsigned short USNOred, USNOblu;
   float color;
@@ -183,5 +183,5 @@
     }
 
-    for (j = 0; valid && (j < Nmodel; j++) {
+    for (j = 0; valid && (j < Nmodel); j++) {
       n = modelRow[j];
       outcat[0].measure[Nmeas].dR_PS       = 0.0;
@@ -222,3 +222,4 @@
 
   SEDfitClear ();
+  return (TRUE);
 }
Index: /trunk/Ohana/src/addstar/src/SEDops.c
===================================================================
--- /trunk/Ohana/src/addstar/src/SEDops.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/SEDops.c	(revision 8361)
@@ -141,5 +141,5 @@
 
   int j, minRow, Nfilter;
-  double tmp, X, Y;
+  double X, Y;
   char line[1024], key[20];
 
Index: /trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c
===================================================================
--- /trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c	(revision 8361)
@@ -12,10 +12,4 @@
   // sky = SkyTableFromGSC (GSCFILE, SKY_DEPTH, VERBOSE);
 
-  if (options[0].update) {
-    catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
-  } else {
-    catalog.catflags = LOAD_AVES | LOAD_MEAS      | LOAD_MISS | LOAD_SECF;
-  }
-  
   if (options[0].mode != M_IMAGE) {
     fprintf (stderr, "error: expecting only IMAGE mode\n");
@@ -23,4 +17,7 @@
   }
 
+  catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+  if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
+  
   SetAirmassQuality (options[0].quality_airmass);
 
@@ -57,10 +54,23 @@
   for (i = 0; i < skylist[0].Nregions; i++) {
 
-    catalog.filename = skylist[0].filename[i];
-    load_pt_catalog (&catalog, skylist[0].regions[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.Nsecfilt  = GetPhotcodeNsecfilt ();
+    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+    if (options[0].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[0].only_match) {
-      unlock_catalog (&catalog);
+      dvo_catalog_unlock (&catalog);
+      dvo_catalog_free (&catalog);
       continue;
     }
@@ -72,12 +82,15 @@
     }
 
-    SetProtect (TRUE);
-    if (!options[0].only_images) wcatalog (&catalog);
-    SetProtect (FALSE);
-    unlock_catalog (&catalog);
+    if (!options[0].only_images) {
+      SetProtect (TRUE);
+      dvo_catalog_save (&catalog, VERBOSE);
+      SetProtect (FALSE);
+    }
+    dvo_catalog_unlock (&catalog);
+    dvo_catalog_free (&catalog);
   }
 
   if (options[0].calibrate) { FindCalibration (image); }
-
+  
   /*** load image db, save new image ***/
   { 
@@ -92,5 +105,5 @@
     overlap = gimages (&db, image, mosaic, &Noverlap);
 
-    if (db.dbstate == LCK_EMPTY) create_image_db (&db);
+    if (db.dbstate == LCK_EMPTY) dvo_image_create (&db, ZeroPt);
   
     /* write out new image */
@@ -101,4 +114,7 @@
     dvo_image_unlock (&db);
   }
+  free (mosaic);
+  free (image);
+  free (stars);
   return (TRUE);
 }
Index: /trunk/Ohana/src/addstar/src/UpdateDatabase_Refcat.c
===================================================================
--- /trunk/Ohana/src/addstar/src/UpdateDatabase_Refcat.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/UpdateDatabase_Refcat.c	(revision 8361)
@@ -8,10 +8,4 @@
   SkyList *skylist;
 
-  if (options[0].update) {
-    catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
-  } else {
-    catalog.catflags = LOAD_AVES | LOAD_MEAS      | LOAD_MISS | LOAD_SECF;
-  }
-  
   if (options[0].mode != M_REFCAT) {
     fprintf (stderr, "error: expecting only REFCAT mode\n");
@@ -19,20 +13,5 @@
   }
 
-  /* check on directory, create if needed */
-  { 
-    int status, cmode;
-    struct stat filestat;
-    
-    status = stat (CATDIR, &filestat);
-    if (status == -1) {
-      fprintf (stderr, "directory %s does not exist, creating...\n", CATDIR);
-      cmode = S_IRWXU | S_IRWXG | S_IRWXO;
-      status = mkdir (CATDIR, cmode);
-      if (status == -1) {
-	fprintf (stderr, "ERROR: can't create %s\n", CATDIR);
-	exit (1);
-      }
-    } 
-  }
+  if (!check_dir_access (CATDIR, VERBOSE)) exit (1);
 
   /*** update catalog: average, measure, etc ***/
@@ -52,14 +31,27 @@
   for (i = 0; i < skylist[0].Nregions; i++) {
 
-    catalog.filename = skylist[0].filename[i];
-    load_pt_catalog (&catalog, skylist[0].regions[i]);
+    // set the parameters which guide catalog open/load/create
+    catalog.filename  = skylist[0].filename[i];
+    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+    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;
+    if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
+  
+    // 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);
+    }
 
-    /* for only_match, skip empty catalogs XXX EAM : this leaves behind empty files */
+    // Nave_disk == 0 implies an empty catalog file
+    // for only_match, skip empty catalogs
     if ((catalog.Nave_disk == 0) && options[0].only_match) {
-      unlock_catalog (&catalog);
+      dvo_catalog_unlock (&catalog);
+      dvo_catalog_free (&catalog);
       continue;
     }
 
-    /* load stars from corresponding catalog */
+    // load stars from corresponding catalog 
     stars = grefcat (refcat, skylist[0].regions[i], options[0].photcode, &Nstars);
 
@@ -68,8 +60,12 @@
     if (Nsubset) free (subset);
 
-    SetProtect (TRUE);
-    if (!options[0].only_images) wcatalog (&catalog);
-    SetProtect (FALSE);
-    unlock_catalog (&catalog);
+    if (!options[0].only_images) {
+      SetProtect (TRUE);
+      dvo_catalog_save (&catalog, VERBOSE);
+      SetProtect (FALSE);
+    }
+    dvo_catalog_unlock (&catalog);
+    dvo_catalog_free (&catalog);
+    free (stars);
   }
   return (TRUE);
Index: /trunk/Ohana/src/addstar/src/UpdateDatabase_Reflist.c
===================================================================
--- /trunk/Ohana/src/addstar/src/UpdateDatabase_Reflist.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/UpdateDatabase_Reflist.c	(revision 8361)
@@ -8,14 +8,4 @@
   SkyList *skylist;
 
-  /* this should be loaded by addstard on start -- keep static? */
-  /* need to load the correct sky table (GSC default or local verison) */
-  // sky = SkyTableFromGSC (GSCFILE, SKY_DEPTH, VERBOSE);
-
-  if (options[0].update) {
-    catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
-  } else {
-    catalog.catflags = LOAD_AVES | LOAD_MEAS      | LOAD_MISS | LOAD_SECF;
-  }
-  
   if (options[0].mode != M_REFLIST) {
     fprintf (stderr, "error: expecting only REFLIST mode\n");
@@ -23,20 +13,5 @@
   }
 
-  /* check on directory, create if needed XXX : move to utils */
-  { 
-    int status, cmode;
-    struct stat filestat;
-    
-    status = stat (CATDIR, &filestat);
-    if (status == -1) {
-      fprintf (stderr, "directory %s does not exist, creating...\n", CATDIR);
-      cmode = S_IRWXU | S_IRWXG | S_IRWXO;
-      status = mkdir (CATDIR, cmode);
-      if (status == -1) {
-	fprintf (stderr, "ERROR: can't create %s\n", CATDIR);
-	exit (1);
-      }
-    } 
-  }
+  if (!check_dir_access (CATDIR, VERBOSE)) exit (1);
 
   /*** update catalog: average, measure, etc ***/
@@ -46,5 +21,4 @@
 
   /* reduce regions to existing subset, if necessary */
-  SkyListSetFilenames (skylist, CATDIR, "cpt");
   if (options[0].only_match || options[0].existing_regions) {
     SkyList *tmp;
@@ -57,10 +31,22 @@
   for (i = 0; i < skylist[0].Nregions; i++) {
 
-    catalog.filename = skylist[0].filename[i];
-    load_pt_catalog (&catalog, skylist[0].regions[i]);
+    // set the parameters which guide catalog open/load/create
+    catalog.filename  = skylist[0].filename[i];
+    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+    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;
+    if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
+
+    // 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);
+    }
 
     /* for only_match, skip empty catalogs XXX EAM : this leaves behind empty files */
     if ((catalog.Nave_disk == 0) && options[0].only_match) {
-      unlock_catalog (&catalog);
+      dvo_catalog_unlock (&catalog);
+      dvo_catalog_free (&catalog);
       continue;
     }
@@ -70,9 +56,14 @@
     if (Nsubset) free (subset);
 
-    SetProtect (TRUE);
-    if (!options[0].only_images) wcatalog (&catalog);
-    SetProtect (FALSE);
-    unlock_catalog (&catalog);
+    if (!options[0].only_images) {
+      SetProtect (TRUE);
+      dvo_catalog_save (&catalog, VERBOSE);
+      SetProtect (FALSE);
+    }
+    dvo_catalog_unlock (&catalog);
+    dvo_catalog_free (&catalog);
   }
+
+  free (stars);
   return (TRUE);
 }
Index: /trunk/Ohana/src/addstar/src/addstar.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstar.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/addstar.c	(revision 8361)
@@ -32,7 +32,7 @@
 
   /* we use the image table to lock db access -- perhaps this is not necessary? */
-  db.mode = dvo_catalog_catmode (CATMODE);
+  db.mode   = dvo_catalog_catmode (CATMODE);
   db.format = dvo_catalog_catformat (CATFORMAT);
-  status = dvo_image_lock (&db, ImageCat, 3600.0, LCK_XCLD);
+  status    = dvo_image_lock (&db, ImageCat, 3600.0, LCK_XCLD);
   if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
 
@@ -96,5 +96,5 @@
     catalog.filename = skylist[0].filename[i];
     catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
-    catalog.catflags = LOAD_AVES | LOAD_MEAS      | LOAD_MISS | LOAD_SECF;
+    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     if (options.update) catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
 
Index: /trunk/Ohana/src/addstar/src/addstart.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstart.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/addstart.c	(revision 8361)
@@ -7,5 +7,4 @@
   pthread_t thread;
   DVO_DATA *dataset;
-  // pthread_attr_t attr;
 
   options = ConfigInit (&argc, argv);
@@ -18,16 +17,11 @@
   VERBOSE = TRUE;
 
-  /* if we separate the incoming data from db update, spawn db thread here */
-  /* this needs to be launched with pthreads
-   * we can probably launch multiple copies of dbthread */
-
   InitDataset ();
 
-  /* decide if we need an argument to dbthread */
+  // launch thread to listen for client data
   pthread_create (&thread, NULL, &ListenClients_Thread, NULL);
 
+  // XXX need to watch for shutdown message
   while (1) {
-
-    /* need to watch for shutdown message */
 
     dataset = PopDataset ();
Index: unk/Ohana/src/addstar/src/check_permissions.c
===================================================================
--- /trunk/Ohana/src/addstar/src/check_permissions.c	(revision 8360)
+++ 	(revision )
@@ -1,67 +1,0 @@
-# include "addstar.h"
-
-void check_permissions (char *basefile) {
-  
-  char *c, dir[256], filename[256];
-  struct stat filestat;
-  uid_t uid;
-  gid_t gid;
-  int status, cmode;
-
-  uid = getuid();
-  gid = getgid();
-
-  /* check permission to write to directory */
-  sprintf (filename, "%s", basefile);
-  c = strrchr (filename, '/');
-  if (c == (char *) NULL) {
-    strcpy (dir, ".");
-  } else {
-    *c = 0;
-    strcpy (dir, filename);
-  }
-  status = stat (dir, &filestat);
-  if (status == -1) {
-    fprintf (stderr, "directory %s does not exist, creating...\n", dir);
-    cmode = S_IRWXU | S_IRWXG | S_IRWXO;
-    status = mkdir (dir, cmode);
-    if (status == -1) {
-      fprintf (stderr, "ERROR: can't create %s\n", dir);
-      exit (1);
-    }
-  } 
-  status = stat (dir, &filestat);
-  if (((uid == filestat.st_uid) && (filestat.st_mode & S_IRWXU)) ||
-      ((gid == filestat.st_gid) && (filestat.st_mode & S_IRWXG)) || 
-      (filestat.st_mode & S_IRWXO)) {
-  } else {
-    fprintf (stderr, "ERROR: can't write to %s\n", dir);
-    exit (1);
-  }
-  
-  /* check permission to write to file */
-  sprintf (filename, "%s", basefile);
-  status = stat (filename, &filestat);
-  if (status == 0) { /* file exists, are permissions OK? */
-    if (((uid == filestat.st_uid) && (filestat.st_mode & S_IRUSR) && (filestat.st_mode & S_IWUSR)) ||
-	((gid == filestat.st_gid) && (filestat.st_mode & S_IRGRP) && (filestat.st_mode & S_IWGRP)) || 
-	((filestat.st_mode & S_IROTH) && (filestat.st_mode & S_IWOTH))) {
-    } else {
-      fprintf (stderr, "ERROR: can't write to %s\n", filename);
-      exit (1);
-    }
-  }
-  
-  /* check permission to write to backup file */
-  sprintf (filename, "%s~", basefile);
-  status = stat (filename, &filestat);
-  if (status == 0) { /* file exists, are permissions OK? */
-    if (((uid == filestat.st_uid) && (filestat.st_mode & S_IRUSR) && (filestat.st_mode & S_IWUSR)) ||
-	((gid == filestat.st_gid) && (filestat.st_mode & S_IRGRP) && (filestat.st_mode & S_IWGRP)) || 
-	((filestat.st_mode & S_IROTH) && (filestat.st_mode & S_IWOTH))) {
-    } else {
-      fprintf (stderr, "ERROR: can't write to %s\n", filename);
-      exit (1);
-    }
-  }
-}
Index: unk/Ohana/src/addstar/src/gcatalog.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gcatalog.c	(revision 8360)
+++ 	(revision )
@@ -1,22 +1,0 @@
-# include "addstar.h"
-
-int gcatalog (Catalog *catalog) {
-  
-  int Nsecfilt, status;
-
-  /* CATMODE and CATFORMAT determined from catalog */
-
-  /* read catalog header */
-  if (!dvo_catalog_load (catalog, VERBOSE)) {
-    fprintf (stderr, "ERROR: failure loading catalog\n");
-    exit (1);
-  }
-
-  /* check Nsecfile value, update if needed */
-  Nsecfilt = GetPhotcodeNsecfilt ();
-  if (!dvo_catalog_check (catalog, Nsecfilt, TRUE)) {
-    fprintf (stderr, "ERROR: can't reduce number of secondary filters\n");
-    exit (2);
-  }
-  return (TRUE);
-}
Index: /trunk/Ohana/src/addstar/src/get2mass_as.c
===================================================================
--- /trunk/Ohana/src/addstar/src/get2mass_as.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/get2mass_as.c	(revision 8361)
@@ -11,14 +11,11 @@
 Stars *get2mass_AS_data (SkyRegion *region, char *filename, SkyRegion *patch, int photcode, int *nstars) {
   
-  int FilterSkip, TimeSkip;
-  int Nstars, NSTARS, Nbyte, Nextra, Qentry;
+  int Nstars, NSTARS, Nbyte, Nextra;
   Stars *stars;
   gzFile gf;
-  char qc;
   char *buffer;
-  char *p, *q, *ptr, *tmp;
-  double RA, DEC, M, dM;
+  char *p, *q, *tmp;
+  double RA, DEC;
   double RA0, RA1, DEC0, DEC1;
-  e_time time;
 
   ALLOCATE (buffer, char, NBYTE);
Index: /trunk/Ohana/src/addstar/src/get2mass_as_raw.c
===================================================================
--- /trunk/Ohana/src/addstar/src/get2mass_as_raw.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/get2mass_as_raw.c	(revision 8361)
@@ -12,15 +12,11 @@
 Stars *get2mass_AS_rawdata (SkyRegion *region, char *filename, SkyRegion *patch, int photcode, int *nstars) {
   
-  int FilterSkip, TimeSkip;
-  int Nstars, NSTARS, Nbyte, Nextra, Qentry;
-  int Noffset, dNoffset;
+  int Nstars, NSTARS, Nbyte, Nextra;
   Stars *stars;
   FILE *f;
-  char qc;
   char *buffer;
-  char *p, *q, *ptr, *tmp;
-  double RA, DEC, M, dM;
+  char *p, *q, *tmp;
+  double RA, DEC;
   double RA0, RA1, DEC0, DEC1;
-  e_time time;
 
   ALLOCATE (buffer, char, NBYTE);
Index: /trunk/Ohana/src/addstar/src/grefstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/grefstars.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/grefstars.c	(revision 8361)
@@ -37,8 +37,5 @@
 
 /* stars.found is set here to FALSE.
-   gregion_stars uses this value as a boolean to decide if the star
-     has been associated with a region.
-   gregion_stars resets stars.found to -1
    find_match_refstars uses stars.found to identify the seq number of the
-     star which is found.  it requires an initial value of -1
+   star which is found.  it requires an initial value of -1 XXX
 */
Index: unk/Ohana/src/addstar/src/gregion_image.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gregion_image.c	(revision 8360)
+++ 	(revision )
@@ -1,33 +1,0 @@
-# include "addstar.h"
-
-/* given image with coords, find regions which overlap image */
-GSCRegion *gregion_image (Image *image, Coords *mosaic, int *Nregions) {
-  
-  GSCRegion *regions, impatch;
-  double x, y, X, Y, ra, dec;
-  
-  /* this has trouble for images which overlap 0,360 */
-  impatch.RA[0]  = 360;
-  impatch.RA[1]  =   0;
-  impatch.DEC[0] = +90;
-  impatch.DEC[1] = -90;
-
-  if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
-    if (mosaic == NULL) Shutdown ("no mosaic for WRP image (use -mosaic)");
-    RegisterMosaic (mosaic);
-  }    
-
-  for (x = 0; x <= 1; x++) {
-    for (y = 0; y <= 1; y++) {
-      X = image[0].NX*(1.1*x - 0.05);
-      Y = image[0].NY*(1.1*y - 0.05);
-      XY_to_RD (&ra, &dec, X, Y, &image[0].coords);
-      impatch.RA[0]  = MIN (ra,  impatch.RA[0]);
-      impatch.RA[1]  = MAX (ra,  impatch.RA[1]);
-      impatch.DEC[0] = MIN (dec, impatch.DEC[0]);
-      impatch.DEC[1] = MAX (dec, impatch.DEC[1]);
-    }
-  }
-  regions = gregion_patch (&impatch, Nregions);
-  return (regions);
-}
Index: unk/Ohana/src/addstar/src/gregion_match.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gregion_match.c	(revision 8360)
+++ 	(revision )
@@ -1,29 +1,0 @@
-# include "addstar.h"
-
-GSCRegion *gregion_match (GSCRegion *regions, int *nregions) {
-  
-  int i, status, Nregions, Nsubset, NSUBSET;
-  GSCRegion *subset;
-  struct stat filestats;
-  
-  Nregions = *nregions;
-
-  Nsubset = 0;
-  NSUBSET = 100;
-  ALLOCATE (subset, GSCRegion, NSUBSET);
-
-  /* match the basename against the GSCRegion file names */
-  for (i = 0; i < Nregions; i++) {
-    status = stat (regions[i].filename, &filestats);
-    if ((status == -1) && (errno == ENOENT)) continue;
-    /* give an error for other conditions? */
-
-    subset[Nsubset] = regions[i];
-    Nsubset ++;
-    CHECK_REALLOCATE (subset, GSCRegion, NSUBSET, Nsubset, 100);
-  }
-  free (regions);
-
-  *nregions = Nsubset;
-  return (subset);
-}
Index: unk/Ohana/src/addstar/src/gregion_match_glob.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gregion_match_glob.c	(revision 8360)
+++ 	(revision )
@@ -1,51 +1,0 @@
-# include "addstar.h"
-# include <glob.h>
-
-GSCRegion *gregion_match (int *nregions) {
-  
-  int i;
-  int    Ngsc, Nregions;
-  glob_t pglob;
-
-  GSCRegion *gsc, *regions;
-  
-  gsc = LoadRegions (&Ngsc);
-
-  sprintf (globline, "%s/[nsNS]????/*.cpt", CATDIR);
-  pglob.gl_offs = 0;
-  glob (globline, 0, NULL, &pglob);
-
-  Nregions = 0;
-  ALLOCATE (regions, GSCRegion, MAX (1, pglob.gl_pathc));
-
-  /* match the basename against the GSCRegion file names */
-  for (i = 0; i < pglob.gl_pathc; i++) {
-    found = FALSE;
-    for (j = 0; !found && (j < Ngsc); j++) {
-      if (strcasecmp (pglob.gl_pathv, gsc[j].filename)) continue;
-      regions[Nregions] = gsc[j];
-      found = TRUE;
-    }
-  }
-  *nregions = Nregions;
-  return (regions);
-  
-  /* should free things up here */
-}
-
-/* given a ra,dec bounded region, find all region files which overlap it
-
-   - split region into two if overlapping 0,360 boundary 
-
-*/
-
-/* the goal here is to return a list of the existing region files
-   this means either: 
-
-      grabbing all files that are on disk and converting 
-      them to GSCRegion files
-
-      trying all GSCRegion files to see if they exist 
-      (and are populated?)
-      
-*/
Index: unk/Ohana/src/addstar/src/gregion_patch.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gregion_patch.c	(revision 8360)
+++ 	(revision )
@@ -1,43 +1,0 @@
-# include "addstar.h"
-
-GSCRegion *gregion_patch (GSCRegion *patch, int *nregions) {
-  
-  int i, Ns, Ne, Ngsc, Nregions;
-  GSCRegion *gsc, *regions;
-  
-  gsc = LoadRegions (&Ngsc);
-
-  /* find lower and upper boundaries */
-  Ns = FindRegionDecBandStart (gsc, Ngsc, patch[0].DEC[0]);
-  Ne = FindRegionDecBandStop (gsc, Ngsc, patch[0].DEC[1]);
-  if (Ns < 0) Shutdown ("invalid patch lower bound %f", patch[0].DEC[0]);
-  if (Ne < 0) Shutdown ("invalid patch upper bound %f", patch[0].DEC[1]);
-  
-  Nregions = 0;
-  ALLOCATE (regions, GSCRegion, Ne - Ns);
-
-  /* find all regions in range within ra range */
-  for (i = Ns; i < Ne; i++) {
-    if (gsc[i].RA[0]  >= patch[0].RA[1]) continue;
-    if (gsc[i].RA[1]  <  patch[0].RA[0]) continue;
-    if (gsc[i].DEC[0] >= patch[0].DEC[1]) continue;
-    if (gsc[i].DEC[1] <  patch[0].DEC[0]) continue;
-    /* add to the list */
-    regions[Nregions] = gsc[i];
-    Nregions ++;
-  }
-
-  if (VERBOSE) fprintf (stderr, "Nregions in patch: %d, Ne: %d, Ns: %d\n", Nregions, Ne, Ns);
-  if (Nregions > (Ne - Ns)) {
-    fprintf (stderr, "ERROR: too many regions found\n");
-    exit (1);
-  }
-
-  *nregions = Nregions;
-  return (regions);
-}
-
-/* given a ra,dec bounded region, find all region files which overlap it
-   - split region into two if overlapping 0,360 boundary 
-*/
-
Index: unk/Ohana/src/addstar/src/gregion_star.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gregion_star.c	(revision 8360)
+++ 	(revision )
@@ -1,51 +1,0 @@
-# include "addstar.h"
-
-GSCRegion *gregion_stars (Stars *stars, int Nstars, int *nregions) {
-  
-  int i, j, Ngsc, Nregions, NREGIONS;
-  GSCRegion *gsc, *regions;
-  
-  gsc = LoadRegions (&Ngsc);
-
-  Nregions = 0;
-  NREGIONS = 100;
-  ALLOCATE (regions, GSCRegion, NREGIONS);
-
-  sort_stars (stars, Nstars); /* sort by RA */
-  for (i = 0; i < Nstars; i++) {
-    if (stars[i].found) continue;
-    FindRegionByPoint (&regions[Nregions], stars[i].R, stars[i].D, gsc, Ngsc);
-    stars[i].found = TRUE;
-    /* search forward for all contained stars */
-    for (j = i; j < Nstars; j++) {
-      if (stars[j].R >= regions[Nregions].RA[1]) break;
-      if (stars[j].D <  regions[Nregions].DEC[0]) continue;
-      if (stars[j].D >= regions[Nregions].DEC[1]) continue;
-      stars[j].found = TRUE;
-    }
-    Nregions ++;
-    CHECK_REALLOCATE (regions, GSCRegion, NREGIONS, Nregions, 100);
-    
-  }
-
-  /* reset to -1 for all stars: required start for find_match_refstars */
-  for (i = 0; i < Nstars; i++) stars[i].found = -1; 
-
-  *nregions = Nregions;
-  return (regions);
-}
-
-/* given a list of stars, find all region files which contain them 
-
-   - sort by ra?
-   - loop over stars
-     - find region file which contains star
-     - go backwards until ra < RA[0]
-       - mark all stars in this region file
-     - go forwards until ra > RA[1]
-       - mark all stars in this region file
-     
-   - use DEC band information?
-   - would like to minimize the number of disk reads
-
-*/
Index: unk/Ohana/src/addstar/src/gregions.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gregions.c	(revision 8360)
+++ 	(revision )
@@ -1,53 +1,0 @@
-# include "addstar.h"
-
-GSCRegion *gregions (Image *image, int *Nregions) {
-  
-  GSCRegion *region;
-  FILE *f;
-  double x, y;
-  double dec, ra;
-  int i, j, done, nregion, NREGION;
-  
-  f = fopen (GSCFILE, "r");
-  if (f == NULL) {
-    fprintf (stderr, "ERROR: can't find GSC region file %s\n", GSCFILE);
-    exit (1);
-  }
-  
-  /* find regions at image corners */
-  NREGION = 10;
-  ALLOCATE (region, GSCRegion, NREGION);
-  nregion = 0;
-
-  /* look for new regions on grid across image */ 
-  for (x = 0.0; x <= 1.0; x+=0.25) {
-    for (y = 0.0; y <= 1.0; y+=0.25) {
-      XY_to_RD (&ra, &dec, image[0].NX*(1.1*x - 0.05), image[0].NY*(1.1*y - 0.05), &image[0].coords);
-      aregion (&region[nregion], f, ra, dec);
-      done = FALSE;
-      for (j = 0; (j < nregion) && !done; j++) {
-	if (!strcmp (region[nregion].filename, region[j].filename)) {
-	  nregion --;
-	  done = TRUE;
-	}
-      }
-      nregion ++;
-      if (nregion == NREGION) {
-	NREGION += 10;
-	REALLOCATE (region, GSCRegion, NREGION);
-      }
-    }
-  }
-
-  if (VERBOSE) {
-    fprintf (stderr, "found %d region files:\n", nregion);
-    for (i = 0; i < nregion; i++) {
-      fprintf (stderr, "  %d %s\n", i, region[i].filename);
-    }
-  }
-  *Nregions = nregion;
-  
-  fclose (f);
-  return (region);
-  
-}
Index: /trunk/Ohana/src/addstar/src/gstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gstars.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/gstars.c	(revision 8361)
@@ -4,5 +4,5 @@
 
   FILE *f;
-  int j, N, Nbytes, extend, naxis;
+  int j, N, Nbytes, naxis;
   int itmp, hour, min;
   char *name, *c, photname[64], line[80];
Index: unk/Ohana/src/addstar/src/image-db.c
===================================================================
--- /trunk/Ohana/src/addstar/src/image-db.c	(revision 8360)
+++ 	(revision )
@@ -1,55 +1,0 @@
-# include "addstar.h"
-
-void create_image_db (FITS_DB *db) {
-
-  if (VERBOSE) fprintf (stderr, "can't find %s, creating a new one\n", ImageCat);
-
-  /* create new header */
-  gfits_init_header (&db[0].header);
-
-  /* set the recommended mode */
-  db[0].mode = DVO_MODE_UNDEF;
-  if (!strcasecmp (CATMODE, "RAW")) {
-    /* make header a fake image */
-    db[0].header.bitpix   = 16;
-    db[0].header.Naxes    = 2;
-    db[0].header.Naxis[0] = 1;
-    db[0].header.Naxis[1] = 1;
-    gfits_create_header (&db[0].header);
-    db[0].mode = DVO_MODE_RAW;
-  }
-  if (!strcasecmp (CATMODE, "MEF") || !strcasecmp (CATMODE, "SPLIT")) {
-    db[0].header.extend   = TRUE;
-    gfits_create_header (&db[0].header);
-    db[0].mode = DVO_MODE_MEF;
-  }
-  if (db[0].mode == DVO_MODE_UNDEF) {
-    fprintf (stderr, "invalid output catalog mode\n");
-    exit (1);
-  }
-
-  /* set the recommended format */
-  db[0].format = DVO_FORMAT_UNDEF;
-  if (!strcasecmp (CATFORMAT, "INTERNAL"))  db[0].format = DVO_FORMAT_INTERNAL;
-  if (!strcasecmp (CATFORMAT, "LONEOS"))    db[0].format = DVO_FORMAT_LONEOS;
-  if (!strcasecmp (CATFORMAT, "ELIXIR"))    db[0].format = DVO_FORMAT_ELIXIR;
-  if (!strcasecmp (CATFORMAT, "PANSTARRS")) db[0].format = DVO_FORMAT_PANSTARRS;
-  if (!strcasecmp (CATFORMAT, "PMTEST"))    db[0].format = DVO_FORMAT_PMTEST;
-  if (db[0].format == DVO_FORMAT_UNDEF) {
-    fprintf (stderr, "invalid output catalog format\n");
-    exit (1);
-  }
-
-  gfits_create_matrix (&db[0].header, &db[0].matrix);
-  gfits_table_set_Image (&db[0].ftable, NULL, 0);
-
-  /* assign Zero Point provided by first image in dB */
-  gfits_modify (&db[0].header, "ZERO_PT", "%lf", 1, ZeroPt);
-  gfits_modify (&db[0].header, "NIMAGES", "%d", 1, 0);
-
-  if (db[0].format == DVO_FORMAT_INTERNAL)  gfits_modify (&db[0].header, "FORMAT", "%s", 1, "INTERNAL");
-  if (db[0].format == DVO_FORMAT_LONEOS)    gfits_modify (&db[0].header, "FORMAT", "%s", 1, "LONEOS");
-  if (db[0].format == DVO_FORMAT_ELIXIR)    gfits_modify (&db[0].header, "FORMAT", "%s", 1, "ELIXIR");
-  if (db[0].format == DVO_FORMAT_PANSTARRS) gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PANSTARRS");
-  if (db[0].format == DVO_FORMAT_PMTEST)    gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PMTEST");
-}
Index: unk/Ohana/src/addstar/src/load2mass_as_raw.c
===================================================================
--- /trunk/Ohana/src/addstar/src/load2mass_as_raw.c	(revision 8360)
+++ 	(revision )
@@ -1,155 +1,0 @@
-# include "addstar.h"
-# include "2mass.h"
-
-/* unlike the DR2 data, the AS data is NOT fixed bytes/row 
- * we need to handle fractional lines at the end of each read block
- */
-
-/* read in chunks of ~16MB */
-# define NBYTE 0x1000000
-# define NBREC 330
-
-int load2mass_as_rawdata (SkyTable *skytable, char *filename, AddstarClientOptions options) {
-  
-  int Nstars, NSTARS, Ntstars, NTSTARS;
-  int Nbyte, Nextra, Ntotal;
-
-  FILE *f;
-  char *buffer, *p, *q;
-
-  Stars *stars;
-  TMStars *tstars;
-
-  get2mass_setup (options.photcode);
-
-  ALLOCATE (buffer, char, NBYTE);
-
-  // scan through the entire 2MASS file
-  f = fopen (filename, "r");
-  if (f == NULL) Shutdown ("can't read 2mass data file: %s", filename);
-  // test if this is a raw datafile or gzipped...
-
-  Nextra = 0;  // number excess bytes from lsat partial row
-  Ntotal = 0;  // track the total number of bytes read 
-  while ((Nbyte = fread (&buffer[Nextra], 1, NBYTE-Nextra, f)) != 0) {
-    if (Nbyte == -1) Shutdown ("error reading from raw file %s", filename);
-    Nbyte += Nextra;
-
-    if (VERBOSE) fprintf (stderr, ".");
-
-    /* find bounds on first complete line */
-    p = buffer;
-    q = memchr (p, '\n', Nbyte);
-    if (q == NULL) Shutdown ("incomplete line at end of file\n");
-    offset = p - buffer; // offset within this scan
-
-    Ntstars = 0;
-    NTSTARS = 10000;
-    ALLOCATE (tstars, TMStars, NTSTARS);
-
-    // scan through entire buffer for star coords
-    while (1) {
-      get2mass_coords (p, &tstars[Ntstars].R, &tstars[Ntstars].D, Nbyte - offset);
-      tstars[Ntstars].offset = offset; // offset within scan
-      tstars[Ntstars].flag = FALSE;
-
-      Ntstars ++;
-      CHECK_REALLOCATE (tstars, TMStars, NTSTARS, Ntstars, 10000);
-
-      /* start of the next line */
-      p = q + 1;
-      offset = p - buffer; // offset within this scan
-      if (offset == Nbyte) {
-	// last line in buffer is a complete line
-	Nextra = 0;
-	break;
-      }
-      /* end of the next line */
-      q = memchr (p, '\n', Nbyte - offset);
-      if (q == NULL) {
-	// last, incomplete line in buffer
-	Nextra = Nbyte - offset;
-	break;
-      } 
-    }
-
-    // scan through the stars, loading the containing catalogs
-    // skip through table for unsaved stars
-    for (i = 0; i < Ntstars; ) {
-      if (tstars[i].flag) continue;
-
-      // collect stars in a new output catalog
-      Nstars = 0;
-      NSTARS = 10000;
-      ALLOCATE (stars, Stars, NSTARS);
-	
-      // identify the relevant catalog
-      skylist = SkyRegionByPoint (skytable, -1, tstars[i].R, tstars[i].D);
-      region = skylist[0].regions[0];
-
-      for (j = i; j < Ntstars; j++) {
-	if (tstars[j].flag) continue;
-
-	// check if in skyregion
-	if (tstars[j].R < region[0].Rmin) continue;
-	if (tstars[j].R > region[0].Rmax) continue;
-	if (tstars[j].D < region[0].Dmin) continue;
-	if (tstars[j].D > region[0].Dmax) continue;
-	  
-	offset = tstars[j].offset;
-
-	stars[Nstars].R = tstars[j].R;
-	stars[Nstars].D = tstars[j].R;
-	get2mass_star (&stars[Nstars], &buffer[offset], Nbyte - offset);
-	tstars[j].flag = TRUE;
-
-	Nstars ++;
-	CHECK_REALLOCATE (stars, Stars, NSTARS, Nstars, 5000);
-      }
-      if (!Nstars) {
-	free (stars);
-	continue;
-      }
-
-      // now we have all of the loaded stars in this catalog
-      catalog.filename = skylist[0].filename[0];
-      load_pt_catalog (&catalog, skylist[0].regions[0]);
-
-      // create the subset pointers
-      ALLOCATE (subset, Stars, *, Nstars);
-      for (j = 0; j < Nstars; j++) subset[j] = &stars[j];
-
-      find_matches_refstars (skylist[0].regions[0], subset, Nstars, &catalog, options);
-      free (subset);
-
-      unlock_catalog (&catalog);
-      free (catalog.filename);
-      free (stars);
-    }
-    free (tstars);
-
-    // at end, p points at the start of last, partial line
-    if (Nextra) memmove (buffer, p, Nextra);
-  }
-
-  if (VERBOSE) fprintf (stderr, "\n");
-  
-  fclose (f);
-  free (buffer);
-  *nstars = Nstars;
-  return (stars);
-}
-
-/*
-  for each 2mass file:
-  for each data block
-  generate a table of: R, D, byte, flag
-  for each unsaved star
-  find containing catalog
-  load catalog
-  find all contained stars
-  add to catalog
-  save catalog 
-  mark all contained stars
-*/
-
Index: /trunk/Ohana/src/addstar/src/load2mass_as_rawdata.c
===================================================================
--- /trunk/Ohana/src/addstar/src/load2mass_as_rawdata.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/load2mass_as_rawdata.c	(revision 8361)
@@ -29,6 +29,4 @@
 
   get2mass_setup (-1);
-
-  catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
 
   ALLOCATE (buffer, char, NBYTE);
@@ -152,7 +150,17 @@
 	verbose = VERBOSE;
 	VERBOSE = FALSE;
+
 	// now we have all of the loaded stars in this catalog
 	catalog.filename = skylist[0].filename[0];
-	load_pt_catalog (&catalog, skylist[0].regions[0]);
+	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 ();
+
+	// 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);
+	}
 
 	// assume no input star matches an existing star 
@@ -160,6 +168,7 @@
 	load2mass_catalog (&catalog, stars, Nstars);
 
-	wcatalog (&catalog);
-	unlock_catalog (&catalog);
+	dvo_catalog_save (&catalog, VERBOSE);
+	dvo_catalog_unlock (&catalog);
+	dvo_catalog_free (&catalog);
 	// free (catalog.filename);
 	// XXX don't free this! it points to an element of the skytable
Index: unk/Ohana/src/addstar/src/load_pt_catalog.c
===================================================================
--- /trunk/Ohana/src/addstar/src/load_pt_catalog.c	(revision 8360)
+++ 	(revision )
@@ -1,39 +1,0 @@
-# include "addstar.h"
-
-// XXX can I replace this with dvo_catalog_open ()
-// XXX set the catalog properties before the function call (not as args)
-int load_pt_catalog (Catalog *catalog, SkyRegion *region) {
-  
-  if (!check_file_access (catalog[0].filename, TRUE, TRUE)) exit (1);
-
-  if (VERBOSE) fprintf (stderr, "adding to %s\n", catalog[0].filename);
-    
-  /* check Nsecfile value, update if needed */
-  Nsecfilt = GetPhotcodeNsecfilt ();
-
-  switch (lock_catalog (catalog, LCK_XCLD)) {
-  case 0:
-    fprintf (stderr, "ERROR: can't lock file %s\n", catalog[0].filename);
-    exit (1);
-  case 1:
-    if (!dvo_catalog_load (catalog, VERBOSE)) {
-      fprintf (stderr, "ERROR: failure loading catalog\n");
-      exit (1);
-    }
-    if (!dvo_catalog_check (catalog, Nsecfilt, TRUE)) {
-      fprintf (stderr, "ERROR: can't reduce number of secondary filters\n");
-      exit (2);
-    }
-    if (VERBOSE) fprintf (stderr, "loaded existing file %s\n", catalog[0].filename);
-    break;
-  case 2:
-    dvo_catalog_create (region, catalog, Nsecfilt, CATFORMAT, CATMODE); /* fills in new header info */
-    if (VERBOSE) fprintf (stderr, "creating new file %s\n", catalog[0].filename);
-    break;
-  }
-  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: unk/Ohana/src/addstar/src/make_backup.c
===================================================================
--- /trunk/Ohana/src/addstar/src/make_backup.c	(revision 8360)
+++ 	(revision )
@@ -1,23 +1,0 @@
-# include "addstar.h"
-
-/* uses cp only */
-void make_backup (char *filename) {
-
-  int status, cmode;
-  struct stat filestat;
-  char line [256];
-
-  status = stat (filename, &filestat);
-  if (status == 0) { /* file exists, make backup copy */
-    sprintf (line, "cp %s %s~", filename, filename);
-    status = system (line);
-    if (status) {
-      fprintf (stderr, "ERROR: unable to create %s~, exiting\n", filename);
-      exit (1);
-    }
-    cmode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
-    sprintf (line, "%s~", filename);
-    chmod (line, cmode);
-  }
-  
-}
Index: unk/Ohana/src/addstar/src/match_refstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/match_refstars.c	(revision 8360)
+++ 	(revision )
@@ -1,70 +1,0 @@
-# include "addstar.h"
-
-int match_refstars (Stars *stars, int Nstars) {
-
-  int i, j, Nm, Nf, Nmissed, Nsubset;
-  int      *subref;
-  Stars    *subset;
-  GSCRegion region;
-  Catalog   catalog;
-
-  /* put stars in the appropriate db file */
-  for (i = 0; i < Nstars; i++) {
-    if (stars[i].found != -1) continue;
-    gregion_star (&stars[i], &region);
-    if (!check_file_access (region.filename, TRUE, TRUE)) {
-      exit (0);
-    }
-    make_backup (region.filename);
-
-    catalog.filename = region.filename;  /* don't free region before catalog! */
-    fprintf (stderr, "adding to %s [star %d]\n", region.filename, i);
-    
-    switch (lock_catalog (&catalog, LCK_XCLD)) {
-    case 0:
-      fprintf (stderr, "ERROR: can't lock file %s\n", catalog.filename);
-      exit (1);
-    case 1:
-      gcatalog (&catalog); /* load from disk */
-      break;
-    case 2:
-      mkcatalog (&region, &catalog); /* fills in new header info */
-      break;
-    }
-    subset = find_subset (&region, stars, Nstars, &subref, &Nsubset);
-    if (VERBOSE) fprintf (stderr, "%d stars in subset for %s\n", Nsubset, region.filename);
-    find_matches_refstars (&region, subset, Nsubset, &catalog);
-
-    /* protect wcatalog from interrupt signals */
-    SetProtect (TRUE);
-    wcatalog (&catalog);
-    SetProtect (FALSE);
-    unlock_catalog (&catalog);
-
-    Nm = 0; Nf = 0;
-    for (j = 0; j < Nsubset; j++) {
-      stars[subref[j]].found = subset[j].found;
-      if (subset[j].found == -2) Nm ++;
-      if (subset[j].found >=  0) Nf ++;
-    }
-    /* found:
-       -1 - not yet tried
-       -2 - found on previous catalog
-       -3 - not found on previous catalog
-       +N - found elsewhere
-    */
-    if (VERBOSE) fprintf (stderr, "found %d stars, skipped %d stars\n", Nf, Nm);
-    free (subset);
-    free (subref);
-  }
-  
-  for (Nmissed = i = 0; i < Nstars; i++) {
-    if (stars[i].found == -1) {
-      fprintf (stderr, "%d %f %f %f %f\n", i, stars[i].R, stars[i].D, stars[i].M, stars[i].dM);
-      Nmissed ++;
-    }
-  }
-  if (Nmissed) fprintf (stderr, "WARNING: %d stars in image were missed!\n", Nmissed);
-
-  return (TRUE);
-}
Index: unk/Ohana/src/addstar/src/mkcatalog.c
===================================================================
--- /trunk/Ohana/src/addstar/src/mkcatalog.c	(revision 8360)
+++ 	(revision )
@@ -1,122 +1,0 @@
-# include "addstar.h"
-
-void mkcatalog (SkyRegion *region, Catalog *catalog) {
-  
-  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);
-  }    
-
-  /* write RA,DEC range in header */
-  gfits_modify (&catalog[0].header, "RA0",  "%lf", 1, region[0].Rmin);
-  gfits_modify (&catalog[0].header, "DEC0", "%lf", 1, region[0].Dmin);
-  gfits_modify (&catalog[0].header, "RA1",  "%lf", 1, region[0].Rmax);
-  gfits_modify (&catalog[0].header, "DEC1", "%lf", 1, region[0].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);
-
-  /* dummy allocation so realloc will succeed */
-  ALLOCATE (catalog[0].average, Average, 1);
-  ALLOCATE (catalog[0].measure, Measure, 1);
-  ALLOCATE (catalog[0].missing, Missing, 1);
-  ALLOCATE (catalog[0].secfilt, SecFilt, 1);
-  catalog[0].Naverage = catalog[0].Nmeasure = catalog[0].Nmissing = 0;
-  catalog[0].Nave_disk = catalog[0].Nmeas_disk = catalog[0].Nmiss_disk = 0;
-  catalog[0].Nmeas_off = 0;
-  catalog[0].Nsecfilt = GetPhotcodeNsecfilt ();
-
-  /* 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: unk/Ohana/src/addstar/src/save_pt_catalog.c
===================================================================
--- /trunk/Ohana/src/addstar/src/save_pt_catalog.c	(revision 8360)
+++ 	(revision )
@@ -1,10 +1,0 @@
-# include "addstar.h"
-
-void save_pt_catalog (Catalog *catalog) {
-
-  /* protect wcatalog from interrupt signals */
-  SetProtect (TRUE);
-  if (!DUMP_MATCHES && !ONLY_IMAGES) wcatalog (catalog);
-  SetProtect (FALSE);
-  unlock_catalog (catalog);
-}
Index: unk/Ohana/src/addstar/src/scan2mass.c
===================================================================
--- /trunk/Ohana/src/addstar/src/scan2mass.c	(revision 8360)
+++ 	(revision )
@@ -1,86 +1,0 @@
-# include "addstar.h"
-# include "2mass.h"
-
-int main (int argc, char **argv) {
-
-  char *path;
-  int i, N, Nrefcat;
-  SkyTable *sky;
-
-  if (argc == 2) {
-    scan2mass_as_data (argv[1]);
-    exit (0);
-  }
-
-  ConfigInit (&argc, argv);
-
-  if (argc != 1) {
-    fprintf (stderr, "USAGE: mkacc.2mass\n");
-    exit (2);
-  }
-
-  path = TWO_MASS_DIR_AS;
-
-  // the accel.dat file has the raw filenames
-  // test if the file exists, or else try the .gz version
-  sky = scan2mass_acc (path, "accel.dat");
-  
-  for (i = 0; i < sky[0].Nregions; i++) {
-    fprintf (stderr, "scanning %s\n", sky[0].filename[i]);
-    scan2mass_as_data (sky[0].filename[i]);
-  }
-  exit (0);
-}  
-
-/* watch for patches which cross 0,360 boundary */
-SkyTable *scan2mass_acc (char *path, char *accel) {
-
-  int Nregions, NREGIONS, Nrec;
-  char accelfile[1024], line[256], filename[128], datafile[256], **filenames;
-  FILE *f;
-  double Rs, Re, Ds, De;
-
-  SkyTable *sky;
-  SkyRegion *regions;
-
-  sprintf (accelfile, "%s/%s", path, accel);
-  f = fopen (accelfile, "r");
-  if (f == NULL) Shutdown ("can't read data from accelerator %s", accelfile);
-
-  Nregions = 0;
-  NREGIONS = 200;
-  ALLOCATE (regions, SkyRegion, NREGIONS);
-  ALLOCATE (filenames, char *, NREGIONS);
-
-  /* read in stars line-by-line */
-  while (scan_line (f, line) != EOF) {
-    stripwhite (line);
-    if (line[0] == 0) continue;
-    if (line[0] == '#') continue;
-    sscanf (line, "%s %lf %lf %lf %lf %d", filename, &Rs, &Re, &Ds, &De, &Nrec);
-    Rs *= 15.0;
-    Re *= 15.0;
-    regions[Nregions].Rmin = Rs;
-    regions[Nregions].Rmax = Re;
-    regions[Nregions].Dmin = Ds;
-    regions[Nregions].Dmax = De;
-    regions[Nregions].childE = Nrec; // a cheat since 2MASS only has one depth
-
-    sprintf (datafile, "%s/%s", path, filename);
-    filenames[Nregions] = strcreate (datafile);
-
-    Nregions ++;
-    if (Nregions >= NREGIONS) {
-	NREGIONS += 20;
-	REALLOCATE (regions, SkyRegion, NREGIONS);
-	REALLOCATE (filenames, char *, NREGIONS);
-    }
-  }    
-  fclose (f);
-
-  ALLOCATE (sky, SkyTable, 1);
-  sky[0].regions = regions;
-  sky[0].filename = filenames;
-  sky[0].Nregions = Nregions;
-  return (sky);
-}
Index: unk/Ohana/src/addstar/src/scan2mass_as_data.c
===================================================================
--- /trunk/Ohana/src/addstar/src/scan2mass_as_data.c	(revision 8360)
+++ 	(revision )
@@ -1,219 +1,0 @@
-# include "addstar.h"
-# include "2mass.h"
-
-/* unlike the DR2 data, the AS data is NOT fixed bytes/row 
- * we need to handle fractional lines at the end of each read block
- */
-
-/* read in chunks of ~16MB */
-# define NBYTE 0x2000000
-# define DSTEP 3000.0
-# define TESTPRINT 0
-
-int scan2mass_as_data (char *filename) {
-  
-  int i, j, Nbands, NBANDS, Nbyte, Nextra, Ntotal, badStar, Nbad;
-  int firstBand, tryBand, newBand, step;
-  FILE *f, *g;
-  char *buffer, newfile[1024], badfile[1024], line[1024];
-  char *p, *q, *ptr;
-  double Ro, Do, Rstep, DmaxLast, Rlast, Dlast;
-  double Rmin, Rmax, Dmin, Dmax;
-  TMBands *bands;
-
-  Nbad = 0;
-  Nbands = 0;
-  NBANDS = 10;
-  ALLOCATE (bands, TMBands, 10);
-  ALLOCATE (buffer, char, NBYTE);
-
-  sprintf (badfile, "%s.bad", filename);
-  g = fopen (badfile, "w");
-  if (g == NULL) Shutdown ("can't write badfile for %s", filename);
-
-  f = fopen (filename, "r");
-  if (f == NULL) Shutdown ("can't read 2mass data file: %s", filename);
-  // test if this is a raw datafile or gzipped...
-
-  firstBand = TRUE;
-  newBand = FALSE;
-  tryBand = FALSE;
-  DmaxLast = 90.0;
-  badStar = FALSE;
-
-  step = 0;
-
-  Nextra = 0;
-  Ntotal = 0;
-  while ((Nbyte = fread (&buffer[Nextra], 1, NBYTE-Nextra, f)) != 0) {
-    if (Nbyte == -1) Shutdown ("error reading from raw file %s", filename);
-    Nbyte += Nextra;
-    fprintf (stderr, ".");
-
-    /* find bounds on first complete line */
-    p = buffer;
-    q = memchr (p, '\n', Nbyte);
-    if (q == NULL) Shutdown ("incomplete line at end of file\n");
-
-    while (1) {
-
-      get2mass_coords (p, &Ro, &Do, Nbyte - (p - buffer));
-
-      if (badStar) {
-      fprintf (stderr, "next R,D: %10.6f %10.6f\n", Ro, Do);
-      }
-
-      if (firstBand) {
-	Rmax = Rmin = Ro;
-	Dmin = Dmax = Do;
-	Rlast = Ro;
-	Dlast = Do;
-
-	/* 
-	if (Do < 0.0) {
-	  Dmax = 0.1*(int)(Do * 10.0);
-	  Dmin = 0.1*(int)(Do * 10.0) - 0.1; 
-	} else {
-	  Dmin = 0.1*(int)(Do * 10.0);
-	  Dmax = 0.1*(int)(Do * 10.0) + 0.1; 
-	}	  
-	*/
-
-	bands[Nbands].index[0] = Ntotal + p - buffer;
-	step = 1;
-	Rstep = Rmin + step*DSTEP;
-	firstBand = FALSE;
-	tryBand = FALSE;
-	if (TESTPRINT) fprintf (stderr, "first: %10.6f, %10.6f\n", Ro, Do);
-      }
-
-      // is star in the next band?
-      badStar = FALSE;
-      if (tryBand && (Ro < 90.0)) {
-	if ((Ro + 360.0 - Rlast) > 0.1) {
-	  fprintf (stderr, "warning: star out of order?\n");
-	  fprintf (stderr, "last R,D: %10.6f %10.6f\n", Rlast, Dlast);
-	  fprintf (stderr, "this R,D: %10.6f %10.6f\n", Ro, Do);
-	  snprintf (line, q-p+1, "%s", p);
-	  fprintf (g, "%s\n", line);
-	  Nbad ++;
-	  badStar = TRUE;
-	} else {
-	  newBand = TRUE;
-	}
-      }
-      Rlast = Ro;
-      Dlast = Do;
-
-      if ((Nbands > 0) && (Do < DmaxLast)) {
-	fprintf (stderr, "warning: star out of order?\n");
-	fprintf (stderr, "R,D: %10.6f %10.6f\n", Ro, Do);
-      }
-
-      if (!newBand && !badStar) {
-	Rmin = MIN (Rmin, Ro);
-	Rmax = MAX (Rmax, Ro);
-	Dmin = MIN (Dmin, Do);
-	Dmax = MAX (Dmax, Do);
-      }
-
-      // test of the next step:
-      if (Ro > Rstep) {
-	bands[Nbands].index[step] = Ntotal + p - buffer;
-	if (TESTPRINT) fprintf (stderr, "  step: %10.6f | %10.6f : %d\n", Ro, Rstep, bands[Nbands].index[step]);
-	step ++;
-	Rstep = Rmin + step*DSTEP;
-      }
-
-      if (Ro > 270.0) tryBand = TRUE;
-
-      // test of end of band
-      if (newBand) {
-	bands[Nbands].index[step] = Ntotal + p - buffer;
-	step ++;
-
-	bands[Nbands].Nindex = step;
-	bands[Nbands].Rmin = Rmin;
-	bands[Nbands].Rmax = Rmax;
-	bands[Nbands].Dmin = Dmin;
-	bands[Nbands].Dmax = Dmax;
-
-	DmaxLast = Dmax;
-
-	if (TESTPRINT) fprintf (stderr, " last: %d steps: %10.6f - %10.6f, %10.6f - %10.6f : %d - %d\n", 
-		 bands[Nbands].Nindex, bands[Nbands].Rmin, bands[Nbands].Rmax, bands[Nbands].Dmin, bands[Nbands].Dmax,
-		 bands[Nbands].index[0], bands[Nbands].index[bands[Nbands].Nindex-1]);
-	if (TESTPRINT) fprintf (stderr, "start: %10.6f, %10.6f\n", Ro, Do);
-
-	Nbands ++;
-	CHECK_REALLOCATE (bands, TMBands, NBANDS, Nbands, 10);
-
-	Rmax = Rmin = Ro;
-	Dmax = Dmin = Do;
-
-	bands[Nbands].index[0] = Ntotal + p - buffer;
-	step = 1;
-	Rstep = Rmin + step*DSTEP;
-
-	newBand = FALSE;
-	tryBand = FALSE;
-      }
-
-      /* start of the next line */
-      p = q + 1;
-      if (p - buffer == Nbyte) {
-	Nextra = 0;
-	Ntotal += Nbyte;
-	break;
-      }
-      /* end of the next line */
-      q = memchr (p, '\n', Nbyte - (p - buffer));
-      if (q == NULL) {
-	Nextra = Nbyte - (p - buffer);
-	memmove (buffer, p, Nextra);
-	Ntotal += Nbyte - Nextra;
-	break;
-      } 
-    }
-  }
-  fprintf (stderr, "\n");
-
-  bands[Nbands].index[step] = Ntotal;
-  step ++;
-  bands[Nbands].Nindex = step;
-  bands[Nbands].Rmin = Rmin;
-  bands[Nbands].Rmax = Rmax;
-  bands[Nbands].Dmin = Dmin;
-  bands[Nbands].Dmax = Dmax;
-  if (TESTPRINT) fprintf (stderr, " last: %d steps: %10.6f - %10.6f, %10.6f - %10.6f : %d - %d\n", 
-	   bands[Nbands].Nindex, bands[Nbands].Rmin, bands[Nbands].Rmax, bands[Nbands].Dmin, bands[Nbands].Dmax,
-	   bands[Nbands].index[0], bands[Nbands].index[bands[Nbands].Nindex-1]);
-  Nbands ++;
-
-  fprintf (stderr, "done with %s: %d bands (%d bad)\n", filename, Nbands, Nbad);
-  
-  fclose (f);
-  fclose (g);
-  free (buffer);
-
-  sprintf (newfile, "%s.idx", filename);
-  f = fopen (newfile, "w");
-  if (f == NULL) {
-    fprintf (stderr, "can't write index file\n");
-    exit (1);
-  }
-
-  for (i = 0; i < Nbands; i++) {
-    fprintf (f, "%10.6f %10.6f %10.6f %10.6f  %d ", 
-	     bands[i].Rmin, bands[i].Rmax, bands[i].Dmin, bands[i].Dmax, bands[i].Nindex);
-
-    for (j = 0; j < bands[i].Nindex; j++) {
-      fprintf (f, " %d", bands[i].index[j]);
-    }
-    fprintf (f, "\n");
-  }    
-  fclose (f);
-
-  free (bands);
-  return (TRUE);
-}
Index: /trunk/Ohana/src/addstar/src/sedstar.c
===================================================================
--- /trunk/Ohana/src/addstar/src/sedstar.c	(revision 8360)
+++ /trunk/Ohana/src/addstar/src/sedstar.c	(revision 8361)
@@ -4,7 +4,7 @@
 
   char *root, *ext, tmp;
-  int i, N, Nbytes, Nrefcat, status;
+  int i, Nbytes;
   SkyList *skylist;
-  SkyTable *sky, *sky2mass;
+  SkyTable *sky;
   AddstarClientOptions options;
   Catalog incatalog, outcatalog;
@@ -28,41 +28,47 @@
     incatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
 
-    // lock and open input catalog
-    status = lock_catalog (&incatalog, LCK_XCLD);
-    if (status != 1) {
-	if (VERBOSE) fprintf (stderr, "skipping empty region\n");
-	continue;
+    // an error exit status here is a significant error
+    if (!dvo_catalog_open (&incatalog, skylist[0].regions[i], VERBOSE, "r")) {
+      fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", incatalog.filename);
+      exit (2);
     }
-    gcatalog (&incatalog);
+
+    // Nave_disk == 0 implies an empty catalog file
+    if ((incatalog.Nave_disk == 0) && options.only_match) {
+      if (VERBOSE) fprintf (stderr, "skipping empty region\n");
+      dvo_catalog_unlock (&incatalog);
+      dvo_catalog_free (&incatalog);
+      continue;
+    }
 
     // create output catalog filename
-    // XXX make the output catalog optional
     root = strstr (incatalog.filename, CATDIR);
     if (root == NULL) Shutdown ("error with input catalog name");
-
     ext = incatalog.filename + strlen(CATDIR);
     while (*ext == '/') ext++;
-
     Nbytes = snprintf (&tmp, 0, "%s/%s", argv[2], ext);
     ALLOCATE (outcatalog.filename, char, Nbytes + 1);
     snprintf (outcatalog.filename, Nbytes + 1, "%s/%s", argv[2], ext);
 
-    if (!check_file_access (outcatalog.filename, TRUE, TRUE)) Shutdown ("can't create output directory");
+    outcatalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
+    outcatalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
+    outcatalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+    outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
 
-    status = lock_catalog (&outcatalog, LCK_XCLD);
-    if (status != 2) Shutdown ("error: output catalog exists");
-    mkcatalog (skylist[0].regions[i], &outcatalog); /* fills in new header info */
+    // an error exit status here is a significant error
+    if (!dvo_catalog_open (&outcatalog, skylist[0].regions[i], VERBOSE, "w")) {
+      Shutdown ("ERROR: failure to open/create catalog file %s\n", outcatalog.filename);
+    }
 
     SEDfitCatalog (&outcatalog, &incatalog, sedtable);
     
-    wcatalog (&outcatalog);
-    unlock_catalog (&outcatalog);
-    free (outcatalog.filename);
-    free_catalog (&outcatalog);
+    dvo_catalog_save (&outcatalog, VERBOSE);
+    dvo_catalog_unlock (&outcatalog);
+    dvo_catalog_free (&outcatalog);
 
-    unlock_catalog (&incatalog);
-    free_catalog (&incatalog);
+    dvo_catalog_unlock (&incatalog);
+    dvo_catalog_free (&incatalog);
+    // XXX free filename or not?
   }
-
   exit (0);
 }  
Index: unk/Ohana/src/addstar/src/wcatalog.c
===================================================================
--- /trunk/Ohana/src/addstar/src/wcatalog.c	(revision 8360)
+++ 	(revision )
@@ -1,21 +1,0 @@
-# include "addstar.h"
-
-void wcatalog (Catalog *catalog) {
-  
-  /* output CATMODE and CATFORMAT are set by mkcatalog 
-     or by mode and format of existing data */
-
-  /* if partial load, must use update */
-  if (catalog[0].Nmeas_off != 0) {
-    if (!update_catalog (catalog, VERBOSE)) {
-      fprintf (stderr, "ERROR: failure updating catalog\n");
-      exit (1);
-    }
-  } else {
-    if (!save_catalog (catalog, VERBOSE)) {
-      fprintf (stderr, "ERROR: failure saving catalog\n");
-      exit (1);
-    }
-  }
-}
-
Index: unk/Ohana/src/addstar/src/wimage.c
===================================================================
--- /trunk/Ohana/src/addstar/src/wimage.c	(revision 8360)
+++ 	(revision )
@@ -1,45 +1,0 @@
-# include "addstar.h"
-
-/* add 1 image to image db */
-void wimages (FITS_DB *db, Image *image, int Nimage) {
-  
-  int status, Nimages;
-
-  /* set permissions somewhere ...
-  mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
-  fchmod (ImageCat, mode); */
-
-  /* adjust header */
-  Nimages = 0;
-  gfits_scan (&db[0].header, "NIMAGES", "%d", 1, &Nimages);
-  Nimages ++;
-  gfits_modify (&db[0].header, "NIMAGES", "%d", 1, Nimages);
-
-  gfits_table_to_vtable (&db[0].ftable, &db[0].vtable, 0, 0);
-  for (i = 0; i < Nimage; i++) {
-    gfits_vadd_rows (&db[0].vtable, (char *) image, 1, sizeof(Image));
-  }
-
-  /* check that primary header and table header agree */
-  if (Nimages != db[0].header.Naxis[1]) {
-    fprintf (stderr, "header / table length mismatch!\n");
-  }
-
-  SetProtect (TRUE);
-  status = dvo_image_update (db, VERBOSE);
-  SetProtect (FALSE);
-
-  if (!status) {
-    fprintf (stderr, "ERROR: failed writing data to image catalog\n");
-    exit (1);
-  }
-}
-
-/* add the new image to the image table:
-   - use the table header (from ftable)
-   - create an empty vtable
-   - add the new image to the end of the vtable
-   
-   - write out the vtable, either as TEXT or FITS
-   * dvo_image_update performs the needed byte-swap on the image data
-*/
