Index: trunk/psLib/src/fits/psFits.c
===================================================================
--- trunk/psLib/src/fits/psFits.c	(revision 21040)
+++ trunk/psLib/src/fits/psFits.c	(revision 21081)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.81 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-08-12 22:54:53 $
+ *  @version $Revision: 1.82 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-03 01:05:47 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -20,4 +20,5 @@
 #include <string.h>
 #include <errno.h>
+#include <libgen.h>
 
 #include "psFits.h"
@@ -123,4 +124,7 @@
 }
 
+# define FITS_OPEN_RETRIES 5
+# define FITS_OPEN_RETRY_WAIT 200000
+
 psFits* psFitsOpen(const char* name, const char* mode)
 {
@@ -129,4 +133,43 @@
     int status = 0;
     fitsfile *fptr = NULL;      /* Pointer to the FITS file */
+
+    // check that the directory exists : for NFS-mounted file systems, the directory may
+    // take some time to appear
+
+    int dirstat = 0;
+    char *tmpname = psStringCopy (name);
+    char *tmpdir = dirname (tmpname);
+    char *dir = psStringCopy (tmpdir);
+    useconds_t waittime = FITS_OPEN_RETRY_WAIT;
+    
+    for (int i = 0; (i < FITS_OPEN_RETRIES) && ((dirstat = access (dir, F_OK)) != 0); i++) {
+	// if the error is not ENOENT, then the error is more serious than NFS-mount delays
+	if (errno != ENOENT) {
+	    int thisErrno = errno;
+	    char errorBuf[64], *errorMsg;
+# if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
+	    errorMsg = strerror_r (thisErrno, errorBuf, 64);
+# else
+	    strerror_r (thisErrno, errorBuf, 64);
+	    errorMsg = errorBuf;		
+# endif
+	    psError (PS_ERR_IO, true, "Directory (%s) for requested file is not accessible: %s", dir, errorMsg);
+
+	    psFree (dir);
+	    psFree (tmpname);
+	    return NULL;
+	}
+
+	usleep (waittime);
+	waittime *= 2;
+    }
+    if (dirstat != 0) {
+	psError (PS_ERR_IO, true, "Directory (%s) for requested file is not accessible, timed out", dir);
+	psFree (dir);
+	psFree (tmpname);
+	return NULL;
+    }
+    psFree (dir);
+    psFree (tmpname);
 
     /* check the mode to determine how to open/create file */
@@ -154,5 +197,5 @@
 
     if (newFile) {
-        /* Check if an existing file is in the way before creating file*/
+        /* Check if an existing file is in the way before creating file */
         if (access(name, F_OK) == 0) {
             // file exists, delete old one first
