00001 /** @file psTime.h 00002 * 00003 * @brief Definitions for time, time utilities, and conversion functions for use 00004 * with psLib astronomy functions. 00005 * 00006 * A collection of functions are required by psLib to manipulate time data. These 00007 * functions primarily consist of conversions between specific time formats. They 00008 * use the UNIX timeval time system as the base upon which International Atomic 00009 * Time (TAI) and Universal Time Coordinated (UTC) are calculated. 00010 * 00011 * @author Ross Harman, MHPCC 00012 * 00013 * @version $Revision: 1.54 $ $Name: $ 00014 * @date $Date: 2007/01/23 22:47:22 $ 00015 * 00016 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 00017 */ 00018 00019 #ifndef PSTIME_H 00020 #define PSTIME_H 00021 00022 /// @addtogroup Astro Astronomy 00023 /// @{ 00024 00025 #include <time.h> 00026 #include <sys/types.h> 00027 #include <sys/time.h> 00028 00029 #include "psType.h" 00030 #include "psImage.h" 00031 #include "psLookupTable.h" 00032 #include "psCoord.h" 00033 00034 #if defined(__APPLE__) // incorrectly missing in time.h 00035 struct tm *gmtime_r(const time_t *, struct tm *); 00036 #endif 00037 00038 struct psSphere; 00039 00040 /** Time type. 00041 * 00042 * Enumeration for psTime types, TAI or UTC time. 00043 */ 00044 typedef enum { 00045 PS_TIME_TAI, ///< Temps Atomique International (TAI) time (time with leapseconds) 00046 PS_TIME_UTC, ///< Universal Time Coordinated (UTC) time (time without leapseconds) 00047 PS_TIME_UT1, ///< Universal Time corrected for polar motion 00048 PS_TIME_TT, ///< Terrestrial Time 00049 } psTimeType; 00050 00051 /** Time Bulletin type 00052 * 00053 * Enumeration for psTimeBulletin type, A or B. 00054 */ 00055 typedef enum { 00056 PS_IERS_A, ///< IERS Bulletin A 00057 PS_IERS_B, ///< IERS Bulletin B 00058 } psTimeBulletin; 00059 00060 /** Definition of psTime. 00061 * 00062 * The psTime struct is used by psLib to represent time values critical to 00063 * astronomical calculations. This structure represents a time which is 00064 * equivalent to TAI (International Atomic Time) and is measured in both 00065 * seconds and microseconds. 00066 */ 00067 typedef struct 00068 { 00069 psS64 sec; ///< Seconds since epoch, Jan 1, 1970. 00070 psU32 nsec; ///< Nanoseconds since last second. 00071 bool leapsecond; ///< if time falls on UTC leapsecond 00072 psTimeType type; ///< Type of time. 00073 } 00074 psTime; 00075 00076 00077 // get the pslib.config filename by checking environment variable first, then original installation area. 00078 const char *p_psTimeConfigFileName(); 00079 00080 00081 /** Initialize time data. 00082 * 00083 * Reads config and data files associated with various time conversions. 00084 * 00085 * @return bool: True for success, false for failure. 00086 */ 00087 psBool p_psTimeInit( 00088 const char *fileName ///< File name containing config/data info 00089 ); 00090 00091 /** Initialize time data. 00092 * 00093 * Reads the configuration file and sets up the appropriate psTimeTables and predictions. 00094 */ 00095 void psTimeInitialize( 00096 const char *timeConfig ///< psTime configuration file 00097 ); 00098 00099 /** Free memory persistant time data. 00100 * 00101 * Frees time data to be held in memory until the end of successful program execution. 00102 * 00103 * @return void: void. 00104 */ 00105 psBool p_psTimeFinalize(void); 00106 00107 /** Frees memory that was allocated by psTime functions. 00108 * 00109 * Allows a subsequent search for leaked memory. 00110 */ 00111 void psTimeFinalize(void); 00112 00113 /** Allocate time struct. 00114 * 00115 * Allocates an empty time struct. User must specify the psTimeType 00116 * (PS_TIME_TAI or PS_TIME_UTC) in the argument. The seconds and microseconds members 00117 * of the struct are set to zero. 00118 * 00119 * @return psTime*: Struct with empty time. 00120 */ 00121 psTime* psTimeAlloc( 00122 psTimeType type ///< Type of time to create (UTC or TAI). 00123 ); 00124 00125 00126 /** Checks the type of a particular pointer. 00127 * 00128 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 00129 * 00130 * @return bool: True if the pointer matches a psTime structure, false otherwise. 00131 */ 00132 bool psMemCheckTime( 00133 psPtr ptr ///< the pointer whose type to check 00134 ); 00135 00136 00137 /** Get current time. 00138 * 00139 * Gets current time from the system clock. User must specify the psTimeType 00140 * (PS_TIME_TAI or PS_TIME_UTC) in the argument. 00141 * 00142 * @return psTime*: Struct with current time. 00143 */ 00144 psTime* psTimeGetNow( 00145 psTimeType type ///< Type of time to get (UTC or TAI). 00146 ); 00147 00148 /** Convert psTime to UTC, TAI, UT1, or TT time. 00149 * 00150 * Converts psTime to UTC, TAI, UT1, or TT time based on the psTimeType argument. 00151 * 00152 * @return psTime*: Pointer to psTime. 00153 */ 00154 psTime* psTimeConvert( 00155 psTime *time, ///< Time to be converted. 00156 psTimeType type ///< Type to be converted to. 00157 ); 00158 00159 /** Convert psTime to Local Mean Sidereal Time (LMST). 00160 * 00161 * Converts psTime at the given longitude to LMST time. If the input time is not 00162 * in UTC format, then it is converted. 00163 * 00164 * @return double: LST Time. 00165 */ 00166 double psTimeToLMST( 00167 psTime *time, ///< psTime to be converted. 00168 double longitude ///< Longitude. 00169 ); 00170 00171 /** Determine UT1 - UTC from table lookup. 00172 * 00173 * This function is necessary to for various SLALIB functions. 00174 * 00175 * @return double: Time difference. 00176 */ 00177 double psTimeGetUT1Delta( 00178 const psTime *time, ///< psTime to be looked up. 00179 psTimeBulletin bulletin ///< IERS bulletin to use 00180 ); 00181 00182 /** Provides tidal corrections to UT1-UTC. 00183 * 00184 * Uses the Ray model of Simon et al. 00185 * 00186 * @return psTime*: The corrected time in UT1. 00187 */ 00188 psTime *psTime_TideUT1Corr( 00189 const psTime *time ///< psTime to be corrected. 00190 ); 00191 00192 /** Determine TAI - UTC from table lookup. 00193 * 00194 * This function is necessary to for various psTime functions. 00195 * 00196 * @return psF64: Time difference. 00197 */ 00198 psF64 p_psTimeGetTAIDelta( 00199 const psTime *time ///< psTime to be looked up. 00200 ); 00201 00202 /** Determine polar coordinates at a given time. 00203 * 00204 * Determines the orientation of the polar axis at the given time. 00205 * 00206 * @return psSphere*: Spherical coordinates of Earth's polar axias. 00207 */ 00208 psSphere* p_psTimeGetPoleCoords( 00209 const psTime *time ///< psTime determine polar orientation. 00210 ); 00211 00212 /** Calculate the number of leapseconds between two times. 00213 * 00214 * Calculates the number of leapseconds between two times. 00215 * 00216 * @return long: leapseconds added between given times 00217 */ 00218 long psTimeLeapSecondDelta( 00219 const psTime* time1, ///< First input time. 00220 const psTime* time2 ///< Second input time. 00221 ); 00222 00223 /** Determine if UTC time is a leapsecond. 00224 * 00225 * Determines if the specified UTC time is a valid leapsecond. 00226 * 00227 * @return bool: valid leap second 00228 */ 00229 bool psTimeIsLeapSecond( 00230 const psTime* utc ///< UTC to verify if leap second 00231 ); 00232 00233 /** Convert psTime to Julian date time. 00234 * 00235 * Converts psTime to Julian date (JD) time. This function does not add or 00236 * subtract leapseconds. 00237 * 00238 * @return double: Julian Date (JD) time. 00239 */ 00240 double psTimeToJD( 00241 const psTime* time ///< Input time to be converted. 00242 ); 00243 /** Convert psTime to modified Julian date time. 00244 * 00245 * Converts psTime to modified Julian date (MJD) time. This function does not 00246 * add or subtract leapseconds. 00247 * 00248 * @return double: Modified Julian Days (MJD) time. 00249 */ 00250 double psTimeToMJD( 00251 const psTime* time ///< Input time to be converted. 00252 ); 00253 00254 /** Convert psTime to ISO8601 formatted string. 00255 * 00256 * Converts psTime to a null terminated string in the form of YYYY-MM-DDThh:mm:ss.sss. 00257 * This function does not add or subtract leapseconds. 00258 * 00259 * @return psString: Pointer null terminated array of chars in ISO time. 00260 */ 00261 psString psTimeToISO( 00262 const psTime* time ///< Input time to be converted. 00263 ); 00264 00265 /** Convert psTime to struct tm time. 00266 * 00267 * Converts psTime to struct tm time. This function should handle 00268 * UTC leapseconds correctly. 00269 * 00270 * @return tm*: tm struct. 00271 */ 00272 struct tm *psTimeToTM( 00273 const psTime* time ///< Input time to be converted. 00274 ); 00275 00276 /** Convert psTime to timeval time. 00277 * 00278 * Converts psTime to timeval time. This function does not add or subtract leapseconds. 00279 * 00280 * @return timeval*: timeval struct time. 00281 */ 00282 struct timeval* psTimeToTimeval( 00283 const psTime* time ///< Input time to be converted. 00284 ); 00285 00286 /* 00287 * Convert psTime to tm time. 00288 * 00289 * Converts psTime to tm time. This function is based on a Perl algorithm availble 00290 * in the Pan-STARRS Image processing Algorithm Design Description (ADD). This function 00291 * does not add or subtract leapseconds. 00292 * 00293 * @return tm: tm struct time. 00294 * 00295 struct tm* p_psTimeToTM( 00296 const psTime *time ///< Input time to be converted. 00297 ); 00298 */ 00299 /** Convert JD to psTime. 00300 * 00301 * Converts JD time to psTime. This function does not add or subtract leapseconds. 00302 * 00303 * @return psTime: time. 00304 */ 00305 psTime* psTimeFromJD( 00306 double jd ///< Input time to be converted. 00307 ); 00308 00309 /** Convert MJD to psTime. 00310 * 00311 * Converts MJD time to psTime. This function does not add or subtract leapseconds. 00312 * 00313 * @return psTime: time. 00314 */ 00315 psTime* psTimeFromMJD( 00316 double mjd ///< Input time to be converted. 00317 ); 00318 00319 /** Convert ISO to psTime. 00320 * 00321 * Converts ISO time to psTime. This function does not add or subtract leapseconds. 00322 * 00323 * @return psTime*: time 00324 */ 00325 psTime* psTimeFromISO( 00326 const char* input, ///< Input time to be converted. 00327 psTimeType type ///< Time type. 00328 ); 00329 00330 /** Convert timeval to psTime. 00331 * 00332 * Converts timeval time to psTime. This function does not add or subtract leapseconds. 00333 * 00334 * @return psTime*: time. 00335 */ 00336 psTime* psTimeFromTimeval( 00337 const struct timeval *input ///< Input time to be converted. 00338 ); 00339 00340 /** Convert Terrestrial Time to psTime 00341 * 00342 * Converts Terrestial Time to psTime. This function assumes resultant time is of type TT. 00343 * 00344 * @return psTime*: time (TT) 00345 */ 00346 psTime* psTimeFromTT( 00347 psS64 sec, ///< Input terrestrial time in seconds 00348 psU32 nsec ///< Input terrestrial time fraction of seconds (nanoseconds) 00349 ); 00350 00351 /** Convert UTC time to psTime 00352 * 00353 * Converts UTC time to psTime. It will verify if time specified is a leapsecond. 00354 * 00355 * @return psTime*: time (UTC)time 00356 */ 00357 psTime* psTimeFromUTC( 00358 psS64 sec, ///< Input time in seconds 00359 psU32 nsec, ///< Input time fraction of seconds (nanoseconds) 00360 bool leapsecond ///< Input time is a leapsecond 00361 ); 00362 00363 /** Convert tm time to psTime. 00364 * 00365 * Converts tm time to psTime. This function is based on a Perl algorithm availble 00366 * in the Pan-STARRS Image processing Algorithm Design Description (ADD). This function 00367 * does not add or subtract leapseconds. 00368 * 00369 * @return psTime*: time. 00370 */ 00371 psTime* psTimeFromTM( 00372 const struct tm *time ///< Input time to be converted. 00373 ); 00374 00375 /** Convert an arbitrary string into a psTime. 00376 * 00377 * Converts a string, using a strptime(3) format, into a psTime. See 00378 * strptime(3) for documentation on this format. 00379 * 00380 * @return psTime*: time. 00381 */ 00382 00383 psTime* psTimeStrptime( 00384 const char *s, ///< string to be converted 00385 const char *format ///< strptime(3) format 00386 ); 00387 00388 /** Convert a psTime into a formated string. 00389 * 00390 * Converts a psTime, using a strftime(3) format, into a formatted string. 00391 * See strftime(3) for documentation on this format. 00392 * 00393 * @return psString: string. 00394 */ 00395 00396 psString psTimeStrftime( 00397 const psTime *time, ///< Time to be formatted. 00398 const char *format ///< strftime(3) format 00399 ); 00400 00401 /** Adds delta to time. Result is in TAI time. 00402 * 00403 * Adds delta to time. Input time is converted to TAI format if necessary. 00404 * 00405 * @return psTime*: time. 00406 */ 00407 psTime* psTimeMath( 00408 const psTime *time, ///< Time. 00409 double delta ///< Time delta. 00410 ); 00411 00412 /** Determine difference between two times. Result is in TAI time. 00413 * 00414 * Determine difference between two times. Input times are converted to TAI format if necessary. 00415 * 00416 * @return double: Time difference. 00417 */ 00418 double psTimeDelta( 00419 const psTime *time1, ///< First time. 00420 const psTime *time2 ///< Second time. 00421 ); 00422 00423 /** Searches the IERS time tables for a specified entry location. 00424 * 00425 * Returns the interpolated double precision (arcsec) value at the specified entry 00426 * location. Inputs to specify are the time index in mjd, the column number 00427 * corresponding to Xp, Yp, or Sp (UT1-UTC) in IERS A or B, the time table names, 00428 * and the number of time tables. 00429 * 00430 * @return psF64: Resulting table entry for specified parameters. 00431 */ 00432 psF64 p_psTimeSearchTables( 00433 psF64 index, ///< time index for which to search 00434 psU64 column, ///< column number of specified index 00435 char *metadataTableNames[], ///< names of IERS tables to search 00436 psU32 nTables, ///< number of IERS tables to search 00437 psLookupStatusType* status ///< status of table search 00438 ); 00439 00440 /** Stores the current time in a psHash of timers, under the supplied name. 00441 * 00442 * @return bool: True if successful, otherwise false. 00443 */ 00444 bool psTimerStart( 00445 char *name ///< timer name to start 00446 ); 00447 00448 /** Resets the named timer. 00449 * 00450 * @return psF64: The time elapsed since start. 00451 */ 00452 psF64 psTimerClear( 00453 char *name ///< timer name to clear 00454 ); 00455 00456 /** Returns the elapsed time, in seconds, for the timer specified by name. 00457 * 00458 * @return psF64: The elapsed time in seconds since timer start. 00459 */ 00460 psF64 psTimerMark( 00461 char *name ///< timer name to mark 00462 ); 00463 00464 /** Frees all memory associated with all timers and returns the expended time. 00465 * 00466 * @return psF64: The maximum time expended. 00467 */ 00468 bool psTimerStop(void); 00469 00470 /** Copy a psTime. 00471 * 00472 * @return psTime*: New copy of existing psTime. 00473 */ 00474 psTime *psTimeCopy( 00475 const psTime *inTime ///< input time to copy. 00476 ); 00477 00478 /// @} 00479 00480 #endif // #ifndef PSTIME_H
1.5.1