	SUBROUTINE PATS(I)
	COMMON IB(10,10),IA(8,2),IC(8,2),NA,IS1,IS2,CHAR,CLEAR
	LOGICAL*1 CLEAR(6),IB
	DIMENSION MSTARS(8)
1	WRITE(5,2)
2	FORMAT(//' * PRESET PATTERNS *'//
     C' Now you have 2 more options:'/
     C' 1) select a specific pattern'/
     C' 2) select a preset pattern randomly'//
     C' The following patterns are available:')
	CALL ASSIGN(1,'DL2:[200,6]BBOXFILES.DAT',24)
	NPATS=0
	DO 320 J=1,8
	MSTARS(J)=0
320	CONTINUE
5	READ(1,6,END=11) NSTARS
6	FORMAT(3X,I3)
	IF(NSTARS.LT.1.OR.NSTARS.GT.8) GOTO 5
	MSTARS(NSTARS)=MSTARS(NSTARS)+1
	NPATS=NPATS+1
	GOTO 5
11	CALL CLOSE(1)
	WRITE(5,211)
211	FORMAT(T10,'stars',T18,'# patterns',T40,'stars',T48,'# paterns')
	DO 13 I=1,7,2
	WRITE(5,12) I,MSTARS(I),I+1,MSTARS(I+1)
13	CONTINUE
	WRITE(5,17) NPATS
17	FORMAT('              (total of',I4,' patterns)')
12	FORMAT(T13,I1,T22,I3,T43,I1,T52,I3)
16	WRITE(5,14)
	CALL CLOSE(5)
14	FORMAT(/' Enter option 1 or 2: ',$)
	I=-1
	READ(5,15,END=100) ANS
15	FORMAT(A1)
	IF(ANS.EQ.'1') GOTO 20
	IF(ANS.EQ.'2') GOTO 30
	GOTO 16
20	WRITE(5,21) NPATS
21	FORMAT(' Enter a pattern number between 1 and',I4,'.'/
     C' This number will set the star pattern AND determine'/
     C' how many stars to use.')
	READ(5,22,END=16,ERR=20) IPAT
22	FORMAT(I3)
	IF(IPAT.LT.1.OR.IPAT.GT.NPATS) GOTO 16
	CALL ASSIGN(1,'DL2:[200,6]BBOXFILES.DAT',24)
24	READ(1,23,END=25) NPAT,NSTARS,IA
23	FORMAT(2I3,16I2)
	IF(NPAT.NE.IPAT) GOTO 24
27	I=IPAT
	CALL CLOSE(1)
	GOTO 300
100	CALL CLOSE(5)
	IF(I.EQ.-1) GOTO 101
102	WRITE(5,103)
103	FORMAT(/' Randomize orientation ?'/' Y/N-',$)
	READ(5,15,END=102) ANS
	IF(ANS.EQ.'N'.OR.ANS.EQ.'n'.OR.ANS.LE.' ') GOTO 101
	IF(ANS.NE.'Y'.AND.ANS.NE.'y') GOTO 102
C	RANDOMIZE:
	N=RAN(IS1,IS2)*4.
	DO 104 J=1,N !  ROTATE 0,90,180,270 DEGREES
	DO 104 K=1,NA
	ITEMP=IA(K,2)
	IA(K,2)=IA(K,1)
	IA(K,1)=11-ITEMP
104	CONTINUE
	IF(RAN(IS1,IS2).GT..5) GOTO 101
	DO 105 J=1,NA !  TRANSPOSE
	ITEMP=IA(J,1)
	IA(J,1)=IA(J,2)
	IA(J,2)=ITEMP
105	CONTINUE
101	RETURN
25	WRITE(5,26)
	CALL CLOSE(1)
26	FORMAT('      ***WARNING***'/' No pattern with that number
     C- try again.')
	GOTO 20
30	WRITE(5,31)
31	FORMAT(' How many stars ?   Enter a number 1 through 8'/
     C' or 0 if you don''t care: ',$)
	READ(5,32,ERR=30,END=16) ISTARS
32	FORMAT(I1)
	JSTARS=ISTARS
	IF(ISTARS.LT.9.OR.ISTARS.GT.0) GOTO 36
37	JSTARS=RAN(IS1,IS2)*7.9999+1
36	K=MSTARS(JSTARS)
	IF(K.GT.0) GOTO 35
	IF(ISTARS.LT.1.OR.ISTARS.GT.8) GOTO 37
	WRITE(5,34) JSTARS
34	FORMAT(' There are no patterns for ',I1,' stars.')
	GOTO 30
35	ISTARS=JSTARS
	CALL ASSIGN(1,'DL2:[200,6]BBOXFILES.DAT',24)
	JSTARS=0
	IRSTAR=RAN(IS1,IS2)*(K-.0001)+1.
33	READ(1,23,END=40)IPAT,NSTARS,IA
	IF(NSTARS.NE.ISTARS) GOTO 33
	JSTARS=JSTARS+1
	IF(JSTARS.EQ.IRSTAR) GOTO 40
	GOTO 33
40	CALL CLOSE(1)
	IF(IRSTAR.EQ.JSTARS) GOTO 27
	I=-1
	WRITE(5,41)
41	FORMAT(' ***WARNING*** - Unable to find pattern.  Search'/
     C' aborted.  Try again.')
	GOTO 16
300	DO 301 J=1,8
	IF(IA(J,1).LE.1) GOTO 302
301	CONTINUE
302	NA=J-1
	GOTO 100
	END
