

C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LSC_SCATTER      **
C**************************
C
C **** LSC SERVICE ROUTINE ONLY ****
C
C Routine: Output histograms of scaling results - LSC_SCATTER
C This routine displays various statistical graphs calculated in LSC_ANALYSES
C
      SUBROUTINE LSC_SCATTER (IOPTX, IOPTY, XVAL, YVAL, NREF, IRFSTAT)
C
      INCLUDE 'implicit_none.finc'
      INCLUDE 'limits.finc'
C
C Purpose: displays various statistical graphs 
C
C Author:  S. Arzt, September 1997
C
C Arguments:
C
      INTEGER IOPTX
      INTEGER IOPTY
      REAL XVAL(MXR)
      REAL YVAL(MXR)
      INTEGER IRFSTAT 
C
C  IOPTX      i      (R)  x-axis input option flag
C                         flag =1 lambda, =2 resolution, =3 reference intensity
C  IOPTY      i      (R)  y-axis input option
C                         flag =1 error
C                         flag =2 I/sig(I)
C                         flag =3 resolution
C                         flag =4 wavelength normalisation curve
C                         flag =5 Laue intensities
C  XVAL()     r      (R)  X-value
C  YVAL()     r      (R)  value
C  NREF()     i      (R)  no. of reflections
C  IRFSTAT    i      (R)  refinement status 
C                         = -1 before refinement
C                         =  1 after refinement
C
C====== Parameter statements
C 

C
C====== GLOBALS:
C
      INCLUDE 'view_handles.finc'
      INCLUDE 'get_soft.finc'
      INCLUDE 'screen_params.finc'
      INCLUDE 'scp.finc'
      INCLUDE 'other_scale.finc'
C
C====== FUNCTION TYPES:
C
      INTEGER XDLSTR
      INTEGER LENSTR
C
C====== LOCALS:
C
      INTEGER I
      INTEGER NREF
      INTEGER IERR
      INTEGER NDX, NDY, NDEVX, NDEVY
      REAL WIDTHX, WIDTHY
      REAL XMIN, XMAX, YMIN, YMAX
      REAL SIZEY
      CHARACTER*100 TITLE
      CHARACTER*25 QUITNAM

      CHARACTER*25 NAMES(4)
      DATA NAMES /'Plot 1',
     *            'Plot 2',
     *            'Plot 3',
     *            'Plot 4'/
      DATA QUITNAM /'Quit'/
C     LOGICAL MARK_OVER       !Mark value >1.0 on normalised histogram
C     INTEGER I               !Temp/loop variable
C     INTEGER KXROOT          !Root window x position for graphics window
C     INTEGER KYROOT          !Root window y position for graphics window
C     INTEGER IERR            !Error flag
C     REAL AX1_DIV            !Axis 1 divisions width
C     REAL X1                 !Start of histogram box (x axis)
C     REAL X2                 !End of histogram box (x axis)
C     REAL Y                  !Height of histogram box (y axis)
C     REAL ARR_H              !Arrow height 
C     REAL ARR_W              !Arrow half width
C     REAL ARR_X(3)           !Arrow head x coordinates
C     REAL ARR_Y(3)           !Arrow head y coordinates
C     REAL YVALMAX            !Maximum value is YVAL array
C     CHARACTER*80 TITLE      !Graph title string
C
C-------------------------------------------------------------------------------
C
C====== Initialise
C
      YMIN = 10.0E20
      YMAX = 0.0
      XMIN = 10.0E20
      XMAX = 0.0
      NDY = 3
      NDX = 2
      NDEVX = 10
      NDEVY = 10
      WIDTHX = 0.0
      WIDTHY = 0.0
      SIZEY = 0.042

      NDY = 2
      NDX = 2

      CALL XDLF_GRAPH_WIN_DELETE (IVH_GRAPH, 0, IERR)
C
C====== Find min and max values of x and y      
C
      IF (IOPTX.GT.1) THEN
         DO 10 I = 1, NREF
            IF(XVAL(I).GT.XMAX) XMAX = XVAL(I) 
            IF(XVAL(I).LT.XMIN) XMIN = XVAL(I) 
            IF(YVAL(I).GT.YMAX) YMAX = YVAL(I) 
            IF(YVAL(I).LT.YMIN) YMIN = YVAL(I) 
 10      CONTINUE
      ELSE IF (IOPTX.EQ.1) THEN
         DO 20 I = 1, NREF
            IF(YVAL(I).GT.YMAX) YMAX = YVAL(I) 
            IF(YVAL(I).LT.YMIN) YMIN = YVAL(I) 
 20      CONTINUE
         XMIN = NORMLAMMIN(1)
         XMAX = NORMLAMMAX(NRAN)
      END IF

      IF(IOPTY.EQ.1) THEN
         IF(YMIN.LT.0.0.AND.YMAX.GT.0.0) THEN
            IF(YMAX.LT.ABS(YMIN)) THEN
               YMAX = ABS(YMIN)
            ELSE
               YMIN = -YMAX
            END IF
         END IF
      END IF

      IF(IOPTX.EQ.3.AND.ABS(IOPTY).EQ.5) THEN
         IF(XMAX.GT.YMAX) THEN
            YMAX = XMAX
         ELSE
            XMAX = YMAX
         END IF
         IF(XMIN.LT.YMIN) THEN
            YMIN = XMIN
         ELSE
            XMIN = YMIN
         END IF         
      END IF
         
C
C====== Plot the scatter diagram frame
C     
      IF (IOPTX.EQ.1.AND.IOPTY.EQ.1) THEN
         TITLE = '(Isc-Imean)/Imean for groups of equivalent'
     +          //' reflections versus lambda'
         SIZEY = 0.036     
      ELSE IF (IOPTX.EQ.1.AND.IOPTY.EQ.2) THEN
         TITLE = 'I/sigma(I) versus lambda'
         SIZEY = 0.04
      ELSE IF (IOPTX.EQ.1.AND.IOPTY.EQ.3) THEN
         TITLE = 'Resolution versus lambda'
         SIZEY = 0.04
      ELSE IF (IOPTX.EQ.2.AND.IOPTY.EQ.2) THEN
         TITLE = 'I/sigma(I) versus resolution'
         SIZEY = 0.04
      ELSE IF (IOPTX.EQ.1.AND.IOPTY.EQ.4) THEN
         TITLE = 'Wavelength normalisation curve'
      ELSE IF (IOPTX.EQ.3.AND.IOPTY.EQ.5) THEN
         TITLE = 'Laue intensities versus Reference Intensities'
      ELSE IF (IOPTX.EQ.3.AND.IOPTY.EQ.-5) THEN
         TITLE = 'Deconv. Reflections versus Reference Intensities'
      END IF

      CALL XDLF_GRAPH_WIN_STYLE (IVH_GRAPH, 0, 1, -1, IERR)
      CALL XDLF_GRAPH_WIN_MAP (IVH_GRAPH, 0.0, 1.0, 
     +                         0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
     +                         0, IERR)
      CALL XDLF_GRAPH_WIN_STEXT (IVH_GRAPH, 0.5, 0.95,
     +                           XDLSTR(TITLE), LENSTR(TITLE),
     +                           0.0, SIZEY, 0, 1, 0.0, IERR)

      IF (IRFSTAT.EQ.-1) TITLE = '(before refinement)'
      IF (IRFSTAT.EQ.1) TITLE = '(after refinement)'

      CALL XDLF_GRAPH_WIN_STEXT (IVH_GRAPH, 0.5, 0.89,
     +                           XDLSTR(TITLE), LENSTR(TITLE),
     +                           0.0, .033, 0, 1, 0.0, IERR)

      IF (IOPTX.EQ.1) TITLE = 'lambda(A)'
      IF (IOPTX.EQ.2) TITLE = 'sin**(theta)/lambda**2'
      IF (IOPTX.EQ.3) TITLE = 'Reference Intensities'

      CALL XDLF_GRAPH_WIN_STEXT (IVH_GRAPH, 0.5, 0.05,
     +                           XDLSTR(TITLE), LENSTR(TITLE),
     +                           0.0, .033, 0, 1, 0.0, IERR)

      CALL XDLF_GRAPH_WIN_MAP (IVH_GRAPH, XMIN, XMAX, 
     +                    YMIN, YMAX, 0.1, 0.9, 0.15, 0.8,
     +                    0, IERR)

      CALL XDLF_GRAPH_WIN_AX1 (IVH_GRAPH, XMIN, YMIN, 
     +                         XMAX-XMIN, NDEVX, WIDTHX, 
     +                         NDX, .015, .03, 0, IERR)

      CALL XDLF_GRAPH_WIN_AX2 (IVH_GRAPH, XMIN, YMIN, 
     +                YMAX-YMIN, NDEVY, WIDTHY, NDY, .015, .03, 
     +                0, IERR)       
C
C====== Plot data
C

      IF (IOPTY.EQ.1) THEN
         CALL XDLF_GRAPH_WIN_LINE (IVH_GRAPH, XMIN, 0.0, 
     +                                        XMAX, 0.0, IERR)
      END IF

      IF (IOPTX.EQ.1.AND.IOPTY.EQ.4) THEN
         CALL XDLF_GRAPH_WIN_STYLE (IVH_GRAPH, 3, 1, -1, IERR)

         CALL XDLF_GRAPH_WIN_LINE (IVH_GRAPH, REFNORMLAM, YMAX, 
     +                                   REFNORMLAM, 0.0, IERR)
         CALL XDLF_GRAPH_WIN_STYLE (IVH_GRAPH, 0, 1, -1, IERR)
      END IF
      DO 100 I = 1, NREF
         IF (IOPTX.EQ.1.AND.IOPTY.EQ.4) THEN
            CALL XDLF_GRAPH_WIN_SYMBOL (IVH_GRAPH, XVAL(I), 
     +                            YVAL(I), 0, 0.01, 0, IERR)
         ELSE
            CALL XDLF_GRAPH_WIN_SYMBOL (IVH_GRAPH, XVAL(I), 
     +                           YVAL(I), 0, 0.01, 0, IERR)
         END IF
 100  CONTINUE

      RETURN

      END
