      SUBROUTINE GRADCO(IXY,JDIM,KDIM,PRESS,XYJ,COEF,PRSS)
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
C
C  IXY = 1  FOR XI  DIRECTION
C  IXY = 2  FOR ETA DIRECTION
      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 PRESS(JDIM,KDIM),XYJ(JDIM,KDIM)
      DIMENSION COEF(JDIM,KDIM),PRSS(JDIM,KDIM)
C
       IF(IXY.EQ.1)THEN
C
            JEDGE1 = JLOW
            JEDGE2 = JUP
C       
C   COMPUTE PRESSURE GRAD 
C
      DO 1 K = KBEGIN,KEND
      DO 1 J = JBEGIN,JEND
      COEF(J,K) = 0.
      PRSS(J,K) = PRESS(J,K)*XYJ(J,K)
1     CONTINUE
C
C   BYPASS LOGIC IF DIS2X = 0.0
C
      IF(DIS2X.EQ.0.0)RETURN
C
      DO 2 J = JLOW,JUP
      JPL = JPLUS(J)
      JMI = JMINU (J)
      DO 2 K = KLOW,KUP
      R1 = PRSS(JPL,K) -2.* PRSS(J,K) + PRSS(JMI,K)
      R2 = PRSS(JPL,K) +2.* PRSS(J,K) + PRSS(JMI,K)
      COEF(J,K) = ABS( R1/R2 )
2     CONTINUE
C
C   C MESH BC
C
         IF(.NOT.PERIDC  )THEN
         DO 3 K = KLOW,KUP
         COEF(JBEGIN,K) = COEF(JLOW,K)
         COEF(JEND,K) = COEF(JUP,K)
         PRSS(JBEGIN,K) = COEF(JLOW,K)
         PRSS(JEND,K) = COEF(JUP,K)
3        CONTINUE
         ENDIF
C
C  SMOOTH OUT PRESSURE COEFFICIENT
C
      DO 4 J = JEDGE1,JEDGE2
      JPL = JPLUS(J)
      JPLPL = JPLUS(JPL)
      JMI = JMINU (J)
      DO 4 K = KLOW,KUP
      PRSS(J,K) = MAX( COEF(JMI,K),COEF(J,K),COEF(JPL,K)
     *                    ,COEF(JPLPL,K) )
C-old      PRSS(J,K) = AMAX1( COEF(JMI,K),COEF(J,K),COEF(JPL,K)
C-old     *                    ,COEF(JPLPL,K) )
4     CONTINUE
C
      DO 5 J = JLOW,JUP
      JPL = JPLUS(J)
      JMI = JMINU (J)
      DO 5 K = KLOW,KUP
      COEF(J,K) = 0.5*PRSS(J,K) + 0.25*(PRSS(JPL,K)+PRSS(JMI,K))
5     CONTINUE
C
      IF(.NOT.PERIDC  )THEN
C  TURN OFF SECOND ORDER NEAR TRAILING EDGE
C
C   C MESH BC
C
         DO 12 K = KLOW,KUP
         COEF(JBEGIN,K) = COEF(JLOW,K)
         COEF(JEND,K) = COEF(JUP,K)
12       CONTINUE
C
         ENDIF
C
       ELSEIF(IXY .EQ. 2)THEN
C
C
C  GRADIANT COEFFICENT IN ETA DIRECTION
C
      DO 21 K = KBEGIN,KEND
      DO 21 J = JBEGIN,JEND
      COEF(J,K) = 0.
      PRSS(J,K) = PRESS(J,K)*XYJ(J,K)
21    CONTINUE
C
C   BYPASS LOGIC IF DIS2Y = 0.0
C
      IF(DIS2Y.EQ.0.0)RETURN
C
      DO 22 K = KLOW,KUP
      KPL = K+1
      KMI = K-1
      DO 22 J = JLOW,JUP
      R1 = PRSS(J,KPL) -2.* PRSS(J,K) + PRSS(J,KMI)
      R2 = PRSS(J,KPL) +2.* PRSS(J,K) + PRSS(J,KMI)
      COEF(J,K) = ABS( R1/R2 )
22    CONTINUE
C
C   BC
C
         DO 24 J = JLOW,JUP 
         COEF(J,KBEGIN) = COEF(J,KLOW)
         COEF(J,KEND) = COEF(J,KUP)
         PRSS(J,KBEGIN) = COEF(J,KLOW)
         PRSS(J,KEND) = COEF(J,KUP)
24       CONTINUE
C
C  SMOOTH OUT PRESSURE COEFFICIENT
C
      DO 26 K = KLOW,KUP
      KPL = K+1
      KMI = K-1
      DO 26 J = JLOW,JUP
      PRSS(J,K) = MAX( COEF(J,KMI),COEF(J,K),COEF(J,KPL))
C-old      PRSS(J,K) = AMAX1( COEF(J,KMI),COEF(J,K),COEF(J,KPL))
26    CONTINUE
C
      DO 28 K = KLOW,KUP
      KPL = K+1
      KMI = K-1
      DO 28 J = JLOW,JUP
      COEF(J,K) = 0.5*PRSS(J,K) + 0.25*(PRSS(J,KPL)+PRSS(J,KMI))
28    CONTINUE
C
       ENDIF
C
         RETURN
         END
