;+ ; NAME: ; TAI_UTC ; ; AUTHOR: ; Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770 ; craigm@lheamail.gsfc.nasa.gov ; UPDATED VERSIONs can be found on my WEB PAGE: ; http://cow.physics.wisc.edu/~craigm/idl/idl.html ; ; PURPOSE: ; Compute (TAI - UTC) time difference (i.e., leap seconds) ; ; MAJOR TOPICS: ; Time ; ; CALLING SEQUENCE: ; LEAP = TAI_UTC(JD_UTC) ;; or, ; LEAP = TAI_UTC(JD_TAI, /INVERT) ; ; DESCRIPTION: ; ; The function TAI_UTC computes the difference between International ; Atomic Time (TAI) and Universal Coordinated Time (UTC), in ; seconds. ; ; After 01 Jan 1972, the two time systems are synchronized, except ; for a number of leap seconds added to account for the varying rate ; of rotation of the earth. While TAI is a continuous atomic time ; system, UTC is a civil time system which may have discontinuities ; where leap seconds are introduced. This function computes the ; differences between the two time systems. ; ; The conversion from UTC to TAI is computed as: ; ; JD_TAI = JD_UTC + TAI_UTC(JD_UTC)/86400 ; ; The inversion conversion, from TAI to UTC, is computed as: ; ; JD_UTC = JD_TAI + TAI_UTC(JD_TAI, /INVERT)/86400 ; ; Here JD_UTC and JD_TAI are the UTC and TAI times measured in ; Julian days respectively. ; ; The introduction of leap seconds is not predictable, owing to the ; non-linear processes that govern the rotation of the earth. The ; International Earth Rotation Service determines when leap seconds ; will be introduced. Thus, the user must download the history of ; leap seconds. This file can be downloaded at the following URL: ; ; ftp://maia.usno.navy.mil/ser7/tai-utc.dat ; ; NOTE - the leap second file must be kept up to date as new leap ; seconds are introduced. The file is kept internally in ; memory, but is reloaded from disk at least once per day. ; ; If the disk file is not available, then a copy of the file as ; available from the USNO in 2009 is used, but a warning message is ; printed. ; ; The leap second data can be loaded in several ways: ; 1. The FILENAME keyword may specify the exact file name and path; ; 2. If FILENAME is not defined, or the empty string, then ; the default location $ASTRO_DATA/tai-utc.dat is used; ; (ASTRO_DATA is a system environment variable, used by ; the IDL astronomy library to store auxiliary data files) ; 3. If neither #1 or #2 are available, then the internal table ; is used. ; ; ; PARAMETERS: ; ; JD - time measured in Julian days. The time being converted ; *from*. ; ; RETURNS: ; ; The number of seconds to be added to the input time, to arrive at ; the desired time. ; ; ; KEYWORD PARAMETERS: ; ; INVERT - if set, then convert from TAI to UTC. If not set ; (default), then convert from UTC to TAI. ; ; FILENAME - a scalar string, indicating the file name containing ; leap second data. The data is only loaded once upon ; the first call, and then with a frequency determined by ; the RELOAD_EVERY keyword. If FILENAME is not ; specified or a blank string, then the leap second data ; is found using the methods described above. ; Default: not defined; i.e. TAI_UTC searches the default ; locations ; ; RELOAD_EVERY - a scalar value, indicates how often the data should ; be reloaded for long-running tasks. The value is ; expressed in days. If the leap second data was ; loaded more than RELOAD_EVERY days ago, then it ; will be reloaded. Note that a value of 0 will ; cause immediate re-load of data. ; Default: 1 (i.e. re-load every 1 day) ; ; EXAMPLE: ; ; For data stored in $ASTRO_DATA, ; print, tai_utc(2451544.5d) ;; Uses $ASTRO_DATA/tai-utc.dat ; 32.000000 ; ; For the data stored in one's home directory, ; filename = getenv('HOME')+'tai-utc.dat' ; print, tai_utc(2451544.5d, filename=filename) ; 32.000000 ; ; ; REFERENCES: ; ; Definition of leap seconds. ; http://tycho.usno.navy.mil/leapsec.html ; ; File containing leap seconds. ; ftp://maia.usno.navy.mil/ser7/tai-utc.dat ; ; ; SEE ALSO ; TDB2TDT, SYSTIME, CALDAT, JULDAY ; ; MODIFICATION HISTORY: ; Written and Documented, CM, Dec 2001 ; Fixed array indexing errors when the requested time range falls in ; the leap second period, and the input is an array; avoided use ; of variable JDAY, which is a function clash for me, 02 Mar 2002, ; CM ; Added helpful usage message, CM, 15 Mar 2002 ; Made file handling more robust (instead of crashing), CM, 19 Jul 2005 ; Add 01 Jan 2006 leap second, CM, 03 Oct 2005 ; Add 01 Jan 2009 leap second, CM, 21 Jul 2008 ; Add documentation and the RELOAD_EVERY keyword, CM, 02 Dec 2009 ; New default file location is $ASTRO_DATA/tai-utc.dat, CM, 28 Dec 2009 ; Add 01 Jul 2012 leap second, CM, 2012-01-05 ; Correct note for previous leap second (thanks James Tursa), CM, 2012-07-19 ; Add 01 Jul 2015 leap second, CM, 2015-02-25 ; Add more error checking for cases of IDL Astronomy and "no" file, ; CM, 2016-07-11 ; Add 01 Jan 2017 leap second, CM, 2016-07-11 ; ; $Id: tai_utc.pro,v 1.16 2016/07/11 21:26:27 cmarkwar Exp $ ; ;- ; Copyright (C) 2001, 2002, 2005, 2008, 2009, 2012, 2015, 2016 Craig Markwardt ; This software is provided as is without any warranty whatsoever. ; Permission to use, copy and distribute unmodified copies for ; non-commercial purposes, and to modify and use for personal or ; internal use, is granted. All other rights are reserved. ;-