Index: /trunk/Ohana/src/imregister/photreg/args.photreg.c
===================================================================
--- /trunk/Ohana/src/imregister/photreg/args.photreg.c	(revision 3537)
+++ /trunk/Ohana/src/imregister/photreg/args.photreg.c	(revision 3538)
@@ -137,5 +137,5 @@
 
 void usage () {  
-  fprintf (stderr, "USAGE: photreg (-zp zp) (-dzp dzp) (-tstart date) (-dt dt) (-photcode code)\n");
+  fprintf (stderr, "USAGE: photreg (-zp zp) (-dzp dzp) (-trange start range|end) (-photcode code)\n");
   fprintf (stderr, "       [-label label] [-offset] [-Nmeas N] [-Ntime N] [-db trans]\n");
   exit (1);
Index: /trunk/Ohana/src/imregister/src/photreg.c
===================================================================
--- /trunk/Ohana/src/imregister/src/photreg.c	(revision 3537)
+++ /trunk/Ohana/src/imregister/src/photreg.c	(revision 3538)
@@ -1,5 +1,5 @@
 # include "imregister.h"
 # include "photreg.h"
-static char *version = "photreg $Revision: 1.4 $";
+static char *version = "photreg $Revision: 1.5 $";
 
 int main (int argc, char **argv) {
@@ -17,14 +17,9 @@
   fits_db_init (&db);
 
-  if (!strcmp (output.db, "phot")) {
-    filename = PhotDB;
-  } else {
-    filename = TransDB;
-  }
+  filename = PhotDB;
+  if (!strcmp (output.db, "trans")) filename = TransDB;
 
-  if (!fits_db_lock (&db, filename)) {
-    fits_db_close (&db);
-    exit (1);
-  }
+  if (!fits_db_lock (&db, filename)) exit (1);
+
   if (db.dbstate == LCK_EMPTY) {
     fits_init_header (&db.header);    
Index: /trunk/Ohana/src/imregister/src/photsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/src/photsearch.c	(revision 3537)
+++ /trunk/Ohana/src/imregister/src/photsearch.c	(revision 3538)
@@ -1,5 +1,5 @@
 # include "imregister.h"
 # include "photreg.h"
-static char *version = "photsearch $Revision: 1.4 $";
+static char *version = "photsearch $Revision: 1.5 $";
 
 int main (int argc, char **argv) {
@@ -25,8 +25,5 @@
   }
 
-  if (!fits_db_lock (&db, filename)) {
-    fits_db_close (&db);
-    exit (1);
-  }
+  if (!fits_db_lock (&db, filename)) exit (1);
   
   if (!fits_db_load (&db)) {
Index: /trunk/Ohana/src/libohana/doc/glockfile.txt
===================================================================
--- /trunk/Ohana/src/libohana/doc/glockfile.txt	(revision 3538)
+++ /trunk/Ohana/src/libohana/doc/glockfile.txt	(revision 3538)
@@ -0,0 +1,45 @@
+
+FILE *fsetlockfile (char *filename, double timeout, int type, int *state);
+   
+ set a lockfile on [path]/filename.  
+
+ we allow three types of locks: 
+ LCK_HARD - exclusive lock with persistent lock file
+ LCK_XCLD - exclusive lock, no persistent lock file
+ LCK_SOFT - shared lock
+
+ all three types of locks set a filesystem lock (using NFS lockd) on
+ the given file, using an exclusive lock for HARD and XCLD and a
+ shared lock for SOFT locks.  
+
+ a HARD lock also uses a lockfile to make the lock persistent in the
+ event the calling program crashes: the lockfile must be actively
+ removed and will not vanish even if the locking program dies
+
+ SOFT and XCLD locks will vanish if the locking program dies.
+
+ if a HARD or XCLD lock is set, HARD, XCLD & SOFT locks will block
+
+ if a SOFT lock is set, HARD and XCLD locks will block, but not a SOFT
+ lock
+
+ the hard lockfile uses the file [path]/.filename.lck
+
+ this function locks and opens the file, returning the file pointer to
+ the now opened file.  the file is either opened for reading and
+ writing (HARD, XCLD == r+) or just reading (SOFT).
+
+ Error Conditions:
+
+ on error, fsetlockfile returns NULL and clears the lock state of the
+ file
+
+ - invalid type 
+ - SOFT and file does not exist
+ - file not accessible (cannot be opened)
+ - lockfile not accessible
+ - cannot lock lockfile (held by another user)
+ - lockfile says 'BUSY' (previous holder crashed)
+ - cannot unlock lockfile (file system error)
+ - error writing 'BUSY' to lockfile
+
Index: /trunk/Ohana/src/libohana/src/fits_db.c
===================================================================
--- /trunk/Ohana/src/libohana/src/fits_db.c	(revision 3537)
+++ /trunk/Ohana/src/libohana/src/fits_db.c	(revision 3538)
@@ -16,5 +16,5 @@
   /* database name must be set first */
   if (filename == NULL) {
-    fprintf (stderr, "ERROR: db file is not set\n");
+    fprintf (stderr, "db file is not set\n");
     return (FALSE);
   }
@@ -22,5 +22,5 @@
   /* database handle must be set first */
   if (db == NULL) {
-    fprintf (stderr, "ERROR: db handle is not set\n");
+    fprintf (stderr, "db handle is not set\n");
     return (FALSE);
   }
@@ -29,5 +29,5 @@
   db[0].f = fsetlockfile (filename, db[0].timeout, db[0].lockstate, &db[0].dbstate);
   if (db[0].f == NULL) {
-    fprintf (stderr, "ERROR: cannot set lock on db\n");
+    fprintf (stderr, "cannot set lock on db file %s\n", filename);
     return (FALSE);
   }
@@ -42,5 +42,5 @@
   /* database name must be set first */
   if (db == NULL) {
-    fprintf (stderr, "ERROR: db handle is not set\n");
+    fprintf (stderr, "db handle is not set\n");
     return (FALSE);
   }
@@ -48,17 +48,17 @@
   /* init & load in FITS table data - return FALSE on error */
   if (!fits_fread_header (db[0].f, &db[0].header)) {
-    fprintf (stderr, "ERROR: can't read primary header\n"); 
+    fprintf (stderr, "can't read primary header\n"); 
     return (FALSE);
   }
   if (!fits_fread_matrix (db[0].f, &db[0].matrix, &db[0].header)) {
-    fprintf (stderr, "ERROR: can't read primary matrix");
+    fprintf (stderr, "can't read primary matrix");
     return (FALSE);
   }
   if (!fits_fread_header (db[0].f, &db[0].theader)) {
-    fprintf (stderr, "ERROR: can't read table header");
+    fprintf (stderr, "can't read table header");
     return (FALSE);
   }
   if (!fits_fread_ftable_data (db[0].f, &db[0].ftable)) {
-    fprintf (stderr, "ERROR: can't read table data");
+    fprintf (stderr, "can't read table data");
     return (FALSE);
   }
@@ -74,17 +74,17 @@
 
   if (!fits_fwrite_header  (db[0].f, &db[0].header)) {
-    fprintf (stderr, "ERROR: can't write primary header");
+    fprintf (stderr, "can't write primary header");
     return (FALSE);
   }
   if (!fits_fwrite_matrix  (db[0].f, &db[0].matrix)) {
-    fprintf (stderr, "ERROR: can't write primary matrix");
+    fprintf (stderr, "can't write primary matrix");
     return (FALSE);
   }
   if (!fits_fwrite_Theader (db[0].f, &db[0].theader)) {
-    fprintf (stderr, "ERROR: can't write table header");
+    fprintf (stderr, "can't write table header");
     return (FALSE);
   }
   if (!fits_fwrite_table   (db[0].f, &db[0].ftable)) {
-    fprintf (stderr, "ERROR: can't write table data");
+    fprintf (stderr, "can't write table data");
     return (FALSE);
   }
@@ -103,17 +103,17 @@
   /* do we revert to the old version if this fails? */
   if (!fits_fwrite_header   (db[0].f, &db[0].header))  {
-    fprintf (stderr, "ERROR: can't update primary header");
+    fprintf (stderr, "can't update primary header");
     return (FALSE);
   }
   if (!fits_fwrite_matrix   (db[0].f, &db[0].matrix))  {
-    fprintf (stderr, "ERROR: can't update primary matrix");
+    fprintf (stderr, "can't update primary matrix");
     return (FALSE);
   }
   if (!fits_fwrite_Theader  (db[0].f, &db[0].theader)) {
-    fprintf (stderr, "ERROR: can't update table header");
+    fprintf (stderr, "can't update table header");
     return (FALSE);
   }
   if (!fits_fwrite_vtable   (db[0].f, vtable))  {
-    fprintf (stderr, "ERROR: can't update table data");
+    fprintf (stderr, "can't update table data");
     return (FALSE);
   }
Index: /trunk/Ohana/src/libohana/src/glockfile.c
===================================================================
--- /trunk/Ohana/src/libohana/src/glockfile.c	(revision 3537)
+++ /trunk/Ohana/src/libohana/src/glockfile.c	(revision 3538)
@@ -1,30 +1,5 @@
 # include <ohana.h>
 
-/* lockfile concepts:
-   
-   set a lockfile on [path]/filename.  
-   we allow three types of locks: 
-   LCK_HARD - exclusive lock with persistent lock file
-   LCK_XCLD - exclusive lock, no persistent lock file
-   LCK_SOFT - shared lock
-
-   both lock types set a filesystem-level lock on the given file, 
-    using exclusive for hard and shared for soft locks
-
-   a hard lock also uses a lockfile to make the lock permanent:
-    the lockfile must be actively removed and will not vanish 
-    even if the locking program dies 
-
-   a soft lock will vanish if the locking program dies.
-
-   if a hard lock is set, both hard & soft locks will block
-   if a soft lock is set, a hard lock will block, but not a soft lock
-
-   the hard lockfile uses the file [path]/.filename.lck
-
-   setlockfile2 returns a file descriptor to an open READ/WRITE access file,
-     or -1 on failure, and sets state.
-*/
-
+/* set a lock on the given file */
 FILE *fsetlockfile (char *filename, double timeout, int type, int *state) {
   
@@ -59,4 +34,8 @@
   return (status);
 }
+
+/* should eventually rewrite these two to use a stream as the basic
+   element and only grab the fileno when needed by fcntl
+   (fileno cannot fail) */
 
 int setlockfile2 (char *filename, double timeout, int type, int *state) {
@@ -94,4 +73,5 @@
   default:
     fprintf (stderr, "invalid lock type %d\n", type);
+    goto failure;
   }
 
@@ -121,5 +101,5 @@
       goto failure;
     }
-    usleep (1000);
+    usleep (10000); /* 10 ms is min */
 
     /* try to lock file */
