C LAST UPDATE:
C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C*************************
C**     LDM_SYSABS      **
C*************************
C
C
CD-Routine: Check for Systematic Absence - LDM_SYSABS
C This routine checks whether a given reflection is a systematic absence
C based on the symmetry information available. Its initial checks are
C based on the lattice type but it will then use the full symmetry
C information if this has been defined.
CD-end
CD-Fortran:
        SUBROUTINE LDM_SYSABS (IH,IK,IL,ABSNT)
CD-end
      INCLUDE 'implicit_none.finc'
C
C Purpose: Determine whether reflection is systematically absent
C
C Author:  Based on CCP4 code & code from GENLAUE by Clifton et al. 
C
C Arguments:
C
      INTEGER IH
      INTEGER IK
      INTEGER IL
      LOGICAL ABSNT
CD-Parameters:
C IH      i (R)     h index 
C IK      i (R)     k index
C IL      i (R)     l index
C ABSNT   l (W)     returns =.TRUE. systematically absent, =.FALSE. not
CD-end
C
C====== GLOBALS:
C
      INCLUDE 'ldm_data.finc'
      INCLUDE 'ldm_derived.finc'
C
C====== LOCALS:
C
        INTEGER I, J
        INTEGER H(3)
        INTEGER JH, JK, JL
        REAL PHAS
        REAL ERR
C
C-------------------------------------------------------------------------------
C
      ABSNT = .FALSE.
      IF (ISYS.EQ.0) GO TO 100
      H(1) = IH
      H(2) = IK
      H(3) = IL
      IF (ISYS.EQ.4) THEN
 
         ABSNT = .TRUE.
         DO 20 I = 1 , 2
            IF (MOD(H(I)+H(I+1),2).NE.0) RETURN
 20      CONTINUE
         ABSNT = .FALSE.
         GO TO 100
      ELSE
C
C====== This version for a,b,c,r,i & f lattice absences
C
         ABSNT = .FALSE.
         J = 0
         DO 30 I = 1 , 3
            J = J + H(I)*KSYS(I)
 30      CONTINUE
         IF (MOD(J,ISYS).NE.0) THEN
            ABSNT = .TRUE.
            RETURN
         END IF
      END IF
C
C====== Additional full check for further absences if full symmetry
C       defined
C
100   IF (NSYM.LT.2) RETURN
      IF (IH.NE.0) THEN
         IF (IK.NE.0) THEN
            IF (IL.NE.0) THEN
               IF (IH.NE.IK) RETURN
               IF (IH.NE.IL) RETURN
            END IF
         END IF
      END IF
C
C====== Test whether h' k' l' equals h k l
C
      DO 120 J = 2, NSYM
         JH = IH*RSMINV(1,1,J)+IK*RSMINV(2,1,J)+IL*RSMINV(3,1,J)
         IF (JH.EQ.IH) THEN
            JK = IH*RSMINV(1,2,J)+IK*RSMINV(2,2,J)+IL*RSMINV(3,2,J)
            IF (JK.EQ.IK) THEN
               JL = IH*RSMINV(1,3,J)+IK*RSMINV(2,3,J)+IL*RSMINV(3,3,J)
               IF (JL.EQ.IL) THEN
C
C====== Test whether this Symmetry equivalent has a different phase to
C       IH, IK, IL - if so it is a systematic absence (... believe me, EJD)
C
                  PHAS = IH*ROTSYM(1,4,J) + IK*ROTSYM(2,4,J) +
     +                   IL*ROTSYM(3,4,J)
                  ERR = ABS(PHAS-NINT(PHAS))
                  IF (ERR.GT.0.05) THEN
                     ABSNT = .TRUE.
                     RETURN
                  END IF
               END IF
            END IF
         END IF
120   CONTINUE
      RETURN
      END
