	SUBROUTINE BSCAN(IOUT,L,IUS,IS0,JS0,ID)
C	ROUTINE TO ROTATE AND INVERT IOUT TO MATCH CRAWLER ORIENTATION
C----------------------standard common block----------------------------
C 
	COMMON ICR(8,12),IPARM(10),IS1,IS2,NT,ICU(10,10,10,2),CLEAR(8)
	COMMON MARKER(4,3,3)
	LOGICAL*1 ICU,CLEAR
C 
C-----------------------------------------------------------------------
	LOGICAL*1 IOUT(10,10),C
C 
C	INV=1 IF INVERT, ELSE 0
C	NR IS NUMBER OF CLOCKWISE ROTATIONS
	INV=0
	NR=1
	GOTO (1,2,3,4,5,6) L
1	IF(IUS.EQ.2) NR=1
	IF(IUS.EQ.5) NR=2
	IF(IUS.EQ.4) NR=3
	IF(IUS.EQ.6) NR=0
	INV=1
	GOTO 7
2	IF(IUS.EQ.1) NR=2
	IF(IUS.EQ.3) NR=0
	IF(IUS.EQ.6) NR=1
	IF(IUS.EQ.5) NR=3
	GOTO 7
3	IF(IUS.EQ.4) NR=0
	IF(IUS.EQ.6) NR=1
	IF(IUS.EQ.2) NR=2
	IF(IUS.EQ.5) NR=3
	GOTO 7
4	IF(IUS.EQ.1) NR=1
	IF(IUS.EQ.3) NR=3
	IF(IUS.EQ.5) NR=2
	IF(IUS.EQ.6) NR=0
	INV=1
	GOTO 7
5	IF(IUS.EQ.3) NR=3
	IF(IUS.EQ.1) NR=1
	IF(IUS.EQ.2) NR=2
	IF(IUS.EQ.4) NR=0
	INV=1
	GOTO 7
6	IF(IUS.EQ.2) NR=3
	IF(IUS.EQ.3) NR=0
	IF(IUS.EQ.4) NR=1
	IF(IUS.EQ.1) NR=2
C 
C	ROTATE ARRAY IOUT NR TIMES WHILE STORING IN JOUT:
C7	WRITE(5,107) L,IUS,INV,NR
C107	FORMAT(' L,IUS,INV,NR:',4I6)
C108	FORMAT(A1)
7	IF(NR.EQ.0) GOTO 19
	DO 18 K=1,NR
C 
C	SINCE EACH PASS THROUGH LOOPS CHANGES ONE POINT IN EACH
C	QUADRANT, INDICES NEED ONLY GO FROM 1 TO 5 TO ROTATE ENTIRE
C	ARRAY 90 DEGREES CLOCKWISE.
	DO 8 I=1,5
	DO 8 J=1,5
	C=IOUT(I,J)
	M=11-I
	N=11-J
	IOUT(I,J)=IOUT(N,I)
	IOUT(N,I)=IOUT(M,N)
	IOUT(M,N)=IOUT(J,M)
	IOUT(J,M)=C
8	CONTINUE
C	WRITE(5,17) K,((IOUT(I,J),J=1,10),I=1,10)
C17	FORMAT(' ROTATION',I2/10(10(X,A1)/))
C	READ(5,108) Z
18	CONTINUE
19	IF(INV.EQ.0) GOTO 10
	DO 9 I=1,10
	DO 9 J=I+1,10
	IF(J.GT.10) GOTO 10
	C=IOUT(I,J)
	IOUT(I,J)=IOUT(J,I)
	IOUT(J,I)=C
9	CONTINUE
C	WRITE(5,16) ((IOUT(I,J),J=1,10),I=1,10)
C16	FORMAT(' INVERTED AND RETURNED AS:'/10(10(X,A1)/))
C	GOTO 12
C10	WRITE(5,15) ((IOUT(I,J),J=1,10),I=1,10)
C15	FORMAT(' RETURNED AS:'/10(10(X,A1)/))
C12	READ(5,108) Z
C 
C	FIND COORDINATES OF CRAWLER ON SCREEN:
10	CONTINUE
12	IF(IS0.NE.0) GOTO 30
	DO 29 I=1,10
	DO 29 J=1,10
	IF(IOUT(I,J).EQ.ID+48) GOTO 28
29	CONTINUE
28	IS0=I
	JS0=J
C	WRITE(5,27) IS0,JS0
C27	FORMAT(' CRAWLER AT',2I3)
C	READ(5,108) Z
30	RETURN
	END
