      SUBROUTINE TRFMAT(A66,ANG)
C
C     SUBROUTINE FOR THE TRANSFORMATION OF THE CRYSTAL FROM ITS OWN
C     COORDINATE SYSTEM TO THE COORDINATE SYSTEM USED BY THE RAY
C     TRACING PROGRAM
C
C **********************************************************************

C
C     ANG(1-3) ROTATION ANGLES
C
      COMMON/ZERRO/RNULL
CINCLUDE CZERO
      DIMENSION A66(6,6),ANG(3),A1N(3,3,3,3),D(3,3),
     1DA1(3,3,3,3)
C
C  COMPUTATION OF THE MATRIX A1N (MATRIX OF ELASTIC COEFICIENTS
C  IN ITS OWN COORDINATE SYSTEM)
C
      DO 30 I=1,3
      DO 30 J=1,3
      DO 30 K=1,3
      DO 30 L=1,3
      CALL INDEX1(I,J,I1)
      CALL INDEX1(K,L,K1)
      A1N(I,J,K,L)=A66(I1,K1)
   30 CONTINUE
C
C  COMPUTATION OF MATRIX D (THE MATRIX FOR TRANSFORMATION)
C
      CALL TRANSF(ANG,D)
C
C  COMPUTATION OF THE MATRIX OF ELASTIC COEFFICIENTS
C  IN THE COORDINATE SYSTEM FOR RAY COMPUTATION
C
      DO 40 I=1,3
      DO 40 N=1,3
      DO 40 IR=1,3
      DO 40 IS=1,3
      DA1(I,N,IR,IS)=0.0
      DO 40 M=1,3
      DA1(I,N,IR,IS)=DA1(I,N,IR,IS)+D(I,M)*A1N(M,N,IR,IS)
   40 CONTINUE
C
      DO 41 I=1,3
      DO 41 J=1,3
      DO 41 IR=1,3
      DO 41 IS=1,3
      A1N(I,J,IR,IS)=0.0
      DO 41 N=1,3
      A1N(I,J,IR,IS)=A1N(I,J,IR,IS)+D(J,N)*DA1(I,N,IR,IS)
   41 CONTINUE
C
      DO 43 I=1,3
      DO 43 J=1,3
      DO 43 K=1,3
      DO 43 IS=1,3
      DA1(I,J,K,IS)=0.0
      DO 43 IR=1,3
      DA1(I,J,K,IS)=DA1(I,J,K,IS)+D(K,IR)*A1N(I,J,IR,IS)
   43 CONTINUE
C
      DO 44 I=1,3
      DO 44 J=1,3
      DO 44 K=1,3
      DO 44 L=1,3
      A1N(I,J,K,L)=0.0
      DO 44 IS=1,3
      A1N(I,J,K,L)=A1N(I,J,K,L)+D(L,IS)*DA1(I,J,K,IS)
   44 CONTINUE
C
C
C  COMPUTATION OF THE MATRIX A66 (THE MATRIX A1N IN THE
C  COMPRESSED FORM)
C
      DO 50 I=1,6
      DO 50 J=1,6
      CALL INDEX2(I,I1,J1)
      CALL INDEX2(J,K1,L1)
      A66(I,J)=A1N(I1,J1,K1,L1)
      IF(ABS(A66(I,J)).LT.RNULL) A66(I,J)=0.
   50 CONTINUE
      RETURN
      END
C
C     ************************************************************
C
      SUBROUTINE INDEX1(I,J,I1)
C
C  SUBROUTINE FOR DETERMINING THE INDEX I1 FOR THE SYMETRIC
C  TENSOR OF SECOND RANK IN COMPRESSED FORM FROM TWO
C  INDICES I,J OF THE SAME TENSOR ELEMENT IN NONCOMPRESSED
C  FORM
C
C
      IF(I.NE.J) GO TO 10
      I1=I
      RETURN
C
   10 CONTINUE
      IJ=I+J-2
      GO TO (20,30,40),IJ
C
   20 CONTINUE
      I1=6
      RETURN
C
   30 CONTINUE
      I1=5
      RETURN
C
   40 CONTINUE
      I1=4
      RETURN
      END
C
C     ***********************************************************
C
      SUBROUTINE INDEX2(I,I1,J1)
C
C  SUBROUTINE FOR DETERMINING THE TWO INDEXES I1,J1 WHICH
C  CORRESPOND TO INDEX I OF THE ELEMENT OF THE SYMETRIC
C  TENSOR OF SECOND RANK IN THE COMPRESSED FORM
C
      GO TO (10,10,10,20,30,40),I
C
   10 CONTINUE
      I1=I
      J1=I
      RETURN
C
   20 CONTINUE
      I1=2
      J1=3
      RETURN
C
   30 CONTINUE
      I1=1
      J1=3
      RETURN
C
   40 CONTINUE
      I1=1
      J1=2
      RETURN
      END
