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.47 $ $Name: rel12 $
00014  *  @date $Date: 2006/06/27 04:13:07 $
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, TAI, UT1, or TT time.
00142  *
00143  *  Converts psTime to UTC, TAI, UT1, or TT 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 /** Provides tidal corrections to UT1-UTC.
00176  *
00177  *  Uses the Ray model of Simon et al.
00178  *
00179  *  @return psTime*:    The corrected time in UT1.
00180  */
00181 psTime *psTime_TideUT1Corr(
00182     const psTime *time                 ///< psTime to be corrected.
00183 );
00184 
00185 /** Determine TAI - UTC from table lookup.
00186  *
00187  *  This function is necessary to for various psTime functions.
00188  *
00189  *  @return psF64:      Time difference.
00190  */
00191 psF64 p_psTimeGetTAIDelta(
00192     const psTime *time                 ///< psTime to be looked up.
00193 );
00194 
00195 /** Determine polar coordinates at a given time.
00196  *
00197  *  Determines the orientation of the polar axis at the given time.
00198  *
00199  *  @return psSphere*:      Spherical coordinates of Earth's polar axias.
00200  */
00201 psSphere* p_psTimeGetPoleCoords(
00202     const psTime *time      ///< psTime determine polar orientation.
00203 );
00204 
00205 /** Calculate the number of leapseconds between two times.
00206  *
00207  *  Calculates the number of leapseconds between two times.
00208  *
00209  *  @return long:   leapseconds added between given times
00210  */
00211 long psTimeLeapSecondDelta(
00212     const psTime* time1,               ///< First input time.
00213     const psTime* time2                ///< Second input time.
00214 );
00215 
00216 /** Determine if UTC time is a leapsecond.
00217  *
00218  *  Determines if the specified UTC time is a valid leapsecond.
00219  *
00220  *  @return bool:   valid leap second
00221  */
00222 bool psTimeIsLeapSecond(
00223     const psTime* utc                  ///< UTC to verify if leap second
00224 );
00225 
00226 /** Convert psTime to Julian date time.
00227  *
00228  *  Converts psTime to Julian date (JD) time. This function does not add or
00229  *  subtract leapseconds.
00230  *
00231  *  @return double:     Julian Date (JD) time.
00232  */
00233 double psTimeToJD(
00234     const psTime* time                 ///< Input time to be converted.
00235 );
00236 /** Convert psTime to modified Julian date time.
00237  *
00238  *  Converts psTime to modified Julian date (MJD) time. This function does not
00239  *  add or subtract leapseconds.
00240  *
00241  *  @return double:     Modified Julian Days (MJD) time.
00242  */
00243 double psTimeToMJD(
00244     const psTime* time                  ///< Input time to be converted.
00245 );
00246 
00247 /** Convert psTime to ISO8601 formatted string.
00248  *
00249  *  Converts psTime to a null terminated string in the form of YYYY-MM-DDThh:mm:ss.sss.
00250  *  This function does not add or subtract leapseconds.
00251  *
00252  *  @return psString:     Pointer null terminated array of chars in ISO time.
00253  */
00254 psString psTimeToISO(
00255     const psTime* time                  ///< Input time to be converted.
00256 );
00257 
00258 /** Convert psTime to struct tm time.
00259  *
00260  *  Converts psTime to struct tm time.  This function should handle
00261  *  UTC leapseconds correctly.
00262  *
00263  *  @return tm*:   tm struct.
00264  */
00265 struct tm *psTimeToTM(
00266                 const psTime* time     ///< Input time to be converted.
00267             );
00268 
00269 /** Convert psTime to timeval time.
00270  *
00271  *  Converts psTime to timeval time. This function does not add or subtract leapseconds.
00272  *
00273  *  @return timeval*:   timeval struct time.
00274  */
00275 struct timeval* psTimeToTimeval(
00276                 const psTime* time     ///< Input time to be converted.
00277             );
00278 
00279 /*
00280  * Convert psTime to tm time.
00281  *
00282  * Converts psTime to tm time. This function is based on a Perl algorithm availble
00283  * in the Pan-STARRS Image processing Algorithm Design Description (ADD). This function
00284  * does not add or subtract leapseconds.
00285  *
00286  *  @return  tm: tm struct time.
00287  *
00288 struct tm* p_psTimeToTM(
00289                 const psTime *time     ///< Input time to be converted.
00290             );
00291 */
00292 /** Convert JD to psTime.
00293  *
00294  *  Converts JD time to psTime. This function does not add or subtract leapseconds.
00295  *
00296  *  @return  psTime: time.
00297  */
00298 psTime* psTimeFromJD(
00299     double jd                          ///< Input time to be converted.
00300 );
00301 
00302 /** Convert MJD to psTime.
00303  *
00304  *  Converts MJD time to psTime. This function does not add or subtract leapseconds.
00305  *
00306  *  @return  psTime: time.
00307  */
00308 psTime* psTimeFromMJD(
00309     double mjd                         ///< Input time to be converted.
00310 );
00311 
00312 /** Convert ISO to psTime.
00313  *
00314  *  Converts ISO time to psTime. This function does not add or subtract leapseconds.
00315  *
00316  *  @return  psTime*: time
00317  */
00318 psTime* psTimeFromISO(
00319     const char* input,                 ///< Input time to be converted.
00320     psTimeType type                    ///< Time type.
00321 );
00322 
00323 /** Convert timeval to psTime.
00324  *
00325  *  Converts timeval time to psTime. This function does not add or subtract leapseconds.
00326  *
00327  *  @return  psTime*: time.
00328  */
00329 psTime* psTimeFromTimeval(
00330     const struct timeval *input        ///< Input time to be converted.
00331 );
00332 
00333 /** Convert Terrestrial Time to psTime
00334  *
00335  *  Converts Terrestial Time to psTime.  This function assumes resultant time is of type TT.
00336  *
00337  *  @return psTime*: time (TT)
00338  */
00339 psTime* psTimeFromTT(
00340     psS64 sec,                         ///< Input terrestrial time in seconds
00341     psU32 nsec                         ///< Input terrestrial time fraction of seconds (nanoseconds)
00342 );
00343 
00344 /** Convert UTC time to psTime
00345  *
00346  *  Converts UTC time to psTime.  It will verify if time specified is a leapsecond.
00347  *
00348  *  @return psTime*: time (UTC)time
00349  */
00350 psTime* psTimeFromUTC(
00351     psS64  sec,                        ///< Input time in seconds
00352     psU32  nsec,                       ///< Input time fraction of seconds (nanoseconds)
00353     bool leapsecond                    ///< Input time is a leapsecond
00354 );
00355 
00356 /** Convert tm time to psTime.
00357  *
00358  *  Converts tm time to psTime. This function is based on a Perl algorithm availble
00359  *  in the Pan-STARRS Image processing Algorithm Design Description (ADD). This function
00360  *  does not add or subtract leapseconds.
00361  *
00362  *  @return  psTime*: time.
00363  */
00364 psTime* psTimeFromTM(
00365     const struct tm *time              ///< Input time to be converted.
00366 );
00367 
00368 /** Convert an arbitrary string into a psTime.
00369  *
00370  *  Converts a string, using a strptime(3) format, into a psTime.  See
00371  *  strptime(3) for documentation on this format.
00372  *
00373  *  @return  psTime*: time.
00374  */
00375 
00376 psTime* psTimeStrptime(
00377     const char *s,                  ///< string to be converted
00378     const char *format              ///< strptime format
00379 );
00380 
00381 /** Adds delta to time. Result is in TAI time.
00382  *
00383  *  Adds delta to time. Input time is converted to TAI format if necessary.
00384  *
00385  *  @return  psTime*: time.
00386  */
00387 psTime* psTimeMath(
00388     const psTime *time,                ///< Time.
00389     double delta                       ///< Time delta.
00390 );
00391 
00392 /** Determine difference between two times. Result is in TAI time.
00393  *
00394  *  Determine difference between two times. Input times are converted to TAI format if necessary.
00395  *
00396  *  @return double: Time difference.
00397  */
00398 double psTimeDelta(
00399     const psTime *time1,               ///< First time.
00400     const psTime *time2                ///< Second time.
00401 );
00402 
00403 /** Get the filename of the psLib configuration file.
00404  *
00405  *  @return char*          If a PS_CONFIG_FILE environment variable exists,
00406  *                         that is returned, otherwise the default location
00407  *                         dependent on the installation location.
00408  */
00409 char* p_psGetConfigFileName();
00410 
00411 /** Searches the IERS time tables for a specified entry location.
00412  *
00413  *  Returns the interpolated double precision (arcsec) value at the specified entry
00414  *  location.  Inputs to specify are the time index in mjd, the column number
00415  *  corresponding to Xp, Yp, or Sp (UT1-UTC) in IERS A or B, the time table names,
00416  *  and the number of time tables.
00417  *
00418  *  @return psF64:          Resulting table entry for specified parameters.
00419  */
00420 psF64 p_psTimeSearchTables(
00421     psF64 index,                       ///< time index for which to search
00422     psU64 column,                      ///< column number of specified index
00423     char *metadataTableNames[],        ///< names of IERS tables to search
00424     psU32 nTables,                     ///< number of IERS tables to search
00425     psLookupStatusType* status         ///< status of table search
00426 );
00427 
00428 /** Stores the current time in a psHash of timers, under the supplied name.
00429  *
00430  *  @return bool:       True if successful, otherwise false.
00431  */
00432 bool psTimerStart(
00433     char *name                         ///< timer name to start
00434 );
00435 
00436 /** Resets the named timer.
00437  *
00438  *  @return psF64:      The time elapsed since start.
00439  */
00440 psF64 psTimerClear(
00441     char *name                         ///< timer name to clear
00442 );
00443 
00444 /** Returns the elapsed time, in seconds, for the timer specified by name.
00445  *
00446  *  @return psF64:      The elapsed time in seconds since timer start.
00447  */
00448 psF64 psTimerMark(
00449     char *name                        ///< timer name to mark
00450 );
00451 
00452 /** Frees all memory associated with all timers and returns the expended time.
00453  *
00454  *  @return psF64:      The maximum time expended.
00455  */
00456 psF64 psTimerStop(void);
00457 
00458 /** Private function for copying a psTime.
00459  *
00460  *  @return psTime*:        New copy of existing psTime.
00461  */
00462 psTime *p_psTimeCopy(
00463     const psTime *inTime               ///< input time to copy.
00464 );
00465 
00466 /// @}
00467 
00468 #endif // #ifndef PSTIME_H

Generated on Mon Jul 3 14:13:44 2006 for Pan-STARRS Foundation Library by  doxygen 1.4.4