	SUBROUTINE ENTOM
C
C ROUTINE TO ENTER ORIENTATION MATRIX
C
	include 'single.inc'
C SAVE CURRENT OM IN 'UBO'
	CALL PUSHOM
	TYPE 2
2	FORMAT('$Type Orientation Matrix by Row'/)
	DO 100 I=1,3
3	  TYPE 4,I
4	  FORMAT('$Row',I2,'?')
	  read(5,6,end=9999,err=3)(UB(I,J),J=1,3)
6	  FORMAT(3F12.0)
100	CONTINUE
	CALL UPDATE
	CALL OMTOB(0)
9999	RETURN
	END
	SUBROUTINE CALCOM
C
C ROUTINE TO CALCULATE AN ORIENTATION MATRIX FROM THE UNIT CELL
C  AND TWO REFLECTIONS
C
	include 'single.inc'
	DIMENSION IH(3,2),ANGL(4,2),C(3,3),O(3,3),H(3,3)
	1,THPHI(3,2),G(3,3)
	byte resp
	DATA RAD/57.2958/
C
C SAVE PRESENT MATRIX
	CALL PUSHOM
C
200	TYPE 201
201	FORMAT('$ Input List Numbers of 2 Reflections: ')
	read(5,202,end=9999,err=200)I1,I2
202	FORMAT(2I5)
	IF(I1 .EQ. 0 .AND. I2 .EQ. 0)THEN
		TYPE 2
2		FORMAT(' Type Indices and Angles for')
		DO I=1,2
3		  TYPE 4,I
4		  FORMAT('$Refl.',I2,'?')
		  read(5,6,end=9999,err=3)(IH(J,I),J=1,3),(ANGL(J,I),J=1,4)
6		  FORMAT(3I3,4F10.0)
		ENDDO
	ELSE
	   ISUM1=ABS(IHLST(1,I1))+ABS(IHLST(2,I1))+ABS(IHLST(3,I1))
	   ISUM2=ABS(IHLST(1,I2))+ABS(IHLST(2,I2))+ABS(IHLST(3,I2))
	   IF(ISUM1 .EQ. 0 .OR. ISUM2 .EQ. 0)THEN
		TYPE 220
220		FORMAT(' Type Indices for')
		DO I=1,2
221		TYPE 4,I
		read(5,230,end=9999,err=221)(IH(J,I),J=1,3)
230		FORMAT(3I3)
		ENDDO
	   ELSE
		DO I=1,3
		IH(I,1)=nint(IHLST(I,I1))
		IH(I,2)=nint(IHLST(I,I2))
		ENDDO
	   ENDIF
	   DO I=1,4
	   ANGL(I,1)=ANGLST(I,I1)
	   ANGL(I,2)=ANGLST(I,I2)
	   ENDDO
	ENDIF
	DO 100 I=1,2	
99	  if(angl(1,i).le.0.0)angl(1,i)=20.0
	  CALL CALCH(ANGL(1,I),THPHI(1,I))
100	CONTINUE
	DOTPR=0.0
	VL1=0.0
	VL2=0.0
	DO 101 I=1,3
	  DOTPR=THPHI(I,1)*THPHI(I,2)+DOTPR
	  VL1=VL1+THPHI(I,1)**2
	  VL2=VL2+THPHI(I,2)**2
101	CONTINUE
	VL1=RAD*ACOS(DOTPR/SQRT(VL1*VL2))
	SUMO=0.
	DO 102 I=1,2
	  DO 102 J=1,3
	    O(J,I)=0.0
	    DO 102 K=1,3
		O(J,I)=O(J,I)+B(J,K)*IH(K,I)
		SUMO=SUMO+O(J,I)
102	CONTINUE
C
C  TRAP CASE OF INVALID UB GIVING O=0.
C
	IF(abs(SUMO) .LT. 1.0E-5)THEN
	  TYPE 105
105	  FORMAT(' INVALID UB MATRIX OR NO UNIT CELL GIVEN')
	  RETURN
	ENDIF
	VL2=ACOS((O(1,1)*O(1,2)+O(2,1)*O(2,2)+O(3,1)*O(3,2))
	1/(SQRT(O(1,1)**2+O(2,1)**2+O(3,1)**2)
	2*SQRT(O(1,2)**2+O(2,2)**2+O(3,2)**2)))*RAD
	TYPE 8,VL1,vl2
8	FORMAT(' Observed Angle:',F8.2,',    Calculated:',f8.2)
C
C CALCULATE MATRIX O
C
	CALL ORTHOG(THPHI(1,1),THPHI(1,2),O)
C
C CALCULATE MATRIX H AND C
C
	DO 130 I=1,2
	  DO 120 J=1,3
	    H(J,I)=0.0
	    DO 110 K=1,3
	      H(J,I)=H(J,I)+B(J,K)*IH(K,I)
110	    CONTINUE
120	  CONTINUE
130	CONTINUE
	CALL ORTHOG(H(1,1),H(1,2),C)
C
C INVERT C AND CALCULATE U=O*C-1
C
	CALL MINV(C,H,DET)
	IF(DET.NE.0.0)GO TO 132
	  TYPE 10
10	  FORMAT(' DEGENERATE SYSTEM')
	  RETURN
132	CONTINUE
	CALL MATMUL(O,H,C)
	CALL MATMUL(C,B,UB)
	TYPE 12
12	FORMAT(' Orientation Matrix')
	DO 140 I=1,3
	  TYPE 14,(UB(I,J),J=1,3)
14	  FORMAT(3F12.5)
140	CONTINUE
141	type 16
16	format('$Do You Wish to Update Matrix<Y,N>? ')
	read(5,18,end=9999,err=141)resp
18	format(a1)
	if(resp.eq.'y'.or.resp.eq.'Y')CALL UPDATE
9999	RETURN
	END
