	IMPLICIT NONE
	DOUBLE PRECISION D, TARTUF
	
	WRITE (6,*) 'Computation of TAI-UTC'
	WRITE (6,*) 'Write the date in MJD'
	READ (5,*) D
	
	WRITE (6,1000) TARTUF(D)
1000	format('TAI - UTC =' ,f12.7,'s') 
     	END
	

c     TARTUF
c ##############################################################
c This function performs the computation of the time shift TAI-UTC, 
c in seconds, to be removed from UT1-UTC = UT1 - TAI + TAI - UTC 
c in order to get UT1-TAI

c input  : D = Date in Modified Julian Day
c output : TARTUF = TAI-UTC 
c ##############################################################
  	
       FUNCTION TARTUF(D)
       IMPLICIT REAL*8(A-H,O-Z)
       DOUBLE PRECISION D
       DOUBLE PRECISION A(50),B(50),C(50),T(50)
   	
       A(1)=1.422818d0
       A(2)=1.372818d0
       A(3)=1.845858d0
       A(4)=1.945858d0
       A(5)=3.240130d0
      
       DO 10 I=6,11
  10   A(I)=A(I-1)+0.1d0
   
       A(12)=4.313170d0
       A(13)=4.213170d0
      
       DO 11 I=14,50
  11   A(I)=I-4
   
       B(1)=37300.d0
       B(2)=37300.d0
       B(3)=37665.d0
       B(4)=37665.d0
      
       DO 12 I=5,11
  12   B(I)=38761.d0
   
       B(12)=39126.d0
       B(13)=39126.d0
   
       DO 13 I=14,50
  13   B(I)=0.d0
   
       ! coefficients lineaires  
       DO 14 I=1,11
 14    C(I)=0.001296d0
   
       C(3)=0.0011232d0
       C(4)=0.0011232d0
       C(12)=0.002592d0
       C(13)=0.002592d0
 
       ! A partir du 1er juillet 1972 il n'y a plus de termes lineaires	
       DO 15 I=14,50
 15    C(I)=0.d0
             
       TA=37300.d0		  ! 010161
       T(1)=37512.d0		  ! 010861
       T(2)=37665.d0		  ! 010162
       T(3)=38334.d0		  ! 011163
       T(4)=38395.d0		  ! 010164
       T(5)=38486.d0		  ! 010464
       T(6)=38639.d0		  ! 010964
       T(7)=38761.d0		  ! 010165
       T(8)=38820.d0		  ! 010365
       T(9)=38942.d0		  ! 010765
       T(10)=39004.d0		  ! 010965
       T(11)=39126.d0		  ! 010166
       T(12)=39887.d0		  ! 010268
       T(13)=41317.d0		  ! 010172
       T(14)=41499.d0		  ! 010772
       T(15)=41683.d0		  ! 010173
C
C   LA BOUCLE 16 EST A JOUR POUR LE 1.7.82
C
       DO 16 I=16,22
       T(I)=T(I-1)+365.d0
       IF(MOD((I-15),4).EQ.0) T(I)=T(I)+1.d0  
       ! prise en compte des annees bissextiles
 16    CONTINUE
     
       T(23) = 44786.d0             ! 010781
       T(24) = 45151.d0             ! 010782
       T(25) = 45516.d0             ! 010783
       T(26) = 46247.d0		    ! 010785
       T(27) = 47161.d0		    ! 010188
       T(28) = 47892.d0             ! 010190
       T(29) = 48257.d0             ! 010191
       T(30) = 48804.d0             ! 010792
       T(31) = 49169.d0             ! 010793
       T(32) = 49534.d0             ! 010794
       T(33) = 50083.d0             ! 010196
       T(34) = 50630.d0             ! 010797
       T(35) = 51179.d0             ! 010199
      
       DO 105 I=36,50
  105  T(I)=52639.d0+365.d0   ! 31 decembre 2003
         
       TARTUF = 0.d0
       IF(D.LT.TA) THEN 
       WRITE(6,*) 'TAI is not defined before this date'
       GOTO 18
       TARTUF = 999.d0
       ENDIF
       
       DO 17 I=1,50     
	      IF(D.GE.T(I)) GO TO 17  
	      TARTUF = A(I) + (D-B(I))*C(I) 
 	      GOTO 18
   17  CONTINUE

       WRITE(6,*) ' TAI - UTC cannot be given after this date'
       TARTUF = 999.d0
   18  RETURN
       END