Index: unk/Ohana/src/imregister/detrend/db.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/db.c	(revision 4847)
+++ 	(revision )
@@ -1,271 +1,0 @@
-# include "imregister.h"
-# include "detrend.h"
-
-/* variables which describe the db */
-FILE *f;
-char *dBFile;
-Header header;
-Header theader;
-Matrix matrix;
-FTable table;
-DetReg *image;
-int Nimage;
-int lockstate;
-int dbstate;
-
-/* special variables unique to detrend.db */
-char *dBPath;
-char *dBTrash;
-
-void init_db () {
-  f              = NULL;
-  dBFile         = NULL;
-  header.buffer  = NULL;
-  matrix.buffer  = NULL;
-  theader.buffer = NULL;
-  table.buffer   = NULL;
-  table.header   = &theader;
-  image          = NULL;
-  Nimage         = 0;
-  lockstate      = LCK_EMPTY;
-  dbstate        = LCK_UNLOCK;
-  dBPath         = NULL;
-  dBTrash        = NULL;
-}
-
-char *get_dBPath () {
-  dBPath = DetrendDB;
-  return (dBPath);
-}
-
-DetReg *get_images (int *N) {
-  *N = Nimage;
-  return (image);
-}
-
-int set_images (DetReg *new, int Nnew) {
-
-  int Nbytes;
-
-  /* assign pointers to new data block */
-  Nimage = Nnew;
-  image = new;
-  if (image == NULL) Nnew = 0;
-
-  /* update header, table structures */
-  fits_modify (table.header, "NAXIS2", "%d", 1, Nnew);
-  table.header[0].Naxis[1] = Nnew;
-  table.buffer = (char *) image;
-
-  /* add padding space to buffer */
-  Nbytes = fits_matrix_size (table.header);
-  if (Nbytes > 0) {
-    REALLOCATE (table.buffer, char, Nbytes);
-    image = (DetReg *) table.buffer;
-  }
-  table.size = Nbytes;
-
-  return (TRUE);
-}
-
-int load_db () {
-
-  struct stat statbuf;
-  int status;
-  int Nx, Ny;
-
-  /* define dBFile based on config data */
-  dBPath = DetrendDB;
-  ALLOCATE (dBFile, char, strlen (dBPath) + 15);
-  sprintf (dBFile, "%s/detrend.db", DetrendDB);;
-  ALLOCATE (dBTrash, char, strlen (dBPath) + 15);
-  sprintf (dBTrash, "%s/trash", DetrendDB);
-
-  /* check on directories */
-  status = stat (dBPath, &statbuf);
-  if (output.Modify) {
-    if (status == -1) {
-      if (mkdirhier (dBPath) == -1) {
-	fprintf (stderr, "ERROR: can't find or create path %s\n", dBPath);
-	exit (1);
-      }
-    }
-  }
-  if (output.Delete) {
-    status = stat (dBTrash, &statbuf);
-    if (status == -1) {
-      if (mkdirhier (dBTrash) == -1) {
-	fprintf (stderr, "ERROR: detrend dB trash not found %s\n", dBTrash);
-	exit (1);
-      }
-    }
-  }
-  lockstate = (output.Modify || output.Delete) ? LCK_HARD : LCK_SOFT;
-  header.buffer = matrix.buffer = theader.buffer = table.buffer = (char *) NULL;
-
-  /* lock database (soft) */
-  f = fsetlockfile (dBFile, 300.0, lockstate, &dbstate);
-  if (dbstate == LCK_EMPTY) return (0);
-
-  if (f == (FILE *) NULL) {
-    fprintf (stderr, "ERROR: can't set lock on %s\n", dBFile);
-    exit (1);
-  }
-
-  /* load in table data */
-  if (!fits_fread_header (f, &header))                     escape (UNLOCK, "ERROR: can't read primary header"); 
-  if (!fits_fread_matrix (f, &matrix, &header))            escape (UNLOCK, "ERROR: can't read primary matrix");
-  if (!fits_fread_ftable  (f, &table, "DETREND_DATABASE")) escape (UNLOCK, "ERROR: can't read table");
-
-  /* convert to internal format */
-  image = (DetReg *) table.buffer;
-  fits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
-  fits_scan (table.header, "NAXIS2", "%d", 1, &Ny);
-  Nimage = Ny;
-
-  if (!ConvertStruct ((char *) image, sizeof (DetReg), Nimage, "detreg")) 
-    escape (UNLOCK, "ERROR: can't convert data"); 
-
-  return (1);
-}
-
-/* save complete db file */
-int save_db () {
-
-  if (!ConvertStruct ((char *) image, sizeof (DetReg), Nimage, "detreg")) 
-    escape (UNLOCK, "ERROR: can't convert from native format");
-
-  /* write all images to file */
-  make_backup (dBFile);
-  Fseek (f, 0, SEEK_SET);
-  if (!fits_fwrite_header (f, &header))   escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_matrix (f, &matrix))   escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_table   (f, &table))   escape (LOCK, "ERROR: can't update db");
-
-  fits_free_table  (&table);
-  close_db ();
-
-  return (TRUE);
-}
-
-/* save subset in db file */
-int update_db (int *match, int Nmatch) {
-
-  int i, N, Nx, Ny;
-  VTable vtable;
-
-  fits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
-  fits_scan (table.header, "NAXIS2", "%d", 1, &Ny);
-
-  /* make empty vtable from table */
-  vtable.header = table.header;
-  vtable.size = table.size;
-  vtable.Nrow = Ny;
-  vtable.pad = vtable.size - Nx*Ny;
-
-  /* insert selected rows in vtable */ 
-  ALLOCATE (vtable.row, int, Nmatch);
-  ALLOCATE (vtable.buffer, char *, Nmatch);
-  for (N = i = 0; i < Nmatch; i++) {
-    if (match[i] == -1) continue;
-    vtable.row[N] = match[i];
-    ALLOCATE (vtable.buffer[N], char, Nx);
-    memcpy (vtable.buffer[N], &image[match[i]], sizeof (DetReg));
-    ConvertStruct ((char *) vtable.buffer[N], sizeof (DetReg), 1, "detreg");
-    N++;
-  }
-  vtable.Nrow = N;
-
-  /* write subset to file */
-  make_backup (dBFile);
-  Fseek (f, 0, SEEK_SET);
-  if (!fits_fwrite_header (f, &header))   escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_matrix (f, &matrix))   escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_vtable   (f, &vtable)) escape (LOCK, "ERROR: can't update db");
-
-  fits_free_table  (&table);
-  fits_free_vtable (&vtable);
-  close_db ();
-
-  return (TRUE);
-}
-
-/* add new entries to db, close db */
-int append_db (DetReg *new, int Nnew) {
-
-  VTable vtable;
-
-  /* convert table to empty table */
-  fits_table_to_vtable (&table, &vtable, 0, 0);
-
-  ConvertStruct ((char *) new, sizeof (DetReg), Nnew, "detreg");
-  fits_vadd_rows (&vtable, (char *) new, Nnew, sizeof(DetReg));
-  Nimage = theader.Naxis[1];
-
-  /* write subset to file */
-  Fseek (f, 0, SEEK_SET);
-  if (!fits_fwrite_header (f, &header))   escape (LOCK, "ERROR: can't append to db");
-  if (!fits_fwrite_matrix (f, &matrix))   escape (LOCK, "ERROR: can't append to db");
-  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't append to db");
-  if (!fits_fwrite_vtable   (f, &vtable)) escape (LOCK, "ERROR: can't append to db");
-
-  fits_free_table (&table);
-  fits_free_vtable (&vtable);
-  close_db ();
-
-  return (TRUE);
-}
-
-int create_db () {
-
-  /* f & dBFile set by load_db */
-
-  /* define table layout */
-  define_table (&header, &matrix, &theader, &table);
-
-  /* convert to internal format */
-  image = (DetReg *) table.buffer;
-  Nimage = 0;
-
-  return (TRUE);
-}
-
-int close_db () {
-
-  /* these are safe even if db is empty */
-  fits_free_header (&header);
-  fits_free_matrix (&matrix);
-  fits_free_header (&theader);
-  /* don't free table: db data may still be used */
-
-  fclearlockfile (dBFile, f, lockstate, &dbstate);
-  if ((Nimage == 0) && (lockstate != LCK_SOFT)) unlink (dBFile);
-
-  return (TRUE);
-}  
-
-int escape (int mode, char *message) {
-  
-  if (mode == UNLOCK) close_db ();
-  fprintf (stderr, "%s\n", message);
-  exit (1);
-}
-
-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: unk/Ohana/src/imregister/detrend/define.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/define.c	(revision 4847)
+++ 	(revision )
@@ -1,40 +1,0 @@
-# include "imregister.h"
-# include "detrend.h"
-
-int define_table (Header *header, Matrix *matrix, Header *theader, FTable *table) {
-
-    /* create primary header */
-    fits_init_header (header);    
-    header[0].extend = TRUE;
-    fits_create_header (header);
-    fits_create_matrix (header, matrix);
-    fits_print (header, "NEXTEND", "%d", 1, 1);
-    
-    /* define bintable header & layout */
-    fits_create_table_header (theader, "BINTABLE", "DETREND_DATABASE");
-    
-    fits_define_bintable_column (theader, "J",    "START_TIME", "start time of measurement", "seconds since Jan 1, 1970 UT",  1.0, 0.0);
-    fits_define_bintable_column (theader, "J",    "STOP_TIME",  "stop time of measurement",  "seconds since Jan 1, 1970 UT",  1.0, 0.0);
-    fits_define_bintable_column (theader, "J",    "REG_TIME",   "time of registration",      "seconds since Jan 1, 1970 UT",  1.0, 0.0);
-    fits_define_bintable_column (theader, "E",    "EXPTIME",    "exposure time",             "seconds",                       1.0, 0.0); 
-    fits_define_bintable_column (theader, "J",    "IMAGETYP",   "detrend type number",       "",                              1.0, 0.0);
-    fits_define_bintable_column (theader, "J",    "FILTER",     "filter number",             "",                              1.0, 0.0);
-    fits_define_bintable_column (theader, "J",    "CCDNUM",     "ccd number",                "",                              1.0, 0.0);
-    fits_define_bintable_column (theader, "J",    "VERSION",    "image version number",      "",                              1.0, 0.0);
-    fits_define_bintable_column (theader, "J",    "ORDER",      "selection order",           "",                              1.0, 0.0);
-    fits_define_bintable_column (theader, "A",    "MODE",       "image mode",                "",                              1.0, 0.0);
-    fits_define_bintable_column (theader, "A",    "ALTPATH",    "available on alt db paths", "",                              1.0, 0.0);
-    fits_define_bintable_column (theader, "58A",  "RESERVED",   "space for additions",       "",                              1.0, 0.0);
-    fits_define_bintable_column (theader, "64A",  "LABEL",      "data label",                "",                              1.0, 0.0);
-    fits_define_bintable_column (theader, "256A", "PATH",       "filename in db",            "",                              1.0, 0.0);
-
-    /* create table, add data values */
-    fits_create_table (theader, table);
-    
-    return (TRUE);
-}
-
-/* changes to this file must also be reflected in 
-   loneos.h.  changes the float or int entries 
-   must also be added to libohana/src/Fread.c
-*/
Index: unk/Ohana/src/imregister/imreg/db.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/db.c	(revision 4847)
+++ 	(revision )
@@ -1,241 +1,0 @@
-# include "imregister.h"
-# include "imreg.h"
-
-/* variables which describe the db */
-FILE *f;
-char *dBFile;
-Header header;
-Header theader;
-Matrix matrix;
-FTable table;
-RegImage *image;
-int Nimage;
-int lockstate;
-int dbstate;
-
-void init_db () {
-  f              = NULL;
-  dBFile         = NULL;
-  header.buffer  = NULL;
-  matrix.buffer  = NULL;
-  theader.buffer = NULL;
-  table.buffer   = NULL;
-  table.header   = &theader;
-  image          = NULL;
-  Nimage         = 0;
-  lockstate      = LCK_EMPTY;
-  dbstate        = LCK_UNLOCK;
-}
-
-int set_db (char *filename) {
-
-  /* be careful: don't change db without closing old db */
-  dBFile = filename;
-  return (TRUE);
-}
-
-RegImage *get_images (int *N) {
-  *N = Nimage;
-  return (image);
-}
-
-int set_images (RegImage *new, int Nnew) {
-
-  int Nbytes;
-
-  /* assign pointers to new data block */
-  Nimage = Nnew;
-  image = new;
-  if (image == NULL) Nnew = 0;
-
-  /* update header, table structures */
-  fits_modify (table.header, "NAXIS2", "%d", 1, Nnew);
-  table.header[0].Naxis[1] = Nnew;
-  table.buffer = (char *) image;
-
-  /* add padding space to buffer */
-  Nbytes = fits_matrix_size (table.header);
-  if (Nbytes > 0) {
-    REALLOCATE (table.buffer, char, Nbytes);
-    image = (RegImage *) table.buffer;
-  }
-  table.size = Nbytes;
-
-  return (TRUE);
-}
-
-int load_db () {
-
-  int Nx, Ny;
-
-  lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
-  header.buffer = matrix.buffer = theader.buffer = table.buffer = (char *) NULL;
-
-  if (dBFile == (char *) NULL) {
-    fprintf (stderr, "ERROR: db file is not set\n");
-    exit (1);
-  }
-
-  /* lock database (soft) */
-  f = fsetlockfile (dBFile, 300.0, lockstate, &dbstate);
-  if (dbstate == LCK_EMPTY) return (0);
-
-  if (f == (FILE *) NULL) {
-    fprintf (stderr, "ERROR: can't set lock on %s\n", dBFile);
-    exit (1);
-  }
-
-  /* init & load in table data */
-  if (!fits_fread_header (f, &header))                  escape (UNLOCK, "ERROR: can't read primary header"); 
-  if (!fits_fread_matrix (f, &matrix, &header))         escape (UNLOCK, "ERROR: can't read primary matrix");
-  if (!fits_fread_ftable (f, &table, "IMAGE_DATABASE")) escape (UNLOCK, "ERROR: can't read table");
-
-  /* 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;
-
-  if (!ConvertStruct ((char *) image, sizeof (RegImage), Nimage, "regimage"))
-    escape (UNLOCK, "ERROR: can't convert data"); 
-
-  return (1);
-}
-
-/* save complete db file */
-int save_db () {
-
-  if (!ConvertStruct ((char *) image, sizeof (RegImage), Nimage, "regimage")) 
-    escape (UNLOCK, "ERROR: can't convert from native format");
-
-  /* write all images to file */
-  make_backup (dBFile);
-  Fseek (f, 0, SEEK_SET);
-  if (!fits_fwrite_header  (f, &header))  escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_matrix  (f, &matrix))  escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_table   (f, &table))   escape (LOCK, "ERROR: can't update db");
-
-  fits_free_table  (&table);
-  close_db ();
-
-  return (TRUE);
-}
-
-/* save subset in db file */
-int update_db (int *match, int Nmatch) {
-
-  int i, N, Nx, Ny;
-  VTable vtable;
-
-  fits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
-  fits_scan (table.header, "NAXIS2", "%d", 1, &Ny);
-
-  /* make empty vtable from table */
-  vtable.header = table.header;
-  vtable.size = table.size;
-  vtable.Nrow = Ny;
-  vtable.pad = vtable.size - Nx*Ny;
-
-  /* insert selected rows in vtable */ 
-  ALLOCATE (vtable.row, int, Nmatch);
-  ALLOCATE (vtable.buffer, char *, Nmatch);
-  for (N = i = 0; i < Nmatch; i++) {
-    if (match[i] == -1) continue;
-    vtable.row[N] = match[i];
-    ALLOCATE (vtable.buffer[N], char, Nx);
-    memcpy (vtable.buffer[N], &image[match[i]], sizeof (RegImage));
-    ConvertStruct ((char *) vtable.buffer[N], sizeof (RegImage), 1, "regimage");
-    N++;
-  }
-  vtable.Nrow = N;
-
-  /* write subset to file */
-  make_backup (dBFile);
-  Fseek (f, 0, SEEK_SET);
-  if (!fits_fwrite_header (f, &header))   escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_matrix (f, &matrix))   escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_vtable   (f, &vtable)) escape (LOCK, "ERROR: can't update db");
-
-  fits_free_table  (&table);
-  fits_free_vtable (&vtable);
-  close_db ();
-
-  return (TRUE);
-}
-
-/* add new entries to db, close db */
-int append_db (RegImage *new, int Nnew) {
-
-  VTable vtable;
-
-  /* add error checks! */
-  fits_table_to_vtable (&table, &vtable, 0, 0);
-
-  ConvertStruct ((char *) new, sizeof (RegImage), Nnew, "regimage");
-  fits_vadd_rows (&vtable, (char *) new, Nnew, sizeof(RegImage));
-  Nimage = theader.Naxis[1];
-
-  /* write subset to file */
-  Fseek (f, 0, SEEK_SET);
-  if (!fits_fwrite_header (f, &header))   escape (LOCK, "ERROR: can't append to db");
-  if (!fits_fwrite_matrix (f, &matrix))   escape (LOCK, "ERROR: can't append to db");
-  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't append to db");
-  if (!fits_fwrite_vtable   (f, &vtable)) escape (LOCK, "ERROR: can't append to db");
-
-  fits_free_table (&table);
-  fits_free_vtable (&vtable);
-  close_db ();
-
-  return (TRUE);
-}
-
-int create_db () {
-
-  /* f & dBFile set by load_db */
-
-  /* define table layout */
-  define_table (&header, &matrix, &theader, &table);
-
-  /* convert to internal format */
-  image = (RegImage *) table.buffer;
-  Nimage = 0;
-
-  return (TRUE);
-}
-
-int close_db () {
-
-  /* these are safe even if db is empty */
-  fits_free_header (&header);
-  fits_free_matrix (&matrix);
-  fits_free_header (&theader);
-  /* don't free table: db data may still be used */
-
-  fclearlockfile (dBFile, f, lockstate, &dbstate);
-  if ((Nimage == 0) && (lockstate != LCK_SOFT)) unlink (dBFile);
-
-  return (TRUE);
-}  
-
-int print_db_status (char *message) {
-
-  int fd;
-
-  if (!output.verbose) return (0);
-  if (f == (FILE *) NULL) {
-    fprintf (stderr, "%s - db: %s - fd: %d\n", message, "null", -1);
-    return (0);
-  }
-  fd = fileno (f);
-  fprintf (stderr, "%s - db: %s - fd: %d\n", message, dBFile, fd);
-  return (1);
-}
-
-int escape (int mode, char *message) {
-  
-  if (mode == UNLOCK) close_db ();
-  fprintf (stderr, "%s\n", message);
-  exit (1);
-}
Index: unk/Ohana/src/imregister/imreg/define.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/define.c	(revision 4847)
+++ 	(revision )
@@ -1,48 +1,0 @@
-# include "imregister.h"
-# include "imreg.h"
-
-int define_table (Header *header, Matrix *matrix, Header *theader, FTable *table) {
-
-  /* create primary header */
-  fits_init_header (header);    
-  header[0].extend = TRUE;
-  fits_create_header (header);
-  fits_create_matrix (header, matrix);
-  fits_print (header, "NEXTEND", "%d", 1, 1);
-    
-  /* define bintable header  layout */
-  fits_create_table_header (theader, "BINTABLE", "IMAGE_DATABASE");
-
-  fits_define_bintable_column (theader, "64A",  "FILE",       "filename in db",        "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "128A", "PATH",       "fullpath in db",        "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "32A",  "FILTER",     "filter name",           "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "32A",  "INSTRUMENT", "instrument",            "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "A",    "CCD",        "ccd identifier",        "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "A",    "MODE",       "mef/split/etc",         "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "A",    "TYPE",       "object/flat/bias/etc",  "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "25A",  "JUNK",       "space for expansion",   "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "E",    "EXPTIME",    "exposure time",        "seconds",                        1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "AIRMASS",    "airmass",              "",                               1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "SKY",        "background level",     "counts / pixel",                 1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "BIAS",       "bias level",           "counts / pixel",                 1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "FWHM",       "image quality",        "pixels",                         1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "TELFOCUS",   "telescope focus",      "microns",                        1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "XPROBE",     "bonnette probe x pos", "microns",                        1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "YPROBE",     "bonnette probe y pos", "microns",                        1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "ZPROBE",     "bonnette focus",       "microns",                        1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "DETTEMP",    "detector temperature", "deg celcius",                    1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "TELTEMP0",   "other temperature",    "deg celcius",                    1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "TELTEMP1",   "other temperature",    "deg celcius",                    1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "TELTEMP2",   "other temperature",    "deg celcius",                    1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "TELTEMP3",   "other temperature",    "deg celcius",                    1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "ROTANGLE",   "camera rotation angle", "degrees",                       1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "RA",         "image ra",              "degrees",                       1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "DEC",        "image dec",             "degrees",                       1.0, 0.0); 
-  fits_define_bintable_column (theader, "J",    "OBS_TIME",   "time of measurement",   "seconds since Jan 1, 1970 UT",  1.0, 0.0);
-  fits_define_bintable_column (theader, "J",    "REG_TIME",   "time of registration",  "seconds since Jan 1, 1970 UT",  1.0, 0.0);
-
-    /* create table, add data values */
-  fits_create_table (theader, table);
-
-  return (TRUE);
-}
Index: unk/Ohana/src/imregister/photreg/db.c
===================================================================
--- /trunk/Ohana/src/imregister/photreg/db.c	(revision 4847)
+++ 	(revision )
@@ -1,344 +1,0 @@
-# include "imregister.h"
-# include "photreg.h"
-
-/**** I am moving the auto-convert functions out of this program 
-      until I can define an appropriate paradigm ****/
-
-/* variables which describe the db */
-FILE *f;
-char *dBFile;
-Header header;
-Header theader;
-Matrix matrix;
-FTable table;
-PhotPars *image;
-int Nimage;
-int lockstate;
-int dbstate;
-char *BinaryName = NULL;
-
-void init_db () {
-  f              = NULL;
-  dBFile         = NULL;
-  header.buffer  = NULL;
-  matrix.buffer  = NULL;
-  theader.buffer = NULL;
-  table.buffer   = NULL;
-  table.header   = &theader;
-  image          = NULL;
-  Nimage         = 0;
-  lockstate      = LCK_EMPTY;
-  dbstate        = LCK_UNLOCK;
-}
-
-/* photreg vs transreg database selection */
-int set_db (char *db) {
-
-  /* be careful: don't change db without closing old db */
-  if (!strcmp (db, "phot")) {
-    dBFile = PhotDB;    
-    BinaryName = "ZERO_POINTS_3.0";
-    set_Binary_name (BinaryName);
-    set_ASCII_name ("IMAGE_ZPTS");
-    return (TRUE);
-  }
-  if (!strcmp (db, "trans")) {
-    dBFile = TransDB;    
-    BinaryName = "TRANS_POINTS_3.0";
-    set_Binary_name (BinaryName);
-    set_ASCII_name ("SUMMARY_ZPTS");
-    return (TRUE);
-  }
-  /*
-  if (!strcmp (db, "phot_old")) {
-    dBFile = PhotDB;    
-    BinaryName = "ZERO_POINTS";
-    set_Binary_name (BinaryName);
-    set_ASCII_name ("IMAGE_ZPTS");
-    return (TRUE);
-  }
-  if (!strcmp (db, "trans_old")) {
-    dBFile = TransDB;    
-    BinaryName = "TRANS_POINTS";
-    set_Binary_name (BinaryName);
-    set_ASCII_name ("SUMMARY_ZPTS");
-    return (TRUE);
-  }
-  */
-  return (FALSE);
-}
-
-PhotPars *get_images (int *N) {
-  *N = Nimage;
-  return (image);
-}
-
-int set_images (PhotPars *new, int Nnew) {
-
-  int Nbytes;
-
-  /* assign pointers to new data block */
-  Nimage = Nnew;
-  image = new;
-  if (image == NULL) Nnew = 0;
-
-  /* update header, table structures */
-  fits_modify (table.header, "NAXIS2", "%d", 1, Nnew);
-  table.header[0].Naxis[1] = Nnew;
-  table.buffer = (char *) image;
-
-  /* add padding space to buffer */
-  Nbytes = fits_matrix_size (table.header);
-  if (Nbytes > 0) {
-    REALLOCATE (table.buffer, char, Nbytes);
-    image = (PhotPars *) table.buffer;
-  }
-  table.size = Nbytes;
-
-  return (TRUE);
-}
-
-int load_db () {
-
-  int Nx, Ny, status;
-
-  if (output.convert) {
-    fprintf (stderr, "conversion not allowed for now\n");
-    status = FALSE;
-    exit (1);
-    /* 
-    status = load_old_db ();
-    return (status);
-    */
-  }
-  set_db (output.db);
-
-  lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
-  header.buffer = matrix.buffer = theader.buffer = table.buffer = (char *) NULL;
-
-  if (dBFile == (char *) NULL) {
-    fprintf (stderr, "ERROR: db file is not set\n");
-    exit (1);
-  }
-
-  /* lock database */
-  f = fsetlockfile (dBFile, 300.0, lockstate, &dbstate);
-  if (dbstate == LCK_EMPTY) return (0);
-
-  if (f == (FILE *) NULL) {
-    fprintf (stderr, "ERROR: can't set lock on %s\n", dBFile);
-    exit (1);
-  }
-
-  /* load in table data */
-  if (!fits_fread_header (f, &header))            escape (UNLOCK, "ERROR: can't read primary header"); 
-  if (!fits_fread_matrix (f, &matrix, &header))   escape (UNLOCK, "ERROR: can't read primary header");
-  if (!fits_fread_ftable (f, &table, BinaryName)) escape (UNLOCK, "ERROR: can't read primary header");
-
-  /* convert to internal format */
-  image = (PhotPars *) table.buffer;
-  fits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
-  fits_scan (table.header, "NAXIS2", "%d", 1, &Ny);
-  Nimage = Ny;
-
-  if (!ConvertStruct ((char *) image, sizeof (PhotPars), Nimage, "photpars"))
-    escape (UNLOCK, "ERROR: can't convert data"); 
-
-  return (1);
-}
-
-# if (0)
-int load_old_db () {
-
-  OldPhotPars *oldimage;
-  int i, Nx, Ny;
-  char tmpname[64];
-
-  sprintf (tmpname, "%s_old", output.db);
-  set_db (tmpname);
-
-  lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
-
-  if (dBFile == (char *) NULL) {
-    fprintf (stderr, "ERROR: db file is not set\n");
-    exit (1);
-  }
-
-  /* lock database */
-  f = fsetlockfile (dBFile, 300.0, lockstate, &dbstate);
-  if (dbstate == LCK_EMPTY) return (0);
-
-  if (f == (FILE *) NULL) {
-    fprintf (stderr, "ERROR: can't set lock on %s\n", dBFile);
-    exit (1);
-  }
-
-  /* load in table data */
-  if (!fits_fread_header (f, &header))            escape (UNLOCK, "ERROR: can't read primary header"); 
-  if (!fits_fread_matrix (f, &matrix, &header))   escape (UNLOCK, "ERROR: can't read primary header");
-  if (!fits_fread_ftable (f, &table, BinaryName)) escape (UNLOCK, "ERROR: can't read primary header");
-
-  /* convert to internal format */
-  oldimage = (OldPhotPars *) table.buffer;
-  fits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
-  fits_scan (table.header, "NAXIS2", "%d", 1, &Ny);
-  Nimage = Ny;
-
-  if (!ConvertStruct ((char *) oldimage, sizeof (OldPhotPars), Nimage, "oldphotpars"))
-    escape (UNLOCK, "ERROR: can't read primary header"); 
-
-  ALLOCATE (image, PhotPars, Nimage);
-  for (i = 0; i < Nimage; i++) {
-    image[i].ZP       = oldimage[i].ZP;
-    image[i].ZPo      = oldimage[i].ZPo;
-    image[i].dZP      = oldimage[i].dZP;
-    image[i].K        = oldimage[i].K;
-    image[i].X        = oldimage[i].X;
-    image[i].tstart   = oldimage[i].tstart;
-    image[i].tstop    = oldimage[i].tstop;
-    image[i].c1       = oldimage[i].c1;
-    image[i].c2       = oldimage[i].c2;
-    image[i].photcode = oldimage[i].photcode;
-    strcpy (image[i].label, oldimage[i].label);
-    image[i].Nmeas = 0;
-    image[i].Ntime = 0;
-  }
-  free (oldimage);
-  close_db ();
-  set_db (output.db);
-  return (1);
-}
-# endif
-
-/* save complete db file */
-int save_db () {
-
-  if (!ConvertStruct ((char *) image, sizeof (PhotPars), Nimage, "photpars")) 
-    escape (UNLOCK, "ERROR: can't convert from native format");
-
-  /* write all images to file */
-  make_backup (dBFile);
-  Fseek (f, 0, SEEK_SET);
-  if (!fits_fwrite_header  (f, &header))  escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_matrix  (f, &matrix))  escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_table   (f, &table))   escape (LOCK, "ERROR: can't update db");
-
-  fits_free_table  (&table);
-  close_db ();
-
-  return (TRUE);
-}
-
-/* save subset in db file */
-int update_db (int *match, int Nmatch) {
-
-  int i, N, Nx, Ny;
-  VTable vtable;
-
-  fits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
-  fits_scan (table.header, "NAXIS2", "%d", 1, &Ny);
-
-  /* make empty vtable from table */
-  vtable.header = table.header;
-  vtable.size = table.size;
-  vtable.Nrow = Ny;
-  vtable.pad = vtable.size - Nx*Ny;
-
-  /* insert selected rows in vtable */ 
-  ALLOCATE (vtable.row, int, Nmatch);
-  ALLOCATE (vtable.buffer, char *, Nmatch);
-  for (N = i = 0; i < Nmatch; i++) {
-    if (match[i] == -1) continue;
-    vtable.row[N] = match[i];
-    ALLOCATE (vtable.buffer[N], char, Nx);
-    memcpy (vtable.buffer[N], &image[match[i]], sizeof (PhotPars));
-    ConvertStruct ((char *) vtable.buffer[N], sizeof (PhotPars), 1, "photpars");
-    N++;
-  }
-  vtable.Nrow = N;
-
-  /* write subset to file */
-  make_backup (dBFile);
-  Fseek (f, 0, SEEK_SET);
-  if (!fits_fwrite_header  (f, &header))  escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_matrix  (f, &matrix))  escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db");
-  if (!fits_fwrite_vtable  (f, &vtable))  escape (LOCK, "ERROR: can't update db");
-
-  fits_free_table  (&table);
-  fits_free_vtable (&vtable);
-  close_db ();
-
-  return (TRUE);
-}
-
-int append_db (PhotPars *new, int Nnew) {
-
-  VTable vtable;
-
-  /* add error checks! */
-  fits_table_to_vtable (&table, &vtable, 0, 0);
-
-  ConvertStruct ((char *) new, sizeof (PhotPars), Nnew, "photpars");
-  fits_vadd_rows (&vtable, (char *) new, Nnew, sizeof(PhotPars));
-  Nimage = theader.Naxis[1];
-
-  /* write subset to file */
-  Fseek (f, 0, SEEK_SET);
-  if (!fits_fwrite_header  (f, &header))  escape (LOCK, "ERROR: can't append to db");
-  if (!fits_fwrite_matrix  (f, &matrix))  escape (LOCK, "ERROR: can't append to db");
-  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't append to db");
-  if (!fits_fwrite_vtable  (f, &vtable))  escape (LOCK, "ERROR: can't append to db");
-
-  fits_free_table (&table);
-  fits_free_vtable (&vtable);
-  close_db ();
-
-  return (TRUE);
-}
-
-int create_db () {
-
-  /* f & dBFile set by load_db */
-
-  /* define table layout */
-  define_table (&header, &matrix, &theader, &table);
-
-  /* convert to internal format */
-  image = (PhotPars *) table.buffer;
-  Nimage = 0;
-
-  return (TRUE);
-}
-
-int close_db () {
-
-  /* these are safe even if db is empty */
-  fits_free_header (&header);
-  fits_free_matrix (&matrix);
-  fits_free_header (&theader);
-  /* don't free table: db data may still be used */
-
-  fclearlockfile (dBFile, f, lockstate, &dbstate);
-  if ((Nimage == 0) && (lockstate != LCK_SOFT)) unlink (dBFile);
-
-  return (TRUE);
-}  
-
-int print_db_fd () {
-
-  int fd;
-
-  fd = fileno (f);
-  fprintf (stderr, "db: %s, fd: %d\n", dBFile, fd);
-  return (TRUE);
-}
-
-int escape (int mode, char *message) {
-  
-  if (mode == UNLOCK) close_db ();
-  fprintf (stderr, "%s\n", message);
-  exit (1);
-}
-
Index: unk/Ohana/src/imregister/photreg/define.c
===================================================================
--- /trunk/Ohana/src/imregister/photreg/define.c	(revision 4847)
+++ 	(revision )
@@ -1,41 +1,0 @@
-# include "imregister.h"
-# include "photreg.h"
-
-static char *BinaryName = (char *) NULL;
-
-void set_Binary_name (char *name) {
-  BinaryName = name;
-}
-
-int define_table (Header *header, Matrix *matrix, Header *theader, FTable *table) {
-
-  /* create primary header */
-  fits_init_header (header);    
-  header[0].extend = TRUE;
-  fits_create_header (header);
-  fits_create_matrix (header, matrix);
-  fits_print (header, "NEXTEND", "%d", 1, 1);
-    
-  /* define bintable header layout */
-  fits_create_table_header (theader, "BINTABLE", BinaryName);
-
-  fits_define_bintable_column (theader, "E",   "ZP_OBS",     "measured zero point",       "mag",                           1.0, 0.0);
-  fits_define_bintable_column (theader, "E",   "ZP_REF",     "nominal zero point",        "mag",                           1.0, 0.0);
-  fits_define_bintable_column (theader, "E",   "ZP_ERR",     "error on zero point",       "mag",                           1.0, 0.0);
-  fits_define_bintable_column (theader, "E",   "C_AIRMASS",  "airmass coeff",             "mag per airmass",               1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",   "C_COLOR",    "color coeff",               "mag per mag",                   1.0, 0.0);
-  fits_define_bintable_column (theader, "J",   "START_TIME", "start time of measurement", "seconds since Jan 1, 1970 UT",  1.0, 0.0);
-  fits_define_bintable_column (theader, "J",   "STOP_TIME",  "stop time of measurement",  "seconds since Jan 1, 1970 UT",  1.0, 0.0);
-  fits_define_bintable_column (theader, "I",   "C1_CODE",    "code 1 for color",          "photcode",                      1.0, 0.0);
-  fits_define_bintable_column (theader, "I",   "C2_CODE",    "code 2 for color",          "photcode",                      1.0, 0.0);
-  fits_define_bintable_column (theader, "I",   "PHOTCODE",   "photcode",                  "photcode",                      1.0, 0.0);
-  fits_define_bintable_column (theader, "64A", "LABEL",      "data label",                "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "I",   "REFCODE",    "photcode",                  "photcode",                      1.0, 0.0);
-  fits_define_bintable_column (theader, "J",   "N_TIME",     "number of times",           "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "J",   "N_MEAS",     "number of measurements",    "",                              1.0, 0.0);
-  
-  /* create table, add data values */
-  fits_create_table (theader, table);
-
-  return (TRUE);
-}
Index: unk/Ohana/src/imregister/spreg/define.c
===================================================================
--- /trunk/Ohana/src/imregister/spreg/define.c	(revision 4847)
+++ 	(revision )
@@ -1,45 +1,0 @@
-# include "imregister.h"
-# include "spreg.h"
-
-int define_table (Header *header, Matrix *matrix, Header *theader, FTable *table) {
-
-  /* create primary header */
-  fits_init_header (header);    
-  header[0].extend = TRUE;
-  fits_create_header (header);
-  fits_create_matrix (header, matrix);
-  fits_print (header, "NEXTEND", "%d", 1, 1);
-    
-  /* define bintable header  layout */
-  fits_create_table_header (theader, "BINTABLE", "SPECTRUM_DATABASE");
-
-  fits_define_bintable_column (theader, "E",    "RA",         "ra",                    "degrees",                       1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "DEC",        "dec",                   "degrees",                       1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "EXPTIME",    "exposure time",         "seconds",                       1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "AIRMASS",    "airmass",               "",                              1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "Ws",         "spectral range start",  "Angstrom",                 	1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "We",         "spectral range end",    "Angstrom",                 	1.0, 0.0); 
-  fits_define_bintable_column (theader, "E",    "dW",         "spectral resolution",   "Angstrom / pix",                1.0, 0.0); 
-
-  fits_define_bintable_column (theader, "J",    "NSPECTRA",   "number of spectra",     "",                              1.0, 0.0); 
-  fits_define_bintable_column (theader, "J",    "OBS_TIME",   "time of measurement",   "seconds since Jan 1, 1970 UT",  1.0, 0.0);
-  fits_define_bintable_column (theader, "J",    "REG_TIME",   "time of registration",  "seconds since Jan 1, 1970 UT",  1.0, 0.0);
-
-  fits_define_bintable_column (theader, "A",    "MODE",       "phu/mef/ext",           "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "A",    "STATE",      "raw/wav/flx/etc",       "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "A",    "FLAG",       "status flags",          "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "13A",  "EXTRA",      "room for expansion",    "",                              1.0, 0.0);
-
-  fits_define_bintable_column (theader, "64A",  "PATHNAME",   "fullpath in db",        "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "32A",  "FILENAME",   "filename in db",        "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "16A",  "EXTNAME",    "extname in file",       "",                              1.0, 0.0);
-
-  fits_define_bintable_column (theader, "16A",  "INSTRUMENT", "instrument",            "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "16A",  "TELESCOPE",  "telescope",             "",                              1.0, 0.0);
-  fits_define_bintable_column (theader, "16A",  "OBJNAME",    "object name",           "",                              1.0, 0.0);
-
-  /* create table, add data values */
-  fits_create_table (theader, table);
-
-  return (TRUE);
-}
