C $Id: test_gse_to_rtn.f,v 1.3 1999/03/12 18:26:30 asc Exp $
C Test code for the transfromation from rtn to gse and gsm
c
       program test_gse_to_rtn
C
       implicit none
C
       integer*4 time(2), VELOCITY_REQ, istatus
       real*8 TRANSFORM_MATRIX(3,3), DERIV_MATRIX(3,3)
       real*8 TEMP_MATRIX(3,3)        !Temporary result matrix
       real*8 GCI(3), RTN(3), GSE(3)
       real*8 spacecraft_pos(3)
       integer*4   ROW /3/                 !# of rows in transf_matrix
       integer*4   COLUMN /3/              !# of columns in transf_matrix
       integer*4   RC                      !row x column
		
C
       OPEN(UNIT=6,STATUS='NEW',file='data.dat')
C
       time(1)=1997181
       time(2)=54466181
       write(6,*) ' AT time =',time
C
C      This is the spacecraft position in J2000 GCI, needed as input
       spacecraft_pos(1) =  7.4545669885d+5
       spacecraft_pos(2) = -1.1366004289d+6
       spacecraft_pos(3) = -4.6248674225d+5
       write(6,*) ' j2000 pos =',spacecraft_pos
C
C      GSE vector to be transformed to RTN
       GSE(1) = 0.98738774
       GSE(2) = 0.151204097
       GSE(3) = 4.6933695774E-002
       write(6,*) ' GSE att =',GSE
       write(6,*)
C
C CONVERT FROM GSE TO GCI
C
       VELOCITY_REQ = 0    ! Have not completed the derivative path
       call  IC_GCI_TO_GSE (TIME,
     1                      TRANSFORM_MATRIX,DERIV_MATRIX,
     2                      VELOCITY_REQ,ISTATUS)
C
C*  call MXTRP8 routine to invert the GCI_GSE_MATRIX to GSE_GCI_MATRIX
C
        call MXTRP8 (TRANSFORM_MATRIX, TEMP_MATRIX, ROW, COLUMN) 
        TRANSFORM_MATRIX(1,1) = TEMP_MATRIX(1,1)
        TRANSFORM_MATRIX(2,1) = TEMP_MATRIX(2,1)
        TRANSFORM_MATRIX(3,1) = TEMP_MATRIX(3,1)
        TRANSFORM_MATRIX(1,2) = TEMP_MATRIX(1,2)
        TRANSFORM_MATRIX(2,2) = TEMP_MATRIX(2,2)
        TRANSFORM_MATRIX(3,2) = TEMP_MATRIX(3,2)
        TRANSFORM_MATRIX(1,3) = TEMP_MATRIX(1,3)
        TRANSFORM_MATRIX(2,3) = TEMP_MATRIX(2,3)
        TRANSFORM_MATRIX(3,3) = TEMP_MATRIX(3,3)

C*  call MULMAT to calculate GCI by multiplying GSE_GCI_MATRIX and GGSE
       call MULMAT(TRANSFORM_MATRIX,GSE,3,3,1,GCI)
       WRITE (6,*) ' GCI att=',GCI
C
C CONVERT FROM GCI TO RTN
C
       call  IC_GCI_TO_RTN (TIME, spacecraft_pos,
     1                      TRANSFORM_MATRIX,DERIV_MATRIX,
     2                      VELOCITY_REQ,
     3                      ISTATUS)
       call MULMAT(TRANSFORM_MATRIX,GCI,3,3,1,RTN)
       WRITE (6,*) ' RTN att=',RTN
C
       STOP
       END

