      SUBROUTINE PCHECK(XP,YP,XN,YN,ZAXIS,XLEN,SHDOWN,SHUP,
     +     COORD,DIM,NNODX)
      INTEGER DIM,NNODX
      DOUBLE PRECISION XP,YP,XN,YN,ZAXIS,XLEN,SHDOWN(*),SHUP(*),
     +     COORD(DIM,*)

      INTEGER I,IND,IND0
      DOUBLE PRECISION EPS,YDOWNX,YUPX,INTSEC
      DOUBLE PRECISION INTSX,INTX
      PARAMETER(EPS=1.0D-12)
      IF (XP .LT. ZAXIS) THEN
         YP=INTSX(ZAXIS,XN,YN,XP,YP)
         XP=ZAXIS
      ENDIF

      IF (XP .GT. XLEN) THEN
         YP=INTSX(XLEN,XN,YN,XP,YP)
         XP=XLEN
      ENDIF

      IF ((YP .LT. SHDOWN(NNODX)) .OR. 
     +     (YP .GT. SHUP(NNODX))) THEN

         DO 10 I=1,NNODX-1
            IF ((XP .GT. COORD(1,I)-EPS) .AND. 
     +           (XP .LT. COORD(1,I+1)+EPS)) GOTO 20
 10      CONTINUE
 20      CONTINUE

         IF (YP .LT. SHDOWN(NNODX)) THEN
            YDOWNX=INTSX(XP,COORD(1,I),SHDOWN(I),
     +           COORD(1,I+1),SHDOWN(I+1))

            IF (YP .GT. YDOWNX) THEN
               GOTO 50
            ELSE
               IF (DABS(XP-XN) .LT. EPS) THEN
                  YP=YDOWNX
               ELSE
                  IND=1
                  IF (XN .LT. XP) THEN
                     IND0=-1
                  ELSE
                     IND0=1
                  ENDIF

 30               INTSEC=INTX(XN,YN,XP,YP,COORD(1,I+IND),
     +                 SHDOWN(I+IND),COORD(1,I+IND-1),SHDOWN(I+IND-1))

                  IF ((INTSEC .GT. COORD(1,I+IND-1)-EPS) .AND.
     +                 (INTSEC .LT. COORD(1,I+IND)+EPS)) THEN
                     YP=INTSX(INTSEC,XN,YN,XP,YP)
                     XP=INTSEC
                  ELSE
                     IND=IND+IND0
                     GOTO 30
                  ENDIF
               ENDIF
            ENDIF
         ENDIF

         IF (YP .GT. SHUP(NNODX)) THEN
            YUPX=INTSX(XP,COORD(1,I),SHUP(I),
     +           COORD(1,I+1),SHUP(I+1))

            IF (YUPX .GT. YP) THEN
               GOTO 50
            ELSE
               IF (DABS(XP-XN) .LT. EPS) THEN
                  YP=YUPX
               ELSE
                  IND=1
                  IF (XN .LT. XP) THEN
                     IND0=-1
                  ELSE
                     IND0=1
                  ENDIF

 40               INTSEC=INTX(XN,YN,XP,YP,COORD(1,I+IND-1),
     +                 SHUP(I+IND-1),COORD(1,I+IND),SHUP(I+IND))

                  IF ((INTSEC .GT. COORD(1,I+IND-1)-EPS) .AND.
     +                 (INTSEC .LT. COORD(1,I+IND)+EPS)) THEN
                     YP=INTSX(INTSEC,XN,YN,XP,YP)
                     XP=INTSEC
                  ELSE
                     IND=IND+IND0
                     GOTO 40
                  ENDIF
               ENDIF
            ENDIF
         ENDIF


      ENDIF
 50   CONTINUE

      RETURN
      END
