      SUBROUTINE XIDIF(JDIM,KDIM,X,Y,XY)
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
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 XY(JDIM,KDIM,4)
      DIMENSION X(JDIM,KDIM),Y(JDIM,KDIM)
C
C
C  XY4 =XXI,XY3 = YXI
C
      DO 11 K=KBEGIN,KEND
         DO 10 J=JLOW,JUP
            JP1 = JPLUS(J)
            JM1 = JMINU (J)
            XY(J,K,4) = ( X(JP1,K) - X(JM1,K))*.5
            XY(J,K,3) = ( Y(JP1,K) - Y(JM1,K))*.5
10       CONTINUE
C
          IF(.NOT.PERIDC  )THEN
            J = JBEGIN
            XY(J,K,4) = .5*( -3.*X(J,K) +4.*X(J+1,K) - X(J+2,K))
            XY(J,K,3) = .5*( -3.*Y(J,K) +4.*Y(J+1,K) - Y(J+2,K))
            J = JEND
            XY(J,K,4) = ( 3.*X(J,K) -4.*X(J-1,K) + X(J-2,K))*.5
            XY(J,K,3) = ( 3.*Y(J,K) -4.*Y(J-1,K) + Y(J-2,K))*.5
          ENDIF
C
   11 CONTINUE
C
        RETURN
        END
