Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

psTime.h

Go to the documentation of this file.
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/10/14 00:32:52 $
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 #include "psLookupTable.h"
00029 #include "psCoord.h"
00030 
00031 struct psSphere;
00032 
00033 /// @addtogroup Time
00034 /// @{
00035 
00036 
00037 /** Time type.
00038  *
00039  * Enumeration for psTime types, TAI or UTC time.
00040  */
00041 typedef enum {
00042     PS_TIME_TAI,                       ///< Temps Atomique International (TAI) time (time with leapseconds)
00043     PS_TIME_UTC,                       ///< Universal Time Coordinated (UTC) time (time without leapseconds)
00044     PS_TIME_UT1,                       ///< Universal Time corrected for polar motion
00045     PS_TIME_TT,                        ///< Terrestrial Time
00046 } psTimeType;
00047 
00048 /** Time Bulletin type
00049  *
00050  * Enumeration for psTimeBulletin type, A or B.
00051  */
00052 typedef enum {
00053     PS_IERS_A,                         ///< IERS Bulletin A
00054     PS_IERS_B,                         ///< IERS Bulletin B
00055 } psTimeBulletin;
00056 
00057 /** Definition of psTime.
00058  *
00059  *  The psTime struct is used by psLib to represent time values critical to
00060  *  astronomical calculations.  This structure represents a time which is
00061  *  equivalent to TAI (International Atomic Time) and is measured in both
00062  *  seconds and microseconds.
00063  */
00064 typedef struct
00065 {
00066     psS64 sec;                         ///< Seconds since epoch, Jan 1, 1970.
00067     psU32 nsec;                        ///< Nanoseconds since last second.
00068     bool leapsecond;                   ///< if time falls on UTC leapsecond
00069     psTimeType type;                   ///< Type of time.
00070 }
00071 psTime;
00072 
00073 
00074 /** Initialize time data.
00075  *
00076  * Reads config and data files associated with various time conversions.
00077  *
00078  * @return  bool: True for success, false for failure.
00079  */
00080 psBool p_psTimeInit(
00081     const char *fileName               ///< File name containing config/data info
00082 );
00083 
00084 /** Initialize time data.
00085  *
00086  *  Reads the configuration file and sets up the appropriate psTimeTables and predictions.
00087  */
00088 void psTimeInitialize(
00089     const char *timeConfig             ///< psTime configuration file
00090 );
00091 
00092 /** Free memory persistant time data.
00093  *
00094  * Frees time data to be held in memory until the end of successful program execution.
00095  *
00096  * @return  void: void.
00097  */
00098 psBool p_psTimeFinalize(void);
00099 
00100 /** Frees memory that was allocated by psTime functions.
00101  *
00102  *  Allows a subsequent search for leaked memory.
00103  */
00104 void psTimeFinalize(void);
00105 
00106 /** Allocate time struct.
00107  *
00108  * Allocates an empty time struct. User must specify the psTimeType
00109  * (PS_TIME_TAI or PS_TIME_UTC) in the argument. The seconds and microseconds members
00110  * of the struct are set to zero.
00111  *
00112  * @return  psTime*: Struct with empty time.
00113  */
00114 psTime* psTimeAlloc(
00115     psTimeType type                    ///< Type of time to create (UTC or TAI).
00116 );
00117 
00118 
00119 /** Checks the type of a particular pointer.
00120  *
00121  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00122  *
00123  *  @return bool:       True if the pointer matches a psTime structure, false otherwise.
00124  */
00125 bool psMemCheckTime(
00126     psPtr ptr                          ///< the pointer whose type to check
00127 );
00128 
00129 
00130 /** Get current time.
00131  *
00132  * Gets current time from the system clock. User must specify the psTimeType
00133  * (PS_TIME_TAI or PS_TIME_UTC) in the argument.
00134  *
00135  *  @return  psTime*: Struct with current time.
00136  */
00137 psTime* psTimeGetNow(
00138     psTimeType type                    ///< Type of time to get (UTC or TAI).
00139 );
00140 
00141 /** Convert psTime to UTC or TAI time.
00142  *
00143  *  Converts psTime to UTC or TAI time based on the psTimeType argument.
00144  *
00145  *  @return  psTime*: Pointer to psTime.
00146  */
00147 psTime* psTimeConvert(
00148     psTime *time,                      ///< Time to be converted.
00149     psTimeType type                    ///< Type to be converted to.
00150 );
00151 
00152 /** Convert psTime to Local Mean Sidereal Time (LMST).
00153  *
00154  *  Converts psTime at the given longitude to LMST time. If the input time is not
00155  *  in UTC format, then it is converted.
00156  *
00157  *  @return  double: LST Time.
00158  */
00159 double psTimeToLMST(
00160     psTime *time,                      ///< psTime to be converted.
00161     double longitude                   ///< Longitude.
00162 );
00163 
00164 /** Determine UT1 - UTC from table lookup.
00165  *
00166  *  This function is necessary to for various SLALIB functions.
00167  *
00168  *  @return  double: Time difference.
00169  */
00170 double psTimeGetUT1Delta(
00171     const psTime *time,                ///< psTime to be looked up.
00172     psTimeBulletin bulletin            ///< IERS bulletin to use
00173 );
00174 
00175 /** Determine TAI - UTC from table lookup.
00176  *
00177  *  This function is necessary to for various psTime functions.
00178  *
00179  *  @return  psF64: Time difference.
00180  */
00181 psF64 p_psTimeGetTAIDelta(
00182     const psTime *time                 ///< psTime to be looked up.
00183 );
00184 
00185 /** Determine polar coordinates at a given time.
00186  *
00187  *  Determines the orientation of the polar axis at the given time.
00188  *
00189  *  @return  psSphere*: Spherical coordinates of Earth's polar axias.
00190  */
00191 psSphere* p_psTimeGetPoleCoords(
00192     const psTime *time      ///< psTime determine polar orientation.
00193 );
00194 
00195 /** Calculate the number of leapseconds between two times.
00196  *
00197  *  Calculates the number of leapseconds between two times.
00198  *
00199  *  @return  long: leapseconds added between given times
00200  */
00201 long psTimeLeapSecondDelta(
00202     const psTime* time1,               ///< First input time.
00203     const psTime* time2                ///< Second input time.
00204 );
00205 
00206 /** Determine if UTC time is a leapsecond.
00207  *
00208  *  Determines if the specified UTC time is a valid leapsecond.
00209  *
00210  *  @return  bool: valid leap second
00211  */
00212 bool psTimeIsLeapSecond(
00213     const psTime* utc                  ///< UTC to verify if leap second
00214 );
00215 
00216 /** Convert psTime to Julian date time.
00217  *
00218  *  Converts psTime to Julian date (JD) time. This function does not add or
00219  *  subtract leapseconds.
00220  *
00221  *  @return  double: Julian Date (JD) time.
00222  */
00223 double psTimeToJD(
00224     const psTime* time                 ///< Input time to be converted.
00225 );
00226 /** Convert psTime to modified Julian date time.
00227  *
00228  *  Converts psTime to modified Julian date (MJD) time. This function does not
00229  *  add or subtract leapseconds.
00230  *
00231  *  @return  double: Modified Julian Days (MJD) time.
00232  */
00233 double psTimeToMJD(
00234     const psTime* time                  ///< Input time to be converted.
00235 );
00236 
00237 /** Convert psTime to ISO8601 formatted string.
00238  *
00239  *  Converts psTime to a null terminated string in the form of YYYY-MM-DDThh:mm:ss.sss.
00240  *  This function does not add or subtract leapseconds.
00241  *
00242  *  @return  psString:     Pointer null terminated array of chars in ISO time.
00243  */
00244 psString psTimeToISO(
00245     const psTime* time                  ///< Input time to be converted.
00246 );
00247 
00248 /** Convert psTime to timeval time.
00249  *
00250  *  Converts psTime to timeval time. This function does not add or subtract leapseconds.
00251  *
00252  *  @return  timeval*: timeval struct time.
00253  */
00254 struct timeval* psTimeToTimeval(
00255                 const psTime* time     ///< Input time to be converted.
00256             );
00257 
00258 /*
00259  * Convert psTime to tm time.
00260  *
00261  * Converts psTime to tm time. This function is based on a Perl algorithm availble
00262  * in the Pan-STARRS Image processing Algorithm Design Description (ADD). This function
00263  * does not add or subtract leapseconds.
00264  *
00265  *  @return  tm: tm struct time.
00266  *
00267 struct tm* p_psTimeToTM(
00268                 const psTime *time     ///< Input time to be converted.
00269             );
00270 */
00271 /** Convert JD to psTime.
00272  *
00273  *  Converts JD time to psTime. This function does not add or subtract leapseconds.
00274  *
00275  *  @return  psTime: time.
00276  */
00277 psTime* psTimeFromJD(
00278     double jd                          ///< Input time to be converted.
00279 );
00280 
00281 /** Convert MJD to psTime.
00282  *
00283  *  Converts MJD time to psTime. This function does not add or subtract leapseconds.
00284  *
00285  *  @return  psTime: time.
00286  */
00287 psTime* psTimeFromMJD(
00288     double mjd                         ///< Input time to be converted.
00289 );
00290 
00291 /** Convert ISO to psTime.
00292  *
00293  *  Converts ISO time to psTime. This function does not add or subtract leapseconds.
00294  *
00295  *  @return  psTime*: time
00296  */
00297 psTime* psTimeFromISO(
00298     const char* input,                 ///< Input time to be converted.
00299     psTimeType type                    ///< Time type.
00300 );
00301 
00302 /** Convert timeval to psTime.
00303  *
00304  *  Converts timeval time to psTime. This function does not add or subtract leapseconds.
00305  *
00306  *  @return  psTime*: time.
00307  */
00308 psTime* psTimeFromTimeval(
00309     const struct timeval *input        ///< Input time to be converted.
00310 );
00311 
00312 /** Convert Terrestrial Time to psTime
00313  *
00314  *  Converts Terrestial Time to psTime.  This function assumes resultant time is of type TT.
00315  *
00316  *  @return psTime*: time (TT)
00317  */
00318 psTime* psTimeFromTT(
00319     psS64 sec,                         ///< Input terrestrial time in seconds
00320     psU32 nsec                         ///< Input terrestrial time fraction of seconds (nanoseconds)
00321 );
00322 
00323 /** Convert UTC time to psTime
00324  *
00325  *  Converts UTC time to psTime.  It will verify if time specified is a leapsecond.
00326  *
00327  *  @return psTime*: time (UTC)time
00328  */
00329 psTime* psTimeFromUTC(
00330     psS64  sec,                        ///< Input time in seconds
00331     psU32  nsec,                       ///< Input time fraction of seconds (nanoseconds)
00332     bool leapsecond                    ///< Input time is a leapsecond
00333 );
00334 
00335 /** Convert tm time to psTime.
00336  *
00337  *  Converts tm time to psTime. This function is based on a Perl algorithm availble
00338  *  in the Pan-STARRS Image processing Algorithm Design Description (ADD). This function
00339  *  does not add or subtract leapseconds.
00340  *
00341  *  @return  psTime*: time.
00342  */
00343 psTime* p_psTimeFromTM(
00344     const struct tm *time              ///< Input time to be converted.
00345 );
00346 
00347 /** Adds delta to time. Result is in TAI time.
00348  *
00349  *  Adds delta to time. Input time is converted to TAI format if necessary.
00350  *
00351  *  @return  psTime*: time.
00352  */
00353 psTime* psTimeMath(
00354     const psTime *time,                ///< Time.
00355     double delta                       ///< Time delta.
00356 );
00357 
00358 /** Determine difference between two times. Result is in TAI time.
00359  *
00360  *  Determine difference between two times. Input times are converted to TAI format if necessary.
00361  *
00362  *  @return double: Time difference.
00363  */
00364 double psTimeDelta(
00365     const psTime *time1,               ///< First time.
00366     const psTime *time2                ///< Second time.
00367 );
00368 
00369 /** Get the filename of the psLib configuration file.
00370  *
00371  *  @return char*          If a PS_CONFIG_FILE environment variable exists,
00372  *                         that is returned, otherwise the default location
00373  *                         dependent on the installation location.
00374  */
00375 char* p_psGetConfigFileName();
00376 
00377 /**
00378  *
00379  *
00380  *
00381  */
00382 psF64 p_psTimeSearchTables(
00383     psF64 index,                       ///<
00384     psU64 column,                      ///<
00385     char *metadataTableNames[],        ///<
00386     psU32 nTables,                     ///<
00387     psLookupStatusType* status         ///<
00388 );
00389 
00390 /** Stores the current time in a psHash of timers, under the supplied name.
00391  *
00392  *  @return bool:       True if successful, otherwise false.
00393  */
00394 bool psTimerStart(
00395     char *name                         ///< timer name to start
00396 );
00397 
00398 /** Resets the named timer.
00399  *
00400  *  @return psF64:      The time elapsed since start.
00401  */
00402 psF64 psTimerClear(
00403     char *name                         ///< timer name to clear
00404 );
00405 
00406 /** Returns the elapsed time, in seconds, for the timer specified by name.
00407  *
00408  *  @return psF64:      The elapsed time in seconds since timer start.
00409  */
00410 psF64 psTimerMark(
00411     char *name                        ///< timer name to mark
00412 );
00413 
00414 /** Frees all memory associated with all timers and returns the expended time.
00415  *
00416  *  @return psF64:      The maximum time expended.
00417  */
00418 psF64 psTimerStop(void);
00419 
00420 /// @}
00421 
00422 #endif // #ifndef PSTIME_H

Generated on Thu Oct 13 14:32:52 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.2