C THIS SUBROUTINE PERFORMS THE CHOPPING OF THE LINES TO FIT
C WITHIN THE LIMITS 'XLOW,XHIGH,YLOW,YHIGH'
	SUBROUTINE FIT
	LOGICAL SWITCH
	COMMON /LIMITS/XMIN,XMAX,YMIN,YMAX
	COMMON /FRAME/ A,B,C,D
	COMMON/SIZE/XLOW,XHIGH,YLOW,YHIGH
	COMMON/SCALE/XDIFF,YDIFF
	COMMON/PAINT/I2STRT,I2END,PICT(4,10)
	COMMON/OUTPUT/I1STRT,I1END,LINE(4,10)
	COMMON/LINEND/XBEGIN,YBEGIN,XFINAL,YFINAL
	DATA CHAN0,CHAN1,CHAN2,CHAN3/00000.5,04096.5,08192.5,12288.5/
C
	L=I1STRT-1
	DO 80 I = I2STRT,I2END
C
C  GET END POINTS OF LINE
C
	XBEGIN = PICT (1,I)
	YBEGIN = PICT (2,I)
	XFINAL = PICT (3,I)
	YFINAL = PICT (4,I)
C
C  TRIM LINE SO THAT IT WILL FIT ON THE SCREEN
C
	SWITCH = ABS(XFINAL-XBEGIN).GT.ABS(YFINAL-YBEGIN)
	IF (SWITCH) GO TO 50
60	IF (XBEGIN.GT.XFINAL) CALL SWAP
	IF (XBEGIN.GT.XHIGH.OR.XFINAL.LT.XLOW) GO TO 80
	IF (XBEGIN.LT.XLOW) CALL TRIM(XBEGIN,YBEGIN,XLOW,XFINAL
	1,YFINAL)
	IF (XFINAL.GT.XHIGH) CALL TRIM(XFINAL,YFINAL,XHIGH,XBEGIN
	2,YBEGIN)
	IF (SWITCH) GO TO 70
50	IF (YBEGIN.GT.YFINAL) CALL SWAP
	IF (YBEGIN.GT.YHIGH.OR.YFINAL.LT.YLOW) GO TO 80
	IF (YBEGIN.LT.YLOW) CALL TRIM(YBEGIN,XBEGIN,YLOW,YFINAL
	3,XFINAL)
	IF (YFINAL.GT.YHIGH) CALL TRIM(YFINAL,XFINAL,YHIGH,YBEGIN
	4,XBEGIN)
	IF (SWITCH) GO TO 60
C
C  CONVERT END POINTS TO SCREEN COORDINATES
C
70	L=L+1
	LINE(1,L) = (XBEGIN - XMIN)*XDIFF + CHAN0
	LINE(2,L) = (YBEGIN - YMIN)*YDIFF + CHAN1
	LINE(3,L) = (XFINAL - XMIN)*XDIFF + CHAN2
	LINE(4,L) = (YFINAL - YMIN)*YDIFF + CHAN3
C
80	CONTINUE
	I1END=L
C
	RETURN
	END
