      SUBROUTINE TKINV(JDIM,KDIM,Q,SNDSP,S,XYJ,XY,IX,IY)
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
C
C  IX = 1, IY = 2  XI  METRICS
C  IX = 3, IY = 4  ETA METRICS
C
      COMMON/BASE/
     1  JMAX,       KMAX,     JM,          KM,          JBEGIN,   JEND,
     1  KBEGIN,     KEND,     JPLUS(999),  JMINU (999), JLOW,     JUP,
     1  KLOW,       KUP,      PERIDC  ,    NP,          DT,   CP2TIM,
     1  FSMACH,     ALPHA,    GAMMA,       GAMI,        PI,
     1  DIS2X,      DIS2Y,    DIS4X,       DIS4Y,       PHIDT,    
     1  THETAD ,    RESID,    JACDT,       IPRINT,      NPCP,
     1  JTAIL1,     JTAIL2,   NUMITE ,     ISTART,      NSTEPS
      LOGICAL PERIDC  
      COMMON/GRID/DYM,YMAX,XMIN,XMAX,THICK
C
      DIMENSION Q(JDIM,KDIM,4),S(JDIM,KDIM,4),SNDSP(JDIM,KDIM)
      DIMENSION XY(JDIM,KDIM,4),XYJ(JDIM,KDIM)
C
      BT = 1./SQRT(2.)
C
C  T INVERSE MATRIX MULTIPLY FOR DIAGONAL ALGORITHM
C   K
C
      DO 1 K = KLOW, KUP
       DO 1 J = JLOW,JUP
         RX        = XY(J,K,IX)
         RY        = XY(J,K,IY)
         RRXY      = 1./SQRT(RX**2+RY**2)
         RX        = RX*RRXY
         RY        = RY*RRXY
            RHO       = Q(J,K,1)*XYJ(J,K)
            RHOINV    = 1./RHO
            RHOINR   = RHOINV*XYJ(J,K)
            U = Q(J,K,2)*RHOINR
            V = Q(J,K,3)*RHOINR
            SNR   = 1./SNDSP(J, K)
            BET0  = BT*RHOINV*SNR
C
               TERM1 = GAMI*( U*S(J,K,2) + V*S(J,K,3) - S(J,K,4) 
     +                 - 0.5*(U**2+V**2)*S(J,K,1) )
C
               S1    =  S(J,K,1) + TERM1*SNR**2
               S2    = ( (- RY*U + RX*V)*S(J,K,1) 
     +                 + RY*S(J,K,2) - RX*S(J,K,3) )*RHOINV
C
               TERM1 =  TERM1*BET0
               TERM2 =  ((RX*U + RY*V)*S(J,K,1)
     +                 - RX*S(J,K,2) - RY*S(J,K,3) )*BT*RHOINV
C
               S(J,K,1) = S1
               S(J,K,2) = S2
               S(J,K,3) = -(TERM1 + TERM2)
               S(J,K,4) = -(TERM1 - TERM2)
C
1       CONTINUE
C
        RETURN
        END
