Index: trunk/psLib/src/astro/psTime.c
===================================================================
--- trunk/psLib/src/astro/psTime.c	(revision 13930)
+++ trunk/psLib/src/astro/psTime.c	(revision 13950)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.112 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-06-21 18:46:38 $
+ *  @version $Revision: 1.113 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-06-22 02:28:48 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -68,4 +68,7 @@
 #define NSEC_PER_DAY 86400000000000.0
 
+// Time config file path
+static char *timeConfig = NULL;
+
 /** Time metadata read from config file */
 static psMetadata *timeMetadata = NULL;
@@ -96,4 +99,5 @@
 static psTime* convertTimeUTCUT1(psTime* time);
 
+static bool p_psTimeInit(const char *fileName);
 
 /** Removes leading and trailing whitespace and # characters from a string. The cleaned string is a new null
@@ -164,14 +168,29 @@
 }
 
-// get the pslib.config filename by checking environment variable first, then original installation area.
-const char* p_psTimeConfigFileName()
-{
-    const char* filename = getenv("PS_CONFIG_FILE");
-
-    if (filename == NULL) { // environment variable not found
-        filename = PS_CONFIG_FILE_DEFAULT; // this should come from configure.ac
-    }
-
-    return filename;
+// get the pslib.config filename by checking environment variable first, then
+// the possiblity set config file name, then the original installation area.
+const char *p_psTimeConfigFilename(const char *filename)
+{
+    // if filename is provided, set timeConfig to this value
+    if (filename) {
+        psFree(timeConfig);
+        timeConfig = psStringCopy(filename);
+        psMemSetPersistent(timeConfig, true);
+        return timeConfig;
+    }
+
+    // check the env var first
+    const char *PS_CONFIG_FILE = getenv("PS_CONFIG_FILE");
+    if (PS_CONFIG_FILE) {
+        return PS_CONFIG_FILE;
+    }
+
+    // check timeConfig var 2nd
+    if (timeConfig) {
+        return timeConfig;
+    }
+
+    // fall back to the default, this should come from configure.ac
+    return PS_CONFIG_FILE_DEFAULT;
 }
 
@@ -191,5 +210,5 @@
 
     // Check if psTime tables are already loaded
-    if(!p_psTimeInit(p_psTimeConfigFileName())) {
+    if(!p_psTimeInit(p_psTimeConfigFilename(NULL))) {
         *status = PS_LOOKUP_ERROR;
         return NAN;
@@ -269,4 +288,5 @@
     }
 
+    // XXX this is not thread safe as the persistence setting is global
     const bool initialPersistence =
         p_psMemAllocatePersistent(true); // All memory allocated below is "persistent"
@@ -881,4 +901,10 @@
     if((bulletin != PS_IERS_A) && (bulletin != PS_IERS_B)) {
         psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Invalid bulletin specified %d",bulletin);
+        return NAN;
+    }
+
+    // Check if psTime tables are already loaded
+    if(!p_psTimeInit(p_psTimeConfigFilename(NULL))) {
+        psError(PS_ERR_UNKNOWN, true, "failed to init time tables.");
         return NAN;
     }
@@ -1065,4 +1091,10 @@
     }
 
+    // Check if psTime tables are already loaded
+    if(!p_psTimeInit(p_psTimeConfigFilename(NULL))) {
+        psError(PS_ERR_UNKNOWN, true, "failed to init time tables.");
+        return NULL;
+    }
+
     // Attempt to find value through table lookup and interpolation
     mjd = psTimeToMJD(time);
@@ -1194,7 +1226,7 @@
 
     // Check if psTime tables are loaded/loadable
-    if(!p_psTimeInit(p_psTimeConfigFileName())) {
+    if (!p_psTimeInit(p_psTimeConfigFilename(NULL))) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed to open file %s."),
-                p_psTimeConfigFileName());
+                p_psTimeConfigFilename(NULL));
         return NAN;
     }
@@ -1712,5 +1744,5 @@
     // Error checks
     PS_ASSERT_PTR_NON_NULL(time,NULL);
-    PS_ASSERT_INT_WITHIN_RANGE(time->nsec,0,(psU32)((1e9)-1),NULL);
+    PS_ASSERT_INT_WITHIN_RANGE(time->nsec, (psU32)0, (psU32)((1e9)-1), NULL);
 
     // Convert time to TAI if necessary, but without changing input arguments
@@ -1796,7 +1828,11 @@
 }
 
-void psTimeInitialize(const char *timeConfig)
-{
-    p_psTimeInit(timeConfig);
+// delay actual init until a timefunction is used
+bool psTimeInit(const char *filename)
+{
+    // at present, this function can not fail
+    p_psTimeConfigFilename(filename);
+
+    return true;
 }
 
