      SUBROUTINE TRANSF(AN,D)
C
C  SUBROUTINE FOR COMPUTING THE MATRIX OF ROTATION FOR THE
C  CRYSTAL AXES, WHICH INITIALLY COINCIDE WITH THE MODEL AXES
C  (X1, X2 SITUATED IN THE HORIZONTAL PLANE, X3 VERTICAL),
C  INTO THEIR PROPER POSITION IN THE MODEL.
C
C  THE MATRIX IS SPECIFIED BY THREE ANGLES, PHI=AN(1), DE=AN(2),
C  GA=AN(3). THE ANGLES PHI AND DE SPECIFY THE ORIENTATION OF
C  THE CRYSTAL AXIS X3 IN THE MODEL, THE ANGLE GA SPECIFIES
C  THE ORIENATION OF CRYSTAL AXES X1, X2 IN THE PLANE PERPEN-
C  DICULAR TO THE CRYSTAL AXIS X3.
C  PHI... AZIMUTH (IN DEGREES). ANGLE BETWEEN POSITIVE DIREC-
C         TIONS OF THE X1 MODEL AXIS AND HORIZONTAL PROJECTION
C         OF X3 CRYSTAL AXIS. IT IS POSITIVE IF MEASURED FROM
C         POSITIVE DIRECTION OF X1 AXIS TOWARDS POSITIVE DIREC-
C         TION OF X2 AXIS OF MODEL COORDINATES.
C  DE ... INCLINATION (0-90 DEGREES). ANGLE BETWEEN THE POSITI-
C         VE DIRECTION OF THE MODEL X3 AXIS AND X3 AXIS OF
C         CRYSTAL COORDINATE SYSTEM.
C  GA ... ROTATION ANGLE (IN DEGREES) IN THE PLANE PERPEN-
C         DICULAR TO THE CRYSTAL X3 AXIS. FOR GA=0, CRYSTAL
C         X2 AXIS IS HORIZONTAL, X1 AXIS IS PERPENDICULAR
C         TO IT AND POINTS DOWN. FOR GA NONZERO, THE CRYSTAL
C         X1, X2 AXES ARE ROTATED POSITIVELY FROM THEIR POSI-
C         TION FOR GA=0.
C  NOTE1: FOR PSI=0, DE=0 AND GA=0 CRYSTAL AXES COINCIDE WITH
C         AXES OF MODEL COORDINATES, I.E. POSITIVE CRYSTAL AXIS
C         POINTS DOWN.
C  NOTE2: BOTH MODEL AND CRYSTAL COORDINATE SYSTEMS ARE RIGHT-
C         HANDED.
C  NOTE3: COMPONENTS OF THE UNIT BASE VECTOR OF THE CRYSTAL
C         AXIS X3 IN MODEL COORDINATES ARE:
C         (COS(PHI)SIN(DE), SIN(PHI)SIN(DE), COS(DE)).
C
C  DECLARATIONS
C
      DIMENSION AN(3),D(3,3)
C
      DATA PI180/0.0174532925/
C
C
C  CONVERSION INTO RAD MODE
C
      PHI=AN(1)*PI180
      DE=AN(2)*PI180
      GA=AN(3)*PI180
C
C
      SF=SIN(PHI)
      CF=COS(PHI)
      SD=SIN(DE)
      CD=COS(DE)
      SG=SIN(GA)
      CG=COS(GA)
C
      IF(ABS(GA).GE..000001)GO TO 10
C
C
C     ONLY X3 AXIS OF CRYSTAL COORDINATE SYSTEM IS
C     SPECIFIED. ORIENTATION OF X1 AND X2 CRYSTAL AXES
C     CAN BE ARBITRARY - CASE OF MEDIUM WITH HEXAGONAL
C     SYMMETRY
C
      D(1,1)=CF*CD
      D(1,2)=-SF
      D(1,3)=CF*SD
      D(2,1)=SF*CD
      D(2,2)=CF
      D(2,3)=SF*SD
      D(3,1)=-SD
      D(3,2)=0.
      D(3,3)=CD
      RETURN
C
C
C     ALL THREE AXES OF CRYSTAL COORDINATE SYSTEM ARE
C     SPECIFIED
C
   10 D(1,1)=-SF*SG+CF*CD*CG
      D(1,2)=-SF*CG-CF*CD*SG
      D(1,3)=CF*SD
      D(2,1)=CF*SG+SF*CD*CG
      D(2,2)=CF*CG-SF*CD*SG
      D(2,3)=SF*SD
      D(3,1)=-SD*CG
      D(3,2)=SD*SG
      D(3,3)=CD
C
      RETURN
      END
