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.1.1.1 $ $Name: $ 00014 * @date $Date: 2005/06/15 21:08:12 $ 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 #include <time.h> 00023 #include <sys/types.h> 00024 #include <sys/time.h> 00025 00026 #include "psType.h" 00027 #include "psImage.h" 00028 00029 struct psSphere; 00030 00031 /// @addtogroup Time 00032 /// @{ 00033 00034 00035 /** Time type. 00036 * 00037 * Enumeration for psTime types, TAI or UTC time. 00038 */ 00039 typedef enum { 00040 PS_TIME_TAI, ///< Temps Atomique International (TAI) time (time with leapseconds). 00041 PS_TIME_UTC, ///< Universal Time Coordinated (UTC) time (time without leapseconds). 00042 PS_TIME_UT1, ///< Universal Time corrected for polar motion 00043 PS_TIME_TT, ///< Terrestrial Time 00044 } psTimeType; 00045 00046 /** Time Bulletin type 00047 * 00048 * Enumeration for psTimeBulletin type, A or B. 00049 */ 00050 typedef enum { 00051 PS_IERS_A, ///< IERS Bulletin A 00052 PS_IERS_B, ///< IERS Bulletin B 00053 } psTimeBulletin; 00054 00055 /** Definition of psTime. 00056 * 00057 * The psTime struct is used by psLib to represent time values critical to 00058 * astronomical calculations. This structure represents a time which is 00059 * equivalent to TAI (International Atomic Time) and is measured in both 00060 * seconds and microseconds. 00061 */ 00062 typedef struct psTime 00063 { 00064 psS64 sec; ///< Seconds since epoch, Jan 1, 1970. 00065 psU32 nsec; ///< Nanoseconds since last second. 00066 psBool leapsecond; ///< if time falls on UTC leapsecond 00067 psTimeType type; ///< Type of time. 00068 } 00069 psTime; 00070 00071 00072 /** Initialize time data. 00073 * 00074 * Reads config and data files associated with various time conversions. 00075 * 00076 * @return bool: True for success, false for failure. 00077 */ 00078 psBool p_psTimeInit(const char *fileName); 00079 00080 /** Free memory persistant time data. 00081 * 00082 * Frees time data to be held in memory until the end of successful program execution. 00083 * 00084 * @return void: void. 00085 */ 00086 psBool p_psTimeFinalize(void); 00087 00088 /** Allocate time struct. 00089 * 00090 * Allocates an empty time struct. User must specify the psTimeType 00091 * (PS_TIME_TAI or PS_TIME_UTC) in the argument. The seconds and microseconds members 00092 * of the struct are set to zero. 00093 * 00094 * @return psTime*: Struct with empty time. 00095 */ 00096 psTime* psTimeAlloc( 00097 psTimeType type ///< Type of time to create (UTC or TAI). 00098 ); 00099 00100 /** Get current time. 00101 * 00102 * Gets current time from the system clock. User must specify the psTimeType 00103 * (PS_TIME_TAI or PS_TIME_UTC) in the argument. 00104 * 00105 * @return psTime*: Struct with current time. 00106 */ 00107 psTime* psTimeGetNow( 00108 psTimeType type ///< Type of time to get (UTC or TAI). 00109 ); 00110 00111 /** Convert psTime to UTC or TAI time. 00112 * 00113 * Converts psTime to UTC or TAI time based on the psTimeType argument. 00114 * 00115 * @return psTime*: Pointer to psTime. 00116 */ 00117 psTime* psTimeConvert( 00118 psTime *time, ///< Time to be converted. 00119 psTimeType type ///< Type to be converted to. 00120 ); 00121 00122 /** Convert psTime to Local Mean Sidereal Time (LMST). 00123 * 00124 * Converts psTime at the given longitude to LMST time. If the input time is not 00125 * in UTC format, then it is converted. 00126 * 00127 * @return psF64: LST Time. 00128 */ 00129 psF64 psTimeToLMST( 00130 psTime *time, ///< psTime to be converted. 00131 psF64 longitude ///< Longitude. 00132 ); 00133 00134 /** Determine UT1 - UTC from table lookup. 00135 * 00136 * This function is necessary to for various SLALIB functions. 00137 * 00138 * @return psF64: Time difference. 00139 */ 00140 psF64 psTimeGetUT1Delta( 00141 const psTime *time, ///< psTime to be looked up. 00142 psTimeBulletin bulletin ///< IERS bulletin to use 00143 ); 00144 00145 /** Determine TAI - UTC from table lookup. 00146 * 00147 * This function is necessary to for various psTime functions. 00148 * 00149 * @return psF64: Time difference. 00150 */ 00151 psF64 p_psTimeGetTAIDelta( 00152 const psTime *time ///< psTime to be looked up. 00153 ); 00154 00155 /** Determine polar coordinates at a given time. 00156 * 00157 * Determines the orientation of the polar axis at the given time. 00158 * 00159 * @return psSphere*: Spherical coordinates of Earth's polar axias. 00160 */ 00161 struct psSphere* p_psTimeGetPoleCoords( 00162 const psTime *time ///< psTime determine polar orientation. 00163 ); 00164 00165 /** Calculate the number of leapseconds between two times. 00166 * 00167 * Calculates the number of leapseconds between two times. 00168 * 00169 * @return psS64: leapseconds added between given times 00170 */ 00171 psS64 psTimeLeapSecondDelta( 00172 const psTime* time1, ///< First input time. 00173 const psTime* time2 ///< Second input time. 00174 ); 00175 00176 /** Determine if UTC time is a leapsecond. 00177 * 00178 * Determines if the specified UTC time is a valid leapsecond. 00179 * 00180 * @return psBool: valid leap second 00181 */ 00182 psBool psTimeIsLeapSecond( 00183 const psTime* utc ///< UTC to verify if leap second 00184 ); 00185 00186 /** Convert psTime to Julian date time. 00187 * 00188 * Converts psTime to Julian date (JD) time. This function does not add or 00189 * subtract leapseconds. 00190 * 00191 * @return psF64: Julian Date (JD) time. 00192 */ 00193 psF64 psTimeToJD( 00194 const psTime* time ///< Input time to be converted. 00195 ); 00196 /** Convert psTime to modified Julian date time. 00197 * 00198 * Converts psTime to modified Julian date (MJD) time. This function does not 00199 * add or subtract leapseconds. 00200 * 00201 * @return psF64: Modified Julian Days (MJD) time. 00202 */ 00203 psF64 psTimeToMJD( 00204 const psTime* time ///< Input time to be converted. 00205 ); 00206 00207 /** Convert psTime to ISO8601 formatted string. 00208 * 00209 * Converts psTime to a null terminated string in the form of YYYY-MM-DDThh:mm:ss.sss. 00210 * This function does not add or subtract leapseconds. 00211 * 00212 * @return char*: Pointer null terminated array of chars in ISO time. 00213 */ 00214 char* psTimeToISO( 00215 const psTime* time ///< Input time to be converted. 00216 ); 00217 00218 /** Convert psTime to timeval time. 00219 * 00220 * Converts psTime to timeval time. This function does not add or subtract leapseconds. 00221 * 00222 * @return timeval*: timeval struct time. 00223 */ 00224 struct timeval* psTimeToTimeval( 00225 const psTime* time ///< Input time to be converted. 00226 ); 00227 00228 /* 00229 * Convert psTime to tm time. 00230 * 00231 * Converts psTime to tm time. This function is based on a Perl algorithm availble 00232 * in the Pan-STARRS Image processing Algorithm Design Description (ADD). This function 00233 * does not add or subtract leapseconds. 00234 * 00235 * @return tm: tm struct time. 00236 * 00237 struct tm* p_psTimeToTM( 00238 const psTime *time ///< Input time to be converted. 00239 ); 00240 */ 00241 /** Convert JD to psTime. 00242 * 00243 * Converts JD time to psTime. This function does not add or subtract leapseconds. 00244 * 00245 * @return psTime: time. 00246 */ 00247 psTime* psTimeFromJD( 00248 psF64 time ///< Input time to be converted. 00249 ); 00250 00251 /** Convert MJD to psTime. 00252 * 00253 * Converts MJD time to psTime. This function does not add or subtract leapseconds. 00254 * 00255 * @return psTime: time. 00256 */ 00257 psTime* psTimeFromMJD( 00258 psF64 time ///< Input time to be converted. 00259 ); 00260 00261 /** Convert ISO to psTime. 00262 * 00263 * Converts ISO time to psTime. This function does not add or subtract leapseconds. 00264 * 00265 * @return psTime*: time 00266 */ 00267 psTime* psTimeFromISO( 00268 const char* time ///< Input time to be converted. 00269 ); 00270 00271 /** Convert timeval to psTime. 00272 * 00273 * Converts timeval time to psTime. This function does not add or subtract leapseconds. 00274 * 00275 * @return psTime*: time. 00276 */ 00277 psTime* psTimeFromTimeval( 00278 const struct timeval *time ///< Input time to be converted. 00279 ); 00280 00281 /** Convert Terrestrial Time to psTime 00282 * 00283 * Converts Terrestial Time to psTime. This function assumes resultant time is of type TT. 00284 * 00285 * @return psTime*: time (TT) 00286 */ 00287 psTime* psTimeFromTT( 00288 psS64 sec, ///< Input terrestrial time in seconds 00289 psU32 nsec ///< Input terrestrial time fraction of seconds (nanoseconds) 00290 ); 00291 00292 /** Convert UTC time to psTime 00293 * 00294 * Converts UTC time to psTime. It will verify if time specified is a leapsecond. 00295 * 00296 * @return psTime*: time (UTC) 00297 */ 00298 psTime* psTimeFromUTC( 00299 psS64 sec, ///< Input time in seconds 00300 psU32 nsec, ///< Input time fraction of seconds (nanoseconds) 00301 psBool leapsecond ///< Input time is a leapsecond 00302 ); 00303 00304 /** Convert tm time to psTime. 00305 * 00306 * Converts tm time to psTime. This function is based on a Perl algorithm availble 00307 * in the Pan-STARRS Image processing Algorithm Design Description (ADD). This function 00308 * does not add or subtract leapseconds. 00309 * 00310 * @return psTime*: time. 00311 */ 00312 psTime* p_psTimeFromTM( 00313 const struct tm *time ///< Input time to be converted. 00314 ); 00315 00316 /** Adds delta to time. Result is in TAI time. 00317 * 00318 * Adds delta to time. Input time is converted to TAI format if necessary. 00319 * 00320 * @return psTime*: time. 00321 */ 00322 psTime* psTimeMath( 00323 const psTime *time, ///< Time. 00324 psF64 delta ///< Time delta. 00325 ); 00326 00327 /** Determine difference between two times. Result is in TAI time. 00328 * 00329 * Determine difference between two times. Input times are converted to TAI format if necessary. 00330 * 00331 * @return psF64: Time difference. 00332 */ 00333 psF64 psTimeDelta( 00334 const psTime *time1, ///< First time. 00335 const psTime *time2 ///< Second time. 00336 ); 00337 00338 /** Get the filename of the psLib configuration file. 00339 * 00340 * @return char* If a PS_CONFIG_FILE environment variable exists, 00341 * that is returned, otherwise the default location 00342 * dependent on the installation location. 00343 */ 00344 char* p_psGetConfigFileName(); 00345 00346 /// @} 00347 00348 #endif // #ifndef PSTIME_H
1.4.1