Changeset 13950 for trunk/psLib/src/astro/psTime.c
- Timestamp:
- Jun 21, 2007, 4:28:48 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/astro/psTime.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psTime.c
r13930 r13950 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1.11 2$ $Name: not supported by cvs2svn $13 * @date $Date: 2007-06-2 1 18:46:38 $12 * @version $Revision: 1.113 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-06-22 02:28:48 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 68 68 #define NSEC_PER_DAY 86400000000000.0 69 69 70 // Time config file path 71 static char *timeConfig = NULL; 72 70 73 /** Time metadata read from config file */ 71 74 static psMetadata *timeMetadata = NULL; … … 96 99 static psTime* convertTimeUTCUT1(psTime* time); 97 100 101 static bool p_psTimeInit(const char *fileName); 98 102 99 103 /** Removes leading and trailing whitespace and # characters from a string. The cleaned string is a new null … … 164 168 } 165 169 166 // get the pslib.config filename by checking environment variable first, then original installation area. 167 const char* p_psTimeConfigFileName() 168 { 169 const char* filename = getenv("PS_CONFIG_FILE"); 170 171 if (filename == NULL) { // environment variable not found 172 filename = PS_CONFIG_FILE_DEFAULT; // this should come from configure.ac 173 } 174 175 return filename; 170 // get the pslib.config filename by checking environment variable first, then 171 // the possiblity set config file name, then the original installation area. 172 const char *p_psTimeConfigFilename(const char *filename) 173 { 174 // if filename is provided, set timeConfig to this value 175 if (filename) { 176 psFree(timeConfig); 177 timeConfig = psStringCopy(filename); 178 psMemSetPersistent(timeConfig, true); 179 return timeConfig; 180 } 181 182 // check the env var first 183 const char *PS_CONFIG_FILE = getenv("PS_CONFIG_FILE"); 184 if (PS_CONFIG_FILE) { 185 return PS_CONFIG_FILE; 186 } 187 188 // check timeConfig var 2nd 189 if (timeConfig) { 190 return timeConfig; 191 } 192 193 // fall back to the default, this should come from configure.ac 194 return PS_CONFIG_FILE_DEFAULT; 176 195 } 177 196 … … 191 210 192 211 // Check if psTime tables are already loaded 193 if(!p_psTimeInit(p_psTimeConfigFile Name())) {212 if(!p_psTimeInit(p_psTimeConfigFilename(NULL))) { 194 213 *status = PS_LOOKUP_ERROR; 195 214 return NAN; … … 269 288 } 270 289 290 // XXX this is not thread safe as the persistence setting is global 271 291 const bool initialPersistence = 272 292 p_psMemAllocatePersistent(true); // All memory allocated below is "persistent" … … 881 901 if((bulletin != PS_IERS_A) && (bulletin != PS_IERS_B)) { 882 902 psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Invalid bulletin specified %d",bulletin); 903 return NAN; 904 } 905 906 // Check if psTime tables are already loaded 907 if(!p_psTimeInit(p_psTimeConfigFilename(NULL))) { 908 psError(PS_ERR_UNKNOWN, true, "failed to init time tables."); 883 909 return NAN; 884 910 } … … 1065 1091 } 1066 1092 1093 // Check if psTime tables are already loaded 1094 if(!p_psTimeInit(p_psTimeConfigFilename(NULL))) { 1095 psError(PS_ERR_UNKNOWN, true, "failed to init time tables."); 1096 return NULL; 1097 } 1098 1067 1099 // Attempt to find value through table lookup and interpolation 1068 1100 mjd = psTimeToMJD(time); … … 1194 1226 1195 1227 // Check if psTime tables are loaded/loadable 1196 if (!p_psTimeInit(p_psTimeConfigFileName())) {1228 if (!p_psTimeInit(p_psTimeConfigFilename(NULL))) { 1197 1229 psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed to open file %s."), 1198 p_psTimeConfigFile Name());1230 p_psTimeConfigFilename(NULL)); 1199 1231 return NAN; 1200 1232 } … … 1712 1744 // Error checks 1713 1745 PS_ASSERT_PTR_NON_NULL(time,NULL); 1714 PS_ASSERT_INT_WITHIN_RANGE(time->nsec, 0,(psU32)((1e9)-1),NULL);1746 PS_ASSERT_INT_WITHIN_RANGE(time->nsec, (psU32)0, (psU32)((1e9)-1), NULL); 1715 1747 1716 1748 // Convert time to TAI if necessary, but without changing input arguments … … 1796 1828 } 1797 1829 1798 void psTimeInitialize(const char *timeConfig) 1799 { 1800 p_psTimeInit(timeConfig); 1830 // delay actual init until a timefunction is used 1831 bool psTimeInit(const char *filename) 1832 { 1833 // at present, this function can not fail 1834 p_psTimeConfigFilename(filename); 1835 1836 return true; 1801 1837 } 1802 1838
Note:
See TracChangeset
for help on using the changeset viewer.
