Index: /trunk/Ohana/doc/dvotools.txt
===================================================================
--- /trunk/Ohana/doc/dvotools.txt	(revision 8341)
+++ /trunk/Ohana/doc/dvotools.txt	(revision 8342)
@@ -4,4 +4,19 @@
 photometric and astrometric calibrations needed by Pan-STARRS, ie the
 AP Survey.
+
+dvo DB manipulations:
+
+  - create a subset of a database (restrict by magnitude limits, time, 
+    region, etc)
+  - re-organize the table structure using a new SkyTable file
+  - remove the automatic extension of the secfilt table; make a mode to 
+    add a new secondary filter
+
+dvo DB organization mods:
+
+  - drop the primary photcodes and put all primaries in the 'secfilt' table
+  - construct a FITS table for the photcodes
+  - tables for the camera and filter data which is currently in the config
+  - tools to update the photcode table
 
 addstar : need a few additional new variations on the addstar concept
Index: /trunk/Ohana/src/addstar/Makefile
===================================================================
--- /trunk/Ohana/src/addstar/Makefile	(revision 8341)
+++ /trunk/Ohana/src/addstar/Makefile	(revision 8342)
@@ -35,5 +35,4 @@
 $(SRC)/find_subset.$(ARCH).o \
 $(SRC)/fakeimage.$(ARCH).o \
-$(SRC)/gcatalog.$(ARCH).o \
 $(SRC)/get2mass.$(ARCH).o \
 $(SRC)/get2mass_as.$(ARCH).o \
@@ -49,9 +48,6 @@
 $(SRC)/gimages.$(ARCH).o \
 $(SRC)/gstars.$(ARCH).o \
-$(SRC)/image-db.$(ARCH).o \
 $(SRC)/in_image.$(ARCH).o \
-$(SRC)/load_pt_catalog.$(ARCH).o \
 $(SRC)/load_subpix.$(ARCH).o \
-$(SRC)/mkcatalog.$(ARCH).o \
 $(SRC)/opening_angle.$(ARCH).o \
 $(SRC)/parse_time.$(ARCH).o \
@@ -61,5 +57,4 @@
 $(SRC)/sort_lists.$(ARCH).o \
 $(SRC)/update_coords.$(ARCH).o \
-$(SRC)/wcatalog.$(ARCH).o \
 $(SRC)/Shutdown.$(ARCH).o \
 $(SRC)/SkyTableFromTychoIndex.$(ARCH).o \
Index: /trunk/Ohana/src/addstar/src/addstar.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstar.c	(revision 8341)
+++ /trunk/Ohana/src/addstar/src/addstar.c	(revision 8342)
@@ -30,11 +30,8 @@
   overlap = NULL;
   set_db (&db);
-  if (options.update) {
-    catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
-  } else {
-    catalog.catflags = LOAD_AVES | LOAD_MEAS      | LOAD_MISS | LOAD_SECF;
-  }
 
   /* we use the image table to lock db access -- perhaps this is not necessary? */
+  db.mode = dvo_catalog_catmode (CATMODE);
+  db.format = dvo_catalog_catformat (CATFORMAT);
   status = dvo_image_lock (&db, ImageCat, 3600.0, LCK_XCLD);
   if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
@@ -61,5 +58,5 @@
 
       if (db.dbstate == LCK_EMPTY) {
-	create_image_db (&db);
+	dvo_image_create (&db, ZeroPt);
       } else {
 	if (!dvo_image_load (&db, VERBOSE, FORCE_READ)) {
@@ -94,14 +91,22 @@
   for (i = 0; i < skylist[0].Nregions; i++) {
 
+    // set the parameters which guide catalog open/load/create
+    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
+    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
     catalog.filename = skylist[0].filename[i];
-    catalog.catformat = dvo_catalog_format (CATFORMAT);  // set the default catformat from config data
-    catalog.catmode   = dvo_catalog_mode (CATMODE);      // set the default catmode from config data
-    catalog.lockmode  = LCK_XCLD;
-    dvo_catalog_open (&catalog, skylist[0].regions[i], Nsecfilt, "w");
+    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+    catalog.catflags = LOAD_AVES | LOAD_MEAS      | LOAD_MISS | LOAD_SECF;
+    if (options.update) catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
 
-    /* for only_match, skip empty catalogs XXX EAM : this leaves behind empty files */
+    // an error exit status here is a significant error
+    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
+      fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
+      exit (2);
+    }
+
+    // Nave_disk == 0 implies an empty catalog file
+    // for only_match, skip empty catalogs
     if ((catalog.Nave_disk == 0) && options.only_match) {
       dvo_catalog_unlock (&catalog);
-      free (catalog.filename);  // can this be done within the dvo_catalog_free function?? 
       dvo_catalog_free (&catalog);
       continue;
@@ -138,23 +143,22 @@
     }
 
-    if (Nsubset == 0) {
-      // XXX remove empty catalogs
-      unlock_catalog (&catalog);
-    } else {
+    // write out catalog, if appropriate
+    if (Nsubset && !options.only_images) {
       SetProtect (TRUE);
-      if (!options.only_images) dvo_catalog_save (&catalog);
+      dvo_catalog_save (&catalog, VERBOSE);
       SetProtect (FALSE);
-      dvo_catalog_unlock (&catalog);
     }
+    dvo_catalog_unlock (&catalog);
     dvo_catalog_free (&catalog);
-    free (catalog.filename); // XXX ????
 
     if (options.mode == M_REFCAT) free (stars);
   }
 
+  // XXX is it necessary to lock the image catalog during this entire process?
   if (options.calibrate) { FindCalibration (&image); }
 
   if (db.dbstate == LCK_EMPTY) {
-    create_image_db (&db);
+    if (VERBOSE) fprintf (stderr, "can't find %s, creating a new one\n", ImageCat);
+    dvo_image_create (&db, ZeroPt);
   }
   
@@ -173,5 +177,5 @@
   gettimeofday (&stop, NULL);
   dtime = DTIME (stop, start);
-  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for %5d stars, %6d average, %7d measure\n", dtime, Nstars, Naverage, Nmeasure);
+  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for %5d stars, %6lld average, %7lld measure\n", dtime, Nstars, Naverage, Nmeasure);
   exit (0);
 }
Index: /trunk/Ohana/src/addstar/src/wcatalog.c
===================================================================
--- /trunk/Ohana/src/addstar/src/wcatalog.c	(revision 8341)
+++ /trunk/Ohana/src/addstar/src/wcatalog.c	(revision 8342)
@@ -5,7 +5,4 @@
   /* output CATMODE and CATFORMAT are set by mkcatalog 
      or by mode and format of existing data */
-
-  /* should this be moved into save_catalog?? */
-  gfits_modify (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
 
   /* if partial load, must use update */
@@ -23,23 +20,2 @@
 }
 
-void free_catalog (Catalog *catalog) {
-
-  /* free, initialize data structures */
-  if (catalog[0].average != NULL) {
-    free (catalog[0].average); 
-    catalog[0].Naverage = 0;
-  }
-  if (catalog[0].measure != NULL) {
-    free (catalog[0].measure); 
-    catalog[0].Nmeasure = 0;
-  }
-  if (catalog[0].missing != NULL) {
-    free (catalog[0].missing); 
-    catalog[0].Nmissing = 0;
-  }
-  if (catalog[0].secfilt != NULL) {
-    free (catalog[0].secfilt); 
-    catalog[0].Nsecfilt = 0;
-  }
-  gfits_free_header (&catalog[0].header);
-}
Index: /trunk/Ohana/src/libdvo/Makefile
===================================================================
--- /trunk/Ohana/src/libdvo/Makefile	(revision 8341)
+++ /trunk/Ohana/src/libdvo/Makefile	(revision 8342)
@@ -37,4 +37,5 @@
 $(SRC)/dvo_catalog_mef.$(ARCH).o       \
 $(SRC)/dvo_catalog_split.$(ARCH).o     \
+$(SRC)/dvo_catalog_create.$(ARCH).o    \
 $(SRC)/dvo_convert.$(ARCH).o           \
 $(SRC)/dvo_convert_elixir.$(ARCH).o    \
Index: /trunk/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /trunk/Ohana/src/libdvo/include/dvo.h	(revision 8341)
+++ /trunk/Ohana/src/libdvo/include/dvo.h	(revision 8342)
@@ -268,11 +268,16 @@
 
 /** dvo_catalog APIs */
-void dvo_catalog_init (Catalog *catalog);
-void dvo_catalog_create (SkyRegion *region, Catalog *catalog, int Nsecfilt, char *catformat, char *catmode);
+void dvo_catalog_init (Catalog *catalog, int complete);
+void dvo_catalog_create (SkyRegion *region, Catalog *catalog, int Nsecfilt);
+void dvo_catalog_free (Catalog *catalog);
+int dvo_catalog_check (Catalog *catalog, int Nsecfilt, int extend);
 int dvo_catalog_lock (Catalog *catalog, int lockmode);
 int dvo_catalog_unlock (Catalog *catalog);
 int dvo_catalog_load (Catalog *catalog, int VERBOSE);
+int dvo_catalog_open (Catalog *catalog, SkyRegion *region, int VERBOSE, char *iomode);
 int dvo_catalog_save (Catalog *catalog, char VERBOSE);
 int dvo_catalog_update (Catalog *catalog, char VERBOSE);
+int dvo_catalog_catformat (char *catformat);
+int dvo_catalog_catmode (char *catmode);
 
 /* catmode-specific APIs */
@@ -333,4 +338,5 @@
 int dvo_image_save_raw (FITS_DB *db, int VERBOSE);
 int dvo_image_addrows (FITS_DB *db, Image *new, int Nnew);
+void dvo_image_create (FITS_DB *db, double ZeroPoint);
 
 int FtableToImage (FTable *ftable, Header *theader, int *format);
Index: /trunk/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 8341)
+++ /trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 8342)
@@ -1,13 +1,43 @@
-# include <ohana.h>
 # include <dvo.h>
 # define DEBUG 1
 
-void dvo_catalog_init (Catalog *catalog) {
-
-  catalog[0].f = NULL;
-  catalog[0].filename = NULL;
-
-  gfits_init_header (&catalog[0].header);
-
+int dvo_catalog_catformat (char *catformat) {
+  
+  /* set the specified CATFORMAT */
+  if (!strcasecmp (catformat, "INTERNAL"))  return (DVO_FORMAT_INTERNAL);
+  if (!strcasecmp (catformat, "LONEOS"))    return (DVO_FORMAT_LONEOS);
+  if (!strcasecmp (catformat, "ELIXIR"))    return (DVO_FORMAT_ELIXIR);
+  if (!strcasecmp (catformat, "PANSTARRS")) return (DVO_FORMAT_PANSTARRS);
+  if (!strcasecmp (catformat, "PMTEST"))    return (DVO_FORMAT_PMTEST);
+  return (DVO_FORMAT_UNDEF);
+}
+
+int dvo_catalog_catmode (char *catmode) {
+
+  /* set the specified CATMODE */
+  if (!strcasecmp (catmode, "RAW"))   return (DVO_MODE_RAW);
+  if (!strcasecmp (catmode, "MEF"))   return (DVO_MODE_MEF);
+  if (!strcasecmp (catmode, "SPLIT")) return (DVO_MODE_SPLIT);
+  return (DVO_MODE_UNDEF);
+}
+
+// init all data, or just catalog data
+void dvo_catalog_init (Catalog *catalog, int complete) {
+
+  // the following are used to guide open/create/load
+  if (complete) {
+    catalog[0].f = NULL;
+    catalog[0].filename = NULL;
+
+    catalog[0].lockmode = 0;
+    catalog[0].catmode  = 0;
+    catalog[0].catformat = 0;
+    catalog[0].catflags = 0;
+    catalog[0].sorted = 0;
+
+    gfits_init_header (&catalog[0].header);
+  }
+
+  // the following describe the catalog files on disk
   catalog[0].average = NULL;
   catalog[0].measure = NULL; 
@@ -30,11 +60,4 @@
   catalog[0].secfilt_catalog = NULL;
 
-  /* extra catalog information */
-  catalog[0].lockmode = 0;
-  catalog[0].catmode  = 0;
-  catalog[0].catformat = 0;
-  catalog[0].catflags = 0;
-  catalog[0].sorted = 0;
-  
   /* pointers for data manipulation */
   catalog[0].found = NULL;
@@ -71,8 +94,18 @@
 int dvo_catalog_unlock (Catalog *catalog) {
 
-  int dbstate;
+  int fd, dbstate;
+  struct stat filestat;
 
   if (catalog[0].f == (FILE *) NULL) return (2);
   // fprintf (stderr, "unlocking: %s\n", catalog[0].filename);
+
+  // attempt to unlink an empty file
+  fd = fileno (catalog[0].f);
+  if (fstat (fd, &filestat)) {
+    if (filestat.st_size == 0) {
+      unlink (catalog[0].filename);
+    }
+  }
+
   fclearlockfile (catalog[0].filename, catalog[0].f, catalog[0].lockmode, &dbstate);
 
@@ -85,8 +118,23 @@
 }
 
-int dvo_catalog_open (Catalog *catalog, int NSECFILT, int VERBOSE, int MODE) {
-
+// open an existing catalog file or or create a new one as needed (iomode == "w")
+// returns FALSE if a catalog could not be opened
+// returns TRUE if the catalog was empty
+int dvo_catalog_open (Catalog *catalog, SkyRegion *region, int VERBOSE, char *iomode) {
+
+  int Nsecfilt;
+  int readonly;
+
+  readonly = -1;
+  if (!strcasecmp (iomode, "r")) readonly = TRUE;
+  if (!strcasecmp (iomode, "w")) readonly = FALSE;
+  if (readonly == -1) return (FALSE);
+
+  catalog[0].lockmode  = LCK_XCLD;
+  if (readonly) catalog[0].lockmode  = LCK_SOFT;
+
+  // XXX make a backup?  always?
   if (!check_file_access (catalog[0].filename, TRUE, VERBOSE)) {
-    if (VERBOSE) fprintf (stderr, "no permission to access %f\n", catalog[0].filename);
+    if (VERBOSE) fprintf (stderr, "no permission to access %s\n", catalog[0].filename);
     return (FALSE);
   }
@@ -94,4 +142,7 @@
   if (VERBOSE) fprintf (stderr, "adding to %s\n", catalog[0].filename);
     
+  // save the expected Nsecfilt value for testing
+  Nsecfilt = catalog[0].Nsecfilt;
+
   switch (dvo_catalog_lock (catalog, catalog[0].lockmode)) {
   case 0:
@@ -110,6 +161,6 @@
     break;
   case 2:
-    if (MODE == DVO_READ_ONLY) return (FALSE);
-    dvo_catalog_create (region, catalog, NSECFILT); /* fills in new header info */
+    if (readonly) return (TRUE);
+    dvo_catalog_create (region, catalog, Nsecfilt); /* fills in new header info */
     if (VERBOSE) fprintf (stderr, "creating new file %s\n", catalog[0].filename);
     break;
@@ -118,32 +169,34 @@
 }
 
+// load an existing dvo_catalog currenly, the catmode information is carried per
+// catalog.  the user-set value of catmode will set the output mode for new
+// tables an old table will keep its mode.
 int dvo_catalog_load (Catalog *catalog, int VERBOSE) {
   
-  int Naxis, split;
+  int Naxis, split, status;
   char measure[80];
 
-  /** we will have to check catmode for MYSQL before reading from the file **/
-
-  gfits_fread_header (catalog[0].f, &catalog[0].header);
+  // load the main catalog header, determine characteristics
+  if (!gfits_fread_header (catalog[0].f, &catalog[0].header)) {
+    if (VERBOSE) fprintf (stderr, "failure to read main catalog header\n");
+    return (FALSE);
+  }
+  // check if the table has been sorted or not 
+  status = gfits_scan (&catalog[0].header, "SORTED", "%t", 1, &catalog[0].sorted);
+  if (!status) catalog[0].sorted = TRUE;
+
+  // determine catmode
   if (!gfits_scan (&catalog[0].header, "NAXIS", "%d", 1, &Naxis)) {
     if (VERBOSE) fprintf (stderr, "can't determine catalog db mode\n");
     return (FALSE);
   }
+  catalog[0].catmode = DVO_MODE_MEF;
   split = gfits_scan (&catalog[0].header, "MEASURE", "%s", 1, measure);
-
-  /* currenly, the catmode information is carried per table.
-     the user-set value of catmode will set the output mode for new tables
-     an old table will keep its mode
-  */
-
-  /* check if the table has been sorted or not */
-  status = gfits_scan (&catalog[0].header, "SORTED", "%t", 1, &catalog[0].sorted);
-  if (!status) catalog[0].sorted = TRUE;
-
-  catalog[0].catmode = DVO_MODE_MEF;
-  catalog[0].catformat = DVO_FORMAT_UNDEF;
   if (split) catalog[0].catmode = DVO_MODE_SPLIT;
   if (Naxis == 2) catalog[0].catmode = DVO_MODE_RAW;
   /* don't use Naxis == 2 and split mode! */
+
+  // catformat determined in dvo_catalog_load_XXX function
+  catalog[0].catformat = DVO_FORMAT_UNDEF;
 
   catalog[0].average = NULL;
@@ -172,5 +225,16 @@
 }
 
+// write out the data, unlink if empty?
 int dvo_catalog_save (Catalog *catalog, char VERBOSE) {
+
+  // set the 'sorted' header keyword
+  gfits_modify (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
+
+  if (catalog[0].Nmeas_off != 0) {
+    if (!dvo_catalog_update (catalog, VERBOSE)) {
+      return (FALSE);
+    } 
+    return (TRUE);
+  }
 
   switch (catalog[0].catmode) {
@@ -210,4 +274,5 @@
       break;
     default:
+      fprintf (stderr, "failure updating catalog\n");
       fprintf (stderr, "invalid catalog mode\n");
       exit (2);
@@ -222,11 +287,8 @@
 
   if (catalog[0].Nsecfilt == Nsecfilt) return (TRUE);
-
   if (catalog[0].Nsecfilt > Nsecfilt) return (FALSE);
-
   if ((catalog[0].Nsecfilt < Nsecfilt) && !extend) return (FALSE);
 
   if ((catalog[0].Nsecfilt < Nsecfilt) && extend) {
-
     Nextra = Nsecfilt - catalog[0].Nsecfilt;
     insec = catalog[0].secfilt;
@@ -251,4 +313,27 @@
 }
 
+void dvo_catalog_free (Catalog *catalog) {
+
+  /* free, initialize data structures */
+  if (catalog[0].average != NULL) {
+    free (catalog[0].average); 
+    catalog[0].Naverage = 0;
+  }
+  if (catalog[0].measure != NULL) {
+    free (catalog[0].measure); 
+    catalog[0].Nmeasure = 0;
+  }
+  if (catalog[0].missing != NULL) {
+    free (catalog[0].missing); 
+    catalog[0].Nmissing = 0;
+  }
+  if (catalog[0].secfilt != NULL) {
+    free (catalog[0].secfilt); 
+    catalog[0].Nsecfilt = 0;
+  }
+  gfits_free_header (&catalog[0].header);
+  // free (catalog[0].filename);
+}
+
 /*
   mode   : items to read (LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF)
Index: /trunk/Ohana/src/libdvo/src/dvo_catalog_create.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/dvo_catalog_create.c	(revision 8341)
+++ /trunk/Ohana/src/libdvo/src/dvo_catalog_create.c	(revision 8342)
@@ -1,10 +1,14 @@
-# include <ohana.h>
 # include <dvo.h>
 # define DEBUG 1
 
 // create a new dvo catalog file (if split, lock extra files as well?)
-void dvo_catalog_create (SkyRegion *region, Catalog *catalog, int Nsecfilt, char *catformat, char *catmode) {
+// catalog internals which must be set:
+// catalog[0].filename
+// catalog[0].catmode
+// catalog[0].catformat (used by dvo_catalog_save)
+// catalog[0].lockmode
+void dvo_catalog_create (SkyRegion *region, Catalog *catalog, int Nsecfilt) {
 
-  int length, status;
+  int length;
   char *path, *root, *file, *line;
   time_t now;
@@ -12,27 +16,6 @@
   if (DEBUG) fprintf (stderr, "new catalog file: %s\n", catalog[0].filename);
 
-  dvo_catalog_init (catalog);
-
-  /* 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);
-  }
+  // init the data values, not the internals listed above
+  dvo_catalog_init (catalog, FALSE);
 
   /* for RAW mode, make header a fake image */
@@ -52,5 +35,5 @@
     /* define measure catalog file */
     ALLOCATE (catalog[0].measure_catalog, Catalog, 1);
-    dvo_catalog_init (catalog[0].measure_catalog);
+    dvo_catalog_init (catalog[0].measure_catalog, TRUE);
 
     /* create basic data for measure catalog file */
@@ -64,5 +47,5 @@
     /* define missing catalog file */
     ALLOCATE (catalog[0].missing_catalog, Catalog, 1);
-    dvo_catalog_init (catalog[0].missing_catalog);
+    dvo_catalog_init (catalog[0].missing_catalog, TRUE);
 
     /* create basic data for missing catalog file */
@@ -76,5 +59,5 @@
     /* define secfilt catalog file */
     ALLOCATE (catalog[0].secfilt_catalog, Catalog, 1);
-    dvo_catalog_init (catalog[0].secfilt_catalog);
+    dvo_catalog_init (catalog[0].secfilt_catalog, TRUE);
 
     /* create basic data for secfilt catalog file */
@@ -90,13 +73,13 @@
     // lock the additional split files
     // XXX clear residual locks if we fail
-    if (lock_catalog (catalog[0].measure_catalog, catalog[0].lockmode) != 2) {
+    if (dvo_catalog_lock (catalog[0].measure_catalog, catalog[0].lockmode) != 2) {
       fprintf (stderr, "error with file lock\n");
       exit (2);
     }
-    if (lock_catalog (catalog[0].missing_catalog, catalog[0].lockmode) != 2) {
+    if (dvo_catalog_lock (catalog[0].missing_catalog, catalog[0].lockmode) != 2) {
       fprintf (stderr, "error with file lock\n");
       exit (2);
     }
-    if (lock_catalog (catalog[0].secfilt_catalog, catalog[0].lockmode) != 2) {
+    if (dvo_catalog_lock (catalog[0].secfilt_catalog, catalog[0].lockmode) != 2) {
       fprintf (stderr, "error with file lock\n");
       exit (2);
Index: /trunk/Ohana/src/libdvo/src/dvo_catalog_split.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/dvo_catalog_split.c	(revision 8341)
+++ /trunk/Ohana/src/libdvo/src/dvo_catalog_split.c	(revision 8342)
@@ -78,5 +78,5 @@
 
     /* lock & open catalog file */
-    if (lock_catalog (measure, catalog[0].lockmode) != 1) {
+    if (dvo_catalog_lock (measure, catalog[0].lockmode) != 1) {
       fprintf (stderr, "cannot access measure file %s\n", measure[0].filename);
       exit (2);
@@ -123,5 +123,5 @@
 
     /* lock & open catalog file */
-    if (lock_catalog (measure, catalog[0].lockmode) != 1) {
+    if (dvo_catalog_lock (measure, catalog[0].lockmode) != 1) {
       fprintf (stderr, "cannot access measure file %s\n", measure[0].filename);
       exit (2);
@@ -158,5 +158,5 @@
 
     /* lock & open catalog file */
-    if (lock_catalog (missing, catalog[0].lockmode) != 1) {
+    if (dvo_catalog_lock (missing, catalog[0].lockmode) != 1) {
       fprintf (stderr, "cannot access missing file %s\n", missing[0].filename);
       exit (2);
@@ -208,5 +208,5 @@
 
     /* lock & open catalog file */
-    if (lock_catalog (secfilt, catalog[0].lockmode) != 1) {
+    if (dvo_catalog_lock (secfilt, catalog[0].lockmode) != 1) {
       fprintf (stderr, "cannot access secfilt file %s\n", secfilt[0].filename);
       exit (2);
Index: /trunk/Ohana/src/libdvo/src/dvo_image.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/dvo_image.c	(revision 8341)
+++ /trunk/Ohana/src/libdvo/src/dvo_image.c	(revision 8342)
@@ -148,2 +148,49 @@
   return (TRUE);
 }
+
+void dvo_image_create (FITS_DB *db, double ZeroPoint) {
+
+  /* create new header */
+  gfits_init_header (&db[0].header);
+
+  /* check the mode */
+  switch (db[0].mode) {
+    case DVO_MODE_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);
+      break;
+    case DVO_MODE_MEF:
+    case DVO_MODE_SPLIT:
+      db[0].header.extend   = TRUE;
+      gfits_create_header (&db[0].header);
+      db[0].mode = DVO_MODE_MEF;
+      break;
+    default:
+      fprintf (stderr, "invalid output catalog mode\n");
+      exit (1);
+  }
+
+  /* check the format */
+  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);
+
+  gfits_modify (&db[0].header, "NIMAGES", "%d", 1, 0);
+  gfits_modify (&db[0].header, "ZERO_PT", "%lf", 1, ZeroPoint);
+
+  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");
+  
+  return;
+}
Index: /trunk/Ohana/src/libdvo/src/skyregion_gsc.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/skyregion_gsc.c	(revision 8341)
+++ /trunk/Ohana/src/libdvo/src/skyregion_gsc.c	(revision 8342)
@@ -41,10 +41,8 @@
 
   int i, j, skipLines, Nzones;
-  char temp[80], name[80];
 
   Header theader;
   FTable ftable;
   SkyTable *skytable;
-  SkyRegion *regions;
   SkyTable *band;
   SkyTable L0, L1, L2, L3, L4;
@@ -202,5 +200,5 @@
 void SkyTableSort (SkyTable *table) {
 
-  int i, j, k, l, ir, N;
+  int i, j, l, ir, N;
   SkyRegion *regions;
   SkyRegion tempregion;
@@ -251,5 +249,5 @@
   
   float Dmin, Dmax, dDec;
-  int i, Nz, NZ, Ndiv, Nregions;
+  int i, Nz, NZ, Nregions;
   SkyRegion *regions;
   SkyRegionZone *zones;
