C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LRL_A_CALC       **
C**************************
C
CD-Routine: Calculate the Master 'A' Matrix - LRL_A_CALC
C This routine calculates the master matrix, a_mat, from the crystal system,
C crystal alignment and cell parameters. This is then premultiplied by the phi 
C matrices. It is used as a service routine for the subroutine LRL_GEN but may
C be called directly if required.
CD-end
CD-Fortran:
      SUBROUTINE  LRL_A_CALC (IPACK, ORIENT, A_MAT)
CD-end
      INCLUDE 'implicit_none.finc'
C
C
C Purpose: Calculates the master matrix, a_mat, from the crystal system,
C          crystal alignment and cell parameters.
C          This is then premultiplied by the phi matrices.
C
C          (Used as a service routine for LRL_GEN but may be
C           called directly if desired)
C
C Author:  Based on code from GENLAUE by Clifton et al.
C
C Arguments:
C
      INTEGER    IPACK
      REAL       ORIENT(3,3)
      REAL       A_MAT(3,3)
CD-Parameters:
C IPACK        i (R)   Pack number
C ORIENT(3,3)  r (R)   Orientation matrix from crystal setting & cell 
C                      parameters
C A_MAT(3,3)   r (W)   The master matrix
CD-end
C
C====== FUNCTION TYPES:
C
      EXTERNAL LRL_BDAT
C
C====== LOCALS:
C
      CHARACTER*1 ERRSTR
      INTEGER IFLAG
      INTEGER ND
      INTEGER IERR
      REAL    PHIS(3)
      REAL    PC(3,3)
C
C------------------------------------------------------------------------------
C
C====== Get Phis
C
      CALL LDM_GET_PHIX (IPACK, PHIS(1), IFLAG, ND, IERR, ERRSTR)
      CALL LDM_GET_PHIY (IPACK, PHIS(2), IFLAG, ND, IERR, ERRSTR)
      CALL LDM_GET_PHIZ (IPACK, PHIS(3), IFLAG, ND, IERR, ERRSTR)
C
C====== Define phi rotation matrix
C
      CALL MTX_ROTATE(PHIS,PC)
C
C====== Apply phi rotations
C
      CALL MTX_MULT(PC,ORIENT,A_MAT,3,3,3)
      RETURN
      END
