      PROGRAM V1_0test

      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      PARAMETER(pi=3.141592653589793D0)
      DIMENSION ELEM(6)
      DATA gk,UA/0.01720209895d0, 149597870.691d0/ !! UA valeur DE406

      WRITE(*,*)'Entrez nsat'
      READ(*,*) nsat
      WRITE(*,*)'Entrez la date'
      READ(*,*) ET

      CALL MarsSatV1_0(ET, nsat, 1, ELEM)
!       open(30,file='essai.res')
!       DO i=0,6
!         ET=0.d0+i*10.d0
!         CALL MarsSatV1_0(ET, 1, 1, ELEM)
!         ET=0.d0+i*10.d0
!         WRITE(30,'(f10.2,f8.2,6f16.12)') 2451545.d0+ET, ET, ELEM
!       ENDDO !i
!         WRITE(30,*)'deimos'
!       DO i=0,6
!         ET=0.d0+i*10.d0
!         CALL MarsSatV1_0(ET, 2, 1, ELEM)
!         ET=0.d0+i*10.d0
!         WRITE(30,'(f10.2,f8.2,6f16.12)') 2451545.d0+ET, ET, ELEM
!       ENDDO !i
!      close(30)
!      STOP

      WRITE(*,*)'         '
      WRITE(*,*) ELEM*UA ! pour avoir des kilometres
      WRITE(*,*)'         '
      WRITE(*,*) ELEM ! pour rester en UA et UA/jour (unites par defaut)

c      CALL V1_1(ET,nsat,1,0,ELEM) ! si on desire des elements elliptiques

c      WRITE(*,*)'Voici la longitude'
c      WRITE(*,*)ELEM(2)

c      WRITE(*,*)'Voici la longitude du perijove'
c      PERI=DATAN2(ELEM(4),ELEM(3))
c      IF(PERI.LT.0.D0)PERI=PERI+2.D0*pi
c      WRITE(*,*)PERI

c      WRITE(*,*)'Voici la longitude du noeud'
c      PNOEUD=DATAN2(ELEM(6),ELEM(5))
c      IF(PNOEUD.LT.0.D0)PNOEUD=PNOEUD+2.D0*pi
c      WRITE(*,*)PNOEUD

      END

      SUBROUTINE MarsSatV1_0(ET, nsat, iv, ELEM) 

      !********************************************************************
      !*              Ephemerides of the Martian satellites               *
      !*                (adjustement from 1877 to 2005)                   *
      !*                                                                  *
      !*                        (Version 1.0)                             *
      !*                                                                  *
      !*------------------------------------------------------------------*
      !*                   V.Lainey (Lainey@oma.be)                       *
      !*                                                                  *
      !*    ROB- 3, Avenue Circulaire, B-1180 Bruxelles (Belgium)         *
      !*------------------------------------------------------------------*
      !*    IMCCE - 77, Avenue Denfert-Rochereau 75014 Paris (France)     *
      !*__________________________________________________________________*
      !*                                                                  *
      !*  ET : Julian day starting at the epoch 01/01/2000 at 12am (TDB)  *
      !* nsat: satellite number (1=Phobos, 2=Deimos)                      *
      !*  iv : output type (0=elliptical elements, 1=J2000-XYZ)           *
      !*                                                                  *
      !* ELEM: output (a,l,Z,ZETA) or (x,y,z,vx,vy,vz)                    *
      !*------------------------------------------------------------------*
      !* references:                                                      *
      !*            (Lainey, Dehant and Patzold, to be submited)          *
      !*             Lainey, Dehant, Oberst and Patzold, AGU 2005         *
      !********************************************************************
      !*                          28/11/2005                              *
      !********************************************************************

      IMPLICIT NONE 
      DOUBLE PRECISION pi, gk2, enrad, L, MU, ome0, ainc0, ome, ainc,
     & dome, dainc, xmu, ACC, ELEM, XV, ET, DAT, EL1Aa, EL1La, EL1Za, 
     & EL1ZETAa, EL1Ap, EL1Lp, EL1Zp, EL1ZETAp, EL1Af, EL1Lf, EL1Zf,
     & EL1ZETAf, EL2Aa, EL2La, EL2Za, EL2ZETAa, EL2Ap, EL2Lp, EL2Zp,
     & EL2ZETAp, EL2Af, EL2Lf, EL2Zf, EL2ZETAf, ELA, ELL, ELZ, ELZETA,
     & DAT2

      INTEGER nf1, nf2, nf, i, j, nsat, iv
      PARAMETER(pi=3.141592653589793D0, gk2=0.01720209895d0**2, 
     & enrad=0.017453292519943d0)
      DIMENSION ELEM(6), L(2), XV(6), MU(2), ACC(2), nf1(4), nf2(4), 
     & nf(4), EL1Aa(33), EL1La(57), EL1Za(28), EL1ZETAa(29), 
     & EL1Ap(33), EL1Lp(57), EL1Zp(28), EL1ZETAp(29), 
     & EL1Af(33), EL1Lf(57), EL1Zf(28), EL1ZETAf(29), 
     & EL2Aa(50), EL2La(30), EL2Za(17), EL2ZETAa(28),
     & EL2Ap(50), EL2Lp(30), EL2Zp(17), EL2ZETAp(28),
     & EL2Af(50), EL2Lf(30), EL2Zf(17), EL2ZETAf(28), 
     & ELA(57,3), ELL(57,3), ELZ(57,3), ELZETA(57,3)

      COMPLEX*16:: ICOMP, RESULT

      ICOMP=(0.d0,1.d0)

      DATA L/ 19.7020556283139d0, 4.9770138896523d0/
      DATA ome0, ainc0/ 47.68143d0, 37.1135d0/
      DATA dome, dainc/ -0.1061d0, 0.0609d0/
      DATA MU/ 3.2271557149889D-07, 3.2271556750209D-07/
      DATA ACC(1), ACC(2)/1.657852042683113d-10,-2.331793571572226d-14/

      DATA nf1/ 33, 57, 28, 29/
      DATA nf2/ 50, 30, 17, 28/

      DATA EL1Aa/ 0.00006269161880d0, 0.00000000226877d0, 
     & 0.00000000226877d0, 0.00000000036560d0, 0.00000000036560d0,
     & 0.00000000038928d0, 0.00000000038928d0, 0.00000000017647d0,
     & 0.00000000017647d0, 0.00000000010473d0, 0.00000000010473d0, 
     & 0.00000000004570d0, 0.00000000004570d0, 0.00000000003102d0,
     & 0.00000000003102d0, 0.00000000002648d0, 0.00000000002648d0,
     & 0.00000000000906d0, 0.00000000000906d0, 0.00000000000782d0,
     & 0.00000000000782d0, 0.00000000000768d0, 0.00000000000768d0,
     & 0.00000000000652d0, 0.00000000000652d0, 0.00000000000831d0,
     & 0.00000000000831d0, 0.00000000000664d0, 0.00000000000664d0,
     & 0.00000000000428d0, 0.00000000000428d0, 0.00000000000362d0, 
     & 0.00000000000362d0/

      DATA EL1Ap/ 0.00000000d0,-0.23137652d0, 0.23137652d0,
     & 0.31903311d0,-0.31903311d0,-0.15425102d0, 0.15425102d0,
     & 0.46275305d0,-0.46275305d0,-0.13411243d0, 0.13411243d0,
     & 0.11568826d0,-0.11568826d0,-0.84211324d0, 0.84211324d0,
     & 0.10397809d0,-0.10397809d0, 0.15952911d0,-0.15952911d0,
     & 0.10875357d0,-0.10875357d0, 0.29864398d0,-0.29864398d0,
     & -0.18884134d0, 0.18884134d0, 0.15951656d0,-0.15951656d0,
     & 0.84383237d0,-0.84383237d0,-0.15939353d0, 0.15939353d0,
     & -0.10628011d0, 0.10628011d0/

      DATA EL1Af/ 0.000000000000d0, 1.269694941721d0,
     & -1.269694972385d0, 0.683991069326d0,-0.683991048830d0,
     & 1.769154106463d0,-1.769154016711d0,-0.751833721919d0,
     & 0.751833534661d0, 0.582878090440d0,-0.582877938274d0,
     & -2.055123065092d0, 2.055123107938d0,-1.167907572776d0,
     & 1.167907593259d0,-1.085910468998d0, 1.085910738159d0,
     & -1.123139908698d0, 1.123139843925d0, 2.223276867087d0,
     & -2.223277592714d0, 0.692161581064d0,-0.692161667059d0,
     & 0.067382573233d0,-0.067382536015d0, 1.368231513583d0,
     & -1.368231474439d0, 0.260153915930d0,-0.260153924005d0,
     & -0.059038385412d0, 0.059038528330d0, 0.103874462974d0,
     & -0.103874462966d0/

      DATA EL1La/ 2.09129739264173d0, 0.00005016848130d0, 
     & 0.00005016848130d0, 0.00003350264970d0, 0.00003350264903d0,
     & 0.00002827839093d0, 0.00002827839093d0, 0.00001578862428d0,
     & 0.00001578862427d0, 0.00001504422160d0, 0.00001504422160d0,
     & 0.00000817856317d0, 0.00000817856334d0, 0.00001022163922d0,
     & 0.00001022163922d0, 0.00000651695172d0, 0.00000651695172d0,
     & 0.00000506658494d0, 0.00000506658494d0, 0.00000374173438d0,
     & 0.00000374173438d0, 0.00000258935939d0, 0.00000258935939d0,
     & 0.00000112514742d0, 0.00000112514742d0, 0.00000076176630d0,
     & 0.00000076176630d0, 0.00000049765123d0, 0.00000049765123d0,
     & 0.00000068419668d0, 0.00000068419668d0, 0.00000056243429d0,
     & 0.00000056243429d0, 0.00000039367057d0, 0.00000039367057d0,
     & 0.00000052032286d0, 0.00000052032286d0, 0.00000035833947d0,
     & 0.00000035833947d0, 0.00000030110114d0, 0.00000030110114d0,
     & 0.00000019649769d0, 0.00000019649645d0, 0.00000024936539d0,
     & 0.00000024936539d0, 0.00000024024140d0, 0.00000024024140d0,
     & 0.00000017471331d0, 0.00000017471331d0, 0.00000017930767d0,
     & 0.00000017930768d0, 0.00000013268776d0, 0.00000013268776d0,
     & 0.00000012696364d0, 0.00000012696364d0, 0.00000012547154d0,
     & 0.00000012547155d0/

      DATA EL1Lp/ 0.00000000d0, 686.99369592d0, -686.99369241d0,
     &  -4077.46840757d0,   4077.46821917d0,   -343.48537930d0,   
     & 343.48537949d0,    826.22438660d0,   -826.22438999d0,     
     & 0.23137650d0,     -0.23137650d0,   2026.08615872d0,  
     & -2026.08614258d0,     -0.31903309d0,      0.31903309d0,   
     & 228.99331848d0,   -228.99331849d0,      0.46275300d0,    
     & -0.46275300d0,      0.15425100d0,     -0.15425100d0,  
     & -242.61956612d0,    242.61956592d0,   -171.74597329d0,   
     & 171.74597310d0,      0.13411241d0,     -0.13411241d0,  
     & -375.12500185d0,    375.12500278d0,   -413.26245099d0,   
     & 413.26245103d0,    179.29817450d0,   -179.29817450d0,    
     & -1.02723078d0,      1.02723078d0,     -0.11568825d0,     
     & 0.11568825d0,      0.84211307d0,     -0.84211307d0,    
     & -4.78104120d0,      4.78104120d0,  -8341.85985545d0,  
     & 8341.72443362d0,      0.15952910d0,     -0.15952910d0,    
     & -0.10397808d0,      0.10397808d0,   -137.39750245d0,   
     & 137.39750251d0,   1035.39217901d0,  -1035.39219300d0,     
     &  0.15951654d0,     -0.15951654d0,     -0.18884132d0,     
     & 0.18884132d0,   -513.09805470d0,    513.09805450d0/

      DATA EL1Lf/ -0.000000000014d0, -0.949015738908d0, 
     & 0.949016158884d0, -0.380534526596d0,  0.380533948496d0,
     & 0.994821588644d0, -0.994821497820d0, -2.870499589128d0, 
     & 2.870499308383d0, -2.834185436330d0,  2.834185466290d0, 
     & 0.919444544403d0, -0.919444319278d0,  0.895559796633d0,
     & -0.895559859111d0,  2.848996739890d0, -2.848996748767d0,
     & -2.328774139340d0,  2.328774139340d0,  2.912659020395d0,
     & -2.912659547077d0,  2.215327142355d0, -2.215327333708d0,
     & -0.377627161385d0,  0.377626798556d0, -2.161248941800d0, 
     & 2.161248590720d0, -1.231836210236d0,  1.231836585135d0,
     & -2.488083095032d0,  2.488083105051d0,  1.576141879515d0,
     & -1.576141881804d0,  0.137856626591d0, -0.137856591483d0,
     & -2.626756099135d0,  2.626756111094d0,  2.759579592331d0,
     & -2.759579510413d0,  0.277512180092d0, -0.277511887506d0,
     & -0.093530900566d0,  0.093432654525d0,  0.430292851332d0,
     & -0.430292825369d0,  2.695745393985d0, -2.695745301579d0, 
     & 2.099637656810d0, -2.099637491253d0, -0.693740926999d0, 
     & 0.693740188061d0, -0.220489234489d0,  0.220488707822d0, 
     & 1.654303228826d0, -1.654303208682d0,  1.546722735399d0, 
     &-1.546722718402d0/

      DATA EL1Za/0.01514110912521d0,0.00038496208674d0,
     & 0.00006903413242d0,0.00004946101994d0,0.00003671320788d0,
     & 0.00003267983782d0,0.00000875048305d0,0.00000617093881d0,
     & 0.00000695700594d0,0.00000573408896d0,0.00000343157786d0,
     & 0.00000403740951d0,0.00000211529622d0,0.00000190482762d0,
     & 0.00000084613232d0,0.00000086960947d0,0.00000063298682d0,
     & 0.00000061303178d0,0.00000057372171d0,0.00000081810883d0,
     & 0.00000074341453d0,0.00000054416478d0,0.00000050445150d0,
     & 0.00000042845991d0,0.00000042249373d0,0.00000035819498d0,
     & 0.00000038088812d0,0.00000040557392d0/

      DATA EL1Zp/ 827.21507332d0, 0.31891012d0, 587.39458533d0,  
     & -826.16172371d0,      0.13409069d0,     -0.84297139d0,    
     &  0.15948580d0,      1.02595676d0,      0.10396503d0,   
     & 316.64130873d0,      0.18879824d0,     -0.29875184d0, 
     &  4054.54269012d0,     -0.10629376d0,      0.00000000d0,   
     &  -0.12164857d0,    686.47877752d0,    375.32150909d0, 
     & -4052.07162766d0,      0.23131182d0,    216.74351242d0,   
     &  -0.23144126d0,     -0.13798985d0,     -0.31920648d0,   
     &  -0.18154621d0,    242.67861994d0,   1035.98671884d0,  
     &  2043.26880788d0/

      DATA EL1Zf/  1.404382124885d0,  2.088385523034d0, 
     & -2.387807946031d0,  0.498957209475d0,  0.821521022172d0, 
     & -2.905108919700d0,  2.772375719698d0,  2.839303414769d0,  
     & 0.318450317043d0,  1.410329121503d0,  1.336796551701d0,
     & -2.429538561192d0,  0.254706736621d0,  1.508224230072d0, 
     & 2.321836603108d0,  0.034626075514d0, -3.084529992972d0,
     & -1.119230636263d0,  0.780393743699d0, -3.018597072641d0,
     & -1.071855877472d0,  2.691716763490d0,  1.001733960626d0, 
     & -3.071035704337d0, -2.137527057619d0, -1.219306169725d0, 
     & 2.558639707373d0, -0.990686281624d0/

      DATA EL1ZETAa/0.00940860518312d0,0.00007892894454d0,
     & 0.00005699538102d0,0.00002474369483d0,0.00002062715397d0,
     & 0.00000594557416d0,0.00000392019020d0,0.00000216779197d0,
     & 0.00000276976375d0,0.00000181353917d0,0.00000108342918d0,
     & 0.00000106665701d0,0.00000079098533d0,0.00000088808851d0,
     & 0.00000055207589d0,0.00000043978860d0,0.00000045836091d0,
     & 0.00000035331311d0,0.00000035029885d0,0.00000038288517d0,
     & 0.00000027112473d0,0.00000019917454d0,0.00000020368977d0,
     & 0.00000017267796d0,0.00000015744728d0,0.00000016985677d0,
     & 0.00000010150045d0,0.00000008259149d0,0.00000008504923d0/

      DATA EL1ZETAp/-826.20642714d0,0.00000000d0,-686.99749665d0,  
     &  343.48630483d0,    827.20268346d0,    228.99362064d0,   
     & 687.00755782d0,   -343.48244903d0,     -0.84297139d0,      
     & 0.15942429d0,      0.31891012d0,    171.74558971d0,   
     & 242.62779510d0,     -4.75353965d0,      1.02595676d0,     
     & 0.13409069d0,   -228.99359936d0,   -374.99999997d0,  
     & 4073.32789493d0,      0.51266007d0,    587.77857598d0, 
     &  -242.62375723d0,    179.29612278d0,      0.23144134d0,   
     &  -0.29875184d0,    137.41607584d0,      0.18879824d0,    
     & -0.31890996d0,  -1028.57142835d0/

      DATA EL1ZETAf/  2.058107128488d0, -2.386965958787d0, 
     & -3.034328817803d0, -1.725904319907d0, -0.169761953966d0, 
     & 2.067112903892d0,  1.700689207004d0, -2.706125953253d0,
     & -1.342900415409d0,  2.117885747855d0,  0.517605536523d0,
     & -0.418936524968d0, -3.042493138839d0,  0.757075199434d0, 
     & 0.660891079606d0, -0.763516173091d0, -0.439185212306d0,
     & -1.680429911951d0,  2.685649467156d0, -2.930008429370d0, 
     & 2.556761413073d0, -1.660815588764d0,  0.749769089433d0,
     & -2.317979704428d0, -1.539326818938d0, -2.877315237045d0, 
     & 0.374238084921d0,  1.374678754422d0,  1.140160118874d0/

      DATA EL2Aa/ 0.00015681340867d0,  0.00000000269918d0, 
     & 0.00000000269918d0,  0.00000000035476d0,  0.00000000035476d0, 
     &   0.00000000018689d0,  0.00000000018689d0,  0.00000000011687d0, 
     &   0.00000000011687d0,  0.00000000008485d0,  0.00000000008485d0, 
     &   0.00000000002657d0,  0.00000000002657d0,  0.00000000003523d0, 
     &   0.00000000003523d0,  0.00000000002117d0,  0.00000000002117d0,  
     &  0.00000000001407d0,  0.00000000001407d0,  0.00000000001275d0,  
     &  0.00000000001275d0,  0.00000000000838d0,  0.00000000000838d0,  
     &  0.00000000000486d0,  0.00000000000486d0,  0.00000000000476d0, 
     &   0.00000000000476d0,  0.00000000000487d0,  0.00000000000487d0, 
     &   0.00000000000514d0,  0.00000000000514d0,  0.00000000000334d0, 
     &   0.00000000000334d0,  0.00000000000344d0,  0.00000000000344d0, 
     &   0.00000000000310d0,  0.00000000000310d0,  0.00000000000268d0, 
     &   0.00000000000268d0,  0.00000000000168d0,  0.00000000000168d0, 
     &   0.00000000000146d0,  0.00000000000146d0,  0.00000000000149d0, 
     &   0.00000000000149d0,  0.00000000000132d0,  0.00000000000132d0, 
     &   0.00000000000102d0,  0.00000000000102d0,  0.00000000000109d0/

      DATA EL2Ap/   0.00000000d0,    2.73847176d0,  -2.73847176d0, 
     &     0.63238251d0,   -0.63238251d0,    1.82564784d0,   
     &  -1.82564784d0,   -0.63296515d0,    0.63296515d0,    
     &  5.47694352d0,   -5.47694352d0,    0.63354887d0,   -0.63354887d0, 
     &     0.63122038d0,   -0.63122038d0,    0.63180092d0,   
     &  -0.63180092d0,    2.73884829d0,   -2.73884829d0,   
     &  -2.73809533d0,    2.73809533d0,    1.36923588d0,   
     &  -1.36923588d0,   -0.63118038d0,    0.63118038d0,   
     &   0.63064094d0,   -0.63064094d0,   -0.42669999d0,    
     &  0.42669999d0,    0.63413367d0,   -0.63413367d0,    
     &  2.34192368d0,   -2.34192368d0,    2.34247408d0,   -2.34247408d0, 
     &     0.63236243d0,   -0.63236243d0,   -1.26252066d0,    
     &  1.26252066d0,    0.63240258d0,   -0.63240258d0,   -1.82581518d0, 
     &     1.82581518d0,    2.34219905d0,   -2.34219905d0,   
     &  -1.82548053d0,    1.82548053d0,    0.63294504d0,   
     &  -0.63294504d0,  2.72759910d0/

      DATA EL2Af/   0.000000000000d0,  -0.136381775523d0,   
     &  0.136381777698d0,  -2.850380153005d0,   2.850380089315d0, 
     &   -1.926604205693d0,   1.926604195461d0,   0.367583823079d0, 
     &   -0.367583824486d0,   1.615243161942d0,  -1.615243160951d0,  
     &   2.114704903813d0,  -2.114704908419d0,   0.939338838730d0,  
     &  -0.939338816854d0,  -2.333690484620d0,   2.333690544274d0,  
     &   2.089322500989d0,  -2.089322282950d0,  -0.779557024035d0,  
     &   0.779557327338d0,   2.361851648242d0,  -2.361851691087d0,   
     & -2.770026814512d0,   2.770026952645d0,  -1.549662975963d0,   
     &  1.549663021137d0,   3.024403974280d0,  -3.024403881041d0,   
     & -1.686885659588d0,   1.686885282544d0,   3.057688429345d0,   
     & -3.057688457348d0,  -0.829253165285d0,   0.829253093148d0,  
     &  -1.954686031809d0,   1.954686103625d0,  -2.168321203999d0,   
     &  2.168321557125d0,   2.516818643150d0,  -2.516818534200d0,  
     &  -0.299782666734d0,   0.299782747411d0,   2.143143410577d0,  
     &  -2.143143430348d0,   1.011403786810d0,  -1.011403745572d0,   
     &  0.538228537741d0,  -0.538228903445d0,  -2.653997343428d0/

      DATA EL2La/   1.91675212352556d0,   0.00248303166019d0,   
     &  0.00248303165949d0,   0.00020234269782d0,   0.00020234269782d0,   
     &  0.00010431675642d0,   0.00010431675643d0,   0.00008185668873d0,   
     &  0.00008185668873d0,   0.00002410335710d0,   0.00002410335710d0,   
     &  0.00001497066023d0,   0.00001497066034d0,   0.00000568514429d0,   
     &  0.00000568514429d0,   0.00000417530493d0,   0.00000417530493d0,   
     &  0.00000438325450d0,   0.00000438325450d0,   0.00000415808821d0,   
     &  0.00000415808821d0,   0.00000322379379d0,   0.00000322379379d0,   
     &  0.00000396334370d0,   0.00000396334370d0,   0.00000390506421d0,   
     &  0.00000311780183d0,   0.00000390506421d0,   0.00000311780183d0,   
     &  0.00000165754846d0/

      DATA EL2Lp/       0.00000000d0,   -19925.25479395d0,    
     &  19925.25482649d0,     -686.99361389d0,      686.99361415d0, 
     &      -343.48525280d0,      343.48525251d0,        2.73847175d0,        
     & -2.73847175d0,     -228.99419233d0,      228.99419233d0,      
     & -337.66341441d0,      337.66341418d0,        5.47694261d0,       
     &  -5.47694261d0,        1.82564754d0,       -1.82564754d0,   
     &   10149.06972719d0,   -10149.06971679d0,      171.76869151d0,     
     &  -171.76869151d0,      226.39849071d0,     -226.39849071d0,       
     &  -0.63238250d0,        0.63238250d0,     -711.69825336d0,     
     &  -663.85314762d0,      711.69825335d0,      663.85314763d0,        
     &  0.00000000d0/

      DATA EL2Lf/ -3.141592653540d0,  -2.488175621789d0,   
     &  2.488175634463d0,   0.946296042215d0,  -0.946295960274d0,   
     &  1.001646985816d0,  -1.001647348657d0,   1.433490072350d0,   
     & -1.433489965321d0,  -2.852007788402d0,   2.852007788273d0,   
     &  3.136008703144d0,  -3.136009000145d0,  -3.100668654449d0,   
     &  3.100668633924d0,  -0.366003419529d0,   0.366003444013d0,   
     & -2.738313647435d0,   2.738313658144d0,   0.461419338359d0,   
     & -0.461419338359d0,   0.675422268593d0,  -0.675422268593d0,   
     &  1.281544455534d0,  -1.281544458794d0,   1.797966683376d0,  
     &  -0.222101391798d0,  -1.797966684284d0,   0.222101394466d0,   
     & -3.141592653523d0 /

      DATA EL2Za/   0.00027441315346d0,   0.00006015912711d0,  
     &   0.00003534984782d0,   0.00003614585349d0,   0.00002577157903d0,   
     &  0.00000680199783d0,   0.00000445297914d0,   0.00000223848292d0,   
     &  0.00000092341709d0,   0.00000147874757d0,   0.00000145772004d0,   
     &  0.00000134703031d0,   0.00000075381791d0,   0.00000087162297d0,   
     &  0.00000101564888d0,   0.00000050909893d0,   0.00000065370775d0/

      DATA EL2Zp/  19956.74479178d0,       1.26244078d0,       
     &  0.00000000d0,  -19926.60456897d0,       2.34219912d0,      
     &  -1.26709782d0,       4.09222912d0,      -1.26943918d0,       
     &  0.00000000d0,   26995.13970336d0,   16059.93520224d0,      
     &   0.86409248d0,       0.42132977d0,     349.50296239d0,     
     &   16.18594275d0,      -1.27178920d0,      -1.26244078d0 /

      DATA EL2Zf/  2.198649419514d0,  -1.916548788202d0,  
     &   2.345230773944d0,   1.463816210370d0,   1.362467588064d0,  
     &   0.933679289332d0,  -3.130753296830d0,  -1.549133813261d0,  
     &   0.599042274749d0,  -0.546542453837d0,  -1.198239348674d0,  
     &  -2.050414656408d0,   1.516439412109d0,   3.100618466711d0,  
     &  -1.127752616215d0,   2.250768124831d0,  -2.860933968311d0 /

      DATA EL2ZETAa/ 0.01562693319959d0,  0.00775101287565d0,  
     &  0.00013218186311d0,  0.00003833652719d0,  0.00002660211842d0, 
     &   0.00002882438535d0,  0.00002713213911d0,  0.00000929632495d0,  
     &  0.00000446096029d0,  0.00000490415603d0,  0.00000236688115d0,  
     &  0.00000205755285d0,  0.00000236575014d0,  0.00000122881444d0,  
     &  0.00000121518946d0,  0.00000096028570d0,  0.00000117447177d0,  
     &  0.00000105844105d0,  0.00000238314749d0,  0.00000076563038d0,  
     &  0.00000040758243d0,  0.00000049623409d0,  0.00000030030779d0,  
     &  0.00000026134164d0,  0.00000028919452d0,  0.00000022137882d0,  
     &  0.00000024499503d0,  0.00000016524166d0/

      DATA EL2ZETAp/ -19916.19973129d0,       0.00000000d0,    
     &   343.48730623d0,    -686.99215577d0,     687.01233091d0,     
     &  228.99391436d0,   19892.53158003d0,     337.66474671d0,    
     &  -343.48211159d0,     171.74656701d0,    -664.09364734d0,     
     &  226.39163557d0,     711.55812043d0,    -337.66025169d0,     
     &  349.52237555d0,  -10037.28889631d0,    -228.99413227d0,     
     &  664.12627842d0,   37351.49200304d0,     137.38646249d0,     
     &  170.59316073d0,       0.63120042d0,    -226.50126587d0,    
     &  -705.59895012d0,     231.14050852d0,    -171.66458272d0,       
     &  0.63238270d0,     692.28265851d0/

      DATA EL2ZETAf/ 2.981506933511d0, -2.386504179132d0, 
     &  -1.725684412813d0, -3.035061242067d0,  1.701551338710d0,  
     &  2.067662003165d0, -1.477858084701d0,  2.318788380092d0,  
     & -2.669604598165d0, -0.415374756507d0, -0.786669759362d0,  
     & -0.162822349334d0, -2.670796098338d0, -0.729022305245d0,  
     & -2.721699324043d0,  1.941975361869d0, -0.437940530420d0,  
     &  1.821048365911d0,  0.758713545461d0, -2.990293668575d0, 
     &  -2.517169198799d0, -0.535940350960d0,  1.724062868741d0, 
     &  -1.853437577537d0,  0.865916190901d0,  2.259603352363d0,  
     &  1.108725025984d0,  1.680391963791d0 /

      DAT=ET
      DAT2=ET+6491.5d0 !retour a la date du 2445053.5 (25/03/1982, 0H00am)

      IF(nsat.EQ.1)THEN
        DO i=1,4
          nf(i)=nf1(i)
        ENDDO
        DO i=1,nf(1)
          ELA(i,1)=EL1Aa(i)
          ELA(i,2)=EL1Ap(i)
          ELA(i,3)=EL1Af(i)
        ENDDO !i
        DO i=1,nf(2)
          ELL(i,1)=EL1La(i)
          ELL(i,2)=EL1Lp(i)
          ELL(i,3)=EL1Lf(i)
       ENDDO !i
        DO i=1,nf(3)
          ELZ(i,1)=EL1Za(i)
          ELZ(i,2)=EL1Zp(i)
          ELZ(i,3)=EL1Zf(i)
       ENDDO !i
        DO i=1,nf(4)
          ELZETA(i,1)=EL1ZETAa(i)
          ELZETA(i,2)=EL1ZETAp(i)
          ELZETA(i,3)=EL1ZETAf(i)
       ENDDO !i
      ELSE
        DO i=1,4
          nf(i)=nf2(i)
        ENDDO
        DO i=1,nf(1)
          ELA(i,1)=EL2Aa(i)
          ELA(i,2)=EL2Ap(i)
          ELA(i,3)=EL2Af(i)
        ENDDO !i
        DO i=1,nf(2)
          ELL(i,1)=EL2La(i)
          ELL(i,2)=EL2Lp(i)
          ELL(i,3)=EL2Lf(i)
       ENDDO !i
        DO i=1,nf(3)
          ELZ(i,1)=EL2Za(i)
          ELZ(i,2)=EL2Zp(i)
          ELZ(i,3)=EL2Zf(i)
       ENDDO !i
        DO i=1,nf(4)
          ELZETA(i,1)=EL2ZETAa(i)
          ELZETA(i,2)=EL2ZETAp(i)
          ELZETA(i,3)=EL2ZETAf(i)
       ENDDO !i
      ENDIF

      RESULT=0.d0
      DO i=1,nf(1)
         IF (ELA(i,2).EQ.0.d0) THEN
            RESULT=RESULT+ELA(i,1)*EXP(ICOMP*ELA(i,3))
         ELSE
            RESULT=RESULT+ELA(i,1)*EXP(ICOMP*((2.d0*pi/ELA(i,2))*DAT2 
     &       +ELA(i,3)))
         ENDIF
      ENDDO !i
      ELEM(1)=DREAL(RESULT)

      RESULT=0.d0
      DO i=1,nf(2)
         IF (ELL(i,2).EQ.0.d0) THEN
            RESULT=RESULT+ELL(i,1)*EXP(ICOMP*ELL(i,3))
         ELSE
            RESULT=RESULT+ELL(i,1)*EXP(ICOMP*((2.d0*pi/ELL(i,2))*DAT2 
     &       +ELL(i,3)))
         ENDIF
      ENDDO !i
      ELEM(2)=DREAL(RESULT)

      RESULT=0.d0
      DO i=1,nf(3)
         IF (ELZ(i,2).EQ.0.d0) THEN
            RESULT=RESULT+ELZ(i,1)*EXP(ICOMP*ELZ(i,3))
         ELSE
            RESULT=RESULT+ELZ(i,1)*EXP(ICOMP*((2.d0*pi/ELZ(i,2))*DAT2 
     &       +ELZ(i,3)))
         ENDIF
      ENDDO !i
      ELEM(3)=DREAL(RESULT)
      ELEM(4)=DIMAG(RESULT)

      RESULT=0.d0
      DO i=1,nf(4)
         IF (ELZETA(i,2).EQ.0.d0) THEN
            RESULT=RESULT+ELZETA(i,1)*EXP(ICOMP*ELZETA(i,3))
         ELSE
            RESULT=RESULT+ELZETA(i,1)*EXP(ICOMP*((2.d0*pi  
     &       /ELZETA(i,2))*DAT2+ELZETA(i,3)))
         ENDIF
      ENDDO !i
      ELEM(5)=DREAL(RESULT)
      ELEM(6)=DIMAG(RESULT)

      ELEM(2)=ELEM(2)+L(nsat)*DAT2+ACC(nsat)*DAT2**2
      ELEM(2)=DATAN2(DSIN(ELEM(2)),DCOS(ELEM(2)))
      IF(ELEM(2).LT.0.D0) ELEM(2)=ELEM(2)+2.D0*pi

      IF(iv.EQ.1)THEN
        xmu=MU(nsat)*gk2
        ome=(ome0+dome*DAT/36525.d0)*enrad
        ainc=(ainc0+dainc*DAT/36525.d0)*enrad
        CALL ELEM2PV(xmu,ELEM,XV)
        ELEM(1)=XV(1)*DCOS(ome)-XV(2)*DSIN(ome)*DCOS(ainc)
     &   +XV(3)*DSIN(ainc)*DSIN(ome)
        ELEM(2)=XV(1)*DSIN(ome)+XV(2)*DCOS(ome)*
     &   DCOS(ainc)-XV(3)*DSIN(ainc)*DCOS(ome)      
        ELEM(3)=XV(2)*DSIN(ainc)+XV(3)*DCOS(ainc)
        ELEM(4)=XV(4)*DCOS(ome)-XV(5)*DSIN(ome)*DCOS(ainc)
     &   +XV(6)*DSIN(ainc)*DSIN(ome)
        ELEM(5)=XV(4)*DSIN(ome)+XV(5)*DCOS(ome)*
     &   DCOS(ainc)-XV(6)*DSIN(ainc)*DCOS(ome)      
        ELEM(6)=XV(5)*DSIN(ainc)+XV(6)*DCOS(ainc)
      ENDIF

      RETURN
      END

************************************************************
      SUBROUTINE ELEM2PV(MU,ELEM,XV) 
      IMPLICIT DOUBLE PRECISION(A-H,O-Z) 
      PARAMETER(PI2=3.141592653589793D0*2.d0) 
      DOUBLE PRECISION MU,K 
      DIMENSION XV(6),ELEM(6),G(3),E(3) 
      K=ELEM(3) 
      H=ELEM(4) 
      Q=ELEM(5) 
      P=ELEM(6) 
      A=ELEM(1) 
      AL=ELEM(2) 
      AN=DSQRT(MU/A**3.D0)
      EE=AL+K*DSIN(AL)-H*DCOS(AL) 
20    CONTINUE 
      CE=DCOS(EE) 
      SE=DSIN(EE) 
      DE=(AL-EE+K*SE-H*CE)/(1.D0-K*CE-H*SE) 
      EE=EE+DE 
      IF (ABS(DE).GE.1.D-11) GOTO 20
      CE=DCOS(EE) 
      SE=DSIN(EE) 
      DLE=H*CE-K*SE 
      RSAM1=-K*CE-H*SE 
      ASR=1.D0/(1.D0+RSAM1) 
      PHI=DSQRT(1.D0-K*K-H*H) 
      PSI=1.D0/(1.D0+PHI) 
      X1=A*(CE-K-PSI*H*DLE) 
      Y1=A*(SE-H+PSI*K*DLE) 
      VX1=AN*ASR*A*(-SE-PSI*H*RSAM1) 
      VY1=AN*ASR*A*( CE+PSI*K*RSAM1) 
      F2=2.D0*DSQRT(1.d0-Q*Q-P*P) 
      P2=1.D0-2.D0*P*P 
      Q2=1.D0-2.D0*Q*Q 
      PQ=2.D0*P*Q 
      XV(1)=X1*P2+Y1*PQ 
      XV(2)=X1*PQ+Y1*Q2 
      XV(3)=(Q*Y1-X1*P)*F2 
      XV(4)=VX1*P2+VY1*PQ 
      XV(5)=VX1*PQ+VY1*Q2 
      XV(6)=(Q*VY1-VX1*P)*F2 
      RETURN 
      END 
******************************************

