	SUBROUTINE CFILL(NP,MP)
C	ROUTINE TO FILL ICR PARAMETERS FOR CRAWLER 'ID'
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-----------------------------------------------------------------------
2	FORMAT(A1)
	ID=1
10	IF(ID.GT.NP+MP) GOTO 30
	LUN=ICR(ID,8)
C 
50	WRITE(LUN,51) ID
51	FORMAT(///' crawler',I2,', enter your position in the cube as'/
     C' X,Y,Z  or enter <CR> for random assignment or enter a negative'/
     C' number for help: ',$)
	READ(LUN,52,ERR=50) X,Y,Z
52	FORMAT(3F6.0)
	IF(X.EQ.0) GOTO 80  ! RANDOM ASSIGN
	IF(X.GT.0) GOTO 60
	WRITE(LUN,53)
53	FORMAT(' imagine a box in front of you.  facing you is side 1.'/
     C' as you walk to the right of the box you will see side 2.'/
     C' to the right of side 2 is side 3, and then side 4.  to the'/
     C' right of side 4 is side 1 again.  the top is side 5, the'/
     C' bottom is 6.'//
     C' if you move in direction 1 from the center of the cube you'/
     C' will hit side 1 of the cube.  other directions are similar.'//
     C' X=1 on side 3, X=10 on side 1, Y=1 on side 2, Y=10 on side 4,'/
     C' Z=1 on side 6, Z=10 on side 5.  X,Y and Z would thus be'/
     C' specified as, for example, 7,6,1.  directions are specified as'/
     C' 1,2,3,4,5 or 6.')
	READ(LUN,2) ANS
	WRITE(LUN,56)
56	FORMAT(///' with a picture:     (X,Y,Z) coordinates'//
     C'                      (1,1,10)                    (1,10,10)'/
     C'                               *-----------------*'/
     C'                              /       side      /|'/
     C'                             /        5        / |'/
     C'                            /                 /  |'/
     C'                           /       (10,10,10)/   |'/
     C'                (10,1,10) *-----------------*   e|'/
     C'                          |                 |  d |'/
     C'                          |                 | i  |'/
     C'                   ------ |                 |s   |'/
     C'                  /       |       side      |  2 * (1,10,1)'/
     C'                 /        |                 |   /'/
     C'                /         |        1        |  /'/
     C'         (side 4)         |                 | /'/
     C'                          |                 |/'/
     C'                 (10,1,1) *-----------------* (10,10,1)'/
     C'                                    /'/
     C'                         (side 6)--/'//)
	READ(LUN,2) ANS
	GOTO 50
60	IF(X.LT.1..OR.Z.GT.10.) GOTO 50
	IF(Y.LT.1..OR.Y.GT.10.) GOTO 50
	IF(Z.LT.1..OR.Z.GT.10.) GOTO 50
	I=X
	J=Y
	K=Z
	IF(ICU(I,J,K,1).LE.' ') GOTO 61
	WRITE(LUN,59)
59	FORMAT(' I`m terribly sorry, you can`t have that space.')
	GOTO 50
61	WRITE(LUN,62)
62	FORMAT('0now enter your FORWARD direction (1,2,3,4,5 or 6): ',$)
	READ(LUN,66,ERR=50) JF
	IF(JF.GT.6.OR.JF.LT.1) GOTO 50
	ICR(ID,2)=JF
	JB=IREVRS(JF)
	ICR(ID,4)=JB
	IF(JF.EQ.1.OR.JF.EQ.3) WRITE(LUN,63)
	IF(JF.EQ.2.OR.JF.EQ.4) WRITE(LUN,64)
	IF(JF.EQ.5.OR.JF.EQ.6) WRITE(LUN,65)
63	FORMAT('0enter your UP direction (2,4,5 or 6): ',$)
64	FORMAT('0enter your UP direction (1,3,5 or 6): ',$)
65	FORMAT('0enter your UP direction (1,2,3 or 4): ',$)
	READ(LUN,66,ERR=50) JU
66	FORMAT(I1)
	IF(JU.EQ.JF.OR.JU.EQ.JB.OR.JU.LT.1.OR.JU.GT.6) GOTO 50
82	ICR(ID,6)=JU
	JD=IREVRS(JU)
	ICR(ID,7)=JD
C 
C	FIGURE LEFT/RIGHT:
	IF(JU.EQ.1) GOTO 71
	IF(JU.EQ.2) GOTO 72
	IF(JU.EQ.3) GOTO 73
	IF(JU.EQ.4) GOTO 74
	IF(JU.EQ.5) JR=JF-1
	IF(JU.EQ.6) JR=JF+1
	IF(JR.GT.4) JR=1
	IF(JR.LT.1) JR=4
	GOTO 75
71	IF(JF.EQ.2) JR=6
	IF(JF.EQ.5) JR=2
	IF(JF.EQ.4) JR=5
	IF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