      SUBROUTINE POS(RE,VE,M5,RH,VH,THETA,BETA,MTB)
C
C ROTATE SPACECRAFT POSITION AND VELOCITY FROM EME'50 COORDINATES 
C TO IHG COORDINATES.
C COMPUTE SPACECRAFT LATITUDE AND LONGITUDE IN IHG COORDINATES.
C COMPUTE THE IHG TO HG ROTATION MATRIX (MTB). 
C 
      REAL*4 RE(3),VE(3),M5(3,3),RH(3),VH(3),MTB(3,3)
C
      DATA TPIE/6.2831853E0/,ARAD/1.495985E8/
C
C ROTATE S/C POSITION VECTOR INTO IHG COORDINATES.
C
      RH(1) = ( M5(1,1)*RE(1) + M5(1,2)*RE(2) + M5(1,3)*RE(3) )/ARAD
      RH(2) = ( M5(2,1)*RE(1) + M5(2,2)*RE(2) + M5(2,3)*RE(3) )/ARAD
      RH(3) = ( M5(3,1)*RE(1) + M5(3,2)*RE(2) + M5(3,3)*RE(3) )/ARAD
C
C ROTATE S/C VELOCITY VECTOR INTO IHG COORDINATES.
C
      VH(1) = M5(1,1)*VE(1) + M5(1,2)*VE(2) + M5(1,3)*VE(3)
      VH(2) = M5(2,1)*VE(1) + M5(2,2)*VE(2) + M5(2,3)*VE(3)
      VH(3) = M5(3,1)*VE(1) + M5(3,2)*VE(2) + M5(3,3)*VE(3)
C
      X = RH(1)
      Y = RH(2)
      Z = RH(3)
C
C SPACECRAFT RANGE
C
      R = SQRT(X**2 + Y**2 + Z**2)
C
C SPACECRAFT LATITUDINAL POSITION ANGLE
C
      THETA = ASIN(Z/R)
C
C SPACECRAFT LONGITUDINAL POSITION ANGLE
C
      BETA = ATAN2(Y,X)
      IF (BETA.LT.0.0) BETA = BETA + TPIE
C
      CSB = X/SQRT(X**2 + Y**2)
      SNB = Y/SQRT(X**2 + Y**2)
      SNT = Z/R
      CST = SQRT(1.0 - SNT**2)
C
      MTB(1,1) =  CST*CSB
      MTB(1,2) =  CST*SNB
      MTB(1,3) =  SNT
C
      MTB(2,1) = -SNB
      MTB(2,2) =  CSB
      MTB(2,3) =  0.0
C
      MTB(3,1) = -SNT*CSB
      MTB(3,2) = -SNT*SNB
      MTB(3,3) =  CST
C
      RETURN
      END
