      SUBROUTINE NINVER(JDIM,KDIM,S,XY,IXX,IXY,IYX,IYY)
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
C
C   IXX = 1, IXY = 2, IYX = 3, IYY = 4
C               -1
C   N  =  T    T
C          XI   ETA
C
C   IXX = 3, IXY = 4, IYX = 1, IYY = 2
C               -1
C   N  =  T    T
C          ETA  XI
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 S(JDIM,KDIM,4),XY(JDIM,KDIM,4)
C
      DIMENSION RG(4,4),SR(4)
C
C  PARAMETERS FOR DIAGONALIZATION
C
      BT = 1./SQRT(2.)
      BT2 = 0.5
C
        DO 1 K = KLOW,KUP
          DO 1 J = JLOW,JUP
           RR1   = XY(J,K,IXX)**2+XY(J,K,IXY)**2
           RR2   = XY(J,K,IYX)**2+XY(J,K,IYY)**2
           RR1   = 1./SQRT(RR1)
           RR2   = 1./SQRT(RR2)
           RM1   = (XY(J,K,IXX)*XY(J,K,IYX)+XY(J,K,IXY)*XY(J,K,IYY))
     *                                          *RR1*RR2
           RM2   = (XY(J,K,IXX)*XY(J,K,IYY)-XY(J,K,IXY)*XY(J,K,IYX))
     *                                          *RR1*RR2
               S34M  = S(J,K,3) - S(J,K,4)
               S34P  = S(J,K,3) + S(J,K,4)
               S2 =  RM1*S(J,K,2)    + BT*S34M*RM2
               S3 = -BT*S(J,K,2)*RM2 + BT2*(S34P+RM1*S34M)
               S4 =  BT*RM2*S(J,K,2) + BT2*(S34P-RM1*S34M)
               S(J,K,2) = S2
               S(J,K,3) = S3
               S(J,K,4) = S4
1      CONTINUE
C
         RETURN
         END
