Index: /trunk/Ohana/src/imregister/imphot/args.c
===================================================================
--- /trunk/Ohana/src/imregister/imphot/args.c	(revision 4017)
+++ /trunk/Ohana/src/imregister/imphot/args.c	(revision 4018)
@@ -1,2 +1,27 @@
+# include "imregister.h" 
+# include "imphot.h"
+
+/* criteria struct is global */
+int args (int argc, char **argv) {
+
+
+  FILE *f;
+  Header header;
+  int i, j, status, N;
+  char *dBFile, *timestr, *photstr;
+  int Nimage, nimage, *index, Ntimes;
+  unsigned long *tstart, *tstop;
+  int VERBOSE, FORCE_READ, PHOTCODE, dbstate;
+  Image *image;
+  int PhotCodeSelect, Nin;
+  int CodeSelect, Code;
+  char *FitsOutput, *NameSelect;
+  int NameSelectLength;
+  struct stat filestatus;
+  int size;
+
+  int N;
+
+  ConfigInit (&argc, argv); /* load elixir config data */
 
   /* load photcode data */
Index: /trunk/Ohana/src/imregister/imphot/db_load.c
===================================================================
--- /trunk/Ohana/src/imregister/imphot/db_load.c	(revision 4018)
+++ /trunk/Ohana/src/imregister/imphot/db_load.c	(revision 4018)
@@ -0,0 +1,48 @@
+
+/* load the complete db table into memory - load first extension, do not validate EXTNAME */
+int db_load (FITS_DB *db) {
+
+  /* database name must be set first */
+  if (db == NULL) {
+    fprintf (stderr, "db handle is not set\n");
+    return (FALSE);
+  }
+
+  /* init & load in FITS table data - return FALSE on error */
+  if (!fits_fread_header (db[0].f, &db[0].header)) {
+    fprintf (stderr, "can't read primary header\n"); 
+    return (FALSE);
+  }
+
+  /* how do we decide if it is text or fits? must examine header */
+  if (FITS) {
+    status = rfits (db);
+  } else {
+    status = rtext (db);
+  }
+  return (TRUE);
+}
+
+/* load the complete db table into memory - load first extension, do not validate EXTNAME */
+int rfits (FITS_DB *db) {
+
+  /* database name must be set first */
+  if (db == NULL) {
+    fprintf (stderr, "db handle is not set\n");
+    return (FALSE);
+  }
+  if (!fits_fread_matrix (db[0].f, &db[0].matrix, &db[0].header)) {
+    fprintf (stderr, "can't read primary matrix");
+    return (FALSE);
+  }
+  if (!fits_fread_header (db[0].f, &db[0].theader)) {
+    fprintf (stderr, "can't read table header");
+    return (FALSE);
+  }
+  if (!fits_fread_ftable_data (db[0].f, &db[0].ftable)) {
+    fprintf (stderr, "can't read table data");
+    return (FALSE);
+  }
+  return (TRUE);
+}
+
Index: /trunk/Ohana/src/imregister/imphot/output.c
===================================================================
--- /trunk/Ohana/src/imregister/imphot/output.c	(revision 4017)
+++ /trunk/Ohana/src/imregister/imphot/output.c	(revision 4018)
@@ -1,2 +1,4 @@
+int DumpFitsTable (char *filename, Image *image, int Nentry, int *index, int Nkeep);
+
 
 output () {
Index: /trunk/Ohana/src/imregister/imphot/rtext.c
===================================================================
--- /trunk/Ohana/src/imregister/imphot/rtext.c	(revision 4017)
+++ /trunk/Ohana/src/imregister/imphot/rtext.c	(revision 4018)
@@ -1,21 +1,8 @@
 
-Image *rtext () {
-
-  f = fsetlockfile (dBFile, 120.0, LCK_SOFT, &dbstate);
-  if (f == (FILE *) NULL) {
-    fprintf (stderr, "ERROR: can't set lock on %s, state is %d\n", dBFile, dbstate);
-    exit (1);
-  }
-  Fseek (f, 0, SEEK_SET);
-
-  /* read header */
-  if (!fits_fread_header (f, &header)) {
-    if (VERBOSE) fprintf (stderr, "ERROR: can't read image catalog %s\n", dBFile);
-    exit (1);
-  }
+int rtext (FITS_DB *db) {
 
   /* check that file size makes sense */
   Nimage = 0;
-  fits_scan (&header, "NIMAGES", "%d", 1, &Nimage);
+  fits_scan (&db[0].header, "NIMAGES", "%d", 1, &Nimage);
   if (stat (dBFile, &filestatus) == -1) {
     if (VERBOSE) fprintf (stderr, "ERROR: failed to get status of image catalog\n");
@@ -33,13 +20,27 @@
   } 
 
+  /* create a dummy set of table information */
+  /* (original table has NAXIS = 2, change to 0) */
+  fits_modify (&db[0].header, "NAXIS", "%d", 1, 0);
+  fits_create_matrix (&db[0].header, &db[0].matrix);
+  fits_table_mkheader_Image (&db[0].theader);
+  db[0].ftable.header = &db[0].theader;
+
+  /* set theader size information to match loaded data */
+
   /* alloc, read images */
   ALLOCATE (image, Image, MAX (Nimage, 1));
-  nimage = Fread (image, sizeof(Image), Nimage, f, "image");
+  nimage = fread (image, sizeof(Image), Nimage, db[0].f);
   if (nimage != Nimage) {
     if (VERBOSE) fprintf (stderr, "ERROR: problem loading image catalog\n");
     exit (1);
   } 
-  fclearlockfile (dBFile, f, LCK_SOFT, &dbstate);
+  db[0].ftable.buffer = image;
+  return (TRUE);
+}
 
-  return (image);
-}
+/* the old Image.dat files used a fake FITS header defining a finite data block
+   this function reads in the 
+*/
+
+
Index: /trunk/Ohana/src/imregister/src/imphotsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imphotsearch.c	(revision 4017)
+++ /trunk/Ohana/src/imregister/src/imphotsearch.c	(revision 4018)
@@ -1,40 +1,30 @@
 # include "imregister.h"
 
-static char PhotError[] = "unknown";
-static char *version = "imphotsearch $Revision: 1.5 $";
-
-int DumpFitsTable (char *filename, Image *image, int Nentry, int *index, int Nkeep);
+static char *version = "imphotsearch $Revision: 1.6 $";
 
 int main (int argc, char **argv) {
  
-  FILE *f;
-  Header header;
-  int i, j, status, N;
-  char *dBFile, *timestr, *photstr;
-  int Nimage, nimage, *index, Ntimes;
-  unsigned long *tstart, *tstop;
-  int VERBOSE, FORCE_READ, PHOTCODE, dbstate;
-  Image *image;
-  int PhotCodeSelect, Nin;
-  int CodeSelect, Code;
-  char *FitsOutput, *NameSelect;
-  int NameSelectLength;
-  struct stat filestatus;
-  int size;
-
   get_version (argc, argv, version);
-  ConfigInit (&argc, argv);
-
   args (&argc, argv);
  
-  /* load image database - still a non-FITS file */
-  dBFile = ImPhotDB;
+  db.lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
+  db.timeout   = 300.0;
+  fits_db_init (&db);
 
-  /* how do we decide if it is text or fits? must examine header */
-  if (FITS) {
-    image = rtext (&Nimage);
-  } else {
-    image = rfits (&Nimage);
+  if (!fits_db_lock (&db, ImPhotDB)) {
+    fprintf (stderr, "ERROR: failure to lock db\n");
+    fits_db_close (&db);
+    exit (1);
   }
+  /* we use a varient of fits_db_load since the file may be in text format */
+  if (!db_load (&db)) {
+    fprintf (stderr, "ERROR: failure to load db\n");
+    fits_db_close (&db);
+    exit (1);
+  }
+
+  if (!output.modify && !output.delete) fits_db_close (&db);
+
+  image = fits_table_get_RegImage (&db.ftable, &Nimage);
 
   subset ();
