
C LAST UPDATE:
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C***************************
C**  LSC_MULT_ANALYSES    **
C***************************
C
C **** LSC SERVICE ROUTINE ONLY ****
C
C Routine:  Displays deconv. multiples against ref. set - LSC_MULT_ANALYSES 
C This routine displays the deconvoluted multiples scaled against the 
C reference intensities and writes Rscale to log-file
C
      SUBROUTINE LSC_MULT_ANALYSES(LINDX)

C
      INCLUDE 'implicit_none.finc'
C
C Purpose : Outputs Ideconv verus Iref and writes R-scale to log-file
C
C Author:  Steffi Arzt, John Campbell, July 1997
C
C Arguments:
C
      INTEGER LINDX
C
C Parameters:
C
C   LINDX   i  (R)    The index of the Laue Integrated Reflections List
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
      INTEGER XDLSTR
C
C====== LOCALS:
C

      INTEGER I, K1, K2, NRR
      INTEGER KERR, IERR
      INTEGER KSYM, NSPOT
      INTEGER IPACK, IPLATE
      INTEGER IH, IK, IL
      INTEGER M_ILOIR
      INTEGER M_ILOIRSIG
      INTEGER NVIEW
      INTEGER IVHLIST(2)
      INTEGER IVH
      INTEGER ITEM
      INTEGER IQUIT
      INTEGER MULT, MINHARM, MAXHARM, INCHARM
      INTEGER ISPAT, IOVLD, IBAD, IMEAS
      INTEGER ICODE, ICLOS
      INTEGER IXROOT, IYROOT
      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 DIFF, SUM
      REAL DIFFC, SUMC
      REAL XFD, YFD
      LOGICAL GRAPH_DISP 
      CHARACTER*19 NAMESMUL(2)
      CHARACTER*25 QUITNAM
      CHARACTER*80 ERRSTR  
      DATA NAMESMUL /'IL vs IR, all refln',
     +               'IL vs IR, sigma cut'/
      DATA QUITNAM /'Return to Previous Menu'/

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

      CALL LIRLF_NUMREFS  (LINDX, NSPOT)

      CALL LSM_CALC_PRESETS 

      CALL XDLF_VIEW_OBJECT_ROOTXY(IVH_GRAPH,120,180,IXROOT,IYROOT,IERR) 
  
      CALL XDLF_PROGRESS_BAR (IVH_BAR, IXROOT, IYROOT, 
     +     XDLSTR('Multiples scaling against reference set:'), 
     +     24, 100, NSPOT, 2, 5)

      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 XDLF_PROGRESS_BAR_VALUE (IVH_BAR, I, IERR)  
         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

      CALL XDLF_DELETE_VIEW_OBJECT (IVH_BAR, IERR)

      CALL XDLF_MENU_AREA_SETMENU (IVH_MENU, 2,  
     +           XDLSTR(NAMESMUL),19, 
     +           XDLSTR('Multiples Analyses'), 18,
     +           XDLSTR(QUITNAM), 25, 0, IERR)
      M_ILOIR = 1
      M_ILOIRSIG = 2
C
C====== Set up list of view-object handles
C
      NVIEW = 1
      IVHLIST(1) = IVH_MENU
C
C====== Start event loop
C
 500  CALL XDLF_GET_EVENTS (NVIEW, IVHLIST, IVH)
      IF (IVH.EQ.IVH_MENU) THEN
C
C======  Menu item selected
C
         CALL XDLF_MENU_AREA_GETITEM (IVH_MENU, ITEM, IQUIT)
C
C======  Quit selected
C
         IF (IQUIT.EQ.1) THEN
            IF (GRAPH_DISP) THEN
               CALL XDLF_GRAPH_WIN_DELETE (IVH_GRAPH, 0, IERR)
            END IF
            RETURN
         END IF

         IF (ITEM.EQ.M_ILOIR) THEN
            CALL LSC_SCATTER (3, -5, RFINT, SCINT, K1, 1)
            GRAPH_DISP = .TRUE.
            GO TO 500     
         ELSE IF (ITEM.EQ.M_ILOIRSIG) THEN
            CALL LSC_SCATTER (3, -5, RFINTCUT, SCINTCUT, K2, 1)
            GRAPH_DISP = .TRUE.
            GO TO 500     
         END IF
      END IF

 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 ICLUDED')
 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
