C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LFN_UNQ_TAB3     **
C**************************
C
C
CD-Routine: Statistics Table 3 Versus Unique Data - LFN_UNQ_TAB3
C This routine is used used to produce a table of Laue statistics data 
C using the statistics returned by the routine LFN_UNQ_STAT. The
C analysis is in bins of 4*sin**2theta/lambda**2.
C This routine lists cumulative (cf LFN_UNQ_TAB1, LFN_UNQ_TAB2) counts in 
C classes of minimum multiplicity from which each reflection may be obtained; 
C note that  a given Laue reflection may fall into only one class (cf 
C LFN_UNQ_TAB1). The data may be written to the terminal or to a file.
CD-end
CD-Fortran:
      SUBROUTINE LFN_UNQ_TAB3 (IUN, ITERM, NBIN, SPAT, RESMIN, RESMAX, 
     +                       NCOUNT, NCOUNT_TOT, PERCENT, PERCENT_TOT)
CD-end
      INCLUDE 'implicit_none.finc'
C
C Purpose: Print table of counts statistics on Laue data wrt. unique data in 
C          bins of 4*sin**2theta/lambda**2 (using data from LFN_UNQ_STAT)
C
C          This routine lists counts in classes of minimum multiplicity from
C          which each reflection may be obtained; note that a given Laue 
C          reflection may fall into only one class (cf LFN_UNQ_TAB1).
C
C Author:  John W. Campbell, September 1993
C
C Arguments:
C
      INTEGER IUN
      INTEGER ITERM
      INTEGER NBIN
      LOGICAL SPAT
      REAL RESMIN(*)
      REAL RESMAX(*)
      INTEGER NCOUNT(10,*)
      INTEGER NCOUNT_TOT(*)
      REAL PERCENT(10,*)
      REAL PERCENT_TOT(*)
      INTEGER IERR
CD-Parameters:
C IUN               i (R)   Unit no. for listing
C ITERM             i (R)   =1, o/p to terminal, =0 o/p to file
C NBIN              i (R)   No. of 4*sin**2theta/lambda**2 bins
C SPAT              l (R)   =.TRUE.  spatially overlapped data were 
C                                    included,
C                           =.FALSE. spatially overlapped data not 
C                                    included,
C                           This must be the value used when LFN_UNQ_STAT 
C                           was called.
C RESMIN(10,NBIN)   r (R)   Start resolution of bins
C RESMAX(10,NBIN)   r (R)   End resolution of bins
C NCOUNT(10,NBIN)   i (R)   No. counts for each bin (see also below)
C NCOUNT_TOT(NBIN)  i (R)   Total numbers (see also below)
C PERCENT(10,NBIN)  r (R)   Counts for each bin as percentages of unique data
C PERCENT_TOT(NBIN) r (R)   Total counts as percentages of unique data
C
C                           First index:
C
C                            = 1    No. of unique reflections
C                            = 2    No. of Laue (single or multiple)
C                            = 3    No. of singles (may also be multiples)
C                            = 4    No. of multiples (may also be singles)
C                            = 5    No. of doubles (may also be otherwise)
C                            = 6    No. of triples (may also be otherwise)
C                            = 7    No. of higher mults. (may also be 
C                                   otherwise)
C                            = 8    No. with double as lowest multiplicity
C                            = 9    No. with triple as lowest multiplicity
C                            = 10   No. with higher mult as lowest 
C                                   multiplicity
CD-end
C
C====== Parameter statements
C 

C
C====== GLOBALS:
C

C
C====== FUNCTION TYPES:
C
      INTEGER LENSTR
C
C====== LOCALS:
C
      INTEGER I
      REAL PC1
      REAL PC2
      REAL PC3
      REAL PC4
      CHARACTER*80 STR

C     INTEGER I           !Loop counter
C     REAL PC1            !Cumulative percentage 1
C     REAL PC2            !Cumulative percentage 2
C     REAL PC3            !Cumulative percentage 3
C     REAL PC4            !Cumulative percentage 4
C     CHARACTER*80 STR    !Output string
C
C-------------------------------------------------------------------------------
C
C====== Output headings
C
      STR = 
     +'Table of Cumulative Laue Data Completeness'
      CALL STR_ADDS (STR,'by Lowest Multiplicity',1)
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
      ELSE
          WRITE(IUN,1000) STR(1:LENSTR(STR))
      END IF
      STR = 
     +'------------------------------------------'
      CALL STR_ADDS (STR,'-----------------------',0)
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
      ELSE
          WRITE(IUN,1000) STR(1:LENSTR(STR))
      END IF
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,' ',1)
      ELSE
          WRITE(IUN,1000) ' '
      END IF
      STR = 'Bin   Resolution      No.     No.'
      CALL STR_ADDS (STR,'Laue-lowest-multiplicities',3)
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
      ELSE
          WRITE(IUN,1000) STR(1:LENSTR(STR))
      END IF
      STR = 'no.    range (A)    Unique   Laue '
      CALL STR_ADDS (STR,'1      2      3     >3',5)
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
      ELSE
          WRITE(IUN,1000) STR(1:LENSTR(STR))
      END IF
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,' ',1)
      ELSE
          WRITE(IUN,1000) ' '
      END IF
C
C====== Output bins data
C
      DO 100 I = 1, NBIN
         STR = ' '
         CALL STR_ADDI (STR, I, 0)
         CALL STR_ADDF (STR(7:),RESMIN(I),2,0)
         CALL STR_ADDS (STR,'-',0)
         CALL STR_ADDF (STR,RESMAX(I),2,0)
         PC1 = PERCENT(3,I)
         PC2 = PC1 + PERCENT(8,I)
         PC3 = PC2 + PERCENT(9,I)
         PC4 = PC3 + PERCENT(10,I)
         WRITE (STR(20:),'(2I7,4F7.1)') NCOUNT(1,I), NCOUNT(2,I),
     +                    PC1, PC2, PC3, PC4
         IF (ITERM.EQ.1) THEN
             CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
             WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
100   CONTINUE
C
C====== Output totals
C
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,' ',1)
      ELSE
          WRITE(IUN,1000) ' '
      END IF
      STR = 'All'
      CALL STR_ADDF (STR(7:),RESMIN(1),2,0)
      CALL STR_ADDS (STR,'-',0)
      CALL STR_ADDF (STR,RESMAX(NBIN),2,0)
      PC1 = PERCENT_TOT(3)
      PC2 = PC1 + PERCENT_TOT(8)
      PC3 = PC2 + PERCENT_TOT(9)
      PC4 = PC3 + PERCENT_TOT(10)
      WRITE (STR(20:),'(2I7,4F7.1)') NCOUNT_TOT(1), NCOUNT_TOT(2),
     +                PC1, PC2, PC3, PC4
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
      ELSE
          WRITE(IUN,1000) STR(1:LENSTR(STR))
      END IF
C
C====== Output notes
C
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,' ',1)
      ELSE
          WRITE(IUN,1000) ' '
      END IF
      STR = 
     +'Note: Reflections may only fall into one multiplicity category'
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
      ELSE
          WRITE(IUN,1000) STR(1:LENSTR(STR))
      END IF
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,' ',1)
      ELSE
          WRITE(IUN,1000) ' '
      END IF
      IF (SPAT) THEN
         STR = 'Note: Spatially overlapped data included'
      ELSE
         STR = 'Note: Spatially overlapped data not included'
      END IF
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
      ELSE
          WRITE(IUN,1000) STR(1:LENSTR(STR))
      END IF
      RETURN
C
C====== Format statements
C
1000  FORMAT(A)
      END
