C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LFN_UNQ_INC      **
C**************************
C
CD-Routine: Increment Counts in Unique Reflections List - LFN_UNQ_INC
C This routine enables counters, associated with the unique reflections list,
C to be incremented for a reflection in the list so that statistics may be 
C subsequently produced comparing the counted reflections with the numbers 
C of unique reflections.
CD-end
CD-Fortran:
      SUBROUTINE LFN_UNQ_INC (IREF, MULT, I_SIGN, ISPAT, IERR)
CD-end
      INCLUDE 'implicit_none.finc'
C
C Purpose: Increment counts for a reflection in unique reflections list
C
C Author:  John W. Campbell, September 1993
C
C Arguments:
C
      INTEGER IREF
      INTEGER MULT
      INTEGER I_SIGN
      INTEGER ISPAT
      INTEGER IERR
CD-Parameters:
C  IREF      i (R)   Reflection number in the list
C  MULT      i (R)   Multiplicity (1 for a single)
C  I_SIGN    i (R)   +1 for I+, -1 for I-
C  ISPAT     i (R)   =0 non-spatially overlapped, =1 spatially overlapped
C  IERR      i (W)   =0 OK, =1 invalid IREF
CD-end
C
C====== GLOBALS:
C
      EXTERNAL LFN_UNQ_BDAT
      INCLUDE 'lfn_unq.finc'
C
C====== FUNCTION TYPES:
C

C
C====== LOCALS:
C
      INTEGER I
      INTEGER NTWO20
      INTEGER NTWO10
      INTEGER INDX
      INTEGER NSING
      INTEGER NMULT
      INTEGER NSPAT
      INTEGER NDOUBLE
      INTEGER NTRIPLE
      INTEGER NHIGHER
      INTEGER NPLUS
      INTEGER NMINUS

C     INTEGER I           !Temp. integer value
C     INTEGER NTWO20      !2**20
C     INTEGER NTWO10      !2**10
C     INTEGER INDX        !Index into reflections list
C     INTEGER NSING       !No. of occurrences as a single
C     INTEGER NMULT       !No. of occurrences as a multiple
C     INTEGER NSPAT       !No. of occurrences as spatially overlapped
C     INTEGER NDOUBLE     !No. of occurrences as a double
C     INTEGER NTRIPLE     !No. of occurrences as a triple
C     INTEGER NHIGHER     !No. of occurrences as a higher multiple
C     INTEGER NPLUS       !No. of occurrences as I+
C     INTEGER NMINUS      !No. of occurrences as I-

      DATA NTWO20/1048576/
      DATA NTWO10/1024/

C
C-------------------------------------------------------------------------------
C
      IERR = 0
      IF (IREF.LT.1.OR.IREF.GT.NUM_UNQ) THEN
         IERR = 1
         RETURN
      ELSE
         INDX = INDX_UNQ(IREF)
         I = COUNTS(INDX)
         NSING = I/NTWO20
         I = I - NTWO20*NSING
         NMULT = I/NTWO10
         NSPAT = I - NTWO10*NMULT
         IF (MULT.GT.1) THEN
            NMULT = NMULT + 1
         ELSE
            NSING = NSING + 1
         END IF
         IF (ISPAT.NE.0) NSPAT = NSPAT + 1
         COUNTS(INDX) = NTWO20*NSING + NTWO10*NMULT + NSPAT
         IF (MULT.GT.1) THEN
            I = MULT_CNT(INDX)
            NDOUBLE = I/NTWO20
            I = I - NTWO20*NDOUBLE
            NTRIPLE = I/NTWO10
            NHIGHER = I - NTWO10*NTRIPLE
            IF (MULT.EQ.2) THEN
               NDOUBLE = NDOUBLE + 1
            ELSE IF (MULT.EQ.3) THEN
               NTRIPLE = NTRIPLE + 1
            ELSE IF (MULT.GT.3) THEN
               NHIGHER = NHIGHER + 1
            END IF
            MULT_CNT(INDX) = NTWO20*NDOUBLE + NTWO10*NTRIPLE + NHIGHER
         END IF
         I = SIGN_CNT(INDX)
         NPLUS = I/NTWO10
         NMINUS = I - NTWO10*NPLUS
         IF (I_SIGN.LT.0) THEN
            NMINUS = NMINUS + 1
         ELSE
            NPLUS = NPLUS + 1
         END IF
         SIGN_CNT(INDX) = NTWO10*NPLUS + NMINUS 
      END IF
      RETURN
      END
