C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LDM_DTOQAX       **
C**************************
C
CD-Routine: Convert Detector to 'Q' Axis Coordinates - LDM_DTOQAX
C This routine converts idela detector axes to coordinates with respect to
C a 'q' set of axes as defined in the parameter description of the routine.
CD-end
CD-Fortran:
      SUBROUTINE LDM_DTOQAX (XF, YF, CTF, XQ, YQ, ZQ)
CD-end
      INCLUDE 'implicit_none.finc'
C
C Purpose: Get detector coordinates with respect to 'q' axes
C
C Author:  John W. Campbell, July 1993, July 1997
C          Cylindrical camera option Wilkinson & Lehmann
C
C Arguments:
C
      REAL XF
      REAL YF
      REAL CTF
      REAL XQ
      REAL YQ
      REAL ZQ

CD-Parameters:
C  XF      r (R)    Detector xf coordinate (mm) (Wonacott convention)
C  YF      r (R)    Detector yf coordinate (mm) (Wonacott convention)
C  CTF     r (R)    Crystal to detector distance (mm)
C  XQ      r (W)    Reciprocal lattice X coordinate wrt 'q' axes
C  YQ      r (W)    Reciprocal lattice Y coordinate wrt 'q' axes
C  ZQ      r (W)    Reciprocal lattice Z coordinate wrt 'q' axes
C
C  'q' axes are as follows:
C
C      Origin at crystal
C      XQ along Wonacott Y
C      YQ along Wonacott Z
C      ZQ along Wonacott X (X-ray beam)
C
C      For untilted flat detector: XQ=XF, YQ=YF, ZQ=CTF
CD-end
C
C====== GLOBALS:
C
      INCLUDE 'ldm_derived.finc'
C
C====== LOCALS:
C
      REAL GAMMA
C
C-------------------------------------------------------------------------------
C
C
C====== Get coordinates of detector position wrt axes rotated to give xq || y,
C====== yq || z and zq along x origin at centre of reflecting sphere. ('q' axes)
C
      IF (IDGEOM.EQ.1) THEN
C
C====== Flat
C
         XQ = XF*COS_DTILT + CTF*SIN_DTILT
         YQ = YF
         ZQ = CTF*COS_DTILT - XF*SIN_DTILT
      ELSE
C
C====== Cylindrical
C
         GAMMA = XF/CTF
         XQ = CTF*SIN(GAMMA)
         YQ = YF
         ZQ = CTF*COS(GAMMA)
      END IF
      RETURN
      END
