C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LFN_SOFT_LIST    **
C**************************
C
CD-Routine: List Soft Limit Results - LFN_SOFT_LIST
C This routine is used to list the results from a soft-limit determination
C using the LFN_SOFT routine. Output may be to a terminal or a file.
CD-end
CD-Fortran:
      SUBROUTINE LFN_SOFT_LIST (IUN, ITERM, IPACK, IPLATE, IOPT, 
     +                     PROMIN, NTHE, PROF_ROT, SIGTEST, FRTEST, 
     +                     NUMBINS, BIN_WIDTH,
     +                     NMEAS, NGTSIG, RBIN,
     +                     SOFT_MIN, SOFT_MAX, SOFT_SEL, IBIN_SEL,
     +                     IWARN, WARNSTR)
CD-end
      INCLUDE 'implicit_none.finc'
C
C Purpose: List soft limits determination results
C
C Author:  J. W. Campbell, June 1994
C
C Arguments:
C
      INTEGER IUN
      INTEGER ITERM
      INTEGER IPACK
      INTEGER IPLATE 
      INTEGER IOPT
      REAL PROMIN
      INTEGER NTHE
      LOGICAL PROF_ROT
      REAL SIGTEST
      REAL FRTEST
      INTEGER NUMBINS
      REAL BIN_WIDTH
      INTEGER NMEAS(NUMBINS)
      INTEGER NGTSIG(NUMBINS)
      REAL RBIN(NUMBINS)
      REAL SOFT_MIN
      REAL SOFT_MAX
      REAL SOFT_SEL
      INTEGER IBIN_SEL
      INTEGER IWARN
      CHARACTER*(*) WARNSTR
CD-Parameters:
C   IUN       i (R)  Unit number for listing
C   ITERM     i (R)  =1 output to a terminal, =0 output to a file
C   IPACK     i (R)  Pack number
C   IPLATE    i (R)  Plate number
C   IOPT      i (R)  Option =1 Dmin soft limit determination
C                           =2 Lambda-min soft limit determination
C   PROMIN    r (R)   Minimum intensity included in profiles determination
C   NTHE      i (R)   Number of theta bins used in profile fitting 
C   PROF_ROT  l (R)   Rotate profiles for elliptical spots flag
C   SIGTEST   r (R)   No. of sigmas used for determining significant
C                     intensities for statistics.
C   FRTEST    r (R)   Fraction for population of significant reflections
C                     just above soft limit.
C   NUMBINS   i (R)   Number of bins used.
C   BIN_WIDTH r (R)   Width of soft limit bins.
C   NMEAS(*)  i (R)   Number of measured spots in each bin (dimensioned 
C                     to at least NUMBINS)
C   NGTSIG(*) i (R)   Number of significant spots in each bin (dimensioned 
C                     to at least NUMBINS)
C   RBIN(*)   r (R)   Ratios of significant to measured spots in each bin
C                     (dimensioned to at least NUMBINS)
C   SOFT_MIN  r (R)   Soft limit minimum used (rounded down to nearest
C                     bin_width multiple value)
C   SOFT_MAX  r (R)   Soft limit maximum used
C   SOFT_SEL  r (R)   Selected value for the soft limit
C   IBIN_SEL  i (R)   Selected bin number
C   IWARN     i (R)   Warning flag = 0 OK 
C                                  = 1 No bin has 10 or more significant 
C                                      reflectionns
C                                  = 2 First bin selected; soft limit needs
C                                      to be determined with a lower start
C                                      value
C                                  = 3 Less than five significant reflection
C                                      in selected 'above soft limit' bin
C   WARNSTR   c (R)   Warning message string if IWARN is non-zero
C
C                     Note: The parameters are those input/returned from
C                           the call to LFN_SOFT (apart from IUN, ITERM)
CD-end
C====== Parameter statements
C 

C
C====== GLOBALS:
C
      
C
C====== FUNCTION TYPES:
C
      INTEGER LENSTR
C
C====== LOCALS:
C
      INTEGER I
      REAL RATMAX
      REAL SFT_MIN
      REAL SFT_MAX
      REAL RATNRM
      CHARACTER*120 STR

C     INTEGER I              !Temp/loop variable
C     REAL RATMAX            !Maximum obs/meas ratio found
C     REAL SFT_MIN           !Minimum soft limit for current range
C     REAL SFT_MAX           !Maximum soft limit for current range
C     REAL RATNRM            !Normalised ratio for current range
C     CHARACTER*120 STR      !Output string
C
C-------------------------------------------------------------------------------
C
      IF (NUMBINS.LE.0) RETURN
      STR = 'Soft limit determination of'
      IF (IOPT.EQ.1) CALL STR_ADDS(STR,'dmin for pack',1)
      IF (IOPT.EQ.2) CALL STR_ADDS(STR,'lambda-min for pack',1)
      CALL STR_ADDI(STR,IPACK,1)
      CALL STR_ADDS(STR,', plate',0)
      CALL STR_ADDI(STR,IPLATE,1)
      IF (ITERM.EQ.1) THEN
         CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         CALL TTSEND (IUN,' ',1)
      ELSE
         WRITE(IUN,1000) STR(1:LENSTR(STR))
         WRITE(IUN,1001)
      END IF
      STR = 'Minimum intensity for profiles ='
      CALL STR_ADDF(STR,PROMIN,1,1)
      CALL STR_ADDS(STR,', number of profile bins =',0)
      CALL STR_ADDI(STR,NTHE,1)
      IF (ITERM.EQ.1) THEN
         CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         CALL TTSEND (IUN,' ',1)
      ELSE
         WRITE(IUN,1000) STR(1:LENSTR(STR))
         WRITE(IUN,1001)
      END IF
      IF (PROF_ROT) THEN
         STR = 'Profiles rotated for elliptical spots'
      ELSE
         STR = 'Profiles not rotated'
      END IF
      IF (ITERM.EQ.1) THEN
         CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         CALL TTSEND (IUN,' ',1)
      ELSE
         WRITE(IUN,1000) STR(1:LENSTR(STR))
         WRITE(IUN,1001)
      END IF
      STR = 'Significance level for observed intensities ='
      CALL STR_ADDF(STR,SIGTEST,1,1)
      IF (ITERM.EQ.1) THEN
         CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         CALL TTSEND (IUN,' ',1)
      ELSE
         WRITE(IUN,1000) STR(1:LENSTR(STR))
         WRITE(IUN,1001)
      END IF
      STR = 'Fraction of significant population above soft limit ='
      CALL STR_ADDF(STR,FRTEST,2,1)
      IF (ITERM.EQ.1) THEN
         CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         CALL TTSEND (IUN,' ',1)
      ELSE
         WRITE(IUN,1000) STR(1:LENSTR(STR))
         WRITE(IUN,1001)
      END IF
      STR = 'Bin   Soft limit  No. Meas.  No. Obs.   Obs./Meas.'
      CALL STR_ADDS(STR,'  Normalised',0)
      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       spots     spots       ratio   '
      CALL STR_ADDS(STR,'ratio',7)
      IF (ITERM.EQ.1) THEN
         CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         CALL TTSEND (IUN,' ',1)
      ELSE
         WRITE(IUN,1000) STR(1:LENSTR(STR))
         WRITE(IUN,1001)
      END IF
      RATMAX = 0.0
      DO 100 I = 1, NUMBINS
         IF (RBIN(I).GT.RATMAX.AND.NGTSIG(I).GE.10) RATMAX = RBIN(I)
100   CONTINUE
      IF (RATMAX.LE.0.0) RETURN
      DO 120 I = 1, NUMBINS
         SFT_MIN = SOFT_MIN + (I-1)*BIN_WIDTH
         SFT_MAX = SFT_MIN + BIN_WIDTH
         RATNRM = RBIN(I)/RATMAX
         WRITE(STR,1010) I, SFT_MIN, SFT_MAX, NMEAS(I),
     +                   NGTSIG(I), RBIN(I), RATNRM
         IF (ITERM.EQ.1) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
120   CONTINUE      
      IF (ITERM.EQ.1) THEN
         CALL TTSEND (IUN,' ',1)
      ELSE
         WRITE(IUN,1001)
      END IF
      STR = 'Value determined for'
      IF (IOPT.EQ.1) CALL STR_ADDS(STR,'dmin =',1)
      IF (IOPT.EQ.2) CALL STR_ADDS(STR,'lambda-min =',1)
      CALL STR_ADDF(STR,SOFT_SEL,2,1)
      IF (ITERM.EQ.1) THEN
         CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         CALL TTSEND (IUN,' ',1)
      ELSE
         WRITE(IUN,1000) STR(1:LENSTR(STR))
         WRITE(IUN,1001)
      END IF
      IF (IWARN.GT.0) THEN
         STR = '*Warning*'
         CALL STR_ADDS(STR,WARNSTR,1)
         IF (ITERM.EQ.1) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            CALL TTSEND (IUN,' ',1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
            WRITE(IUN,1001)
         END IF
      END IF
      RETURN
C
C====== Format statements
C
1000  FORMAT(A)
1001  FORMAT(' ')
1010  FORMAT(I3,F6.2,' -',F5.2,I9,I10,F11.2,F12.2)
      END
