Index: /trunk/Ohana/src/imregister/Makefile
===================================================================
--- /trunk/Ohana/src/imregister/Makefile	(revision 3605)
+++ /trunk/Ohana/src/imregister/Makefile	(revision 3606)
@@ -43,11 +43,10 @@
 
 IMOBJ  = \
-$(IMREG)/db.$(ARCH).o     \
 $(IMREG)/delete.$(ARCH).o \
-$(IMREG)/define.$(ARCH).o \
 $(IMREG)/iminfo.$(ARCH).o \
 $(IMREG)/load_probes.$(ARCH).o  \
 $(IMREG)/match.$(ARCH).o  \
 $(IMREG)/modify.$(ARCH).o \
+$(IMREG)/newimages.$(ARCH).o \
 $(IMREG)/output.$(ARCH).o \
 $(IMREG)/unique.$(ARCH).o \
@@ -56,9 +55,10 @@
 $(IMREG)/ConfigPID.$(ARCH).o   \
 $(IMREG)/SetSignals.$(ARCH).o   \
-$(IMREG)/imregclient.$(ARCH).o   \
 $(IMREG)/rconnect.$(ARCH).o   \
 $(IMREG)/FifoOps.$(ARCH).o   \
 $(IMREG)/SockScan.$(ARCH).o   \
 $(IMREG)/submit.$(ARCH).o 
+
+# $(IMREG)/imregclient.$(ARCH).o   \
 
 SPOBJ  = \
@@ -75,5 +75,4 @@
 $(PHOTREG)/delete.$(ARCH).o  \
 $(PHOTREG)/match.$(ARCH).o   \
-$(PHOTREG)/define.$(ARCH).o  \
 $(PHOTREG)/convert.$(ARCH).o \
 $(PHOTREG)/output.$(ARCH).o  \
@@ -82,5 +81,4 @@
 DETOBJ  = \
 $(DETREND)/criteria.$(ARCH).o  \
-$(DETREND)/define.$(ARCH).o    \
 $(DETREND)/delete.$(ARCH).o    \
 $(DETREND)/entry.$(ARCH).o     \
@@ -95,4 +93,5 @@
 $(DETREND)/unique.$(ARCH).o    \
 $(DETREND)/altpath.$(ARCH).o   \
+$(DETREND)/db_names.$(ARCH).o   \
 $(DETREND)/usage.$(ARCH).o
 
Index: /trunk/Ohana/src/imregister/detrend/altpath.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/altpath.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/detrend/altpath.c	(revision 3606)
@@ -8,4 +8,5 @@
   char *dBPath, infile[256], outfile[256], line[1024];
   struct stat statbuf;
+  VTable vtable;
 
   ALLOCATE (current, int, Nimage);
Index: /trunk/Ohana/src/imregister/detrend/db_names.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/db_names.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/detrend/db_names.c	(revision 3606)
@@ -3,41 +3,28 @@
 
 static char *dBFile  = NULL;
+static char *dBPath  = NULL;
 static char *dBTrash = NULL;
 
 /*** these are functions to handle the special detrend.db file/trash names ****/
 
-int delete_image (DetReg *item) {
-  
-  int status;
-  char line[256];
-
-  if (output.verbose) fprintf (stderr, "deleting %s\n", item[0].filename);
-  sprintf (line, "mv -f %s/%s %s", DetrendDB, item[0].filename, dBTrash);
-  status = system (line);
-  if (status) fprintf (stderr, "trouble moving %s to trash (%s)\n", item[0].filename, dBTrash);
-
-  if (status) 
-    return (FALSE);
-  else 
-    return (TRUE);
-}
-
-char *set_db_name () {
+char *set_dBFile () {
 
   struct stat statbuf;
   int status;
 
+  dBPath = DetrendDB;
+
   /* define dBFile based on config data */
-  ALLOCATE (dBFile, char, strlen (DetrendDB) + 15);
-  sprintf (dBFile, "%s/detrend.db", DetrendDB);;
-  ALLOCATE (dBTrash, char, strlen (DetrendDB) + 15);
-  sprintf (dBTrash, "%s/trash", DetrendDB);
+  ALLOCATE (dBFile, char, strlen (dBPath) + 15);
+  sprintf (dBFile, "%s/detrend.db", dBPath);;
+  ALLOCATE (dBTrash, char, strlen (dBPath) + 15);
+  sprintf (dBTrash, "%s/trash", dBPath);
 
   /* check on directories */
-  status = stat (DetrendDB, &statbuf);
+  status = stat (dBPath, &statbuf);
   if (output.Modify) {
     if (status == -1) {
-      if (mkdirhier (DetrendDB) == -1) {
-	fprintf (stderr, "ERROR: can't find or create path %s\n", DetrendDB);
+      if (mkdirhier (dBPath) == -1) {
+	fprintf (stderr, "ERROR: can't find or create path %s\n", dBPath);
 	exit (1);
       }
@@ -55,2 +42,25 @@
   return (dBFile);
 }
+
+char *get_dBPath () {
+
+  return (dBPath);
+
+}
+
+int delete_image (DetReg *item) {
+  
+  int status;
+  char line[256];
+
+  if (output.verbose) fprintf (stderr, "deleting %s\n", item[0].filename);
+  sprintf (line, "mv -f %s/%s %s", dBPath, item[0].filename, dBTrash);
+  status = system (line);
+  if (status) fprintf (stderr, "trouble moving %s to trash (%s)\n", item[0].filename, dBTrash);
+
+  if (status) 
+    return (FALSE);
+  else 
+    return (TRUE);
+}
+
Index: /trunk/Ohana/src/imregister/detrend/delete.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/delete.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/detrend/delete.c	(revision 3606)
@@ -23,5 +23,5 @@
   if (Ndel == 0) { 
     fprintf (stderr, "SUCCESS\n");
-    fits_close_db (&db);
+    fits_db_close (db);
     exit (0);
   }
Index: /trunk/Ohana/src/imregister/detrend/modify.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/modify.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/detrend/modify.c	(revision 3606)
@@ -6,4 +6,5 @@
   int i, j, value;
   int *list;
+  VTable vtable;
   
   value = M_UNDEF;
@@ -44,5 +45,5 @@
 
   /** we may later want to pull this out and put it elsewhere **/
-  fits_vtable_from_ftable (&db[0].ftable, &vtable, match, Nmatch);
+  fits_vtable_from_ftable (&db[0].ftable, &vtable, list, Nmatch);
   for (i = 0; i < Nmatch; i++) {
     fits_convert_DetReg ((DetReg *) vtable.buffer[i], sizeof (DetReg), 1);
Index: /trunk/Ohana/src/imregister/detrend/output.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/output.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/detrend/output.c	(revision 3606)
@@ -6,6 +6,4 @@
 
 int OutputSubset (DetReg *image, int Nimage, Match *match, int Nmatch) {
-
-  image = get_images (&Nimage);
 
   if (output.table != (char *) NULL) {
@@ -25,9 +23,10 @@
 
   int i, j;
-  Header header, theader;
+  FILE *f;
+  Header header;
   Matrix matrix;
-  FTable table;
+  Header theader;
+  FTable ftable;
   DetReg *subset;
-  FILE *f;
 
   ALLOCATE (subset, DetReg, MAX (1, Nmatch));
@@ -54,8 +53,9 @@
   fits_table_set_DetReg (&ftable, subset, Nmatch);
 
-  fits_write_header  (f, &header);
-  fits_write_matrix  (f, &matrix);
-  fits_write_Theader (f, &theader);
-  fits_write_table   (f, &table);
+  fits_fwrite_header  (f, &header);
+  fits_fwrite_matrix  (f, &matrix);
+  fits_fwrite_Theader (f, &theader);
+  fits_fwrite_table   (f, &ftable);
+  fclose (f);
   exit (0);
 }
Index: /trunk/Ohana/src/imregister/detrend/select.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/select.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/detrend/select.c	(revision 3606)
@@ -2,5 +2,5 @@
 # include "detrend.h"
 
-Match SelectEntry (Match *list, int Nlist, Criteria *crit) {
+Match SelectEntry (DetReg *image, int Nimage, Match *list, int Nlist, Criteria *crit) {
 
   /* force a single selection */
@@ -16,10 +16,7 @@
 
   int i, j, entry, order, matchnum;
-  int nmatch, Nmatch, Nimage;
+  int nmatch, Nmatch;
   unsigned int tstart;
   Match *match, *tmatch, answer;
-  DetReg *image;
-
-  image = get_images (&Nimage);
 
   Nmatch = Nlist;
Index: /trunk/Ohana/src/imregister/detrend/unique.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/unique.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/detrend/unique.c	(revision 3606)
@@ -61,5 +61,5 @@
 
     /* subset, Nsubset has a unique list of matched images */
-    unique[Nunique] = SelectEntry (subset, Nsubset, crit);
+    unique[Nunique] = SelectEntry (image, Nimage, subset, Nsubset, crit);
     Nunique ++;
   }
Index: /trunk/Ohana/src/imregister/doc/autocode.txt
===================================================================
--- /trunk/Ohana/src/imregister/doc/autocode.txt	(revision 3606)
+++ /trunk/Ohana/src/imregister/doc/autocode.txt	(revision 3606)
@@ -0,0 +1,20 @@
+
+I have been working to convert these functions to use libautocode to
+generate the table I/O APIs automatically.  A single table defines the
+layout of the table as well as the C structure.  A perl script uses a
+template to generate code to perform the byte swaping, to construct
+the table and add data or extract data from the table.
+
+I discovered that 'photreg' was mis-coded in Fread: it was not
+swapping the entry for refcode.  I have put in a 'rawshort' method to
+handle this for now, but it is fragile: it will only work on
+big-endian machines.  The tables need to be updated and the entry
+returned to short.  This can be done with the existing convert
+operations.
+
+as of 2005/03/30, I have converted the spsearch, photsearch functions,
+but I have not completely tested them.
+
+I am having some errors in the table creation: some lines are dropping
+the leading ' in the wrong place.  
+
Index: /trunk/Ohana/src/imregister/doc/spdb2.txt
===================================================================
--- /trunk/Ohana/src/imregister/doc/spdb2.txt	(revision 3606)
+++ /trunk/Ohana/src/imregister/doc/spdb2.txt	(revision 3606)
@@ -0,0 +1,58 @@
+
+metadata to extract:
+
+typedef struct {
+  char filename[64];
+  char pathname[128];
+  char instrument[32];
+  char telescope[32];
+  char objname[64];
+  char extname[64];
+
+  float ra, dec;
+  float exptime;
+  float airmass;
+
+  float W0, W1, dW;
+  int Nspec;				/* number of spectra associated with entry */
+
+  char mode;			/* PHU, MEF, EXT */
+  char state;			/* image state: raw, flx, etc */
+  char flag;			/* image status flags */
+  char junk[9];
+
+  unsigned long int obstime;
+  unsigned long int regtime;
+} Spectrum;
+
+
+FITS Keywords for metadata
+
+case 1:
+NAXIS  = 1
+NAXIS1 = Nw
+
+case 2:
+NAXIS  = 2
+NAXIS1 = Nw
+NAXIS2 = 1
+
+case 3:
+NAXIS  = 2
+NAXIS1 = 1
+NAXIS2 = Nw
+
+case 4:
+NAXIS  = 2
+NAXIS1 = Nw
+NAXIS2 = n   (flux, dflux, etc)
+
+case 5:
+NAXIS  = 3
+NAXIS1 = Nw
+NAXIS2 = 1
+NAXIS3 = n   (flux, dflux, etc)
+
+0         1         2         3         4         5         6         7         8
+012345678901234567890123456789012345678901234567890123456789012345678901234567890
+/data/elixir2/datdir/megacam/03Am02/taurus/L1551/VLT/spectra/2002.04.01
Index: /trunk/Ohana/src/imregister/imreg/delete.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/delete.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/imreg/delete.c	(revision 3606)
@@ -2,11 +2,9 @@
 # include "imreg.h"
 
-void DeleteSubset (int *match, int Nmatch) {
+void DeleteSubset (FITS_DB *db, RegImage *image, int Nimage, int *match, int Nmatch) {
 
   int i, j;
-  int *keep, Ndel, Nimage, Nsubset;
-  RegImage *image, *subset;
-
-  image = get_images (&Nimage);
+  int *keep, Ndel, Nsubset;
+  RegImage *subset;
 
   ALLOCATE (keep, int, MAX (Nimage, 1));
@@ -22,8 +20,7 @@
   }
   fprintf (stderr, "delete %d images\n", Ndel);
-
   if (Ndel == 0) { 
     fprintf (stderr, "SUCCESS\n");
-    close_db ();
+    fits_db_close (db);
     exit (0);
   }
@@ -41,7 +38,12 @@
   free (keep);
   free (image);
-  set_images (subset, Nsubset);
 
-  save_db ();
+  /** we may later want to pull this out and put it elsewhere **/
+  /** free db[0].theader, db[0].table.buffer? **/
+  fits_table_set_RegImage (&db[0].ftable, subset, Nsubset);
+  fits_db_save (db);
+  fits_db_close (db);
+  fits_db_free (db);
+
   fprintf (stderr, "SUCCESS\n");
   exit (0);
Index: /trunk/Ohana/src/imregister/imreg/iminfo.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/iminfo.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/imreg/iminfo.c	(revision 3606)
@@ -9,10 +9,9 @@
   Header header;
   int extend;
-  int Naxes, Nextend;
+  int Naxes, Nextend, Nseq;
   char Imagetype[80], line[80];
   struct timeval now;
   char *name, *cwd, *tempname;
   double tmp;
-  float *dtime;
 
   ALLOCATE (image, RegImage, 1);
@@ -36,7 +35,9 @@
   Naxes = 2; 
   extend = FALSE;
-  image[0].mode = M_SINGLE;
-  image[0].flag = 0;
-  image[0].ccd  = 0;
+  image[0].mode     = M_SINGLE;
+  image[0].flag     = 0;
+  image[0].ccd      = 0;
+  image[0].seq      = 0;
+  image[0].seqtime  = 0;
 
   /* determine data layout (SINGLE, SPLIT, MEF, CUBE, SLICE) */
@@ -48,10 +49,15 @@
     image[0].ccd  = Nextend;
   } 
+  /* need to distinguish MEF, CUBE, and MEF-CUBE */
   if (Naxes == 3) { /* data cube */
-    fits_scan (&header, "NAXIS3",  "%d", 1, &Nextend);
+    fits_scan (&header, "NAXIS3",  "%d", 1, &Nseq);
+    if (image[0].mode == M_MEF) {
+      fprintf (stderr, "MEF-CUBE not ready\n");
+      exit (1);
+    }
     image[0].mode = M_CUBE;
-    image[0].ccd  = Nextend;
-    dtime = (float *)&image[0].junk[0];
-    fits_scan (&header, "SEQTIME", "%f", 1, dtime);
+    image[0].seq  = Nseq;
+    /* abstract this name somewhere ? */
+    fits_scan (&header, "SEQTIME", "%f", 1, &image[0].seqtime);
   }
   if (SingleIsSplit && (image[0].mode == M_SINGLE)) {
@@ -119,17 +125,17 @@
   /* the probes have to agree with the entries in the program 'gettemps' */
   {
-    int i;
     double pvalues[4];
     static int probes[] = {2, 36, 43, 45};
     if (load_probes (TempLogFile, image[0].obstime, probes, pvalues, 4)) {
-      for (i = 0; i < 4; i++) {
-	image[0].teltemp[i] = pvalues[i];
-      }
+	image[0].teltemp_0 = pvalues[0];
+	image[0].teltemp_1 = pvalues[1];
+	image[0].teltemp_2 = pvalues[2];
+	image[0].teltemp_3 = pvalues[3];
     } else {
       fprintf (stderr, "failure to get probe data\n");
-      image[0].teltemp[0] = 200.0;
-      image[0].teltemp[1] = 200.0;
-      image[0].teltemp[2] = 200.0;
-      image[0].teltemp[3] = 200.0;
+      image[0].teltemp_0 = 200.0;
+      image[0].teltemp_1 = 200.0;
+      image[0].teltemp_2 = 200.0;
+      image[0].teltemp_3 = 200.0;
     }
   }
Index: /trunk/Ohana/src/imregister/imreg/match.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/match.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/imreg/match.c	(revision 3606)
@@ -2,11 +2,10 @@
 # include "imreg.h"
 
-int *match_criteria (int *Nmatch) {
+int *match_criteria (RegImage *image, int Nimage, int *Nmatch) {
 
-  int i, j, Nname, Nimage;
+  int i, j, Nname;
   int N, NMATCH;
   int *match;
   int reject;
-  RegImage *image;
 
   /* create selection index */
@@ -18,6 +17,4 @@
   if (criteria.NameSelect) Nname = strlen (criteria.Name);
   
-  image = get_images (&Nimage);
-
   /* find entries that matches criteria */
   for (i = 0; i < Nimage; i++) {
@@ -46,11 +43,8 @@
 }
 
-int *match_images (RegImage *subset, int Nsubset, int *Nmatch) {
+int *match_images (RegImage *image, int Nimage, RegImage *subset, int Nsubset, int *Nmatch) {
   
-  int i, j, N, Nimage, Nfound;
+  int i, j, N, Nfound;
   int *match;
-  RegImage *image;
-
-  image = get_images (&Nimage);
 
   /* find matching images - very inefficient : sort by obstime, find those first? */
Index: /trunk/Ohana/src/imregister/imreg/modify.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/modify.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/imreg/modify.c	(revision 3606)
@@ -2,16 +2,13 @@
 # include "imreg.h"
 
-void ModifySubset (int *match, int Nmatch) {
+void ModifySubset (FITS_DB *db, RegImage *image, int Nimage, int *match, int Nmatch) {
 
   int i, j, Nold;
   char *tmppath;
   char *ext, *root, *path, dist;
-  int Nimage;
-  RegImage *image;
+  VTable vtable;
 
   Nold = 0;
   tmppath = NULL;
-
-  image = get_images (&Nimage);
 
   /* create some necessary variables */
@@ -81,5 +78,13 @@
   }
 
-  update_db (match, Nmatch);
+  /** we may later want to pull this out and put it elsewhere **/
+  fits_vtable_from_ftable (&db[0].ftable, &vtable, match, Nmatch);
+  for (i = 0; i < Nmatch; i++) {
+    fits_convert_RegImage ((RegImage *) vtable.buffer[i], sizeof (RegImage), 1);
+  }
+  fits_db_update (db, &vtable);
+  fits_db_close (db);
+  fits_db_free (db);
+
   fprintf (stderr, "SUCCESS\n");
   exit (0);
Index: /trunk/Ohana/src/imregister/imreg/newimages.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/newimages.c	(revision 3606)
+++ /trunk/Ohana/src/imregister/imreg/newimages.c	(revision 3606)
@@ -0,0 +1,60 @@
+# include "imregister.h"
+# include "imreg.h"
+
+RegImage *newimages (RegImage *image, int *Nimage) {
+
+  int i, Nnew;
+  RegImage *regimage;
+
+  Nnew = 0;
+  regimage = NULL;
+
+  /* identify new entries based on mode */
+  switch (image[0].mode) {
+  case M_CUBE:
+    Nnew = image[0].seq + 1;
+    ALLOCATE (regimage, RegImage, Nnew);
+    regimage[0] = image[0];
+    for (i = 1; i < Nnew; i++) {
+      regimage[i] = image[0]; 
+      regimage[i].seq = i - 1;
+      regimage[i].mode = M_SLICE;
+      regimage[i].obstime += image[0].seqtime*regimage[i].seq;
+    }
+    break;
+  case M_MEF:
+    Nnew = image[0].ccd;
+    ALLOCATE (regimage, RegImage, Nnew);
+    for (i = 0; i < Nnew; i++) {
+      regimage[i] = image[0]; 
+      regimage[i].ccd = i;
+    }
+    break;
+  case M_SPLIT:
+  case M_SINGLE:
+    Nnew = 1;
+    regimage = &image[0];
+    break;
+  }
+  *Nimage = Nnew;
+  return (regimage);
+}
+
+
+/* meaning of image fields for different data modes:
+
+   mode      ccd                    seq
+   SINGLE    0                      0
+   SPLIT     ccd seq number         0
+   MEF       Nccd                   0
+   CUBE      ccd seq number         Nseq
+   SLICE     ccd seq number         seq number
+   CUBE-MEF  Nccd                   Nseq
+   SLICE-MEF Nccd                   seq number
+
+*/
+
+/*
+ we need to consider modifying this to separately ID MEF/SPLIT/SINGLE and CUBE/SLICE 
+ for the moment, we are keeping this the same as the old style
+*/
Index: /trunk/Ohana/src/imregister/imreg/output.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/output.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/imreg/output.c	(revision 3606)
@@ -24,10 +24,5 @@
 
 /* given a subset list, write out the selected images, if desired */
-void OutputSubset (int *match, int Nmatch) {
-
-  int Nimage;
-  RegImage *image;
-
-  image = get_images (&Nimage);
+void OutputSubset (RegImage *image, int Nimage, int *match, int Nmatch) {
 
   if (output.table != (char *) NULL) {
@@ -53,12 +48,12 @@
 
   int i, j;
-  Header header, theader;
+  FILE *f;
+  Header header;
   Matrix matrix;
-  FTable table;
+  Header theader;
+  FTable ftable;
   RegImage *subset;
 
-  /* define table layout */
-  define_table (&header, &matrix, &theader, &table);
-
+  /* extract subset list to single array */
   ALLOCATE (subset, RegImage, MAX (1, Nmatch));
   for (i = 0; i < Nmatch; i++){
@@ -66,11 +61,27 @@
     memcpy (&subset[i], &image[j], sizeof (RegImage));
   }
-  ConvertStruct ((char *) subset, sizeof (RegImage), Nmatch, "regimage");
-  fits_add_rows (&table, (char *) subset, Nmatch, sizeof (RegImage));
-
-  fits_write_header  (filename, &header);
-  fits_write_matrix  (filename, &matrix);
-  fits_write_Theader (filename, &theader);
-  fits_write_table   (filename, &table);
+
+  /* open file for output */
+  f = fopen (filename, "w");
+  if (f == NULL) {
+    fprintf (stderr, "ERROR: can't open output file %s\n", filename);
+    exit (1);
+  }
+
+  /* create primary header */
+  fits_init_header (&header);    
+  header.extend = TRUE;
+  fits_create_header (&header);
+  fits_create_matrix (&header, &matrix);
+  fits_print (&header, "NEXTEND", "%d", 1, 1);
+
+  ftable.header = &theader;
+  fits_table_set_RegImage (&ftable, subset, Nmatch);
+
+  fits_fwrite_header  (f, &header);
+  fits_fwrite_matrix  (f, &matrix);
+  fits_fwrite_Theader (f, &theader);
+  fits_fwrite_table   (f, &ftable);
+  fclose (f);
   exit (0);
 }
@@ -154,6 +165,5 @@
 			     subset[0].telfocus, subset[0].xprobe, subset[0].yprobe, subset[0].zprobe, 
 			     subset[0].dettemp, 
-			     subset[0].teltemp[0], subset[0].teltemp[1], 
-			     subset[0].teltemp[2], subset[0].teltemp[3],
+			     subset[0].teltemp_0, subset[0].teltemp_1, subset[0].teltemp_2, subset[0].teltemp_3,
 			     subset[0].rotangle, 
 			     subset[0].ra, subset[0].dec, 
Index: /trunk/Ohana/src/imregister/imreg/submit.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/submit.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/imreg/submit.c	(revision 3606)
@@ -8,12 +8,4 @@
 
   /* send these images to FIFOs for imstat and ptolemy */ 
-
-  /* image[0].ccd contains:
-     MEF    : Nccd
-     SPLIT  : ccd number
-     CUBE   : Nslice
-     SLICE  : slice number
-     SINGLE : 0
-  */
 
   if (image[0].mode == M_MEF) {
Index: /trunk/Ohana/src/imregister/imreg/unique.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/unique.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/imreg/unique.c	(revision 3606)
@@ -3,10 +3,9 @@
 
 /* input is a subset index of image list, output is a new subset */
-int *unique_entries (int *subset, int *Nmatch) {
+int *unique_entries (RegImage *image, int Nimage, int *subset, int *Nmatch) {
 
-  int i, j, k, m, Nimage, Nsubset;
+  int i, j, k, m, Nsubset;
   int N, NMATCH;
   int *match, *entry;
-  RegImage *image;
   char idxline[128];
   char **index;
@@ -20,5 +19,4 @@
 
   Nsubset = *Nmatch;
-  image = get_images (&Nimage);
 
   /* index = filename.ccd */
@@ -65,3 +63,2 @@
   return (match);
 }
-
Index: /trunk/Ohana/src/imregister/include/detrend.h
===================================================================
--- /trunk/Ohana/src/imregister/include/detrend.h	(revision 3605)
+++ /trunk/Ohana/src/imregister/include/detrend.h	(revision 3606)
@@ -74,5 +74,8 @@
 DetReg DefineEntry (Descriptor descriptor);
 
+char *set_dBFile ();
 char *get_dBPath ();
+int delete_image (DetReg *image);
+
 int SaveEntry (char *input, DetReg *newdata, char *ID);
 
@@ -86,12 +89,8 @@
 Match CheckCriteria (DetReg *image);
 
-int delete_image (DetReg *image);
 int OutputSubset (DetReg *image, int Nimage, Match *match, int Nmatch);
 int DumpFitsTable (char *filename, DetReg *detdata, Match *match, int Nmatch);
 int PrintSubset (DetReg *detdata, Match *match, int Nmatch);
-Match SelectEntry (Match *list, int Nlist, Criteria *crit);
-
-int ModifySubset (DetReg *image, int Nimage, Match *match, int Nmatch);
-void DeleteSubset (DetReg *image, int Nimage, Match *match, int Nmatch);
+Match SelectEntry (DetReg *image, int Nimage, Match *list, int Nlist, Criteria *crit);
 
 int usage ();
@@ -107,4 +106,6 @@
 int ckpathname (char *newpath);
 int PrintCriteria ();
-int SetAltpath (Match *match, int Nmatch);
 
+int SetAltpath (FITS_DB *db, DetReg *image, int Nimage, Match *match, int Nmatch);
+int ModifySubset (FITS_DB *db, DetReg *image, int Nimage, Match *match, int Nmatch);
+void DeleteSubset (FITS_DB *db, DetReg *image, int Nimage, Match *match, int Nmatch);
Index: /trunk/Ohana/src/imregister/include/imreg.h
===================================================================
--- /trunk/Ohana/src/imregister/include/imreg.h	(revision 3605)
+++ /trunk/Ohana/src/imregister/include/imreg.h	(revision 3606)
@@ -73,20 +73,16 @@
 
 int args (int argc, char **argv);
-RegImage *get_images (int *N);
-int set_images (RegImage *new, int Nnew);
-void init_db ();
-int load_db ();
-int save_db ();
-int update_db (int *match, int Nmatch);
-int append_db (RegImage *new, int Nnew);
-int create_db ();
-int close_db ();
-void DeleteSubset (int *match, int Nmatch);
+
+void DeleteSubset (FITS_DB *db, RegImage *image, int Nimage, int *match, int Nmatch);
 RegImage *iminfo (char *filename);
-int *match_criteria (int *Nmatch);
-int *match_images (RegImage *subset, int Nsubset, int *Nmatch);
-void ModifySubset (int *match, int Nmatch);
+
+int *match_criteria (RegImage *image, int Nimage, int *Nmatch);
+int *match_images (RegImage *image, int Nimage, RegImage *subset, int Nsubset, int *Nmatch);
+
+RegImage *newimages (RegImage *image, int *Nimage);
+
+void ModifySubset (FITS_DB *db, RegImage *image, int Nimage, int *match, int Nmatch);
 void SetOutputMode (char *mode);
-void OutputSubset (int *match, int Nmatch);
+void OutputSubset (RegImage *image, int Nimage, int *match, int Nmatch);
 void DumpFitsBintable (char *filename, RegImage *image, int *match, int Nmatch);
 void DumpFitsTable (char *filename, RegImage *image, int *match, int Nmatch);
@@ -132,3 +128,3 @@
 int memstr (char *m1, char *m2, int n);
 
-int *unique_entries (int *subset, int *Nmatch);
+int *unique_entries (RegImage *image, int Nimage, int *subset, int *Nmatch);
Index: /trunk/Ohana/src/imregister/include/photreg.h
===================================================================
--- /trunk/Ohana/src/imregister/include/photreg.h	(revision 3605)
+++ /trunk/Ohana/src/imregister/include/photreg.h	(revision 3606)
@@ -21,4 +21,5 @@
   int offset;
   char *db;
+  int photcodenames;
 } output;
 
Index: /trunk/Ohana/src/imregister/photreg/args.photreg.c
===================================================================
--- /trunk/Ohana/src/imregister/photreg/args.photreg.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/photreg/args.photreg.c	(revision 3606)
@@ -119,4 +119,5 @@
   fprintf (stderr, "missing required fields\n");
   usage ();
+  return (FALSE);
 }
 
Index: /trunk/Ohana/src/imregister/photreg/args.photsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/photreg/args.photsearch.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/photreg/args.photsearch.c	(revision 3606)
@@ -79,4 +79,10 @@
   }
 
+  output.photcodenames = TRUE;
+  if ((N = get_argument (argc, argv, "-photcodes"))) {
+    remove_argument (N, &argc, argv);
+    output.photcodenames = FALSE;
+  }
+
   output.convert = FALSE;
   if ((N = get_argument (argc, argv, "-convert"))) {
Index: /trunk/Ohana/src/imregister/photreg/output.c
===================================================================
--- /trunk/Ohana/src/imregister/photreg/output.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/photreg/output.c	(revision 3606)
@@ -4,5 +4,4 @@
 static char PhotError[] = "unknown";
 static char PhotNA[] = "unknown";
-static char *ASCIIName = (char *) NULL;
 
 /* given a subset list, write out the selected images, if desired */
@@ -210,19 +209,32 @@
     timestr = sec_to_date (photdata[i].tstart);
     
-    /* convert photcode to filter name */
-    photstr = GetPhotcodeNamebyCode (photdata[i].photcode);
-    refcode = GetPhotcodeNamebyCode (photdata[i].refcode);
-    c1      = GetPhotcodeNamebyCode (photdata[i].c1);
-    c2      = GetPhotcodeNamebyCode (photdata[i].c2);
-    if (photstr == (char *) NULL) photstr = PhotError;
-    if (refcode == (char *) NULL) refcode = PhotError;
-    if (c1      == (char *) NULL) c1      = PhotError;
-    if (c2      == (char *) NULL) c2      = PhotError;
+    if (output.photcodenames) {
+      /* convert photcode to filter name */
+      photstr = GetPhotcodeNamebyCode (photdata[i].photcode);
+      refcode = GetPhotcodeNamebyCode (photdata[i].refcode);
+      c1      = GetPhotcodeNamebyCode (photdata[i].c1);
+      c2      = GetPhotcodeNamebyCode (photdata[i].c2);
+
+      if (photstr == NULL) photstr = PhotError;
+      if (refcode == NULL) refcode = PhotError;
+      if (c1      == NULL) c1      = PhotError;
+      if (c2      == NULL) c2      = PhotError;
       
-    fprintf (stdout, "%s %s  %7.4f %7.4f %7.4f  %3d %3d  %7.4f %7.4f  %s  %s %s %s\n", 
-	     photstr, timestr, photdata[i].ZP, photdata[i].ZPo, photdata[i].dZP, photdata[i].Nmeas, photdata[i].Ntime, 
-	     photdata[i].X, photdata[i].K, refcode, c1, c2, photdata[i].label); 
+      fprintf (stdout, "%s %s  %7.4f %7.4f %7.4f  %3d %3d  %7.4f %7.4f  %s  %s %s %s\n", 
+	       photstr, timestr, photdata[i].ZP, photdata[i].ZPo, photdata[i].dZP, photdata[i].Nmeas, photdata[i].Ntime, 
+	       photdata[i].X, photdata[i].K, refcode, c1, c2, photdata[i].label); 
+    } else {
+      fprintf (stdout, "%4d %s  %7.4f %7.4f %7.4f  %3d %3d  %7.4f %7.4f  %4d %4d %4d  %s\n", 
+	       photdata[i].photcode, timestr, photdata[i].ZP, photdata[i].ZPo, photdata[i].dZP, photdata[i].Nmeas, 
+	       photdata[i].Ntime, photdata[i].X, photdata[i].K, 
+	       photdata[i].refcode, photdata[i].c1, photdata[i].c2, photdata[i].label); 
+    }
+      
     free (timestr);
   }
   return (TRUE);
 }
+
+/**** the pre-autocode implementation of this program failed to byte-swap refcode!
+      any tables from before the new implementation have to be treated carefully
+****/
Index: /trunk/Ohana/src/imregister/src/detregister.c
===================================================================
--- /trunk/Ohana/src/imregister/src/detregister.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/src/detregister.c	(revision 3606)
@@ -1,11 +1,13 @@
 # include "imregister.h"
 # include "detrend.h"
-static char *version = "detregister $Revision: 3.1 $";
+static char *version = "detregister $Revision: 3.2 $";
 
 int main (int argc, char **argv) {
  
-  int status;
+  char *dBFile;
   DetReg newdata;
   Descriptor descriptor;
+  VTable vtable;
+  FITS_DB db;
   
   get_version (argc, argv, version);
@@ -16,14 +18,34 @@
   SaveEntry (argv[1], &newdata, descriptor.imageID);
 
-  init_db ();
-  status = load_db ();
-  if (!status) {
-    create_db ();
+  db.lockstate = LCK_HARD;
+  db.timeout   = 300.0;
+  fits_db_init (&db);
+
+  dBFile = set_dBFile ();
+  if (!fits_db_lock (&db, dBFile)) {
+    fits_db_close (&db);
+    exit (1);
   }
-  append_db (&newdata, 1);
+  if (db.dbstate == LCK_EMPTY) {
+    fits_db_create (&db);    
+    fits_table_set_DetReg (&db.ftable, NULL, 0);
+  } else {  
+    if (!fits_db_load (&db)) {
+      fits_db_close (&db);
+      exit (1);
+    }
+  }
+
+  /** we may later want to pull this out and put it elsewhere **/
+  fits_convert_DetReg (&newdata, sizeof (DetReg), 1);
+  fits_table_to_vtable (&db.ftable, &vtable, 0, 0);
+  fits_vadd_rows (&vtable, (char *) &newdata, 1, sizeof(DetReg));
+
+  fits_db_update (&db, &vtable);
+  fits_db_close (&db);
+  fits_db_free (&db);
 
   fprintf (stderr, "SUCCESS\n");
   exit (0);
-
 }
 
Index: /trunk/Ohana/src/imregister/src/detsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/src/detsearch.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/src/detsearch.c	(revision 3606)
@@ -1,11 +1,13 @@
 # include "imregister.h"
 # include "detrend.h"
-static char *version = "detsearch $Revision: 3.4 $";
+static char *version = "detsearch $Revision: 3.5 $";
 
 int main (int argc, char **argv) {
  
-  int status;
+  int Nmatch, Ndetrend;
+  char *dBFile;
+  FITS_DB db;
   Match *match;
-  int Nmatch;
+  DetReg *detrend;
 
   /* args searches the argument list and generates an array of criteria */
@@ -15,9 +17,9 @@
   if (output.Criteria) PrintCriteria ();
 	
-  db.lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
+  db.lockstate = (output.Modify || output.Delete) ? LCK_HARD : LCK_SOFT;
   db.timeout   = 300.0;
   fits_db_init (&db);
 
-  dBFile = set_db_name ();
+  dBFile = set_dBFile ();
   if (!fits_db_lock (&db, dBFile)) {
     fits_db_close (&db);
@@ -30,5 +32,5 @@
   }
 
-  if (!output.Modify && !output.Delete && !output.Altpath) fits_close_db (&db);
+  if (!output.Modify && !output.Delete && !output.Altpath) fits_db_close (&db);
   detrend = fits_table_get_DetReg (&db.ftable, &Ndetrend);
   
@@ -41,5 +43,5 @@
     if (Nmatch == 0) {
       if (output.verbose) fprintf (stderr, "ERROR: can't find any valid detrend files (%s %s %d)\n", get_type_name(criteria[0].Type), filtername[criteria[0].Filter], criteria[0].CCD);
-      fits_close_db (&db);
+      fits_db_close (&db);
       exit (1);
     }
Index: /trunk/Ohana/src/imregister/src/imregister.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imregister.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/src/imregister.c	(revision 3606)
@@ -1,59 +1,48 @@
 # include "imregister.h"
 # include "imreg.h"
-static char *version = "imregister $Revision: 3.4 $";
+static char *version = "imregister $Revision: 3.5 $";
 
 int main (int argc, char **argv) {
  
-  RegImage *image, *pimage;
-  int i, status, Nnew;
-  float *dtime;
+  int Nregimage;
+  RegImage *image, *regimage;
+  VTable vtable;
+  FITS_DB db;
 
   get_version (argc, argv, version);
   args (argc, argv);
+
   image = iminfo (argv[1]);
-  init_db ();
+  regimage = newimages (image, &Nregimage);
 
-  Nnew = 0;
-  pimage = NULL;
+  if (NoReg) goto skip_reg;
 
-  /* define new entries (pimage, Nnew) */
-  switch (image[0].mode) {
-  case M_CUBE:
-    Nnew = image[0].ccd + 1;
-    ALLOCATE (pimage, RegImage, Nnew);
-    pimage[0] = image[0];
-    dtime = (float *)&image[0].junk[0];
-    for (i = 1; i < Nnew; i++) {
-      pimage[i] = image[0]; 
-      pimage[i].ccd = i - 1;
-      pimage[i].mode = M_SLICE;
-      pimage[i].obstime += *dtime*pimage[i].ccd;
+  db.lockstate = LCK_HARD;
+  db.timeout   = 300.0;
+  fits_db_init (&db);
+
+  if (!fits_db_lock (&db, ImageDB)) {
+    fits_db_close (&db);
+    exit (1);
+  }
+  if (db.dbstate == LCK_EMPTY) {
+    fits_db_create (&db);
+    fits_table_set_RegImage (&db.ftable, NULL, 0);
+  } else {  
+    if (!fits_db_load (&db)) {
+      fits_db_close (&db);
+      exit (1);
     }
-    break;
-  case M_MEF:
-    Nnew = image[0].ccd;
-    ALLOCATE (pimage, RegImage, Nnew);
-    for (i = 0; i < Nnew; i++) {
-      pimage[i] = image[0]; 
-      pimage[i].ccd = i;
-    }
-    break;
-  case M_SPLIT:
-  case M_SINGLE:
-    Nnew = 1;
-    pimage = &image[0];
-    break;
   }
 
-  set_db (ImageDB);
+  fits_convert_RegImage (regimage, sizeof (RegImage), Nregimage);
+  fits_table_to_vtable (&db.ftable, &vtable, 0, 0);
+  fits_vadd_rows (&vtable, (char *) regimage, Nregimage, sizeof(RegImage));
 
-  if (!NoReg) {
-    status = load_db ();
-    if (!status) {
-      create_db ();
-    }
-    append_db (pimage, Nnew);
-  }
+  fits_db_update (&db, &vtable);
+  fits_db_close (&db);
+  fits_db_free (&db);
 
+skip_reg:
   if (IMSORT) SubmitImages (image);
   fprintf (stderr, "SUCCESS: registered %s\n", argv[1]);
Index: /trunk/Ohana/src/imregister/src/imregtable.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imregtable.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/src/imregtable.c	(revision 3606)
@@ -1,14 +1,17 @@
 # include "imregister.h"
 # include "imreg.h"
-static char *version = "imregtable $Revision: 3.4 $";
+static char *version = "imregtable $Revision: 3.5 $";
 
 int main (int argc, char **argv) {
  
-  int status, Nimage, Nx, Ny;
+  int Nimage;
   char *infile;
   RegImage *image;
-  Header header, theader;
+  Header header;
+  Header theader;
   Matrix matrix;
-  FTable table;
+  FTable ftable;
+  VTable vtable;
+  FITS_DB db;
 
   get_version (argc, argv, version);
@@ -16,34 +19,47 @@
   ConfigCamera ();
   ConfigFilter ();
-  init_db ();
-  
+
   if (argc != 2) {
     fprintf (stderr, "USAGE: imregtable (table)\n");
     exit (1);
   }
-  infile = argv[1];
-  output.modify = TRUE;
 
   /* load in table data */
-  table.header = &theader;
-  if (!fits_read_header (infile, &header))                   escape (UNLOCK, "can't open file header");
-  if (!fits_read_matrix (infile, &matrix))                   escape (UNLOCK, "can't open file matrix");
-  if (!fits_read_ftable  (infile, &table, "IMAGE_DATABASE")) escape (UNLOCK, "can't open file table");
+  infile = argv[1];
 
-  /* convert to internal format */
-  image = (RegImage *) table.buffer;
-  fits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
-  fits_scan (table.header, "NAXIS2", "%d", 1, &Ny);
-  Nimage = Ny;
+  /* need to error check these */
+  ftable.header = &theader;
+  fits_read_header  (infile, &header);
+  fits_read_matrix  (infile, &matrix);
+  fits_read_ftable  (infile, &ftable, "IMAGE_DATABASE");
 
-  ConvertStruct ((char *) image, sizeof (RegImage), Nimage, "regimage");
+  image = fits_table_get_RegImage (&ftable, &Nimage);
 
-  set_db (ImageDB);
+  /* load database table */
+  db.lockstate = LCK_HARD;
+  db.timeout   = 300.0;
+  fits_db_init (&db);
 
-  status = load_db ();
-  if (!status) {
-    create_db ();
+  if (!fits_db_lock (&db, ImageDB)) {
+    fits_db_close (&db);
+    exit (1);
   }
-  append_db (image, Nimage);
+  if (db.dbstate == LCK_EMPTY) {
+    fits_db_create (&db);
+    fits_table_set_RegImage (&db.ftable, NULL, 0);
+  } else {  
+    if (!fits_db_load (&db)) {
+      fits_db_close (&db);
+      exit (1);
+    }
+  }
+
+  fits_convert_RegImage (image, sizeof (RegImage), Nimage);
+  fits_table_to_vtable (&db.ftable, &vtable, 0, 0);
+  fits_vadd_rows (&vtable, (char *) image, Nimage, sizeof(RegImage));
+
+  fits_db_update (&db, &vtable);
+  fits_db_close (&db);
+  fits_db_free (&db);
 
   fprintf (stderr, "SUCCESS: registered %s\n", argv[1]);
Index: /trunk/Ohana/src/imregister/src/imsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imsearch.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/src/imsearch.c	(revision 3606)
@@ -1,32 +1,39 @@
 # include "imregister.h"
 # include "imreg.h"
-static char *version = "imsearch $Revision: 3.3 $";
+static char *version = "imsearch $Revision: 3.4 $";
 
 int main (int argc, char **argv) {
  
-  int status, Nmatch;
-  int *match;
+  int Nmatch, Nimage, *match;
+  RegImage *image;
+  FITS_DB db;
 
   get_version (argc, argv, version);
   args (argc, argv);
-  init_db ();
 
-  set_db (ImageDB);
+  db.lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
+  db.timeout   = 300.0;
+  fits_db_init (&db);
 
-  status = load_db ();
-  if (!status) {
-    close_db ();
-    fprintf (stderr, "database missing or empty\n");
-    exit (0);
+  if (!fits_db_lock (&db, ImageDB)) {
+    fits_db_close (&db);
+    exit (1);
   }
-  if (!output.modify && !output.delete) close_db ();
+  if (!fits_db_load (&db)) {
+    fits_db_close (&db);
+    exit (1);
+  }
+
+  if (!output.modify && !output.delete) fits_db_close (&db);
+
+  image = fits_table_get_RegImage (&db.ftable, &Nimage);
   
-  match = match_criteria (&Nmatch);
-  match = unique_entries (match, &Nmatch);
+  match = match_criteria (image, Nimage, &Nmatch);
+  match = unique_entries (image, Nimage, match, &Nmatch);
 
-  if (output.modify) ModifySubset (match, Nmatch);
-  if (output.delete) DeleteSubset (match, Nmatch);
+  if (output.modify) ModifySubset (&db, image, Nimage, match, Nmatch);
+  if (output.delete) DeleteSubset (&db, image, Nimage, match, Nmatch);
 
-  OutputSubset (match, Nmatch);
+  OutputSubset (image, Nimage, match, Nmatch);
 
   exit (0);
Index: /trunk/Ohana/src/imregister/src/imstatreg.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imstatreg.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/src/imstatreg.c	(revision 3606)
@@ -1,12 +1,12 @@
 # include "imregister.h"
 # include "imreg.h"
-static char *version = "imstatreg $Revision: 3.8 $";
-# define DEBUG 0
+static char *version = "imstatreg $Revision: 3.9 $";
 
 int main (int argc, char **argv) {
  
   RegImage *image;
-  int *match, Nmatch, status, child, Nentry;
+  int *match, Nmatch, status, Nentry;
   FILE *f;
+  FITS_DB db;
 
   get_version (argc, argv, version);
@@ -18,8 +18,6 @@
   SetSignals ();
 
-# if (!DEBUG)
   /* fork in background */
-  if ((child = fork ())) {
-    if (child == -1) {
+  if (fork () == -1) {
       fprintf (stderr, "error forking imstatreg -daemon \n");
       exit (1);
@@ -28,10 +26,8 @@
     exit (0);
   }
-# endif
 
   /* child process, check for process */
   ConfigPID (PIDFILE);
 
-# if (!DEBUG)
   /* redirect stderr, stdout to logfile */
   f = freopen (LogFile, "a", stdout);
@@ -42,7 +38,8 @@
     f = freopen (LogFile, "a", stderr);
   }
-# else
-  f = stderr;
-# endif
+
+  db.lockstate = LCK_HARD;
+  db.timeout   = 300.0;
+  fits_db_init (&db);
 
   /* start loop */
@@ -50,17 +47,24 @@
 
     /* check / load / delete temporary database */
-    set_db (TempDB);
-    status = load_db ();
-    if (!status) {
-      print_db_status ("temporary database empty");
-      close_db (); 
+    if (!fits_db_lock (&db, TempDB)) {
+      fits_db_close (&db);
+      fprintf (stderr, "error locking db (path missing? access permission?)\n");
+      exit (1);
+    }
+    if (db.dbstate == LCK_EMPTY) {
+      fprintf (stderr, "temporary database empty\n");
+      goto next;
+    } 
+    if (!fits_db_load (&db)) {
+      fprintf (stderr, "error reading temp db\n");
       goto next;
     }
-    image = get_images (&Nentry);
-    print_db_status ("temporary database read");
-    status = set_images (NULL, 0);
-    close_db (); 
-    print_db_status ("temporary database closed");
+    image = fits_table_get_RegImage (&db.ftable, &Nimage);
+    fprintf (stderr, "temporary database read\n");
+
+    /* need to zero out this file */
+    fprintf (stderr, "temporary database closed\n");
  
+    /******* need to finish this section up *****/
     /* check / load main database */
     set_db (ImageDB);
Index: unk/Ohana/src/imregister/src/notes.txt
===================================================================
--- /trunk/Ohana/src/imregister/src/notes.txt	(revision 3605)
+++ 	(revision )
@@ -1,58 +1,0 @@
-
-metadata to extract:
-
-typedef struct {
-  char filename[64];
-  char pathname[128];
-  char instrument[32];
-  char telescope[32];
-  char objname[64];
-  char extname[64];
-
-  float ra, dec;
-  float exptime;
-  float airmass;
-
-  float W0, W1, dW;
-  int Nspec;				/* number of spectra associated with entry */
-
-  char mode;			/* PHU, MEF, EXT */
-  char state;			/* image state: raw, flx, etc */
-  char flag;			/* image status flags */
-  char junk[9];
-
-  unsigned long int obstime;
-  unsigned long int regtime;
-} Spectrum;
-
-
-FITS Keywords for metadata
-
-case 1:
-NAXIS  = 1
-NAXIS1 = Nw
-
-case 2:
-NAXIS  = 2
-NAXIS1 = Nw
-NAXIS2 = 1
-
-case 3:
-NAXIS  = 2
-NAXIS1 = 1
-NAXIS2 = Nw
-
-case 4:
-NAXIS  = 2
-NAXIS1 = Nw
-NAXIS2 = n   (flux, dflux, etc)
-
-case 5:
-NAXIS  = 3
-NAXIS1 = Nw
-NAXIS2 = 1
-NAXIS3 = n   (flux, dflux, etc)
-
-0         1         2         3         4         5         6         7         8
-012345678901234567890123456789012345678901234567890123456789012345678901234567890
-/data/elixir2/datdir/megacam/03Am02/taurus/L1551/VLT/spectra/2002.04.01
Index: /trunk/Ohana/src/imregister/src/photreg.c
===================================================================
--- /trunk/Ohana/src/imregister/src/photreg.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/src/photreg.c	(revision 3606)
@@ -1,10 +1,10 @@
 # include "imregister.h"
 # include "photreg.h"
-static char *version = "photreg $Revision: 1.5 $";
+static char *version = "photreg $Revision: 1.6 $";
 
 int main (int argc, char **argv) {
  
   char *filename;
-  PhotPars newdata, *photdata;
+  PhotPars newdata;
   VTable vtable;
   FITS_DB db;
@@ -23,10 +23,5 @@
 
   if (db.dbstate == LCK_EMPTY) {
-    fits_init_header (&db.header);    
-    db.header.extend = TRUE;
-    fits_create_header (&db.header);
-    fits_create_matrix (&db.header, &db.matrix);
-    fits_print (&db.header, "NEXTEND", "%d", 1, 1);
-    db.ftable.header = &db.theader;
+    fits_db_create (&db);
     fits_table_set_PhotPars (&db.ftable, NULL, 0);
     /* EXTNAME is set to ZERO_POINTS_3.0 by default */
@@ -43,5 +38,7 @@
   /** we may later want to pull this out and put it elsewhere **/
   fits_convert_PhotPars (&newdata, sizeof (PhotPars), 1);
-  fits_table_to_vtable (&db.ftable, &vtable, 0, 1);
+  fits_table_to_vtable (&db.ftable, &vtable, 0, 0);
+  fits_vadd_rows (&vtable, (char *) &newdata, 1, sizeof(PhotPars));
+
   fits_db_update (&db, &vtable);
   fits_db_close (&db);
Index: /trunk/Ohana/src/imregister/src/photsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/src/photsearch.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/src/photsearch.c	(revision 3606)
@@ -1,10 +1,10 @@
 # include "imregister.h"
 # include "photreg.h"
-static char *version = "photsearch $Revision: 1.5 $";
+static char *version = "photsearch $Revision: 1.6 $";
 
 int main (int argc, char **argv) {
 
   char *filename;
-  int status, Nmatch, Nphotpars;
+  int Nmatch, Nphotpars;
   int *match;
   FITS_DB db;
Index: unk/Ohana/src/imregister/src/select.c
===================================================================
--- /trunk/Ohana/src/imregister/src/select.c	(revision 3605)
+++ 	(revision )
@@ -1,31 +1,0 @@
-# include "imregister.h"
-
-char *select_dbfile () {
-
-  if (!strcmp (output.db, "phot")) {
-    return (PhotDB);
-  }
-
-  if (!strcmp (output.db, "trans")) {
-    return (TransDB);
-  }
-
-  fprintf (stderr, "ERROR: invalid option for db source: %s\n", output.db);
-  exit (1);
-}
-
-/* valid EXTNAME values:
-
-   phot, !output.convert, bintable: "ZERO_POINTS_3.0"
-   phot, !output.convert, table:    "IMAGE_ZPTS"
-
-   trans, !output.convert, bintable: "TRANS_POINTS_3.0"
-   trans, !output.convert, table:    "SUMMARY_ZPTS"
-
-   phot, !output.convert, bintable: "ZERO_POINTS"
-   phot, !output.convert, table:    "IMAGE_ZPTS"
-
-   trans, !output.convert, bintable: "TRANS_POINTS"
-   trans, !output.convert, table:    "SUMMARY_ZPTS"
-
-*/
Index: /trunk/Ohana/src/imregister/src/showiminfo.c
===================================================================
--- /trunk/Ohana/src/imregister/src/showiminfo.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/src/showiminfo.c	(revision 3606)
@@ -1,5 +1,5 @@
 # include "imregister.h"
 # include "imreg.h"
-static char *version = "showiminfo $Revision: 3.0 $";
+static char *version = "showiminfo $Revision: 3.1 $";
 
 int main (int argc, char **argv) {
@@ -24,5 +24,5 @@
   fprintf (stderr, "xprobe: %f, yprobe: %f, zprobe: %f\n", im.xprobe, im.yprobe, im.zprobe);
   fprintf (stderr, "dettemp: %f, temp0: %f temp1: %f, temp2: %f, temp3: %f\n\n", 
-	   im.dettemp, im.teltemp[0], im.teltemp[1], im.teltemp[2], im.teltemp[3]);
+	   im.dettemp, im.teltemp_0, im.teltemp_1, im.teltemp_2, im.teltemp_3);
 
   fprintf (stderr, "ra: %f, dec: %f, rotangle: %f\n", im.ra, im.dec, im.rotangle);
Index: /trunk/Ohana/src/imregister/src/spregister.c
===================================================================
--- /trunk/Ohana/src/imregister/src/spregister.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/src/spregister.c	(revision 3606)
@@ -1,5 +1,5 @@
 # include "imregister.h"
 # include "spreg.h"
-static char *version = "spregister $Revision: 1.5 $";
+static char *version = "spregister $Revision: 1.6 $";
 
 int main (int argc, char **argv) {
@@ -20,5 +20,4 @@
   db.lockstate = LCK_HARD;
   db.timeout   = 300.0;
-
   fits_db_init (&db);
 
@@ -28,10 +27,5 @@
   }
   if (db.dbstate == LCK_EMPTY) {
-    fits_init_header (&db.header);    
-    db.header.extend = TRUE;
-    fits_create_header (&db.header);
-    fits_create_matrix (&db.header, &db.matrix);
-    fits_print (&db.header, "NEXTEND", "%d", 1, 1);
-    db.ftable.header = &db.theader;
+    fits_db_create (&db);
     fits_table_set_Spectrum (&db.ftable, NULL, 0);
   } else {  
@@ -42,7 +36,8 @@
   }
 
-  /** we may later want to pull this out and put it elsewhere **/
   fits_convert_Spectrum (spectrum, sizeof (Spectrum), 1);
-  fits_table_to_vtable (&db.ftable, &vtable, 0, 1);
+  fits_table_to_vtable (&db.ftable, &vtable, 0, 0);
+  fits_vadd_rows (&vtable, (char *) spectrum, 1, sizeof(Spectrum));
+
   fits_db_update (&db, &vtable);
   fits_db_close (&db);
Index: /trunk/Ohana/src/imregister/src/spsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/src/spsearch.c	(revision 3605)
+++ /trunk/Ohana/src/imregister/src/spsearch.c	(revision 3606)
@@ -1,5 +1,5 @@
 # include "imregister.h"
 # include "spreg.h"
-static char *version = "spsearch $Revision: 1.4 $";
+static char *version = "spsearch $Revision: 1.5 $";
 
 int main (int argc, char **argv) {
@@ -20,5 +20,4 @@
     exit (1);
   }
-  
   if (!fits_db_load (&db)) {
     fits_db_close (&db);
