C
C
	SUBROUTINE XYPLOT(X,Y,NLOW,NHI,IPEN,XMIN,XPER,YMIN,YPER,ICROSS)
C
C  J.C. PHILLIPS 10/24/83
C
C  TO UTILISE RETROGRAPHICS CAPABILITIES OF THE VT100
C
C  You may have to say $ SET TERM/FORM_FEED and set the terminal
C  into VT52 mode first.
C
	DIMENSION X(512),Y(512),XCROSS(10),YCROSS(10)
	INTEGER NPCR(10)
	BYTE BUFFER(6),BOX(16),SCROSS(10)
	INTEGER IPARAM(6)
	COMMON /HAIRS/ XCROSS,YCROSS,NCROSS,NPCR,SCROSS
	DATA BOX /"40,"140,"40,"100,"64,"176,"40,"100,
     Q"64,"176,"77,"137,"40,"140,"77,"137/
	NCROSS=0
C	CALL GETADR(IPARAM(1),BUFFER(1))
	NPNTS=NHI-NLOW+1
	IF(ABS(XPER).GT.0.00001) GO TO 2
	WRITE(5,100)		! CLEAR SCREEN ETC.
	BUFFER(1)="33
	BUFFER(2)="14
	BUFFER(3)="7
	BUFFER(4)="35
	IPARAM(2)=4
C
	WRITE(5,142) (BUFFER(I),I=1,IPARAM(2))
142	FORMAT('$',80A1)
C	CALL QIO("410,5,1,,,IPARAM)
C
	XPER=1.1*(X(NHI)-X(NLOW))	! CALCULATE MAXIMUM AND MINIMUM
	XMIN=X(NLOW)-XPER/22.
	YMIN=Y(NLOW)
	YPER=YMIN
	DO 20 I=NLOW,NHI
	IF(YMIN.GT.Y(I)) YMIN=Y(I)
	IF(YPER.LT.Y(I)) YPER=Y(I)
20	CONTINUE
C  DRAW BOX
	DO 1 I=1,13,4
C	CALL GETADR(IPARAM(1),BOX(I))
	WRITE(5,142)(BOX(K),K=I,I+IPARAM(2)-1)
C	CALL QIO("410,5,1,,,IPARAM)
1	CONTINUE
C	CALL GETADR(IPARAM(1),BOX(1))
C	CALL QIO("410,5,1,,,IPARAM)
	WRITE(5,142) (BOX(1),I=1,IPARAM(2))
C	CALL GETADR(IPARAM(1),BUFFER(1))
	IPARAM(2)=6
	BUFFER(1)="35
	BUFFER(2)="64
	BUFFER(3)="176
	BUFFER(4)="40
	BUFFER(5)="100
	BUFFER(6)="37
C	CALL QIO("410,5,1,,,IPARAM)
	WRITE(5,142) (BUFFER(I),I=1,IPARAM(2))
	WRITE(5,102) NHI,X(NHI),YPER,NLOW,X(NLOW),YMIN
	YPER=1.1*(YPER-YMIN)
	YMIN=YMIN-YPER/22.
2	BUFFER(1)="35
	BUFFER(2)="33
	IPARAM(2)=1
	IF(XPER.LT.0.0001.OR.YPER.LT.0.0001) GO TO 900
	GOTO(11,12,13,14,15,16) IPEN		! SET PEN
12	BUFFER(1)="34
	GO TO 11
13	BUFFER(3)="141
	GO TO 17
14	BUFFER(3)="142
	GO TO 17
15	BUFFER(3)="143
	GO TO 17
16	BUFFER(3)="144
17	IPARAM(2)=3
C11	CALL QIO("410,5,1,,,IPARAM)
11	WRITE(5,142) (BUFFER(I),I=1,IPARAM(2))
	IPARAM(2)=4
	DO 3 I=NLOW,NHI			! PLOT DATA
	IX=IFIX((X(I)-XMIN)*1023./XPER)
	BUFFER(3)=(IX/"40).OR."40
	BUFFER(4)=(IX.AND."37).OR."100
	IY=IFIX((Y(I)-YMIN)*670./YPER)
	BUFFER(1)=(IY/"40).OR."40
	BUFFER(2)=(IY.AND."37).OR."140
C	CALL QIO("410,5,1,,,IPARAM)
	WRITE(5,142) (BUFFER(K),K=1,IPARAM(2))
3	CONTINUE
	NCROSS=0
4	IF(ICROSS.NE.1.OR.NCROSS.EQ.10) GO TO 5
	NCROSS=NCROSS+1
	BUFFER(1)="35
	BUFFER(2)="33
	BUFFER(3)="32
	IPARAM(2)=3
C	CALL QIO("410,5,1,,,IPARAM)
	WRITE(5,142) (BUFFER(I),I=1,IPARAM(2))
	READ(5,101) SCROSS(NCROSS),(BUFFER(I), I=1,4)
	IX=(BUFFER(1).AND."37)
	IY=(BUFFER(2).AND."37)
	IX=32*IX+IY
	XCROSS(NCROSS)=XMIN+XPER*IX/1023.
	DO 6 I=NLOW,NHI
	IF(X(I).LT.XCROSS(NCROSS)) GO TO 6
	NPCR(NCROSS)=I
	GO TO 8
6	CONTINUE
8	IY=(BUFFER(3).AND."37)
	IX=(BUFFER(4).AND."37)
	IY=32*IY+IX
	YCROSS(NCROSS)=YMIN+YPER*IY/670.
	IF(SCROSS(NCROSS).NE."121) GO TO 4
	NCROSS=NCROSS-1
900	CONTINUE
5	BUFFER(1)="35
	BUFFER(2)="70
	BUFFER(3)="153
	BUFFER(4)="40
	BUFFER(5)="100
	BUFFER(6)="37
	IPARAM(2)=6
C	CALL QIO("410,5,1,,,IPARAM)
	WRITE(5,142) (BUFFER(I),I=1,IPARAM(2))
	IF(XPER.GT.0.0001.AND.YPER.GT.0.0001) RETURN
	WRITE(5,103)
	RETURN
100	FORMAT(30(/))
101	FORMAT(5A1)
102	FORMAT(' ',40X,I3,2(1X,E15.8),28(/),' ',5X,I3,2(1X,E15.8))
103	FORMAT(' SCALES TOO SMALL NO DATA PLOTTED')
	END

