C   25/07/79 C9073101   MEMBER NAME  LGEHIT   (SOURCE)      FORTRAN
      SUBROUTINE LGEHIT(XY,IE,*)
C     CODED BY Y.WATANABE ON 29/7/79, 01:00
C     LAST CHANGE ON 31/7/79, 01:00
C     IE=+/-1, FOR +/-Z END CAP
      DIMENSION XY(2,4),IX(4),YCOR(2),SY(2)
      DATA DY/0.357143/
C     DY IS THE DISPLACEMENT CORRECTION
C*****THE FOLLOWING IS A STATEMENT FUNCTION
C*****BE CAREFUL TO CHECK IF EVERYTHING IS DEFIND BEFOREHAND!!!
      YF(J,I)=SY(J)*(I1-XY(1,I))+XY(2,I)
C
      DO 20 I=1,4
      DO 10 J=1,2
10    XY(J,I)=XY(J,I)+6.
      IX(I)=XY(1,I)
20    CONTINUE
C     WRITE(6,600) IX
C600  FORMAT(' LGEHIT;IX',10I10)
C     WRITE(6,605) XY
C605  FORMAT(' LGEHIT;XY',10F10.4)
C     THIS IS TO AVOID WORKING WITH NEGATIVE INTEGER
C     REMENBER THAT I=-ABS(X)-1 TO GET IT RIGHT
      IMIN=IX(1)
      IF(IMIN.GT.11) RETURN
      IMAX=IX(4)
      IF(IMAX.LT.0) RETURN
      IF(IMIN.GT.IMAX) RETURN
      IF(IMIN.LT.0) IMIN=0
      IF(IMAX.GT.11) IMAX=11
      IF(IX(1).EQ.IX(2).AND.IX(3).EQ.IX(4)) GO TO 100
      IF(IX(1).EQ.IX(3).AND.IX(2).EQ.IX(4)) GO TO 100
      SLP=(XY(2,3)-XY(2,1))/(XY(1,3)-XY(1,1))
      I1=IMIN
      J1O=XY(2,1)
      J2O=J1O
      SY(1)=SLP
      SY(2)=-1./SLP
      Y1=YF(1,1)
      Y2=YF(2,1)
      YCOR(1)=DY*SY(1)
      YCOR(2)=DY*SY(2)
      IF1=1
      IF2=2
      I1=IMIN-1
C
C     NOW SCAN OVER X FINDING THE BOUNDARY IN Y WITHIN THE
C     RECTANGLE
30    I1=I1+1
      IF(I1-IMAX) 34,32,200
32    Y1S=XY(2,4)
      Y2S=Y1S
C     THE END VALUES
      GO TO 51
34    IF(I1.NE.IX(3)) GO TO 40
      Y1=YF(2,3)
      IF1=2
40    Y1=Y1+SY(IF1)
      IF(I1.NE.IX(2)) GO TO 50
      Y2=YF(1,2)
      IF2=1
50    Y2=Y2+SY(IF2)
      Y1S=Y1
      Y2S=Y2
      COR1=0.
      COR2=0.
      IF(I1.EQ.IX(3)) Y1S=XY(2,3)
      IF(I1.EQ.IX(2)) Y2S=XY(2,2)
C     BY DOING THIS WE PICK UP THE CORNER BUT PICK UP UNWANTED
C     PART,TOO. IT IS NOT EASY PREVENT IT SIMPLY.
C.....THE FOLLOWING IS AN IMPERFECT CORRECTIONS FOR THE DISPLACEMENT OF
C     OF CERTAIN COUNTERS FROM THE GRID.
51    IF(I1.GE.5) GO TO 52
      IF(ABS(Y1S-YCOR(IF1)).LT.1.) COR1=-YCOR(IF1)
      IF(ABS(Y2S-YCOR(IF2)).LT.1.) COR2=-YCOR(IF2)
      GO TO 60
52    IF(I1.GE.7) GO TO 54
      IF(Y1S.GT.0.) COR1=-DY
      IF(Y1S.LT.0.) COR1=DY
      IF(Y2S.GT.0.) COR2=-DY
      IF(Y2S.LT.0.) COR2=DY
      GO TO 60
54    IF(ABS(Y1S+YCOR(IF1)).LT.1.) COR1=YCOR(IF1)
      IF(ABS(Y2S+YCOR(IF2)).LT.1.) COR2=YCOR(IF2)
60    CONTINUE
C.....UNCORRECTED REGION IS THE END POINTS THAT LIE IN ABS(Y)<1.
      Y1S=Y1S+COR1
      Y2S=Y2S+COR2
      J1N=MIN1(Y1+COR1,Y2+COR2)
      J2N=MAX1(Y1+COR1,Y2+COR2)
      J1=MIN1(Y1S,Y2S)
      J2=MAX1(Y1S,Y2S)
      IF(J1.GT.J1O) J1=J1O
      IF(J2.LT.J2O) J2=J2O
C     WRITE(6,610) I1,IF1,IF2,J1,J2,J1N,J2N,J1O,J2O
C610  FORMAT(' I1,IF1..',12I10)
C     WRITE(6,620) Y1,Y2,Y1S,Y2S,SY
C620  FORMAT(' Y1,Y2..',10F10.4)
      J1O=J1N
      J2O=J2N
      IF(J1.GT.11) GO TO 30
      IF(J2.LT.0) GO TO 30
      IF(J1.GT.J2) GO TO 30
      IF(J1.LT.0) J1=0
      IF(J2.GT.11) J2=11
      CALL LGEFIL(I1,J1,J2,IE,&300)
      GO TO 30
C
100   J2=XY(2,3)
      J1=XY(2,2)
      IF(J2.GT.J1) GO TO 140
      I=J1
      J1=J2
      J2=I
140   IF(J1.LT.0) J1=0
      IF(J2.GT.11) J2=11
C     WRITE(6,630) IMIN,IMAX,J1,J2
C630  FORMAT(' SIMPLE',10I10)
      DO 150 I=IMIN,IMAX
150   CALL LGEFIL(I,J1,J2,IE,&300)
200   RETURN
C
300   RETURN1
      END
