
C LAST UPDATE:
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C***************************
C**  LSC_MULT_ANALOG      **
C***************************
C
CD-Routine: Output of RSCALE of multiples vs. reference data - LSC_MULT_ANALOG
C This routine writes RSCALE of deconvoluted multiples reflections against
C the reference set to the log-file.
CD-end
CD-Fortran:
C
      SUBROUTINE LSC_MULT_ANALOG (LINDX, IUN)
C
CD-end
C
      INCLUDE 'implicit_none.finc'
C
C Purpose : Output files for multiple deconvolution diagnostics into log-file
C
C Author:  Steffi Arzt, John Campbell, July 1997
C
C Arguments:
C
      INTEGER LINDX
      INTEGER IUN
C
CD-Parameters:
C   LINDX   i  (R)    The index of the Laue Integrated Reflections List
C   IUN     i  (R)    Output unit number of log-file
CD-end

C 
C====== PARAMETERS:
C
      INCLUDE 'limits.finc'
C
C====== GLOBALS:
C
      INCLUDE 'scale_presets.finc'
      INCLUDE 'use_reflns.finc'
      INCLUDE 'scp.finc'
      INCLUDE 'scps_counters.finc'
      INCLUDE 'ref_flags.finc'
      INCLUDE 'other_scale.finc'
      INCLUDE 'view_handles.finc'
C
C====== FUNCTION TYPES:
C

C
C====== LOCALS:
C

      INTEGER I, K1, K2, NRR
      INTEGER KERR, IERR
      INTEGER KSYM, NSPOT
      INTEGER IPACK, IPLATE
      INTEGER IH, IK, IL
      INTEGER MULT, MINHARM, MAXHARM, INCHARM
      INTEGER ISPAT, IOVLD, IBAD, IMEAS
      INTEGER ICODE, ICLOS
      REAL REFINT
      REAL ALAM
      REAL AI, SIGMA
      REAL MULINT(MAX_SYMEQ)
      REAL AREFMEAN(MAX_SYMEQ)
      REAL AIMEAN, ASIGMEAN, AMEAN
      REAL AIMEAN1, ASIGMEAN1, AMEAN1
      REAL RFINT(MXR), SCINT(MXR), SIGREF
      REAL RFINTCUT(MXR), SCINTCUT(MXR)
      REAL RFAC, DIFF, SUM
      REAL RFACC, DIFFC, SUMC
      REAL XFD, YFD
      CHARACTER*80 ERRSTR  

      K1 = 0
      K2 = 0
      DIFF = 0.0
      SUM = 0.0
      DIFFC = 0.0
      SUMC = 0.0
     
      CALL LSM_KDMCOPY (1, KERR, ERRSTR)

      CALL LIRLF_NUMREFS  (LINDX, NSPOT)

      CALL LSM_CALC_PRESETS 


      AIMEAN = 0.0
      AMEAN = 0.0
      ASIGMEAN = 0.0
      AIMEAN1 = 0.0
      AMEAN1 = 0.0
      ASIGMEAN1 = 0.0

      NRR = 0

      DO 240 I = 1, NSPOT
         CALL LIRLF_GETREF (LINDX, I, IH, IK, IL, IPACK,  
     +          IPLATE, KSYM, XFD, YFD, ALAM,
     +          MULT, MINHARM, MAXHARM, INCHARM, AI, SIGMA,
     +          ISPAT, ICLOS, IMEAS, IBAD, IOVLD, 
     +          ICODE, IERR)
         IF(MULT.EQ.0) THEN
            CALL LIRLF_GET_REFINT (LINDX, I, REFINT, SIGREF, KERR)
            IF (REFINT.GT.0.0) THEN
               MULINT(NRR+1) = AI
               AREFMEAN(NRR+1) = REFINT
               K1 = K1 + 1
               RFINT(K1) = REFINT
               SCINT(K1) = MULINT(NRR+1)
               IF(AI.GT.(SIGCUT_USE)*SIGMA) THEN
                 K2 = K2 + 1
                 RFINTCUT(K2) = REFINT
                 SCINTCUT(K2) = MULINT(NRR+1)
               END IF
               NRR = NRR + 1
            ELSE
               GO TO 240
            END IF
         ELSE
            GO TO 240
         END IF
 240  CONTINUE

      DO 20 I= 1, NRR-1
         DIFF = DIFF + ABS(MULINT(I)-AREFMEAN(I))
         SUM = SUM + MULINT(I)+AREFMEAN(I)
 20   CONTINUE
         
      DO 30 I= 1, K2
         DIFFC = DIFFC + ABS(SCINTCUT(I)-RFINTCUT(I))
         SUMC = SUMC + SCINTCUT(I)+RFINTCUT(I)
 30   CONTINUE

      RFAC  = DIFF/SUM
      RFACC = DIFFC/SUMC

      WRITE (IUN,6030)
      WRITE (IUN,6035)
      WRITE (IUN,6050)
      WRITE (IUN,6055)
      WRITE (IUN,6060) RFAC
      WRITE (IUN,6040) K1
      WRITE (IUN,6070) SIGCUT_USE
      WRITE (IUN,6060) RFACC
      WRITE (IUN,6040) K2

 6040 FORMAT (/,'   N =',I6,//)
 6030 FORMAT (///,' DECONVOLUTED MULTIPLES SCALED VS. REFERENCE SET')
 6035 FORMAT (' ______________________________________________')
 6050 FORMAT (//,'   SCALING R-FACTOR = SUM(ABS(IM-IS)/SUM(IM+IS)',//,
     +        '         (SUM FOR UNIQUE DECONVOLUTED MULTIPLES',/,
     +        '                PRESENT IN BOTH DATA SETS)')
 6055 FORMAT (//,'   ALL DECONVOLUTED REFLECTIONS WITH REFERENCE ',
     +       'INTENSITY INCLUDED')
 6060 FORMAT (/,'   RSCALE =',F6.3)
 6070 FORMAT (/,'   DECONVOLUTED REFLECTIONS WITH I >',F4.1, 
     +       '*SIGMA INCLUDED')
 6200 FORMAT (4F11.3,4I6,2F11.3)
 6300 FORMAT (4F12.3,3I8,F11.3)
 6400 FORMAT (5F12.3)
 6500 FORMAT (40I3)
 6600 FORMAT (25I4)
 1000 FORMAT (4I6,F13.2,2I6)

      END
