Index: /trunk/Ohana/src/imregister/Makefile
===================================================================
--- /trunk/Ohana/src/imregister/Makefile	(revision 3649)
+++ /trunk/Ohana/src/imregister/Makefile	(revision 3650)
@@ -57,7 +57,6 @@
 $(IMREG)/FifoOps.$(ARCH).o   \
 $(IMREG)/SockScan.$(ARCH).o   \
-$(IMREG)/submit.$(ARCH).o 
-
-# $(IMREG)/imregclient.$(ARCH).o   \
+$(IMREG)/submit.$(ARCH).o \
+$(IMREG)/imregclient.$(ARCH).o
 
 SPOBJ  = \
Index: /trunk/Ohana/src/imregister/detrend/entry.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/entry.c	(revision 3649)
+++ /trunk/Ohana/src/imregister/detrend/entry.c	(revision 3650)
@@ -107,5 +107,5 @@
     exit (1);
   }
-  fclearlockfile2 (fullname, f, LCK_XCLD, &filestate);
+  fclearlockfile (fullname, f, LCK_XCLD, &filestate);
 
   return (TRUE);
Index: /trunk/Ohana/src/imregister/imphot/args.c
===================================================================
--- /trunk/Ohana/src/imregister/imphot/args.c	(revision 3650)
+++ /trunk/Ohana/src/imregister/imphot/args.c	(revision 3650)
@@ -0,0 +1,69 @@
+
+  /* load photcode data */
+  if (!LoadPhotcodes (PhotCodeFile)) {
+    fprintf (stderr, "error loading photcodes from %s\n", PhotCodeFile);
+    exit (1);
+  }
+
+  /* interpret command-line arguments */
+  if (!get_trange_arguments (&argc, argv, &tstart, &tstop, &Ntimes)) {
+    fprintf (stderr, "ERROR: syntax error\n");
+    exit (1);
+  }
+
+  /* select by image photcode */
+  PhotCodeSelect = FALSE;
+  PHOTCODE = 0;
+  if ((N = get_argument (argc, argv, "-photcode"))) {
+    remove_argument (N, &argc, argv);
+    if (!(PHOTCODE = GetPhotcodeCodebyName (argv[N]))) {
+      fprintf (stderr, "ERROR: photcode not found in photcode table\n");
+      exit (1);
+    }
+    remove_argument (N, &argc, argv);
+    PhotCodeSelect = TRUE;
+  }
+
+  /* string in image name */
+  NameSelect = (char *) NULL;
+  NameSelectLength = 0;
+  if ((N = get_argument (argc, argv, "-name"))) {
+    remove_argument (N, &argc, argv);
+    NameSelect = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+    NameSelectLength = strlen (NameSelect);
+  }
+
+  /* string in image name */
+  CodeSelect = FALSE;
+  Code = 0;
+  if ((N = get_argument (argc, argv, "-code"))) {
+    CodeSelect = TRUE;
+    remove_argument (N, &argc, argv);
+    Code = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  FitsOutput = (char *) NULL;
+  if ((N = get_argument (argc, argv, "-fits"))) {
+    remove_argument (N, &argc, argv);
+    FitsOutput = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    remove_argument (N, &argc, argv);
+    VERBOSE = TRUE;
+  }
+
+  FORCE_READ = FALSE;
+  if ((N = get_argument (argc, argv, "-force"))) {
+    remove_argument (N, &argc, argv);
+    FORCE_READ = TRUE;
+  }
+
+  if (argc != 1) {
+    fprintf (stderr, "USAGE: imphotsearch [config ops] [-trange start stop/delta] [-photcode code] [-fits out.fits]\n");
+    exit (1);
+  }
Index: /trunk/Ohana/src/imregister/imphot/dumpfits.c
===================================================================
--- /trunk/Ohana/src/imregister/imphot/dumpfits.c	(revision 3650)
+++ /trunk/Ohana/src/imregister/imphot/dumpfits.c	(revision 3650)
@@ -0,0 +1,109 @@
+int DumpFitsTable (char *filename, Image *image, int Nentry, int *index, int Nkeep) {
+  
+  Header header, theader;
+  Matrix matrix;
+  FTable table;
+  Image *newdata;
+  FILE *f;
+  char *startstr, *filtstr, *datestr, *line;
+  int i;
+  double zp, dzp, ra, dec, airmass, sky;
+  unsigned long tsecond;
+
+  /* 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);
+  
+  /* create table header */
+  fits_create_table_header (&theader, "TABLE", "ZPTS");
+    
+  /* add current date/time to header */
+  str_to_time ("now", &tsecond);
+  datestr = sec_to_date (tsecond);
+  fits_modify (&header,  "DATE", "%s", 1, datestr);
+  fits_modify (&theader, "DATE", "%s", 1, datestr);
+  
+  /* define table layout */
+  fits_define_table_column (&theader, "A20",   "START_TIME", "start time of measurement", "yyyy/mm/dd,hh:mm:ss");
+  fits_define_table_column (&theader, "A10",   "FILTER",     "filter and camera name",    "");
+  fits_define_table_column (&theader, "F8.4",  "ZP_OBS",     "measured zero point",       "mag");
+  fits_define_table_column (&theader, "F7.4",  "ZP_ERR",     "error on zero point",       "mag");
+  fits_define_table_column (&theader, "F11.6", "RA",         "RA (J2000)",                "dec. degrees");
+  fits_define_table_column (&theader, "F11.6", "DEC",        "DEC (J2000)",               "dec. degrees");
+  fits_define_table_column (&theader, "F7.3",  "C_AIRMASS",  "airmass coeff",             "mag per airmass"); 
+  fits_define_table_column (&theader, "F7.1",  "SKY",        "median sky flux",           "counts");
+  fits_define_table_column (&theader, "I6",    "NSTAR",      "Number of stars in image",  "stars");
+  
+  /* define TNULL, TNVAL values */
+  fits_modify (&theader, "TNULL1",  "%s", 1, "NULL"); /* START_TIME */
+  fits_modify (&theader, "TNULL2",  "%s", 1, "NULL"); /* FILTER     */
+  fits_modify (&theader, "TNULL3",  "%s", 1, "NaN");  /* ZP_OBS     */
+  fits_modify (&theader, "TNULL4",  "%s", 1, "NaN");  /* ZP_ERR     */
+  fits_modify (&theader, "TNULL5",  "%s", 1, "NaN");  /* RA         */
+  fits_modify (&theader, "TNULL6",  "%s", 1, "NaN");  /* DEC        */
+  fits_modify (&theader, "TNULL7",  "%s", 1, "NaN");  /* C_AIRMASS  */
+  fits_modify (&theader, "TNULL8",  "%s", 1, "NaN");  /* SKY        */
+  fits_modify (&theader, "TNULL9",  "%s", 1,  "-1");  /* NSTAR      */
+
+  fits_modify (&theader, "TNVAL1",  "%s", 1, "NA");   /* START_TIME */
+  fits_modify (&theader, "TNVAL2",  "%s", 1, "NA");   /* FILTER     */
+  fits_modify (&theader, "TNVAL3",  "%s", 1, "Inf");  /* ZP_OBS     */
+  fits_modify (&theader, "TNVAL4",  "%s", 1, "Inf");  /* ZP_ERR     */
+  fits_modify (&theader, "TNVAL5",  "%s", 1, "Inf");  /* RA         */
+  fits_modify (&theader, "TNVAL6",  "%s", 1, "Inf");  /* DEC        */
+  fits_modify (&theader, "TNVAL7",  "%s", 1, "Inf");  /* C_AIRMASS  */
+  fits_modify (&theader, "TNVAL8",  "%s", 1, "Inf");  /* SKY        */
+  fits_modify (&theader, "TNVAL9",  "%s", 1,  "-2");  /* NSTAR      */
+
+  /* create table, add data values */
+  fits_create_table (&theader, &table);
+  
+  /* add selected data to table */
+  for (i = 0; i < Nkeep; i++) {
+    newdata  = &image[index[i]];
+    startstr = sec_to_date (newdata[0].tzero);
+    filtstr  = GetPhotcodeNamebyCode (newdata[0].source);
+    zp       = 0.001*newdata[0].Mcal;
+    dzp      = 0.001*newdata[0].dMcal;
+    
+    XY_to_RD (&ra, &dec, 0.0, 0.0, &newdata[0].coords);
+    airmass  = 0.001*newdata[0].secz;
+    sky      = newdata[0].Myyyy + 0x8000;
+
+    line = fits_table_print (&table, startstr, filtstr, zp, dzp, ra, dec, airmass, sky, newdata[0].nstar);
+    fits_add_rows (&table, line, 1, strlen(line));
+
+    free (line);
+    free (startstr);
+  }
+    
+  /* write data to output file */
+  f = fopen (filename, "w");
+  if (f == (FILE *) NULL) {
+    fprintf (stderr, "Failure writing fits table\n");
+    return (FALSE);
+  }
+  fits_fwrite_header  (f, &header);
+  fits_fwrite_matrix  (f, &matrix);
+  fits_fwrite_Theader (f, &theader);
+  fits_fwrite_table   (f, &table);
+  fclose (f);
+  return (TRUE);
+}
+
+/*
+
+  selection options:
+
+  CCDSelect
+  TypeSelect
+  TimeSelect
+  FilterSelect
+  ExptimeSelect
+  EntrySelect
+  LabelSelect
+
+*/
Index: /trunk/Ohana/src/imregister/imphot/output.c
===================================================================
--- /trunk/Ohana/src/imregister/imphot/output.c	(revision 3650)
+++ /trunk/Ohana/src/imregister/imphot/output.c	(revision 3650)
@@ -0,0 +1,22 @@
+
+output () {
+  /* output the selected entries */
+  if (FitsOutput != (char *) NULL) {
+    status = DumpFitsTable (FitsOutput, image, Nimage, index, Nin);
+  } else {
+    for (j = 0; j < Nin; j++) {
+      i = index[j];
+      
+      /* convert UNIX time to Elixir-style date string */
+      timestr = sec_to_date (image[i].tzero);
+      
+      /* convert photcode to filter name */
+      photstr = GetPhotcodeNamebyCode (image[i].source);
+      if (photstr == (char *) NULL) photstr = PhotError;
+      
+      fprintf (stdout, "%s %s %s  %7.4f %7.4f  %7.4f %5d %02x\n", image[i].name, photstr, timestr, 
+	       0.001*image[i].Mcal, 0.001*image[i].dMcal, 0.001*image[i].secz, image[i].nstar, image[i].code); 
+      free (timestr);
+    }
+  }
+}
Index: /trunk/Ohana/src/imregister/imphot/rtext.c
===================================================================
--- /trunk/Ohana/src/imregister/imphot/rtext.c	(revision 3650)
+++ /trunk/Ohana/src/imregister/imphot/rtext.c	(revision 3650)
@@ -0,0 +1,45 @@
+
+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);
+  }
+
+  /* check that file size makes sense */
+  Nimage = 0;
+  fits_scan (&header, "NIMAGES", "%d", 1, &Nimage);
+  if (stat (dBFile, &filestatus) == -1) {
+    if (VERBOSE) fprintf (stderr, "ERROR: failed to get status of image catalog\n");
+    exit (1);
+  }
+  size = Nimage*sizeof(Image) + header.size;
+  if (size != filestatus.st_size) {
+    int Ndata;
+
+    Ndata = (filestatus.st_size - header.size) / sizeof (Image);
+    if (VERBOSE) fprintf (stderr, "ERROR: image catalog has inconsistent size\n");
+    if (VERBOSE) fprintf (stderr, "header: %d, data: %d\n", Nimage, Ndata);
+    if (!FORCE_READ) exit (1);
+    Nimage = Ndata;
+  } 
+
+  /* alloc, read images */
+  ALLOCATE (image, Image, MAX (Nimage, 1));
+  nimage = Fread (image, sizeof(Image), Nimage, f, "image");
+  if (nimage != Nimage) {
+    if (VERBOSE) fprintf (stderr, "ERROR: problem loading image catalog\n");
+    exit (1);
+  } 
+  fclearlockfile (dBFile, f, LCK_SOFT, &dbstate);
+
+  return (image);
+}
Index: /trunk/Ohana/src/imregister/imphot/subset.c
===================================================================
--- /trunk/Ohana/src/imregister/imphot/subset.c	(revision 3650)
+++ /trunk/Ohana/src/imregister/imphot/subset.c	(revision 3650)
@@ -0,0 +1,21 @@
+
+subset () {
+
+  /* allocate space for reference lists */
+  Nin = 0;
+  ALLOCATE (index, int, Nimage);
+  
+  /* note that we are looking for overlap only with tstart */
+  for (i = 0; i < Nimage; i++) {
+    for (j = 0, status = FALSE; !status && (j < Ntimes); j++) {
+      status = (image[i].tzero >= tstart[j]) && (image[i].tzero <= tstop[j]);
+    }
+    if (!status && Ntimes) continue;
+    if (PhotCodeSelect && (image[i].source != PHOTCODE)) continue;
+    if ((NameSelect != (char *) NULL) && (strncasecmp (image[i].name, NameSelect, NameSelectLength))) continue;
+    if (CodeSelect && (image[i].code != Code)) continue;
+
+    index[Nin] = i;
+    Nin ++;
+  }
+}
Index: /trunk/Ohana/src/imregister/imreg/imregclient.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/imregclient.c	(revision 3649)
+++ /trunk/Ohana/src/imregister/imreg/imregclient.c	(revision 3650)
@@ -4,8 +4,9 @@
 int imregclient (char *fitsfile, char *statfile, char *datfile) {
 
+  int i, Nentry, Nslice, status, tmpint;
   FILE *f;
   RegImage *image;
-  int i, Nentry, Nslice, status, tmpint;
-  float *dtime;
+  VTable vtable;
+  FITS_DB db;
 
   Nentry = 0;
@@ -45,14 +46,13 @@
     }
     status = 3;
-    Nslice = image[0].ccd;
+    Nslice = image[0].seq;
     Nentry = Nslice + 1;
     REALLOCATE (image, RegImage, Nentry);
-    dtime = (float *)&image[0].junk[0];
     for (i = 0; i < Nentry; i++) {
       image[i] = image[0];
       status = fscanf (f, "%d %f %f", &tmpint, &image[i].sky, &image[i].fwhm);
-      image[i].ccd = tmpint;
-      if (image[i].ccd == Nslice) continue;
-      image[i].obstime += *dtime*image[i].ccd;
+      image[i].seq = tmpint;
+      if (image[i].seq == Nslice) continue;
+      image[i].obstime += image[0].seqtime*image[i].seq;
     }
     fclose (f);
@@ -62,11 +62,32 @@
   if (NoReg) dump_data (image, Nentry);
 
-  set_db (TempDB);
+  db.lockstate = LCK_HARD;
+  db.timeout   = 300.0;
+  fits_db_init (&db);
 
-  status = load_db ();
-  if (!status) {
-    create_db ();
+  if (!fits_db_lock (&db, TempDB)) {
+    fprintf (stderr, "ERROR: failure to lock db\n");
+    fits_db_close (&db);
+    exit (1);
   }
-  append_db (image, Nentry);
+  if (db.dbstate == LCK_EMPTY) {
+    fits_db_create (&db);
+    fits_table_set_RegImage (&db.ftable, NULL, 0);
+  } else {  
+    if (!fits_db_load (&db)) {
+      fprintf (stderr, "ERROR: failure to load db\n");
+      fits_db_close (&db);
+      exit (1);
+    }
+  }
+
+  fits_convert_RegImage (image, sizeof (RegImage), Nentry);
+  fits_table_to_vtable (&db.ftable, &vtable, 0, 0);
+  fits_vadd_rows (&vtable, (char *) image, Nentry, sizeof(RegImage));
+
+  fits_db_update (&db, &vtable);
+  fits_db_close (&db);
+  fits_db_free (&db);
+
   fprintf (stderr, "SUCCESS: wrote temp image data\n");
   exit (0);
Index: /trunk/Ohana/src/imregister/spreg/delete.c
===================================================================
--- /trunk/Ohana/src/imregister/spreg/delete.c	(revision 3649)
+++ /trunk/Ohana/src/imregister/spreg/delete.c	(revision 3650)
@@ -22,5 +22,5 @@
   if (Nbad == 0) { 
     fprintf (stderr, "SUCCESS\n");
-    fits_close_db (&db);
+    fits_db_close (db);
     exit (0);
   }
Index: /trunk/Ohana/src/imregister/src/imphotsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imphotsearch.c	(revision 3649)
+++ /trunk/Ohana/src/imregister/src/imphotsearch.c	(revision 3650)
@@ -2,5 +2,5 @@
 
 static char PhotError[] = "unknown";
-static char *version = "imphotsearch $Revision: 1.4 $";
+static char *version = "imphotsearch $Revision: 1.5 $";
 
 int DumpFitsTable (char *filename, Image *image, int Nentry, int *index, int Nkeep);
@@ -26,153 +26,19 @@
   ConfigInit (&argc, argv);
 
-  /* load photcode data */
-  if (!LoadPhotcodes (PhotCodeFile)) {
-    fprintf (stderr, "error loading photcodes from %s\n", PhotCodeFile);
-    exit (1);
-  }
-
-  /* interpret command-line arguments */
-  if (!get_trange_arguments (&argc, argv, &tstart, &tstop, &Ntimes)) {
-    fprintf (stderr, "ERROR: syntax error\n");
-    exit (1);
-  }
-
-  /* select by image photcode */
-  PhotCodeSelect = FALSE;
-  PHOTCODE = 0;
-  if ((N = get_argument (argc, argv, "-photcode"))) {
-    remove_argument (N, &argc, argv);
-    if (!(PHOTCODE = GetPhotcodeCodebyName (argv[N]))) {
-      fprintf (stderr, "ERROR: photcode not found in photcode table\n");
-      exit (1);
-    }
-    remove_argument (N, &argc, argv);
-    PhotCodeSelect = TRUE;
-  }
-
-  /* string in image name */
-  NameSelect = (char *) NULL;
-  NameSelectLength = 0;
-  if ((N = get_argument (argc, argv, "-name"))) {
-    remove_argument (N, &argc, argv);
-    NameSelect = strcreate (argv[N]);
-    remove_argument (N, &argc, argv);
-    NameSelectLength = strlen (NameSelect);
-  }
-
-  /* string in image name */
-  CodeSelect = FALSE;
-  Code = 0;
-  if ((N = get_argument (argc, argv, "-code"))) {
-    CodeSelect = TRUE;
-    remove_argument (N, &argc, argv);
-    Code = atoi (argv[N]);
-    remove_argument (N, &argc, argv);
-  }
-
-  FitsOutput = (char *) NULL;
-  if ((N = get_argument (argc, argv, "-fits"))) {
-    remove_argument (N, &argc, argv);
-    FitsOutput = strcreate (argv[N]);
-    remove_argument (N, &argc, argv);
-  }
-
-  VERBOSE = FALSE;
-  if ((N = get_argument (argc, argv, "-v"))) {
-    remove_argument (N, &argc, argv);
-    VERBOSE = TRUE;
-  }
-
-  FORCE_READ = FALSE;
-  if ((N = get_argument (argc, argv, "-force"))) {
-    remove_argument (N, &argc, argv);
-    FORCE_READ = TRUE;
-  }
-
-  if (argc != 1) {
-    fprintf (stderr, "USAGE: imphotsearch [config ops] [-trange start stop/delta] [-photcode code] [-fits out.fits]\n");
-    exit (1);
-  }
+  args (&argc, argv);
  
   /* load image database - still a non-FITS file */
   dBFile = ImPhotDB;
 
-  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);
+  /* how do we decide if it is text or fits? must examine header */
+  if (FITS) {
+    image = rtext (&Nimage);
+  } else {
+    image = rfits (&Nimage);
   }
 
-  /* check that file size makes sense */
-  Nimage = 0;
-  fits_scan (&header, "NIMAGES", "%d", 1, &Nimage);
-  if (stat (dBFile, &filestatus) == -1) {
-    if (VERBOSE) fprintf (stderr, "ERROR: failed to get status of image catalog\n");
-    exit (1);
-  }
-  size = Nimage*sizeof(Image) + header.size;
-  if (size != filestatus.st_size) {
-    int Ndata;
+  subset ();
 
-    Ndata = (filestatus.st_size - header.size) / sizeof (Image);
-    if (VERBOSE) fprintf (stderr, "ERROR: image catalog has inconsistent size\n");
-    if (VERBOSE) fprintf (stderr, "header: %d, data: %d\n", Nimage, Ndata);
-    if (!FORCE_READ) exit (1);
-    Nimage = Ndata;
-  } 
-
-  /* alloc, read images */
-  ALLOCATE (image, Image, MAX (Nimage, 1));
-  nimage = Fread (image, sizeof(Image), Nimage, f, "image");
-  if (nimage != Nimage) {
-    if (VERBOSE) fprintf (stderr, "ERROR: problem loading image catalog\n");
-    exit (1);
-  } 
-  fclearlockfile (dBFile, f, LCK_SOFT, &dbstate);
-
-  /* allocate space for reference lists */
-  Nin = 0;
-  ALLOCATE (index, int, Nimage);
-  
-  /* note that we are looking for overlap only with tstart */
-  for (i = 0; i < Nimage; i++) {
-    for (j = 0, status = FALSE; !status && (j < Ntimes); j++) {
-      status = (image[i].tzero >= tstart[j]) && (image[i].tzero <= tstop[j]);
-    }
-    if (!status && Ntimes) continue;
-    if (PhotCodeSelect && (image[i].source != PHOTCODE)) continue;
-    if ((NameSelect != (char *) NULL) && (strncasecmp (image[i].name, NameSelect, NameSelectLength))) continue;
-    if (CodeSelect && (image[i].code != Code)) continue;
-
-    index[Nin] = i;
-    Nin ++;
-  }
-
-  /* output the selected entries */
-  if (FitsOutput != (char *) NULL) {
-    status = DumpFitsTable (FitsOutput, image, Nimage, index, Nin);
-  } else {
-    for (j = 0; j < Nin; j++) {
-      i = index[j];
-      
-      /* convert UNIX time to Elixir-style date string */
-      timestr = sec_to_date (image[i].tzero);
-      
-      /* convert photcode to filter name */
-      photstr = GetPhotcodeNamebyCode (image[i].source);
-      if (photstr == (char *) NULL) photstr = PhotError;
-      
-      fprintf (stdout, "%s %s %s  %7.4f %7.4f  %7.4f %5d %02x\n", image[i].name, photstr, timestr, 
-	       0.001*image[i].Mcal, 0.001*image[i].dMcal, 0.001*image[i].secz, image[i].nstar, image[i].code); 
-      free (timestr);
-    }
-  }
+  output ();
 
   if (VERBOSE) fprintf (stderr, "SUCCESS\n");
@@ -180,112 +46,2 @@
 
 }
-
-int DumpFitsTable (char *filename, Image *image, int Nentry, int *index, int Nkeep) {
-  
-  Header header, theader;
-  Matrix matrix;
-  FTable table;
-  Image *newdata;
-  FILE *f;
-  char *startstr, *filtstr, *datestr, *line;
-  int i;
-  double zp, dzp, ra, dec, airmass, sky;
-  unsigned long tsecond;
-
-  /* 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);
-  
-  /* create table header */
-  fits_create_table_header (&theader, "TABLE", "ZPTS");
-    
-  /* add current date/time to header */
-  str_to_time ("now", &tsecond);
-  datestr = sec_to_date (tsecond);
-  fits_modify (&header,  "DATE", "%s", 1, datestr);
-  fits_modify (&theader, "DATE", "%s", 1, datestr);
-  
-  /* define table layout */
-  fits_define_table_column (&theader, "A20",   "START_TIME", "start time of measurement", "yyyy/mm/dd,hh:mm:ss");
-  fits_define_table_column (&theader, "A10",   "FILTER",     "filter and camera name",    "");
-  fits_define_table_column (&theader, "F8.4",  "ZP_OBS",     "measured zero point",       "mag");
-  fits_define_table_column (&theader, "F7.4",  "ZP_ERR",     "error on zero point",       "mag");
-  fits_define_table_column (&theader, "F11.6", "RA",         "RA (J2000)",                "dec. degrees");
-  fits_define_table_column (&theader, "F11.6", "DEC",        "DEC (J2000)",               "dec. degrees");
-  fits_define_table_column (&theader, "F7.3",  "C_AIRMASS",  "airmass coeff",             "mag per airmass"); 
-  fits_define_table_column (&theader, "F7.1",  "SKY",        "median sky flux",           "counts");
-  fits_define_table_column (&theader, "I6",    "NSTAR",      "Number of stars in image",  "stars");
-  
-  /* define TNULL, TNVAL values */
-  fits_modify (&theader, "TNULL1",  "%s", 1, "NULL"); /* START_TIME */
-  fits_modify (&theader, "TNULL2",  "%s", 1, "NULL"); /* FILTER     */
-  fits_modify (&theader, "TNULL3",  "%s", 1, "NaN");  /* ZP_OBS     */
-  fits_modify (&theader, "TNULL4",  "%s", 1, "NaN");  /* ZP_ERR     */
-  fits_modify (&theader, "TNULL5",  "%s", 1, "NaN");  /* RA         */
-  fits_modify (&theader, "TNULL6",  "%s", 1, "NaN");  /* DEC        */
-  fits_modify (&theader, "TNULL7",  "%s", 1, "NaN");  /* C_AIRMASS  */
-  fits_modify (&theader, "TNULL8",  "%s", 1, "NaN");  /* SKY        */
-  fits_modify (&theader, "TNULL9",  "%s", 1,  "-1");  /* NSTAR      */
-
-  fits_modify (&theader, "TNVAL1",  "%s", 1, "NA");   /* START_TIME */
-  fits_modify (&theader, "TNVAL2",  "%s", 1, "NA");   /* FILTER     */
-  fits_modify (&theader, "TNVAL3",  "%s", 1, "Inf");  /* ZP_OBS     */
-  fits_modify (&theader, "TNVAL4",  "%s", 1, "Inf");  /* ZP_ERR     */
-  fits_modify (&theader, "TNVAL5",  "%s", 1, "Inf");  /* RA         */
-  fits_modify (&theader, "TNVAL6",  "%s", 1, "Inf");  /* DEC        */
-  fits_modify (&theader, "TNVAL7",  "%s", 1, "Inf");  /* C_AIRMASS  */
-  fits_modify (&theader, "TNVAL8",  "%s", 1, "Inf");  /* SKY        */
-  fits_modify (&theader, "TNVAL9",  "%s", 1,  "-2");  /* NSTAR      */
-
-  /* create table, add data values */
-  fits_create_table (&theader, &table);
-  
-  /* add selected data to table */
-  for (i = 0; i < Nkeep; i++) {
-    newdata  = &image[index[i]];
-    startstr = sec_to_date (newdata[0].tzero);
-    filtstr  = GetPhotcodeNamebyCode (newdata[0].source);
-    zp       = 0.001*newdata[0].Mcal;
-    dzp      = 0.001*newdata[0].dMcal;
-    
-    XY_to_RD (&ra, &dec, 0.0, 0.0, &newdata[0].coords);
-    airmass  = 0.001*newdata[0].secz;
-    sky      = newdata[0].Myyyy + 0x8000;
-
-    line = fits_table_print (&table, startstr, filtstr, zp, dzp, ra, dec, airmass, sky, newdata[0].nstar);
-    fits_add_rows (&table, line, 1, strlen(line));
-
-    free (line);
-    free (startstr);
-  }
-    
-  /* write data to output file */
-  f = fopen (filename, "w");
-  if (f == (FILE *) NULL) {
-    fprintf (stderr, "Failure writing fits table\n");
-    return (FALSE);
-  }
-  fits_fwrite_header  (f, &header);
-  fits_fwrite_matrix  (f, &matrix);
-  fits_fwrite_Theader (f, &theader);
-  fits_fwrite_table   (f, &table);
-  fclose (f);
-  return (TRUE);
-}
-
-/*
-
-  selection options:
-
-  CCDSelect
-  TypeSelect
-  TimeSelect
-  FilterSelect
-  ExptimeSelect
-  EntrySelect
-  LabelSelect
-
-*/
Index: /trunk/Ohana/src/imregister/src/imstatreg.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imstatreg.c	(revision 3649)
+++ /trunk/Ohana/src/imregister/src/imstatreg.c	(revision 3650)
@@ -1,12 +1,14 @@
 # include "imregister.h"
 # include "imreg.h"
-static char *version = "imstatreg $Revision: 3.12 $";
+static char *version = "imstatreg $Revision: 3.13 $";
 
 int main (int argc, char **argv) {
  
-  RegImage *image;
-  int *match, Nmatch, status, Nentry;
+  int i, child, status;
+  int *match, Nmatch, Nimage, Nsubset;
   FILE *f;
+  RegImage *image, *subset;
   FITS_DB image_db, temp_db;
+  VTable vtable;
 
   get_version (argc, argv, version);
@@ -68,6 +70,6 @@
     fprintf (stderr, "temporary database read\n");
 
-    /* DELETE and unlock temporary database */
-    truncate or delete_db; /****** *****/
+    /* delete, unlock existing database */
+    truncate (TempDB, 0);
     fits_db_close (&temp_db);
     fprintf (stderr, "temporary database closed\n");
@@ -115,21 +117,2 @@
   }
 }
-
-/* basic outline:
-
-   - lock temp db
-     - if empty, continue
-   - load temp db
-   - clear temp db
-
-   - lock image db
-     - if empty, resave temp db
-
-   - load image db
-   - match temp and main 
-
-   - update image db
-
-   - unlock temp db
-*/
-
