/*  
 *  - - - - - - - -  
 *   g a l _ d a t  
 *  - - - - - - - -  
 *  
 *  This routine is part of the General Astrodynamics Library  
 *  
 *  Description: 
 *  
 *  For a given UTC date, calculate delta(AT) = TAI-UTC.  
 *  
 *     :------------------------------------------:  
 *     :                                          :  
 *     :                 IMPORTANT                :  
 *     :                                          :  
 *     :  A new version of this routine must be   :  
 *     :  produced whenever a new leap second is  :  
 *     :  announced.  There are five items to     :  
 *     :  change on each such occasion:           :  
 *     :                                          :  
 *     :  1) The parameter NDAT must be           :  
 *     :     increased by 1.                      :  
 *     :                                          :  
 *     :  2) A new line must be added to the      :  
 *     :     arrays IDATE and DATS.               :  
 *     :                                          :  
 *     :  3) The parameter IYV must be set to     :  
 *     :     the current year.                    :  
 *     :                                          :  
 *     :  4) The "Latest leap second" comment     :  
 *     :     below must be set to the new leap    :  
 *     :     second date.                         :  
 *     :                                          :  
 *     :  5) The "This revision" comment, later,  :  
 *     :     must be set to the current date.     :  
 *     :                                          :  
 *     :  Change (3) must also be carried out     :  
 *     :  whenever the routine is re-issued,      :  
 *     :  even if no leap seconds have been       :  
 *     :  added.                                  :  
 *     :                                          :  
 *     :  Latest leap second:  2006 January 1     :  
 *     :                                          :  
 *     :__________________________________________:  
 *  
 *  This routine is an independent translation of a FORTRAN routine  
 *  that is part of IAU's SOFA software collection.  
 *  
 *  Status:
 *  
 *     support routine.  
 *  
 *  Given:
 *  
 *     iy                  i        UTC:  year (Notes 1 and 2)  
 *     im                  i        month (Note 2)  
 *     id                  i        day (Notes 2 and 3)  
 *     fd                  d        fraction of day (Note 4)  
 *  
 *  Returned:
 *  
 *     *deltat             d        TAI minus UTC, seconds  
 *     gal_dat             i        status (Note 5):  
 *                                    1 = dubious year (Note 1)  
 *                                    0 = OK  
 *                                   -1 = bad year  
 *                                   -2 = bad month  
 *                                   -3 = bad day (Note 3)  
 *                                   -4 = bad fraction (Note 4)  
 *  
 *  Notes:  
 *  
 *  1) UTC began at 1960 January 1.0 (JD 2436934.5) and it is improper  
 *     to call the routine with an earlier epoch.  If this is attempted,  
 *     zero is returned together with a warning status.  
 *  
 *     Because leap seconds cannot, in principle, be predicted in  
 *     advance, a reliable check for dates beyond the valid range is  
 *     impossible.  To guard against gross errors, a year five or more  
 *     after the release year of the present routine (see parameter IYV)  
 *     is considered dubious.  In this case a warning status is returned  
 *     but the result is computed in the normal way.  
 *  
 *     For both too-early and too-late years, the warning status is j=+1.  
 *     This is distinct from the error status j=-1, which signifies a  
 *     year so early that JD could not be computed.  
 *  
 *  2) If the specified date is for a day which ends with a leap second,  
 *     the UTC-TAI value returned is for the period leading up to the  
 *     leap second.  If the date is for a day which begins as a leap  
 *     second ends, the UTC-TAI returned is for the period following the  
 *     leap second.  
 *  
 *  3) The day number must be in the normal calendar range, for example  
 *     1 through 30 for April.  The "almanac" convention of allowing  
 *     such dates as January 0 and December 32 is not supported in this  
 *     routine, in order to avoid confusion near leap seconds.  
 *  
 *  4) The fraction of day is used only for dates before the introduction  
 *     of leap seconds, the first of which occurred at the end of 1971.  
 *     It is tested for validity (zero to less than 1 is the valid range)  
 *     even if not used;  if invalid, zero is used and status j=-4 is  
 *     returned.  For many applications, setting FD to zero is  
 *     acceptable;  the resulting error is always less than 3 ms (and  
 *     occurs only pre-1972).  
 *  
 *  5) The status value returned in the case where there are multiple  
 *     errors refers to the first error detected.  For example, if the  
 *     month and day are 13 and 32 respectively, j=-2 (bad month)  
 *     will be returned.  
 *  
 *  6) In cases where a valid result is not available, zero is returned.  
 *  
 *  References:  
 *  
 *  1) For epochs from 1961 January 1 onwards, the expressions from the  
 *     file ftp://maia.usno.navy.mil/ser7/tai-utc.dat are used.  
 *  
 *  2) The 5ms timestep at 1961 January 1 is taken from 2.58.1 (p87) of  
 *     the 1992 Explanatory Supplement.  
 *  
 *  Called:
 *  
 *     gal_cal2jd         Gregorian calendar to Julian Day number  
 *  
 *  This revision:
 *  
 *     2006 November 13 ( c version 2008 June 8 )  
 *  
 *  
 *  Copyright (C) 2008 Paul C. L. Willmott. See notes at end.  
 *  
 *-----------------------------------------------------------------------  
 */  
  
#ifndef _GAL_DAT_H_  
#define _GAL_DAT_H_ 1  

#undef __BEGIN_DECLS  
#undef __END_DECLS  
#ifdef __cplusplus  
#define __BEGIN_DECLS extern "C" {  
#define __END_DECLS }  
#else  
#define __BEGIN_DECLS /* empty */  
#define __END_DECLS   /* empty */  
#endif
  
__BEGIN_DECLS  
  
int  
gal_dat  
 (  
    int iy,  
    int im,  
    int id,  
    double fd,  
    double *deltat
 ) ;  
  
__END_DECLS  
  
#endif /* !_GAL_DAT_H_ */  

/*  
 *  gal - General Astrodynamics Library  
 *  Copyright (C) 2008 Paul C. L. Willmott  
 *  
 *  This program is free software; you can redistribute it and/or modify  
 *  it under the terms of the GNU General Public License as published by  
 *  the Free Software Foundation; either version 2 of the License, or  
 *  (at your option) any later version.  
 *  
 *  This program is distributed in the hope that it will be useful,  
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of  
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
 *  GNU General Public License for more details.  
 *  
 *  You should have received a copy of the GNU General Public License along  
 *  with this program; if not, write to the Free Software Foundation, Inc.,  
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.  
 *  
 *  Contact:  
 *  
 *  Paul Willmott  
 *  vp9mu@amsat.org  
 */  
