
CD-Section: Analysing the Intensity Statistics after Scaling
C Routines are available to collect R-factor statistics data and routines
C are available to print the gathered information to a Fortran output
C channel or to return it for alternative use e.g. within a windows based
C program.
CD-end

C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LSC_GRAPHSETUP   **
C**************************
C
CD-Routine: Prepares graphic windows for statistics output - LSC_GRAPHSETUP
C This routines sets the size and layout for the graphics output windows
C and menus.
CD-end
CD-Fortran:
C
      SUBROUTINE LSC_GRAPHSETUP (IERR, MESSAGE)
C
CD-end
C
      INCLUDE 'implicit_none.finc'
C
C Purpose: Prepare output windows 
C
C Author:  S.Arzt, March 1997
C
C Arguments:
C
      INTEGER IERR
      CHARACTER*120 MESSAGE
C     
CD-Parameters:
C  IERR    i  (W)   Error flag = 0 OK
C                              = 1 Error
C  MESSAGE c  (W)   Error message if IERR = 1    
CD-end
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
      INTEGER LENSTR
C
C====== LOCALS:
C
      INTEGER NUMC 
      INTEGER NCOLORS(2)
      INTEGER NPLANES(2) 
      INTEGER IFONT
      INTEGER  IWIDTH_FRAME
      INTEGER  IHEIGHT_FRAME
      INTEGER  IW
      INTEGER  IH
      INTEGER  MENW
      INTEGER  MENH
      INTEGER  IGW
      INTEGER  IGH
      INTEGER  IX
      INTEGER  IY
      CHARACTER*80 HEADER
      CHARACTER*25 QUITNAM

      CHARACTER*25 NAMES(4)
      DATA NAMES /'Plot 1',
     *            'Plot 2',
     *            'Plot 3',
     *            'Plot 4'/
      DATA QUITNAM /'Quit'/
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     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     CHARACTER*80 TITLE      !Graph title string
C
C-------------------------------------------------------------------------------
C
C====== Initialise the xdl_view routines
C
      NUMC = 1
      NCOLORS(1) = 72
      NPLANES(1) = 0
      IERR = 0
      MESSAGE = ' '

      CALL XDLF_OPEN_VIEW (NUMC, NCOLORS, NPLANES, IERR)
      IF(IERR.GT.0) THEN
         IERR = 1
         MESSAGE = ' ERROR RETURN FROM XDLF_OPEN_VIEW'
         IF (IERR.NE.1) RETURN
         IERR = 0
      END IF
C
C====== Assign the view-object handles
C
      IVH_BASE = 1
      IVH_MENU = 2
      IVH_GRAPH = 3
      IVH_ABSURF = 4
      IVH_BAR = 5
      IVH_MENU = 6
      IVH_MENU = 7

      IFONT = 2

C
C====== Calculate size requirements and layout parameters
C
      CALL XDLF_MENU_AREA_GETSIZE (MAX_MEN_ITMS, MAX_MEN_NAME,
     +     IFONT, 1, MAX_MEN_TITLE, MENW, MENH)
      CALL XDLF_GRAPH_WIN_GETSIZE (600, 400, IGW, IGH)
C
C====== Get layout parameters
C
      CALL XDLF_LAYOUT_INIT (IERR)
      IF(IERR.GT.0) THEN
         IERR = 1
         MESSAGE = ' ERROR RETURN FROM XDLF_LAYOUT_INIT'
         RETURN
      END IF
      CALL XDLF_LAYOUT_SET_SINGLE (XDLSTR('menu'), 4, MENW, MENH,
     +                             0, 0, IERR)
      IF(IERR.GT.0) THEN
         IERR = 1
         MESSAGE = ' ERROR RETURN FROM XDLF_LAYOUT_SET_SINGLE'
         RETURN
      END IF
      CALL XDLF_LAYOUT_SET_SINGLE (XDLSTR('grw'), 3, IGW, IGH,
     +                             0, 0, IERR)
      IF(IERR.GT.0) THEN
         IERR = 1
         MESSAGE = ' ERROR RETURN FROM XDLF_LAYOUT_SET_SINGLE'
         RETURN
      END IF
      CALL XDLF_LAYOUT_SET_PAIR (0, 1, XDLSTR('top'), 3, 
     +                           XDLSTR('menu'), 4,
     +                           XDLSTR('grw'), 3,
     +                           0, 0, ISEP, 25, IERR)
      IF(IERR.GT.0) THEN
         IERR = 1
         MESSAGE = ' ERROR RETURN FROM XDLF_LAYOUT_SET_PAIR'
         RETURN
      END IF
      CALL XDLF_LAYOUT (XDLSTR('top'), 3, IBORDER, IBORDER, IW, IH,
     +                  IERR)
      IF(IERR.GT.0) THEN
         IERR = 1
         MESSAGE = ' ERROR RETURN FROM XDLF_LAYOUT'
         RETURN
      END IF
C
C====== Create main frame
C
      IWIDTH_FRAME = IW + 2*IBORDER
      IHEIGHT_FRAME = IH + 2*IBORDER
      HEADER = 'CCLRC Daresbury Laboratory program ''LSCALE'''
      CALL XDLF_BASE_FRAME (IVH_BASE, IWIDTH_FRAME, IHEIGHT_FRAME,
     +     XDLSTR(HEADER), LENSTR(HEADER), XDLSTR('lscale'), 9, 
     +     -1, -1)

C
C====== Set up menu area
C
      CALL XDLF_LAYOUT_GET_POSITION (XDLSTR('menu'), 4, IX, IY, 
     +                               IW, IH, IERR)
      IF(IERR.GT.0) THEN
         IERR = 1
         MESSAGE = ' ERROR RETURN FROM XDLF_LAYOUT_GET_POSITION'
         RETURN
      END IF
      CALL XDLF_MENU_AREA (IVH_MENU, IVH_BASE, IX, IY, 0,
     +     MAX_MEN_ITMS, MAX_MEN_NAME, IFONT, 1, MAX_MEN_TITLE,
     +     IW, IH, IERR)
      IF(IERR.GT.0) THEN
         IERR = 1
         MESSAGE = ' ERROR RETURN FROM XDLF_MENU_AREA'
         RETURN
      END IF
C
C====== Set up graphics window 
C
      CALL XDLF_LAYOUT_GET_POSITION (XDLSTR('grw'), 3, IX, IY, 
     +                               IW, IH, IERR)
      IF(IERR.GT.0) THEN
         IERR = 1
         MESSAGE = ' ERROR RETURN FROM XDLF_LAYOUT_GET_POSITION'
         RETURN
      END IF
      CALL XDLF_GRAPH_WIN (IVH_GRAPH, IVH_BASE, IX, IY, 0, 0,
     +                     600, 400, IW, IH, 2, 0, IERR)
      IF(IERR.GT.0) THEN
         IERR = 1
         MESSAGE = ' ERROR RETURN FROM XDLF_GRAPH_WIN'
         RETURN
      END IF
      CALL XDLF_MENU_AREA_SETMENU (IVH_MENU, 4, XDLSTR(NAMES), 25,
     +     XDLSTR('MAIN MENU'), 9, XDLSTR(QUITNAM), 
     +     25, 0, IERR)
      IF(IERR.GT.0) THEN
         IERR = 1
         MESSAGE = ' ERROR RETURN FROM MENU_AREA_SETMENU'
         RETURN
      END IF

      END
