
C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LSC_HIST_THETA     **
C**************************
C
C **** LSC SERVICE ROUTINE ONLY ****
C
C Routine: Output of reference set scaling results - LSC_HIST_THETA
C This routine is called by LSC_REFSET_ANALYSES and prepares menues for
C the windows output of the reference set scaling statistics vs. theta
C
      SUBROUTINE LSC_HIST_THETA (NUMBINS, BIN_WIDTH, 
     +                      VAL_MIN, VAL_MAX, NREF, MEANTHETA, 
     +                      RFACTTHETA)
C
      INCLUDE 'implicit_none.finc'
C
C Purpose: Output histograms of scaling results
C
C Author:  S. Arzt, September 1997
C
C Arguments:
C
      INTEGER NUMBINS
      INTEGER NREF(10)
      REAL BIN_WIDTH
      REAL VAL_MIN
      REAL VAL_MAX
      REAL MEANTHETA(10)
      REAL RFACTTHETA(10)
C
C Parameters:
C  NUMBINS     (R)  Number of bins
C  BIN_WIDTH   (R)  Bin width
C  VAL_MIN     (R)  Minimum soft limits value
C  VAL_MAX     (R)  Maximum soft limits value
C  NREF()      (R)  No. of relections per resolution bin
C  MEANTHETA() (R)  mean Il/Iref per resolution bin
C  RFACTTHETA()(R)  mean R-factor per resolution bin

C
C====== PARAMETERS:
C
      INCLUDE 'limits.finc'
C
C====== GLOBALS:
C
      INCLUDE 'view_handles.finc'
      INCLUDE 'get_soft.finc'
      INCLUDE 'screen_params.finc'
C
C====== FUNCTION TYPES:
C
      INTEGER XDLSTR
C
C====== LOCALS:
C
      INTEGER M_NREF
      INTEGER M_ILOIREF 
      INTEGER M_RFAC 
      INTEGER NVIEW
      INTEGER IVH
      INTEGER IQUIT
      INTEGER IVHLIST(2)
      INTEGER ITEM
      INTEGER IERR, I
      REAL RNREF(10)
      LOGICAL GRAPH_DISP 
      CHARACTER*18 NAMES(3)
      CHARACTER*25 QUITNAM

      DATA NAMES /'No. of reflections',
     +            'mean Ilaue/Iref',
     +            'R-factor'/
      DATA QUITNAM /'Return to Previous Menu'/

      GRAPH_DISP = .FALSE.

      DO 10 I = 1, NUMBINS
         RNREF(I) = NREF(I)
 10   CONTINUE

      M_NREF = 1
      M_ILOIREF = 2
      M_RFAC = 3

      CALL XDLF_MENU_AREA_SETMENU (IVH_MENU, 3, XDLSTR(NAMES), 
     +                 18, XDLSTR('Data in theta bins'), 18,
     +                 XDLSTR(QUITNAM), 25, 0, IERR)

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_NREF) THEN
            CALL LSC_HIST (4, 1, NUMBINS, BIN_WIDTH, 
     +                     VAL_MIN, VAL_MAX, RNREF)
            GRAPH_DISP = .TRUE.
            GO TO 500
         ELSE IF (ITEM.EQ.M_ILOIREF) THEN
            CALL LSC_HIST (4, 2, NUMBINS, BIN_WIDTH, 
     +               VAL_MIN, VAL_MAX, MEANTHETA)
            GRAPH_DISP = .TRUE.
            GO TO 500
         ELSE IF (ITEM.EQ.M_RFAC) THEN
            CALL LSC_HIST (4, 5, NUMBINS, BIN_WIDTH, 
     +                     VAL_MIN, VAL_MAX, RFACTTHETA)
            GRAPH_DISP = .TRUE.
            GO TO 500
         END IF
      END IF

      END
