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/09/14 20:42:48 $
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 /** Free memory persistant time data.
00085  *
00086  * Frees time data to be held in memory until the end of successful program execution.
00087  *
00088  * @return  void: void.
00089  */
00090 psBool p_psTimeFinalize(void);
00091 
00092 /** Allocate time struct.
00093  *
00094  * Allocates an empty time struct. User must specify the psTimeType
00095  * (PS_TIME_TAI or PS_TIME_UTC) in the argument. The seconds and microseconds members
00096  * of the struct are set to zero.
00097  *
00098  * @return  psTime*: Struct with empty time.
00099  */
00100 psTime* psTimeAlloc(
00101     psTimeType type                    ///< Type of time to create (UTC or TAI).
00102 );
00103 
00104 
00105 /** Checks the type of a particular pointer.
00106  *
00107  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00108  *
00109  *  @return bool:       True if the pointer matches a psTime structure, false otherwise.
00110  */
00111 bool psMemCheckTime(
00112     psPtr ptr                          ///< the pointer whose type to check
00113 );
00114 
00115 
00116 /** Get current time.
00117  *
00118  * Gets current time from the system clock. User must specify the psTimeType
00119  * (PS_TIME_TAI or PS_TIME_UTC) in the argument.
00120  *
00121  *  @return  psTime*: Struct with current time.
00122  */
00123 psTime* psTimeGetNow(
00124     psTimeType type                    ///< Type of time to get (UTC or TAI).
00125 );
00126 
00127 /** Convert psTime to UTC or TAI time.
00128  *
00129  *  Converts psTime to UTC or TAI time based on the psTimeType argument.
00130  *
00131  *  @return  psTime*: Pointer to psTime.
00132  */
00133 psTime* psTimeConvert(
00134     psTime *time,                      ///< Time to be converted.
00135     psTimeType type                    ///< Type to be converted to.
00136 );
00137 
00138 /** Convert psTime to Local Mean Sidereal Time (LMST).
00139  *
00140  *  Converts psTime at the given longitude to LMST time. If the input time is not
00141  *  in UTC format, then it is converted.
00142  *
00143  *  @return  double: LST Time.
00144  */
00145 double psTimeToLMST(
00146     psTime *time,                      ///< psTime to be converted.
00147     double longitude                   ///< Longitude.
00148 );
00149 
00150 /** Determine UT1 - UTC from table lookup.
00151  *
00152  *  This function is necessary to for various SLALIB functions.
00153  *
00154  *  @return  double: Time difference.
00155  */
00156 double psTimeGetUT1Delta(
00157     const psTime *time,                ///< psTime to be looked up.
00158     psTimeBulletin bulletin            ///< IERS bulletin to use
00159 );
00160 
00161 /** Determine TAI - UTC from table lookup.
00162  *
00163  *  This function is necessary to for various psTime functions.
00164  *
00165  *  @return  psF64: Time difference.
00166  */
00167 psF64 p_psTimeGetTAIDelta(
00168     const psTime *time                 ///< psTime to be looked up.
00169 );
00170 
00171 /** Determine polar coordinates at a given time.
00172  *
00173  *  Determines the orientation of the polar axis at the given time.
00174  *
00175  *  @return  psSphere*: Spherical coordinates of Earth's polar axias.
00176  */
00177 psSphere* p_psTimeGetPoleCoords(
00178     const psTime *time      ///< psTime determine polar orientation.
00179 );
00180 
00181 /** Calculate the number of leapseconds between two times.
00182  *
00183  *  Calculates the number of leapseconds between two times.
00184  *
00185  *  @return  long: leapseconds added between given times
00186  */
00187 long psTimeLeapSecondDelta(
00188     const psTime* time1,               ///< First input time.
00189     const psTime* time2                ///< Second input time.
00190 );
00191 
00192 /** Determine if UTC time is a leapsecond.
00193  *
00194  *  Determines if the specified UTC time is a valid leapsecond.
00195  *
00196  *  @return  bool: valid leap second
00197  */
00198 bool psTimeIsLeapSecond(
00199     const psTime* utc                  ///< UTC to verify if leap second
00200 );
00201 
00202 /** Convert psTime to Julian date time.
00203  *
00204  *  Converts psTime to Julian date (JD) time. This function does not add or
00205  *  subtract leapseconds.
00206  *
00207  *  @return  double: Julian Date (JD) time.
00208  */
00209 double psTimeToJD(
00210     const psTime* time                 ///< Input time to be converted.
00211 );
00212 /** Convert psTime to modified Julian date time.
00213  *
00214  *  Converts psTime to modified Julian date (MJD) time. This function does not
00215  *  add or subtract leapseconds.
00216  *
00217  *  @return  double: Modified Julian Days (MJD) time.
00218  */
00219 double psTimeToMJD(
00220     const psTime* time                  ///< Input time to be converted.
00221 );
00222 
00223 /** Convert psTime to ISO8601 formatted string.
00224  *
00225  *  Converts psTime to a null terminated string in the form of YYYY-MM-DDThh:mm:ss.sss.
00226  *  This function does not add or subtract leapseconds.
00227  *
00228  *  @return  psString:     Pointer null terminated array of chars in ISO time.
00229  */
00230 psString psTimeToISO(
00231     const psTime* time                  ///< Input time to be converted.
00232 );
00233 
00234 /** Convert psTime to timeval time.
00235  *
00236  *  Converts psTime to timeval time. This function does not add or subtract leapseconds.
00237  *
00238  *  @return  timeval*: timeval struct time.
00239  */
00240 struct timeval* psTimeToTimeval(
00241                 const psTime* time     ///< Input time to be converted.
00242             );
00243 
00244 /*
00245  * Convert psTime to tm time.
00246  *
00247  * Converts psTime to tm time. This function is based on a Perl algorithm availble
00248  * in the Pan-STARRS Image processing Algorithm Design Description (ADD). This function
00249  * does not add or subtract leapseconds.
00250  *
00251  *  @return  tm: tm struct time.
00252  *
00253 struct tm* p_psTimeToTM(
00254                 const psTime *time     ///< Input time to be converted.
00255             );
00256 */
00257 /** Convert JD to psTime.
00258  *
00259  *  Converts JD time to psTime. This function does not add or subtract leapseconds.
00260  *
00261  *  @return  psTime: time.
00262  */
00263 psTime* psTimeFromJD(
00264     double jd                          ///< Input time to be converted.
00265 );
00266 
00267 /** Convert MJD to psTime.
00268  *
00269  *  Converts MJD time to psTime. This function does not add or subtract leapseconds.
00270  *
00271  *  @return  psTime: time.
00272  */
00273 psTime* psTimeFromMJD(
00274     double mjd                         ///< Input time to be converted.
00275 );
00276 
00277 /** Convert ISO to psTime.
00278  *
00279  *  Converts ISO time to psTime. This function does not add or subtract leapseconds.
00280  *
00281  *  @return  psTime*: time
00282  */
00283 psTime* psTimeFromISO(
00284     const char* input,                 ///< Input time to be converted.
00285     psTimeType type                    ///< Time type.
00286 );
00287 
00288 /** Convert timeval to psTime.
00289  *
00290  *  Converts timeval time to psTime. This function does not add or subtract leapseconds.
00291  *
00292  *  @return  psTime*: time.
00293  */
00294 psTime* psTimeFromTimeval(
00295     const struct timeval *input        ///< Input time to be converted.
00296 );
00297 
00298 /** Convert Terrestrial Time to psTime
00299  *
00300  *  Converts Terrestial Time to psTime.  This function assumes resultant time is of type TT.
00301  *
00302  *  @return psTime*: time (TT)
00303  */
00304 psTime* psTimeFromTT(
00305     psS64 sec,                         ///< Input terrestrial time in seconds
00306     psU32 nsec                         ///< Input terrestrial time fraction of seconds (nanoseconds)
00307 );
00308 
00309 /** Convert UTC time to psTime
00310  *
00311  *  Converts UTC time to psTime.  It will verify if time specified is a leapsecond.
00312  *
00313  *  @return psTime*: time (UTC)time
00314  */
00315 psTime* psTimeFromUTC(
00316     psS64  sec,                        ///< Input time in seconds
00317     psU32  nsec,                       ///< Input time fraction of seconds (nanoseconds)
00318     bool leapsecond                    ///< Input time is a leapsecond
00319 );
00320 
00321 /** Convert tm time to psTime.
00322  *
00323  *  Converts tm time to psTime. This function is based on a Perl algorithm availble
00324  *  in the Pan-STARRS Image processing Algorithm Design Description (ADD). This function
00325  *  does not add or subtract leapseconds.
00326  *
00327  *  @return  psTime*: time.
00328  */
00329 psTime* p_psTimeFromTM(
00330     const struct tm *time              ///< Input time to be converted.
00331 );
00332 
00333 /** Adds delta to time. Result is in TAI time.
00334  *
00335  *  Adds delta to time. Input time is converted to TAI format if necessary.
00336  *
00337  *  @return  psTime*: time.
00338  */
00339 psTime* psTimeMath(
00340     const psTime *time,                ///< Time.
00341     double delta                       ///< Time delta.
00342 );
00343 
00344 /** Determine difference between two times. Result is in TAI time.
00345  *
00346  *  Determine difference between two times. Input times are converted to TAI format if necessary.
00347  *
00348  *  @return double: Time difference.
00349  */
00350 double psTimeDelta(
00351     const psTime *time1,               ///< First time.
00352     const psTime *time2                ///< Second time.
00353 );
00354 
00355 /** Get the filename of the psLib configuration file.
00356  *
00357  *  @return char*          If a PS_CONFIG_FILE environment variable exists,
00358  *                         that is returned, otherwise the default location
00359  *                         dependent on the installation location.
00360  */
00361 char* p_psGetConfigFileName();
00362 
00363 psF64 p_psTimeSearchTables(
00364     psF64 index,
00365     psU64 column,
00366     char *metadataTableNames[],
00367     psU32 nTables,
00368     psLookupStatusType* status
00369 );
00370 
00371 /// @}
00372 
00373 #endif // #ifndef PSTIME_H

Generated on Wed Sep 14 10:42:48 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.2