C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LFN_UNQ_TAB1     **
C**************************
C
CD-Routine: Statistics Table 1 Versus Unique Data - LFN_UNQ_TAB1
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 counts in classes of multiplicity; note that
C a given Laue reflection may fall into more than one class (cf LFN_UNQ_TAB2).
C The data may be written to the terminal or to a file.
CD-end
CD-Fortran:
      SUBROUTINE LFN_UNQ_TAB1 (IUN, ITERM, NBIN, SPAT, RESMIN, RESMAX, 
     +                         NCOUNT, NCOUNT_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 multiplicity; note that
C          a given Laue reflection may fall into more than one class.
C          (cf LFN_UNQ_TAB2)
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(*)
      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                           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
      CHARACTER*80 STR

C     INTEGER I           !Loop counter
C     CHARACTER*80 STR    !Output string
C
C-------------------------------------------------------------------------------
C
C====== Output headings
C
      STR = 'Table of Laue Data Reflection Counts by Multiplicity'
      IF (ITERM.EQ.1) THEN
          CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
      ELSE
          WRITE(IUN,1000) STR(1:LENSTR(STR))
      END IF
      STR = '----------------------------------------------------'
      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-data-multiplicities',4)
      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',6)
      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)
         WRITE (STR(20:),'(6I7)') NCOUNT(1,I), NCOUNT(2,I),
     +      NCOUNT(3,I), NCOUNT(5,I), NCOUNT(6,I), NCOUNT(7,I)
         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)
      WRITE (STR(20:),'(6I7)') NCOUNT_TOT(1), NCOUNT_TOT(2),
     +   NCOUNT_TOT(3), NCOUNT_TOT(5), NCOUNT_TOT(6), NCOUNT_TOT(7)
      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 fall into more than one 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
