c --------------------------------------------------------------c
c Fonction UTMARZ en ligne de commande 
c 
c Effet des marees zonales selon le modele de Yoder (1981) - IERS CONV 2010 sur : 
c                 - UT1
c                 - LOD
c pour une date donnee en jours juliens modifies
c
c Ch. Bizouard - Mars 2023
c --------------------------------------------------------------c   
	   implicit none
	
	   real*8 mjd,utz
	   integer eop,option,w1,w2
	   character*80 c_mjd, c_eop, c_option, c_w1, c_w2

       !  Input :  time in mjd    
	   call getarg(1,c_mjd)  ! MJD
        
	   if (Len_trim(c_mjd).eq.0) then
	   write(6,*) '<< utmarz [mjd] [eop] [w1] [w2] >>'
           write(6,*) '[mjd] .....Modified Julian Date          ' 
	   write(6,*) '[eop] .....1 --> correction on UT1 in ms '		   
	   write(6,*) '           2 --> correction on LOD in ms ' 
	   write(6,*) '-----------------------------------------' 
	   write(6,*) '[w1] ..... First tidal term [1-62]'
	   write(6,*) '[w2] .....  Last tidal term [1-62]'                
                      
   	   stop     
	   endif
		
	   call getarg(2,c_eop)
	   call getarg(3,c_w1)
	   call getarg(4,c_w2)
	
	   read(c_mjd,*) mjd
	   read(c_eop,*) eop
	   read(c_w1,*) w1  
	   read(c_w2,*) w2 
	
	   write(6,*)  utz(mjd,eop,w1,w2)
	
	   end

           FUNCTION UTZ(MJD,eop,w1,w2)

c ======================================================================================= c
c Calcul de l'effet des marees zonales sur UT1/LOD en ms d'apres le modele de Yoder (1981)
c
c Valeurs du modele IERS Conventions 2010 tire de RG_ZONT2.f  - mise a jour du code utz
c
c Cree en Juin 2017 modifie en mars 2023 sur iers                          
c input : MJD..... date MJD
c         eop     ... 1 correction sur UT1   
c                  2 correction sur LOD
c
c         w1 ...  :  premier terme de maree [1-62] 
c         w2         dernier terme de maree [1-62] w2 >= w1
c
c output en ms 
c ======================================================================================= c
      
	   implicit none 
	   double precision MJD,UTZ
	   double precision l,ls,F,D,W,a,DELAU(5),degrad,pi
  
           double precision ARG(12,62)

	   integer eop, w1, w2, n, i, j
	   
	   pi = 4.d0 *datan(1.d0) 	   
	   degrad = pi / 180.d0
	   
c ###########################################
c Based on Yoder et al.(1981),with K/C = 0.94
c ###########################################
  	         
       ! ARGUMENT ( xi)      PERIOD   UT1-UT1R           D-DR                   w-wR                                              
       ! l  ls  F   D   W    DAYS     0.1 ms             0.01ms                 1e-14 rad/s     
       !                               sin       cos        cos       sin         cos       sin
       DATA ( ( ARG(I,J), I=1,12 ), J= 1, 62 ) /
     : 1,  0,  2,  2,  2,    5.64,    -0.0235D0, 0.0000D0,  0.2617D0, 0.0000D0,  -0.2209D0, 0.0000D0,
     : 2,  0,  2,  0,  1,    6.85,    -0.0404D0, 0.0000D0,  0.3706D0, 0.0000D0,  -0.3128D0, 0.0000D0,
     : 2,  0,  2,  0,  2,    6.86,    -0.0987D0, 0.0000D0,  0.9041D0, 0.0000D0,  -0.7630D0, 0.0000D0,
     : 0,  0,  2,  2,  1,    7.09,    -0.0508D0, 0.0000D0,  0.4499D0, 0.0000D0,  -0.3797D0, 0.0000D0,
     : 0,  0,  2,  2,  2,    7.10,    -0.1231D0, 0.0000D0,  1.0904D0, 0.0000D0,  -0.9203D0, 0.0000D0,
     : 1,  0,  2,  0,  0,    9.11,    -0.0385D0, 0.0000D0,  0.2659D0, 0.0000D0,  -0.2244D0, 0.0000D0,
     : 1,  0,  2,  0,  1,    9.12,    -0.4108D0, 0.0000D0,  2.8298D0, 0.0000D0,  -2.3884D0, 0.0000D0,
     : 1,  0,  2,  0,  2,    9.13,    -0.9926D0, 0.0000D0,  6.8291D0, 0.0000D0,  -5.7637D0, 0.0000D0,
     : 3,  0,  0,  0,  0,    9.18,    -0.0179D0, 0.0000D0,  0.1222D0, 0.0000D0,  -0.1031D0, 0.0000D0,
     :-1,  0,  2,  2,  1,    9.54,    -0.0818D0, 0.0000D0,  0.5384D0, 0.0000D0,  -0.4544D0, 0.0000D0,
     :-1,  0,  2,  2,  2,    9.56,    -0.1974D0, 0.0000D0,  1.2978D0, 0.0000D0,  -1.0953D0, 0.0000D0,
     : 1,  0,  0,  2,  0,    9.61,    -0.0761D0, 0.0000D0,  0.4976D0, 0.0000D0,  -0.4200D0, 0.0000D0,
     : 2,  0,  2, -2,  2,   12.81,     0.0216D0, 0.0000D0, -0.1060D0, 0.0000D0,   0.0895D0, 0.0000D0,
     : 0,  1,  2,  0,  2,   13.17,     0.0254D0, 0.0000D0, -0.1211D0, 0.0000D0,   0.1022D0, 0.0000D0,
     : 0,  0,  2,  0,  0,   13.61,    -0.2989D0, 0.0000D0,  1.3804D0, 0.0000D0,  -1.1650D0, 0.0000D0,
     : 0,  0,  2,  0,  1,   13.63,    -3.1873D0, 0.2010D0, 14.6890D0, 0.9266D0,  -12.3974D0,-0.7820D0,
     : 0,  0,  2,  0,  2,   13.66,    -7.8468D0, 0.5320D0, 36.0910D0, 2.4469D0,  -30.4606D0,-2.0652D0,
     : 2,  0,  0,  0, -1,   13.75,     0.0216D0, 0.0000D0, -0.0988D0, 0.0000D0,   0.0834D0, 0.0000D0,
     : 2,  0,  0,  0,  0,   13.78,    -0.3384D0, 0.0000D0,  1.5433D0, 0.0000D0,  -1.3025D0, 0.0000D0,
     : 2,  0,  0,  0,  1,   13.81,     0.0179D0, 0.0000D0, -0.0813D0, 0.0000D0,   0.0686D0, 0.0000D0,
     : 0, -1,  2,  0,  2,   14.19,    -0.0244D0, 0.0000D0,  0.1082D0, 0.0000D0,  -0.0913D0, 0.0000D0,
     : 0,  0,  0,  2, -1,   14.73,     0.0470D0, 0.0000D0, -0.2004D0, 0.0000D0,   0.1692D0, 0.0000D0,
     : 0,  0,  0,  2,  0,   14.77,    -0.7341D0, 0.0000D0,  3.1240D0, 0.0000D0,  -2.6367D0, 0.0000D0,
     : 0,  0,  0,  2,  1,   14.80,    -0.0526D0, 0.0000D0,  0.2235D0, 0.0000D0,  -0.1886D0, 0.0000D0,
     : 0, -1,  0,  2,  0,   15.39,    -0.0508D0, 0.0000D0,  0.2073D0, 0.0000D0,  -0.1749D0, 0.0000D0,
     : 1,  0,  2, -2,  1,   23.86,     0.0498D0, 0.0000D0, -0.1312D0, 0.0000D0,   0.1107D0, 0.0000D0,
     : 1,  0,  2, -2,  2,   23.94,     0.1006D0, 0.0000D0, -0.2640D0, 0.0000D0,   0.2228D0, 0.0000D0,
     : 1,  1,  0,  0,  0,   25.62,     0.0395D0, 0.0000D0, -0.0968D0, 0.0000D0,   0.0817D0, 0.0000D0,
     :-1,  0,  2,  0,  0,   26.88,     0.0470D0, 0.0000D0, -0.1099D0, 0.0000D0,   0.0927D0, 0.0000D0,
     :-1,  0,  2,  0,  1,   26.98,     0.1767D0, 0.0000D0, -0.4115D0, 0.0000D0,   0.3473D0, 0.0000D0,
     :-1,  0,  2,  0,  2,   27.09,     0.4352D0, 0.0000D0, -1.0093D0, 0.0000D0,   0.8519D0, 0.0000D0,
     : 1,  0,  0,  0, -1,   27.44,     0.5339D0, 0.0000D0, -1.2224D0, 0.0000D0,   1.0317D0, 0.0000D0,
     : 1,  0,  0,  0,  0,   27.56,    -8.4046D0, 0.2500D0, 19.1647D0, 0.5701D0, -16.1749D0,-0.4811D0,
     : 1,  0,  0,  0,  1,   27.67,     0.5443D0, 0.0000D0, -1.2360D0, 0.0000D0,   1.0432D0, 0.0000D0,
     : 0,  0,  0,  1,  0,   29.53,     0.0470D0, 0.0000D0, -0.1000D0, 0.0000D0,   0.0844D0, 0.0000D0,
     : 1, -1,  0,  0,  0,   29.80,    -0.0555D0, 0.0000D0,  0.1169D0, 0.0000D0,  -0.0987D0, 0.0000D0,
     :-1,  0,  0,  2, -1,   31.66,     0.1175D0, 0.0000D0, -0.2332D0, 0.0000D0,   0.1968D0, 0.0000D0,
     :-1,  0,  0,  2,  0,   31.81,    -1.8236D0, 0.0000D0,  3.6018D0, 0.0000D0,  -3.0399D0, 0.0000D0,
     :-1,  0,  0,  2,  1,   31.96,     0.1316D0, 0.0000D0, -0.2587D0, 0.0000D0,   0.2183D0, 0.0000D0,
     : 1,  0, -2,  2, -1,   32.61,     0.0179D0, 0.0000D0, -0.0344D0, 0.0000D0,   0.0290D0, 0.0000D0, 
     :-1, -1,  0,  2,  0,   34.85,    -0.0855D0, 0.0000D0,  0.1542D0, 0.0000D0,  -0.1302D0, 0.0000D0,
     : 0,  2,  2, -2,  2,   91.31,    -0.0573D0, 0.0000D0,  0.0395D0, 0.0000D0,  -0.0333D0, 0.0000D0,  
     : 0,  1,  2, -2,  1,  119.61,     0.0329D0, 0.0000D0, -0.0173D0, 0.0000D0,   0.0146D0, 0.0000D0,
     : 0,  1,  2, -2,  2,  121.75,    -1.8847D0, 0.0000D0,  0.9726D0, 0.0000D0,  -0.8209D0, 0.0000D0,
     : 0,  0,  2, -2,  0,  173.31,     0.2510D0, 0.0000D0, -0.0910D0, 0.0000D0,   0.0768D0, 0.0000D0,
     : 0,  0,  2, -2,  1,  177.84,     1.1703D0, 0.0000D0, -0.4135D0, 0.0000D0,   0.3490D0, 0.0000D0,
     : 0,  0,  2, -2,  2,  182.62,   -49.7174D0, 0.4330D0, 17.1056D0, 0.1490D0, -14.4370D0,-0.1257D0,
     : 0,  2,  0,  0,  0,  182.63,    -0.1936D0, 0.0000D0,  0.0666D0, 0.0000D0,  -0.0562D0, 0.0000D0,
     : 2,  0,  0, -2, -1,  199.84,     0.0489D0, 0.0000D0, -0.0154D0, 0.0000D0,   0.0130D0, 0.0000D0,
     : 2,  0,  0, -2,  0,  205.89,    -0.5471D0, 0.0000D0,  0.1670D0, 0.0000D0,  -0.1409D0, 0.0000D0,
     : 2,  0,  0, -2,  1,  212.32,     0.0367D0, 0.0000D0, -0.0108D0, 0.0000D0,   0.0092D0, 0.0000D0,
     : 0, -1,  2, -2,  1,  346.60,    -0.0451D0, 0.0000D0,  0.0082D0, 0.0000D0,  -0.0069D0, 0.0000D0,
     : 0,  1,  0,  0, -1,  346.64,     0.0921D0, 0.0000D0, -0.0167D0, 0.0000D0,   0.0141D0, 0.0000D0,
     : 0, -1,  2, -2,  2,  365.22,     0.8281D0, 0.0000D0, -0.1425D0, 0.0000D0,   0.1202D0, 0.0000D0,
     : 0,  1,  0,  0,  0,  365.26,   -15.8887D0, 0.1530D0,  2.7332D0, 0.0267D0,  -2.3068D0,-0.0222D0,
     : 0,  1,  0,  0,  1,  386.00,    -0.1382D0, 0.0000D0,  0.0225D0, 0.0000D0,  -0.0190D0, 0.0000D0,
     : 1,  0,  0, -1,  0,  411.78,     0.0348D0, 0.0000D0, -0.0053D0, 0.0000D0,   0.0045D0, 0.0000D0,
     : 2,  0, -2,  0,  0, 1095.17,    -0.1372D0, 0.0000D0, -0.0079D0, 0.0000D0,   0.0066D0, 0.0000D0,
     :-2,  0,  2,  0,  1, 1305.47,     0.4211D0, 0.0000D0, -0.0203D0, 0.0000D0,   0.0171D0, 0.0000D0,
     :-1,  1,  0,  1,  0, 3232.85,    -0.0404D0, 0.0000D0,  0.0008D0, 0.0000D0,  -0.0007D0, 0.0000D0, 
     : 0,  0,  0,  0,  2, 3399.18,     7.8998D0, 0.0000D0,  0.1460D0, 0.0000D0,  -0.1232D0, 0.0000D0,
     : 0,  0,  0,  0,  1, 6790.36, -1617.2681D0, 0.0000D0,-14.9471D0, 0.0000D0,  12.6153D0, 0.0000D0/


c Delaunay arguments : following approximate expressions are sufficient for computing zonal tides effects :
         
	   DELAU(1)  = (134.96d0 + 13.064993d0 * (MJD-51544.5d0) ) * degrad  ! Mean anomaly of the Moon      
	   DELAU(2)  = (357.53d0 +  0.985600d0 * (MJD-51544.5d0) ) * degrad  ! Mean anomaly of the Sun            
	   DELAU(3)  = ( 93.27d0 + 13.229350d0 * (MJD-51544.5d0) ) * degrad  ! L -W  with L : mean longitude of the Moon			
	   DELAU(4)  = (297.85d0 + 12.190749d0 * (MJD-51544.5d0) ) * degrad  ! Mean elongation of the Moon from the Sun            
	   DELAU(5)  = (125.04d0 -  0.052954d0 * (MJD-51544.5d0) ) * degrad  ! Mean longitude of the ascending node of the Moon
         	   
	   UTZ = 0.d0		    
	
	    
	   do i= w1, w2	   
		   a = 0.d0
	   
		   do j = 1,5
		   a = a + ARG(j,i) * DELAU(j)
		   enddo
	   	   a = dmod(a,2.d0*pi) 
		   
	   	   if (eop.eq.1) UTZ = UTZ + ( ARG(7,i) * dsin(a) + ARG(8,i)  * dcos(a) ) / 10.d0   ! UT1 ms
		   if (eop.eq.2) UTZ = UTZ + ( ARG(9,i) * dcos(a) + ARG(10,i) * dsin(a) ) / 100.d0  ! LOD ms
	   
	   enddo
	   	   
	   end 
	   
