Index: trunk/Ohana/src/libdvo/doc/locking.txt
===================================================================
--- trunk/Ohana/src/libdvo/doc/locking.txt	(revision 25757)
+++ trunk/Ohana/src/libdvo/doc/locking.txt	(revision 25757)
@@ -0,0 +1,13 @@
+
+The DVO locking policy is a little bit broken.  DVO currently
+(2009.08.10) requires that users have write access to files because
+the code does not distinguish well cases where read-only (soft locks)
+are used vs cases of read/write (hard locks) are needed.
+
+locks set in DVO:
+
+dvo_catalog_lock -- on catalog open & catalog create (all files for
+		    split mode)
+
+gfits_db_lock -- on photcode table read/write and dvo_image_lock
+
Index: trunk/Ohana/src/libdvo/include/dvo.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvo.h	(revision 24976)
+++ trunk/Ohana/src/libdvo/include/dvo.h	(revision 25757)
@@ -325,5 +325,5 @@
 PhotCodeData *GetPhotcodeTable (void);
 
-int LoadPhotcodes (char *catdir_file, char *master_file);
+int LoadPhotcodes (char *catdir_file, char *master_file, int readwrite);
 int LoadPhotcodesText (char *filename);
 int LoadPhotcodesFITS (char *filename);
@@ -432,5 +432,5 @@
 SkyTable  *SkyTableLoad        	   PROTO((char *filename, int VERBOSE));
 SkyTable  *SkyTableFromGSC     	   PROTO((char *filename, int depth, int VERBOSE));
-SkyTable  *SkyTableLoadOptimal 	   PROTO((char *catdir, char *SKYFILE, char *GSCFILE, int depth, int VERBOSE));
+SkyTable  *SkyTableLoadOptimal 	   PROTO((char *catdir, char *SKYFILE, char *GSCFILE, int readwrite, int depth, int VERBOSE));
 int        SkyTableSetDepth    	   PROTO((SkyTable *sky, int depth));
 SkyList   *SkyRegionByPoint    	   PROTO((SkyTable *table, int depth, double ra, double dec));
Index: trunk/Ohana/src/libdvo/src/LoadPhotcodes.c
===================================================================
--- trunk/Ohana/src/libdvo/src/LoadPhotcodes.c	(revision 24976)
+++ trunk/Ohana/src/libdvo/src/LoadPhotcodes.c	(revision 25757)
@@ -1,15 +1,20 @@
 # include <dvo.h>
 
-int LoadPhotcodes (char *catdir_file, char *master_file) {
+int LoadPhotcodes (char *catdir_file, char *master_file, int readwrite) {
 
   /* first try to load the photcodes from the specified CATDIR location */
   if (LoadPhotcodesFITS (catdir_file)) return TRUE;
   
+  if (!readwrite) {
+    fprintf (stderr, "db is missing a photcode table & access is read-only -- create one with photcode-table -import\n");
+    return FALSE;
+  }
+
   /* next try to load the photcodes from the master text photcode file */
   /* automatically (or on demand?) save the text file to the FITS version */
   if (LoadPhotcodesText (master_file)) { 
-      if (!check_file_access (catdir_file, TRUE, TRUE)) return TRUE;
-      SavePhotcodesFITS (catdir_file);
-      return TRUE;
+    if (!check_file_access (catdir_file, TRUE, TRUE, TRUE)) return TRUE;
+    SavePhotcodesFITS (catdir_file);
+    return TRUE;
   }
 
Index: trunk/Ohana/src/libdvo/src/coordops.c
===================================================================
--- trunk/Ohana/src/libdvo/src/coordops.c	(revision 24976)
+++ trunk/Ohana/src/libdvo/src/coordops.c	(revision 25757)
@@ -163,4 +163,5 @@
 	return (FALSE);
     }
+    if (fabs(alpha) >= 180.0) return (FALSE);
     *ra  = alpha + coords[0].crval1;
     *dec = delta + coords[0].crval2;
Index: trunk/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 24976)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 25757)
@@ -180,4 +180,5 @@
 
   int Nsecfilt, mode;
+  int BACKUP, READWRITE;
 
   mode = DVO_OPEN_NONE;
@@ -192,9 +193,17 @@
   dvo_catalog_init (catalog, FALSE);
 
+  // default access control options:
   catalog[0].lockmode  = LCK_XCLD;
-  if (mode == DVO_OPEN_READ) catalog[0].lockmode  = LCK_SOFT;
+  BACKUP = TRUE;
+  READWRITE = TRUE;
+
+  // in read-only mode, do not backup or require write access
+  if (mode == DVO_OPEN_READ) {
+    catalog[0].lockmode  = LCK_SOFT;
+    BACKUP = FALSE;
+    READWRITE = FALSE;
+  }
   
-  // XXX make a backup?  always?
-  if (!check_file_access (catalog[0].filename, TRUE, VERBOSE)) {
+  if (!check_file_access (catalog[0].filename, BACKUP, READWRITE, VERBOSE)) {
     if (VERBOSE) fprintf (stderr, "no permission to access %s\n", catalog[0].filename);
     return (FALSE);
Index: trunk/Ohana/src/libdvo/src/dvo_image.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_image.c	(revision 24976)
+++ trunk/Ohana/src/libdvo/src/dvo_image.c	(revision 25757)
@@ -4,6 +4,16 @@
 int dvo_image_lock (FITS_DB *db, char *filename, double timeout, int lockstate) {
 
-  /* lock the image catalog */
-  if (!check_file_access (filename, FALSE, TRUE)) return (FALSE);
+  int READWRITE;
+
+  // default access control options:
+  READWRITE = TRUE;
+
+  // in read-only mode, do not backup or require write access
+  if (lockstate == LCK_SOFT) {
+    READWRITE = FALSE;
+  }
+
+  // do not perform a backup here
+  if (!check_file_access (filename, FALSE, READWRITE, TRUE)) return (FALSE);
 
   db[0].lockstate = lockstate;
Index: trunk/Ohana/src/libdvo/src/skyregion_io.c
===================================================================
--- trunk/Ohana/src/libdvo/src/skyregion_io.c	(revision 24976)
+++ trunk/Ohana/src/libdvo/src/skyregion_io.c	(revision 25757)
@@ -84,5 +84,5 @@
 }
 
-SkyTable *SkyTableLoadOptimal (char *catdir, char *skyfile, char *gscfile, int depth, int verbose) {
+SkyTable *SkyTableLoadOptimal (char *catdir, char *skyfile, char *gscfile, int readwrite, int depth, int verbose) {
 
   char filename[256];
@@ -93,5 +93,5 @@
   sprintf (filename, "%s/SkyTable.fits", catdir);
   if (stat (filename, &filestat)) goto SKYFILE;
-  if (!check_file_access (filename, FALSE, verbose)) goto SKYFILE;
+  if (!check_file_access (filename, FALSE, readwrite, verbose)) goto SKYFILE;
   sky = SkyTableLoad (filename, verbose);
   if (sky == NULL) {
@@ -106,5 +106,5 @@
   if (skyfile[0] != 0) goto GSCFILE;
   if (stat (skyfile, &filestat)) goto GSCFILE;
-  if (!check_file_access (skyfile, FALSE, verbose)) goto GSCFILE;
+  if (!check_file_access (skyfile, FALSE, readwrite, verbose)) goto GSCFILE;
   sky = SkyTableLoad (skyfile, verbose);
   if (sky == NULL) {
@@ -117,5 +117,5 @@
   /* create CATDIR copy */
   sprintf (filename, "%s/SkyTable.fits", catdir);
-  check_file_access (filename, FALSE, verbose);
+  check_file_access (filename, FALSE, readwrite, verbose);
   if (!SkyTableSave (sky, filename)) return NULL;
 
@@ -134,5 +134,5 @@
   /* create CATDIR copy */
   sprintf (filename, "%s/SkyTable.fits", catdir);
-  check_file_access (filename, FALSE, verbose);
+  check_file_access (filename, FALSE, readwrite, verbose);
   if (!SkyTableSave (sky, filename)) return NULL;
 
