     	PROGRAM BARPLT_MAIN
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY   JULY-1985
C
C	MAIN ROUTINE OF HISTOGRAM PLOT.
C
    	INCLUDE		'BARPLT.CBS'
C
C  INITIALIZE THE SESSION...
C
     	CALL IFINIT_SESSION
C
C  INITIALIZE PLOT PARAMETERS...
C
     	CALL BARPLT_INIT( 0 )
C
C  CHECK DCL COMMAND LINE INPUT...
C
     	CALL BARPLT_DCL( KEY )
     	IF( KEY.NE.0 ) GOTO 333
C
C  CONDUCT THE DIALOGUE...
C
  222	CALL BARPLT_MENU( KEY )
     	IF( KEY.NE.0 ) THEN
     	    IF( .NOT.IFINIT_DIFF() ) GOTO 999
     	    GOTO 444
     	ENDIF
C
C  CARRY OUT THE PLOTTING...
C
  333	CALL BARPLT_PLOT
     	IF( CRT.EQ.1 ) THEN
     	    CALL IFANSI_CURSOR(1,1)
     	    CALL IFANSI_CLEAR(6)
     	ENDIF
     	WRITE(6,334)
  334	FORMAT(' BARPLT> Please press a desired function key:')
C
C  PRESENT LOCAL COMMAND MENU...
C
  444	CALL IFANSI_VIDEO(47)
     	WRITE(6,445)
  445	FORMAT(' BARPLT> ?>Help 0>Exit 1>Hardcopy 2>Layout 3>Dialog',
     +' 6>Redraw $>DCL_prompt ...')
     	CALL IFANSI_CURSOR(0,8)
     	CALL IFQIOW_KEY( KEY )

     	IF( KEY.EQ.26 .OR. KEY.EQ.48 .OR. KEY.EQ.69 ) GOTO 999
     	IF( KEY.EQ.49 .OR. KEY.EQ.72 ) THEN	!HARDCOPY WITH PAGE SETUP
     	    CALL IFCOPY( HPAR(1), PLOTID )
     	    CALL BARPLT_SETUP( 0, PARNAM )
     	    CALL IFINIT_LINE( -3 )
     	ELSE IF( KEY.EQ.-80 ) THEN	!HARDCOPY WITHOUT PAGE SETUP
     	    CALL IFANSI_CURSOR(0,14)
     	    CALL IFANSI_LEDS(1)
     	    CALL IFFEED( HPAR(1), PLOTID, ' ' )
     	    CALL IFANSI_LEDS(0)
     	ELSE IF( KEY.EQ.50 .OR. KEY.EQ.76 ) THEN	!LAYOUT
     	    IF( DESNAM.EQ.' ' ) THEN
     		DESNAM = DATNAM
     		CALL IFMISC_NAMEXT( DESNAM, '.DES' )
     	    ENDIF
     	    CALL LAYOUT_AUX( 2, XORG, YORG, DESNAM )
     	ELSE IF( KEY.EQ.51 .OR. KEY.EQ.-82 .OR. KEY.EQ.68 ) THEN
     	    MENU = .TRUE.
     	    GOTO 222				!DIALOGUE MENU
     	ELSE IF( KEY.EQ.13 ) THEN		!DIALOGUE WITHOUT THE MENU
     	    MENU = .FALSE.
     	    GOTO 222
     	ELSE IF( KEY.EQ.54 .OR. KEY.EQ.82 ) THEN
     	    GOTO 333				!REDRAW THE PLOT
     	ELSE IF( KEY.EQ.32 .OR. KEY.EQ.63 .OR. KEY.EQ.-81 ) THEN
     	    CALL IFMISC_HLP( 'BARPLT', '$ MENU', -2, 0 )
     	ELSE IF( KEY.EQ.36 .OR. KEY.EQ.-83 ) THEN	!SPAWN
     	    CALL IFMISC_SPAWN( '$', 0 )
     	    CALL IFINIT_LINE( -3 )
     	ELSE
     	    CALL IFMISC_OOPS( 5, 0, 0, ' ' )
     	ENDIF
    	GOTO 444
C
C  DEALLOCATE THE VIRTUAL MEMORY BEFORE EXIT...
C
  999	CALL LIB$FREE_VM(4*MNST*MNPT,IYAR)
     	CALL LIB$FREE_VM(IXAR(1),IXAR(2))
     	CALL IFINIT_EXIT
     	CALL EXIT
	END

     	SUBROUTINE BARPLT_DCL( ICODE )
C
C	THIS ROUTINE CHECKS DCL COMMAND LINE INPUT.
C
     	INCLUDE 'BARPLT.CBS'
C
C  IS THERE A DATA FILE IN THE LINE...
C
     	ICODE = 0
     	CALL IF_DCL_FILE( 1, DATNAM )
     	IF( DATNAM.EQ.' ' ) THEN
     	    DATNAM = ' Data file here'
     	    RETURN
     	ENDIF
     	SLIN = -1
     	SCOL = 0
     	IERR = BARPLT_DATA( DATNAM, MNST, MNPT, IXAR, %VAL(IYAR) )
     	IF( IERR.GT.0 ) GOTO 999
C
C  YES, WE HAVE A NEW PLOT...
C
     	CALL IF_DCL_SETUP( PARNAM )
     	IF( PARNAM.EQ.' ' ) THEN
     	    PARNAM = DATNAM
     	    CALL IFMISC_NAMEXT( PARNAM, '.PAR' )
     	ENDIF
     	CALL IF_DCL_LAYOUT( DESNAM )
     	IF( DESNAM.EQ.' ' ) THEN
     	    DESNAM = DATNAM
     	    CALL IFMISC_NAMEXT( DESNAM, '.DES' )
     	ENDIF
C
C  SCALE THE DATA...
C
     	CALL BARPLT_INIT(1)
     	IERR = BARPLT_SETUP( 1, PARNAM )
     	IF( IERR.EQ.0 ) CALL BARPLT_SCALE( MNST, MNPT, %VAL(IYAR) )
     	ICODE = 1
C
C  MAKE THE HARDCOPY...
C
     	IF( IF_DCL_HARDCOPY() ) THEN
     	    CALL BARPLT_PLOT
     	    CALL IFCOPY( HPAR(1), PLOTID )
     	ENDIF
     	GOTO 888
C
C  ERROR FROM READING THE DATA FILE...
C
999	IF( IERR.EQ.1 ) WRITE(6,1001) DATNAM
     	IF( IERR.EQ.13) WRITE(6,1002) DATNAM
     	IF( IERR.EQ.14) WRITE(6,1003) DATNAM
1001	FORMAT(' %BARPLT: can not open file ',A32)
1002	FORMAT(' %BARPLT: no data found in file ',A32)
1003	FORMAT(' %BARPLT: error from reading file ',A32)
888	IF( .NOT.IF_DCL_HARDCOPY() ) RETURN
     	CALL EXIT
     	END

     	SUBROUTINE BARPLT_MENU( ICODE )
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY, FEB-1985
C
C  	INTERACTIVE DIALOGUE MENU FOR HISTOGRAM PLOT.
C	RETURN WITH "ICODE=1" IF QUITING.
C
    	INCLUDE		'BARPLT.CBS'
     	PARAMETER	(NKS = 31)
     	CHARACTER	KWD(NKS)*2
    	CHARACTER	TEXT*80, KEY*2, SYM*1
     	EQUIVALENCE	(SYM,TEXT(3:3)), (KEY,TEXT(1:2))
     	COMMON/BARPLT_MENU/  JSET, IKEY, NCHS, TEXT
C
C  ACCESS 2 LETTER CODES TO GRAPH PARAMETERS...
C
     	DATA KWD / 'F1', 'F3', 'F4', 'GT', 'L1', 'L2', 'GO', 'SF',
     + 'VT', 'SE', 'C1', 'BC', 'BP', 'BS', 'BO', 'LB', 'LP', 'T2',
     + 'X2', 'S2', 'PN', 'PT', 'LI', 'BL', 'SQ', 'WD', 'XO', 'YO',
     + 'YS', 'NO', 'ID' /
C
C  PRESENT THE DIALOGUE MENU...
C
    	JSET = 1			!ACTIVE DATA SET POINTER
     	IF( MENU ) THEN
     	    SLIN = 21
     	    SCOL = 6
     	    CALL BARPLT_FORM( JSET )
     	    CALL IFANSI_VIDEO(47)
        CALL IFANSI_TEXT( ' Type HELP (or press PF2) if you need any',
     +      42, SLIN, SCOL+10 )
     	ELSE
     	    CALL IFANSI_LEDS(3)
     	    SLIN = -1
     	    SCOL = 0
     	    WRITE(6,1)
  1	    FORMAT('_BARPLT> You are in dialogue mode without',
     +' the dialogue menu. Proceed as usual.')
     	ENDIF
C
C  START THE DIALOGUE LOOP...
C
111	CALL IFANSI_VIDEO(47)
     	IF( MENU ) THEN
     	    CALL IFANSI_TEXT('BARPLT> ', 8, 22, 1 )
     	    CALL IFANSI_CLEAR(4)
     	ELSE
     	    WRITE(6,112)
112	    FORMAT(' BARPLT> ',$)
     	ENDIF
     	IKEY = IFQIOW( NCHS, TEXT )
     	IF( IKEY.EQ.26) GOTO 888
     	IF( NCHS.EQ.0 ) GOTO 111
     	NCHS = IFMISC_STRIP(TEXT)
     	CALL   IFMISC_UPPER(2,KEY)
     	IF( KEY.EQ.'QU' .OR. KEY.EQ.'EX' ) GOTO 888
     	IF( NCHS.EQ.2  .AND. KEY.EQ.'GO' ) GOTO 999
     	IF( MENU ) CALL BARPLT_CLEAR_OOPS
C
C  COMMAND INPUT...
C
     	IF( SYM.NE.'='  ) THEN
     	    CALL BARPLT_COM
     	    IF( IKEY.EQ.-999 ) GOTO 999
     	ELSE
C
C  PARAMETER INPUT...
C
     	    DO IKEY = 1, NKS
     		IF( KEY.EQ.KWD(IKEY) ) GOTO 222
     	    ENDDO
     	    CALL IFMISC_OOPS( 2, SLIN, SCOL, KEY )
     	ENDIF
     	GOTO 111
C
C  YES, WE HAVE A VALID KEYWORD...
C
222	IF( NSET.EQ.0 .AND. IKEY.NE.1 ) GOTO 777
     	TEXT = TEXT(4:)
     	NCHS = NCHS-3
     	IF( IKEY.LT.4 ) THEN
     	    CALL BARPLT_FILES
     	    GOTO 111
     	ELSE IF( IKEY.LT.7 ) THEN
     	    IKEY = IKEY-3
     	    TITL(IKEY) = TEXT
     	    CALL BARPLT_PARS_ALL(IKEY)
     	ELSE IF( IKEY.LT.18 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-3
     	    CALL BARPLT_OVERALL
     	ELSE IF( IKEY.EQ.18 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-17
     	    CALL BARPLT_AXIS_A
     	ELSE IF( IKEY.EQ.19 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-18
     	    CALL BARPLT_AXIS_B
     	ELSE IF( IKEY.EQ.20 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-19
     	    CALL BARPLT_AXIS_C
     	ELSE IF( IKEY.LT.31 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-20
     	    CALL BARPLT_SET
     	ELSE
     	    LABL(JSET) = TEXT
     	    CALL BARPLT_PARS_SET(JSET,10)
     	ENDIF
     	GOTO 111
C
C  ERROR TRANSFER...
C
666	CALL IFMISC_OOPS( 4, SLIN, SCOL, ' ' )
     	GOTO 111
777	CALL IFMISC_OOPS( 11, SLIN, SCOL, ' ' )
     	GOTO 111
888	ICODE = 1		!QUIT FROM THE DIALOGUE
     	CALL IFANSI_CLEAR(2)
     	IF( .NOT.MENU ) CALL IFANSI_LEDS(0)
     	RETURN
999	IF( NSET.EQ.0 ) GOTO 888
     	CALL BARPLT_SETUP( 0, PARNAM )
     	ICODE = 0
     	IF( .NOT.MENU ) CALL IFANSI_LEDS(0)
     	RETURN
    	END

     	SUBROUTINE BARPLT_FORM( JSET )
C
C	THIS ROUTINE LAYOUTS THE DIALOGUE MENU FOR HISTOGRAM PLOT.
C
    	INCLUDE 'BARPLT.CBS'
        CHARACTER TEXT*80
C
C  LAYOUT THE MENU...
C
     	IF( .NOT.MENU ) RETURN
        TEXT(1:31) = 'GRAFIT: Histogram (data storage'
     	TEXT(32: ) = ' allocated:   sets,      bars/set)'
     	CALL IFINIT_LINE(24)
     	CALL IFANSI_TITLE( TEXT )
     	IF( CRT.EQ.2 ) THEN
     	    CALL IFANSI_VIDEO(50)
     	ELSE
     	    CALL IFANSI_VIDEO(47)
     	    CALL IFANSI_VIDEO(90)
     	ENDIF
     	WRITE(6,1000)
1000	FORMAT('     * * * * *   O V E R A L L   G R A P H'
     +,'   P A R A M E T E R S   * * * * *     ')
     	CALL IFANSI_VIDEO(47)
     	WRITE(6,1001)
1001	FORMAT(' GT='/' L1=',38X,'L2='/' GO=',17X,'SF='
     +, 36X,'VT=     SE=     C1=')
     	IF( CRT.NE.2 ) CALL IFANSI_VIDEO(90)
     	WRITE(6,1002)
1002	FORMAT(' BC=',10X,'BP=',10X,'BS=',8X,'BO=',18X,'LB=',4X,'LP=')
     	IF( CRT.EQ.2 ) CALL IFANSI_VIDEO(50)
     	CALL IFANSI_VIDEO(90)
     	WRITE(6,2000)
2000	FORMAT('      * * * * *   A X I S   D R A W I N G'
     +,'   P A R A M E T E R S   * * * * *      ')
     	IF( CRT.EQ.2 ) CALL IFANSI_VIDEO(50)
     	WRITE(6,2001)
2001	FORMAT('     TY DV dv DG PT     XLENG YLENG  TOFF',
     +'         LOW        HIGH        STEP    ')
     	CALL IFANSI_VIDEO(47)
     	IF( CRT.NE.2 ) CALL IFANSI_VIDEO(90)
     	WRITE(6,2002)
2002	FORMAT(' T2=',16X,'X2=',19X,'S2=')
     	IF( CRT.EQ.2 ) CALL IFANSI_VIDEO(50)
     	CALL IFANSI_VIDEO(90)
     	WRITE(6,3000)
3000	FORMAT('      * * *   D A T A   S E T   D R A W I N G'
     +,'   P A R A M E T E R S   * * *      ')
     	IF( CRT.EQ.2 ) CALL IFANSI_VIDEO(50)
     	WRITE(6,3001)
3001	FORMAT('  NO: PN  PT  LI  BL  SQ             WD    XO'
     +,'    YO                       YS     ')
     	CALL IFANSI_VIDEO(47)
     	WRITE(6,3002)
3002	FORMAT(4X,':')
     	IF( CRT.NE.2 ) CALL IFANSI_VIDEO(90)
     	WRITE(6,3003)
3003	FORMAT('  ID=',25X,'PT:     YL:',12X,'YH:',12X,'TOTAL SETS:')

     	IF( CRT.EQ.2 ) THEN
     	    CALL IFANSI_VIDEO(50)
     	ELSE
     	    CALL IFANSI_VIDEO(90)
     	ENDIF
     	WRITE(6,4000)
4000	FORMAT('     * * * * * * * *   I N P U T  &  O U T P U T'
     +,'   F I L E S   * * * * * * *     ')
     	CALL IFANSI_VIDEO(47)
     	WRITE(6,4001)
4001	FORMAT(' F1=',24X,'F3=',24X,'F4=')
     	CALL IFANSI_VIDEO(90)
     	CALL IFANSI_TEXT( ' ', 80, 20, 1 )
     	CALL IFANSI_VIDEO(20)
     	WRITE(6,5000)
5000	FORMAT(' oops:'//' Auxiliary: HELP/PF2, DCL/PF4,',
     +' DOWN_SET/PF1, UP_SET/PF3, LIST, REFRESH,          '/
     +' _commands: GO, ALLOCATE, READ, PLOT, SAVE, RESET,',
     +' SETUP, LAYOUT, TIME ...      ',$)
C
C  INSERT THE PARAMETERS...
C
     	CALL BARPLT_PARS_VM(MNST,MNPT)
     	CALL BARPLT_PARS(JSET)
     	RETURN
     	END

     	SUBROUTINE BARPLT_PARS_VM( MS, MP )
     	INCLUDE 'BARPLT.CBS'
     	IF( MENU ) THEN
     	    CALL IFANSI_VIDEO(60)
     	    CALL IFANSI_IFL( MS, 1, 'I2', 1, 43 )
     	    CALL IFANSI_IFL( MP, 1, 'I4', 1, 52 )
     	ENDIF
     	RETURN
     	END

     	SUBROUTINE BARPLT_PARS(JSET)
C
C	THIS ROUTINE INSERTS ALL GRAPH PARAMETERS.
C
     	INCLUDE 'BARPLT.CBS'
     	IF( MENU ) THEN
     	    CALL BARPLT_PARS_ALL(0)	!OVERALL PLOT PARAMETER GROUP
     	    CALL BARPLT_PARS_AXIS(0)	!AXIS DRAWING PARAMETER GROUP
     	    CALL BARPLT_PARS_SET(JSET,0)!DATA SET DRAWING PARAMETER GROUP
     	    CALL BARPLT_PARS_NSET	!TOTAL NUMBER OF DATA SETS
     	    CALL BARPLT_PARS_FILE(0)	!I/O FILE GROUP
     	ENDIF
     	RETURN
    	END

     	SUBROUTINE BARPLT_PARS_ALL( ICODE )
C
C	THIS ROUTINE DISPLAYS OVERALL PLOT PARAMETERS.
C
     	INCLUDE 'BARPLT.CBS'
     	CHARACTER PLOT*8
     	DIMENSION RP(2)

     	IF( .NOT.MENU ) RETURN
     	CALL IFANSI_VIDEO(30)
     	I = ICODE
    	IF(I.EQ.0.OR.I.EQ.1) CALL IFANSI_TEXT( TITL(1), 77, 3, 4 )
    	IF(I.EQ.0.OR.I.EQ.2) CALL IFANSI_TEXT( TITL(2), 36, 4, 4 )
    	IF(I.EQ.0.OR.I.EQ.3) CALL IFANSI_TEXT( TITL(3), 36, 4, 45)
    	IF(I.EQ.0.OR.I.EQ.4) THEN
     	   RP(1) = XORG
     	   RP(2) = YORG
     	   CALL IFANSI_FFL( RP, 2, '2F6.2', 5, 4 )
     	ENDIF
     	IF(I.EQ.0.OR.I.EQ.5) THEN
     	   RP(1) = XSCL
     	   RP(2) = YSCL
    	   CALL IFANSI_FFL( RP, 2, '2F6.3', 5, 24)
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.6) THEN
     	   PLOT = 'NO'
     	   IF( ANSI ) PLOT = 'YES'
     	   CALL IFANSI_TEXT( PLOT, 3, 5, 63)
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.7) THEN
     	   PLOT = 'YES'
     	   IF( .NOT.INIT ) PLOT = 'NO'
     	   CALL IFANSI_TEXT( PLOT, 3, 5, 71)
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.8) CALL IFANSI_IFL( IAXS, 1, 'I2', 5, 79 )
    	IF(I.EQ.0.OR.I.EQ.9) THEN
     	   PLOT = 'SIDE'
     	   IF( SIDE.EQ.2 ) PLOT = 'STACK'
     	   CALL IFANSI_TEXT( PLOT, 8, 6, 4 )
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.10) THEN
     	   PLOT = 'SKIP'
     	   IF( PBAR.EQ.1 ) PLOT = 'BOTTOM'
     	   IF( PBAR.EQ.2 ) PLOT = 'TOP'
     	   CALL IFANSI_TEXT( PLOT, 8, 6, 17 )
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.11) CALL IFANSI_FFL( SPAC,1,'F6.2',6,30 )
    	IF(I.EQ.0.OR.I.EQ.12) CALL IFANSI_FFL( BARD,1,'F6.2',6,41 )
     	IF(I.EQ.0.OR.I.EQ.13) CALL IFANSI_IFL( DRAW,1,'I2', 6, 62 )
    	IF(I.EQ.0.OR.I.EQ.14) THEN
     	   RP(1) = XLPS
     	   RP(2) = YLPS
     	   CALL IFANSI_FFL( RP, 2, '2F6.2', 6, 69 )
     	ENDIF

     	RETURN
     	END

     	SUBROUTINE BARPLT_PARS_AXIS( ICODE )
C
C	THIS ROUTINE DISPLAYS AXIS DRAWING PARAMETERS.
C
     	INCLUDE  'BARPLT.CBS'
     	DIMENSION KP(5), RP(3)

     	IF( .NOT.MENU ) RETURN
     	CALL IFANSI_VIDEO(30)
     	I = ICODE
     	IF( I.LT.2 ) THEN
     	    KP(1) = LAXS
     	    KP(2) = NTKS
     	    KP(3) = MTKS
     	    KP(4) = NDGS
     	    KP(5) = IGDS
     	    CALL IFANSI_IFL( KP, 5, '5I3', 9, 4  )
     	ENDIF
     	IF( I.EQ.0 .OR. I.EQ.2 ) THEN
     	    RP(1) = XLNS
     	    RP(2) = YLNS
     	    RP(3) = OFFS
     	    CALL IFANSI_FFL( RP, 3, '3F6.2', 9, 23 )
     	ENDIF
     	IF( I.EQ.0. OR. I.EQ.3 ) THEN
     	    RP(1) = YLOW
     	    RP(2) = YHIG
     	    RP(3) = YINC
     	    CALL IFANSI_FFL( RP, 3, '3G12.5', 9, 45 )
     	ENDIF

     	RETURN
     	END

	SUBROUTINE BARPLT_PARS_SET( ICODE, IPAR )
C
C	THIS ROUTINE DISPLAYS DATA SET DRAWING PARAMETERS.
C
    	INCLUDE 'BARPLT.CBS'

     	IF( .NOT.MENU ) RETURN
     	JSET = ICODE
     	I = IPAR
     	IF( I.EQ.0 ) THEN
     	    CALL IFANSI_VIDEO(47)
    	    CALL IFANSI_IFL( JSET, 1, 'I3', 12, 1 )
     	ENDIF
     	CALL IFANSI_VIDEO(30)
    	IF(I.EQ.0.OR.I.EQ.1) CALL IFANSI_IFL(IPEN(JSET),1,'I3',12,5)
    	IF(I.EQ.0.OR.I.EQ.2) CALL IFANSI_IFL(IPAT(JSET),1,'I3',12,9)
    	IF(I.EQ.0.OR.I.EQ.3) CALL IFANSI_IFL(ILIN(JSET),1,'I3',12,13)
    	IF(I.EQ.0.OR.I.EQ.4) CALL IFANSI_IFL(IBOL(JSET),1,'I3',12,17)
    	IF(I.EQ.0.OR.I.EQ.5) CALL IFANSI_IFL(ISEQ(JSET),1,'I3',12,21)
    	IF(I.EQ.0.OR.I.EQ.6) CALL IFANSI_FFL(BARW(JSET),1,'F6.2',12,34)
    	IF(I.EQ.0.OR.I.EQ.7) CALL IFANSI_FFL(XOFF(JSET),1,'F5.2',12,41)
    	IF(I.EQ.0.OR.I.EQ.8) CALL IFANSI_FFL(YOFF(JSET),1,'F5.2',12,47)
    	IF(I.EQ.0.OR.I.EQ.9) CALL IFANSI_FFL(BARS(JSET),1,'G12.5',12,69)
    	IF(I.EQ.0.OR.I.EQ.10)CALL IFANSI_TEXT(LABL(JSET), 24, 13, 5 )
     	IF(I.EQ.0) THEN
     	   CALL IFANSI_VIDEO(60)
     	   CALL IFANSI_IFL( NUMS(JSET),   1, 'I4', 13, 33 )
     	   CALL IFANSI_FFL( SRNG(1,JSET), 1, 'G11.4', 13, 41 )
     	   CALL IFANSI_FFL( SRNG(2,JSET), 1, 'G11.4', 13, 56 )
     	ENDIF

     	RETURN
	END

     	SUBROUTINE BARPLT_PARS_FILE( ICODE )
C
C	THIS ROUTINE DISPLAYS FILENAMES.
C
     	INCLUDE 'BARPLT.CBS'
     	CHARACTER DNAME*23

     	IF( .NOT.MENU ) RETURN
     	I = ICODE
     	CALL IFANSI_VIDEO(20)
     	IF( I.EQ.0 .OR. I.EQ.1 ) THEN
     	    DNAME = DATNAM
     	    K = INDEX( DNAME, ']' )
     	    IF( K.GT.0 ) DNAME = DNAME(K+1:)
     	    CALL IFANSI_TEXT( DNAME, 23, 15, 4 )
     	ENDIF
     	IF( I.EQ.0 .OR. I.EQ.2 ) THEN
     	    DNAME = PARNAM
     	    K = INDEX( DNAME, ']' )
     	    IF( K.GT.0 ) DNAME = DNAME(K+1:)
     	    CALL IFANSI_TEXT( DNAME, 23, 15, 31)
     	ENDIF
     	IF( I.EQ.0 .OR. I.EQ.3 ) THEN
     	    DNAME = DESNAM
     	    K = INDEX( DNAME, ']' )
     	    IF( K.GT.0 ) DNAME = DNAME(K+1:)
     	    CALL IFANSI_TEXT( DNAME, 23, 15, 58)
     	ENDIF

     	RETURN
     	END

     	SUBROUTINE BARPLT_PARS_NSET
     	INCLUDE 'BARPLT.CBS'
     	IF( MENU ) THEN
     	    CALL IFANSI_VIDEO(24)
     	    CALL IFANSI_VIDEO(80)
     	    CALL IFANSI_IFL( NSET, 1, 'I2', 13, 79 )
     	ENDIF
     	RETURN
     	END

     	SUBROUTINE BARPLT_COM
C
C	THIS ROUTINE IMPLEMENTS SOME DIALOGUE COMMANDS.
C
C	LIST OF COMMANDS:
C
C	HELP   : display help information.
C	REFRESH: re-layout the dialogue menu.
C	RESET  : reset graph parameters.
C	SAVE   : save graph parameters.
C	READ   : read a data file to start a new plot.
C	PLOT   : read and plot a data file to start a new plot.
C	SETUP  : use another setup/parameter file.
C	LAYOUT : use another layout file.
C	LIST   : list all data set parameters.
C	DCL    : spawn a system subprocess.
C	DOWN   : step data set pointer down by one.
C	UP     : step data set pointer back by one.
C
     	INCLUDE		'BARPLT.CBS'
    	CHARACTER	TEXT*80
     	COMMON/BARPLT_MENU/  JSET, IKEY, NCHS, TEXT

     	CALL IFMISC_UPPER(NCHS,TEXT)		!CONVERT TO UPPERCASES
C
C  IF "TEXT" IS A SINGLE WORD AND CONTAINS A DOT, TAKE IT
C  AS A DATA FILENAME TO BE PLOTTED...
C
     	JKEY = INDEX( TEXT(1:NCHS), ' ' )
     	IF( JKEY.EQ.0 ) THEN
     	    JKEY = INDEX( TEXT(1:NCHS), '.' )
     	    IF( JKEY.GT.0 ) THEN
     		IKEY = 1
     		CALL BARPLT_FILES
     		RETURN
     	    ENDIF
     	ENDIF
     	IF( TEXT(1:4).EQ.'DOWN'
     + .OR. (IKEY.EQ.27 .AND. TEXT(1:2).EQ.'OP') ) THEN
C
C  DOWN...
     	    IF( NSET.EQ.0 ) GOTO 888
     	    JSET = JSET + 1
     	    IF( JSET.GT.NSET ) JSET = 1
     	    CALL BARPLT_PARS_SET(JSET,0)
     	ELSE IF( KEY.EQ.'UP'
     + .OR. (IKEY.EQ.27 .AND. TEXT(1:2).EQ.'OR') ) THEN
C
C  UP...
     	    IF( NSET.EQ.0 ) GOTO 888
     	    JSET = JSET - 1
     	    IF( JSET.LT.1 ) JSET = NSET
     	    CALL BARPLT_PARS_SET(JSET,0)
     	ELSE IF( TEXT(1:4).EQ.'LIST' ) THEN
C
C  LIST...
     	    IF( NSET.EQ.0 ) GOTO 888
     	    CALL BARPLT_LIST( JSET )
     	ELSE IF( TEXT(1:4).EQ.'HELP'
     + .OR. (IKEY.EQ.27 .AND. TEXT(1:2).EQ.'OQ') ) THEN
C
C  HELP...
     	    IF( MENU ) THEN
     		IKEY = IFMISC_HLP( 'BARPLT', TEXT, SLIN, SCOL )
     		IF( IKEY.EQ.0 ) CALL BARPLT_FORM(JSET)
     	    ELSE
     		IKEY = IFMISC_HLP( 'BARPLT', TEXT, 22, 0 )
     		CALL IFINIT_LINE(-3)
     	    ENDIF
     	ELSE IF( TEXT(1:3).EQ.'REF' .OR. TEXT(1:4).EQ.'MENU' ) THEN
C
C  REFRESH...
     	    IF( .NOT.MENU ) THEN
     		MENU = .TRUE.
     		SLIN = 21
     		SCOL = 6
     		CALL IFANSI_LEDS(0)
     	    ENDIF
     	    CALL BARPLT_FORM(JSET)
     	ELSE IF( TEXT(1:5).EQ.'RESET' ) THEN
C
C  RESET...
     	    IF( NSET.EQ.0 ) GOTO 888
     	    CALL BARPLT_RESET( JSET )
     	ELSE IF( TEXT(1:4).EQ.'SAVE' ) THEN
C
C  SAVE...
     	    IF( NSET.EQ.0 ) GOTO 888
     	    CALL BARPLT_SAVE
     	ELSE IF( TEXT(1:4).EQ.'READ' .OR. TEXT(1:4).EQ.'PLOT' ) THEN
C
C  READ...
     	    IKEY = 1
     	    IF( TEXT(1:4).EQ.'PLOT' ) IKEY = -1
     	    NCHS = IFMISC_NEXT(TEXT)
     	    CALL BARPLT_FILES
     	ELSE IF( TEXT(1:5).EQ.'SETUP' ) THEN
C
C  SETUP...
     	    IKEY = 2
     	    NCHS = IFMISC_NEXT(TEXT)
     	    CALL BARPLT_FILES
     	ELSE IF( TEXT(1:6).EQ.'LAYOUT' ) THEN
C
C  LAYOUT...
     	    IKEY = 3
     	    NCHS = IFMISC_NEXT(TEXT)
     	    CALL BARPLT_FILES
     	ELSE IF( TEXT(1:3).EQ.'DCL'
     + .OR. (IKEY.EQ.27 .AND. TEXT(1:2).EQ.'OS') ) THEN
C
C  SPAWN...
     	    CALL IFANSI_CLEAR(2)
     	    CALL IFMISC_SPAWN( TEXT, 0 )
     	    CALL BARPLT_FORM(JSET)
     	ELSE IF( TEXT(1:3).EQ.'ALL' ) THEN
C
C  ALLOCATE...
     	    CALL BARPLT_VM
     	ELSE IF( TEXT(1:4).EQ.'TIME' ) THEN
C
C  TIME...
     	    IF( MENU ) CALL IFMISC_TIME
     	ELSE
     	    IF( IKEY.NE.27 ) THEN
     		CALL IFMISC_OOPS( 2, SLIN, SCOL, TEXT )
     	    ELSE
     		CALL IFMISC_OOPS( 5, SLIN, SCOL, ' ' )
     	    ENDIF
     	ENDIF
     	RETURN
888	CALL IFMISC_OOPS( 11, SLIN, SCOL, ' ' )	!NO DATA YET TO PROCEED
     	RETURN
     	END

     	SUBROUTINE BARPLT_RESET( JSET )
C
C	THIS ROUTINE RESETS THE PLOT.
C
     	INCLUDE 'BARPLT.CBS'
     	IF( MENU ) CALL BARPLT_CLEAR_OOPS
     	CALL BARPLT_OOPS(' Resetting the plot...')
     	CALL BARPLT_INIT(1)
     	CALL BARPLT_SCALE( MNST, MNPT, %VAL(IYAR) )
     	CALL BARPLT_WIDTH(0)
     	IF( MENU ) THEN
     	    CALL BARPLT_PARS(JSET)
     	    CALL BARPLT_CLEAR_OOPS
     	ENDIF
     	RETURN
     	END

     	SUBROUTINE BARPLT_FILES
C
C	THIS ROUTINE GETS INPUT DATA/PARAMETER/LAYOUT FILES.
C
     	INCLUDE		'BARPLT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/BARPLT_MENU/  JSET, IKEY, NCHS, TEXT

     	JKEY = IKEY
     	IKEY = IABS(IKEY)
     	IF( NCHS.EQ.0  ) THEN
     	    NCHS = IFMISC_PROMPT('_Filename:',TEXT,SLIN+1,9)
     	    IF( NCHS.EQ.0 ) GOTO 999
     	ENDIF
     	JUNK = INDEX( TEXT, '/' )
     	IFL1 = 0
     	IFL2 = 0
     	IFL3 = 0
     	IF( JUNK.GT.0 ) THEN
     	    IF( NSET.GT.0 ) IFL1 = INDEX( TEXT, '/NOINI' )
     	    IFL2 = INDEX( TEXT, '/NOSET' )
     	    IFL3 = INDEX( TEXT, '/NOLAY' )
     	    TEXT = TEXT(1:JUNK-1)
     	    NCHS = IFMISC_LENG(TEXT)
     	ENDIF
     	IF( NCHS.GT.32 ) THEN
     	    CALL IFMISC_OOPS( 7, SLIN, SCOL, TEXT )
     	    GOTO 999
     	ENDIF
     	CALL IFMISC_UPPER(NCHS,TEXT)
     	IF( IKEY.NE.1 ) GOTO 222
C
C  START A NEW PLOT WITH A NEW DATA FILE...
C
     	IKEY = BARPLT_DATA( TEXT, MNST, MNPT, IXAR, %VAL(IYAR) )
     	IF( IKEY.GT.0 ) THEN
     	    CALL IFMISC_OOPS( IKEY, SLIN, SCOL, TEXT )
     	    GOTO 999
     	ENDIF
C
C  YES, WE HAVE A NEW PLOT...
C
     	JSET = 1
     	DATNAM = TEXT
     	PARNAM = DATNAM
     	CALL IFMISC_NAMEXT( PARNAM, '.PAR' )
     	DESNAM = ' '
     	IF( IFL3.EQ.0 ) THEN
     	    DESNAM = DATNAM
     	    CALL IFMISC_NAMEXT( DESNAM, '.DES' )
     	ENDIF
     	TEXT = ' '
     	WRITE( TEXT(1:), 1000 ) NSET
1000	FORMAT(I4)
     	TEXT(5:) = ' set(s) of data have been read from'
     	TEXT(41:) = DATNAM
     	CALL IFANSI_VIDEO(20)
     	CALL BARPLT_OOPS( TEXT )
     	IF( IFL1.EQ.0 ) CALL BARPLT_INIT(1)
     	IKEY = 0
     	IF( IFL2.EQ.0 ) IKEY = BARPLT_SETUP( 1, PARNAM )
     	IF( IKEY.EQ.0 .AND. IFL1.EQ.0 ) CALL BARPLT_SCALE( MNST,
     +      MNPT, %VAL(IYAR) )
     	IF( JKEY.GT.0 .AND. (IFL1.EQ.0.OR.IFL2.EQ.0) ) THEN
     	    CALL IFANSI_VIDEO(30)
     	    CALL BARPLT_PARS(JSET)
     	ELSE
     	    IKEY = -999
     	ENDIF
     	GOTO 999

222	IF( IKEY.NE.2 ) GOTO 333
C
C  USE ANOTHER SETUP FILE ...
C
     	CALL IFMISC_DEFEXT( TEXT, '.PAR' )
     	IKEY = BARPLT_SETUP( 1, TEXT )
     	IF( IKEY.EQ.0 ) THEN
     	    CALL IFMISC_OOPS( 1, SLIN, SCOL, TEXT )
     	ELSE
     	    CALL IFANSI_VIDEO(30)
     	    CALL BARPLT_PARS(JSET)
     	ENDIF
     	GOTO 999

333	IF( IKEY.NE.3 ) GOTO 999
C
C  NEW LAYOUT FILE (ONLY *.DES FILENAME IS ALLOWED SO THAT THE USER
C  MAY NOT RISK LOOSING HIS/HER FILE BY MIS-ENTERING A FILENAME...
C
     	DESNAM = TEXT
     	CALL IFMISC_NAMEXT( DESNAM, '.DES' )
     	CALL BARPLT_PARS_FILE(3)

999	RETURN
     	END

     	FUNCTION BARPLT_DATA( FNAME, MS, MP, X, Y )
C
C	THIS ROUTINE READS A HISTOGRAM DATA FILE.
C
     	INCLUDE  'BARPLT.CBS'
     	CHARACTER TEXT*132, FNAME*(*), X(MP)*8
     	DIMENSION RP(MNS), KP(MNS), Y(MP,MS)
     	LOGICAL   YES

    	NCHS = IFMISC_LENG(FNAME)
    	NDOT = INDEX( FNAME(1:NCHS), ']' )
    	NDOT = INDEX( FNAME(NDOT+1:NCHS), '.' )
     	IF( NDOT.GT.0 ) GOTO 9
     	IERR = 1
     	GOTO 2
C
C  OPEN FILE IN THE PRIORITY FROM *.BAR, *.DAT, *.RAW...
C
  1	CLOSE(13)
     	IF( NDOT.GT.0 ) GOTO 666
  2	IF( IERR.EQ.1 ) THEN
     	    FNAME(NCHS+1: ) = '.BAR'
     	    IERR = 2
     	ELSE IF( IERR.EQ.2 ) THEN
    	    FNAME(NCHS+1: ) = '.DAT'
    	    IERR = 3
     	ELSE IF( IERR.EQ.3 ) THEN
     	    FNAME(NCHS+1: ) = '.RAW'
    	    NDOT = 1
     	ENDIF

  9	INQUIRE( FILE=FNAME, EXIST=YES )
     	IF( .NOT.YES ) GOTO 1
C
C  OPEN THE FILE...
C
     	OPEN(13,FILE=FNAME,STATUS='OLD',FORM='FORMATTED',ERR=1)
     	NDOT = 0
222	READ(13,223,ERR=888,END=444) TEXT
223	FORMAT(A)
     	IF( TEXT.EQ.' ' ) GOTO 222
     	NCHS = IFMISC_STRIP(TEXT)
     	ISPC = INDEX( TEXT(1:NCHS), ' ' ) + 1
     	ICOM = INDEX( TEXT(1:NCHS), ',' ) + 1
     	IF( ICOM.GT.1 .AND. ICOM.LT.ISPC ) ISPC = ICOM
     	IF( ISPC.LT.2 ) GOTO 888
     	ICOM = IFMISC_DECODE( TEXT(ISPC:), NCHS-ISPC+1, MNST, RP, KP )
     	IF( ICOM.EQ.0 ) GOTO 888
     	NDOT = NDOT + 1
     	X(NDOT) = TEXT(1:ISPC-2)
     	DO I=1, MNST
     	   Y(NDOT,I) = RP(I)
     	ENDDO
     	IF( NDOT.LT.MNPT ) GOTO 222
444	IF( NDOT.EQ.0 ) GOTO 777
C
C  SET DEFAULT BAR WIDTH AND BAR GROUP SPACING...
C
     	NBAR = NDOT
     	DO  I=1, MNST
     	    NDOT = 0
     	    YMIN = Y(1,I)
     	    YMAX = YMIN
     	    DO  J=1, NBAR
     		YJI = Y(J,I)
     		IF( YJI.NE.0.0 ) THEN
     		    NDOT = NDOT + 1
     		    IF( YJI.GT.YMAX ) THEN
     			YMAX = YJI
     		    ELSE IF( YJI.LT.YMIN ) THEN
     			YMIN = YJI
     		    ENDIF
     		ENDIF
     	    ENDDO
     	    IF( NDOT.EQ.0 ) GOTO 555
     	    NUMS(I) = NDOT
     	    SRNG(1,I) = YMIN
     	    SRNG(2,I) = YMAX
     	ENDDO
555	IF( I.LT.2 ) GOTO 777
     	NSET = I-1
     	CALL BARPLT_WIDTH(0)
     	IERR = 0
     	GOTO 999
666	IERR = 1
     	GOTO 999
777	IERR = 13
     	GOTO 999
888	IERR = 14
999	BARPLT_DATA = FLOAT(IERR)
     	CLOSE(UNIT=13)
     	RETURN
     	END

     	SUBROUTINE BARPLT_WIDTH(ICODE)
C
C	THIS ROUTINE CHECKS OVERALL BAR WIDTH AND SPACING.
C
     	INCLUDE 'BARPLT.CBS'

     	KSET = NSET
     	IF( SIDE.EQ.2 ) KSET = 1		!STACK UP
     	WIDTH = ABS(XLNS) - BARD - SPAC*(NBAR-1)
     	DO  I=1, KSET
     	    WIDTH = WIDTH - BARW(I)*NBAR
     	    IF( WIDTH.LT.0.1 ) GOTO 111
     	ENDDO
     	IF( ICODE.EQ.1 .OR. WIDTH.LE.BARD ) RETURN
111	WIDTH = ABS(XLNS)/(NBAR*(KSET+1)+1)
     	IF( WIDTH.LT.0.02 ) THEN
     	    WIDTH = 0.02
     	    XLNS  = WIDTH*(NBAR*(KSET+1)+1)
     	ENDIF
     	BARD = WIDTH
     	SPAC = WIDTH
     	DO  I=1, NSET
     	    BARW(I) = WIDTH
     	ENDDO
     	RETURN
     	END

    	SUBROUTINE BARPLT_INIT( ICODE )
C
C	THIS ROUTINE INITIALIZES THE COMMON BLOCKS FOR HISTOGRAM PLOT.
C
    	INCLUDE 'BARPLT.CBS'

     	IF( ICODE.EQ.0 ) THEN
     	    CRT = IFINIT_ITM(0)		!GET THE TYPE OF TERMINAL
     	    DATNAM = ' Data file here'
     	    PARNAM = ' Setup file here '
     	    DESNAM = ' Layout file here '
    	    DO I=1, 3
     	       TITL(I) = ' '
    	    ENDDO
     	    DO I=1, MNS
     	       NUMS(I) = 0
     	       BARW(I) = 0.1
    	       LABL(I) = ' '
     	       SRNG(1,I) = 0.0
     	       SRNG(2,I) = 0.0
     	    ENDDO
     	    SPAC = 0.1
     	    BARD = 0.25
     	    NSET = 0
     	    NBAR = 0
     	    INIT = .TRUE.
     	    ANSI = .FALSE.
     	    MENU = .TRUE.
	    PLOTID = ' '
     	    MNST = 4
     	    MNPT = 128
     	    CALL IF_DCL_VM( NTKS, MTKS )
     	    IF( NTKS.GT.0 .AND. NTKS.LE.MNS ) MNST = NTKS
     	    IF( MTKS.GT.1 .AND. MTKS.LT.10000 ) MNPT = MTKS
     	    IXAR(1) = 8*MNPT
     	    IAXS = LIB$GET_VM(IXAR(1),IXAR(2))
     	    IF( .NOT.IAXS ) GOTO 888
     	    IAXS = LIB$GET_VM(4*MNST*MNPT,IYAR)
     	    IF( .NOT.IAXS ) GOTO 888
     	ENDIF

     	LAXS = 1
     	NTKS = 1
     	MTKS =-1
     	NDGS = 0
     	IGDS = 1
     	XLNS = 6.0
     	YLNS = 4.0
     	OFFS = 0.0
     	YLOW = 0.0
     	YHIG = 0.0
     	YINC = 0.0

     	DO I=1, MNS
     	   IPEN(I) = I
     	   IPAT(I) = 1
     	   ILIN(I) = 1
    	   IBOL(I) = 1
    	   ISEQ(I) = I
    	   XOFF(I) = 0.0
    	   YOFF(I) = 0.0
    	   BARS(I) = 1.0
    	ENDDO

    	IAXS = 1
     	DRAW = 2
     	SIDE = 1
     	PBAR = 1
     	XLPS = 0.5
     	YLPS = 0.5
     	XORG = 2.25
     	YORG = 2.25
     	XSCL = 1.00
     	YSCL = 1.00
    	RETURN
888	CALL IFMISC_OOPS( 6, 0, 0, ' ' )
     	CALL EXIT
    	END

	SUBROUTINE BARPLT_OVERALL
C
C	THIS ROUTINE CHANGES OVREALL PLOT PARAMETERS.
C
    	INCLUDE		'BARPLT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/BARPLT_MENU/ JSET, IKEY, NCHS, TEXT
     	DIMENSION	RP(2), KP(2)
C
C  DECODE THE PARAMETERS...
C
     	IF( IKEY.NE.6 .AND. IKEY.NE.7
     +.AND. IKEY.NE.9 .AND. IKEY.NE.10 ) THEN
     	    NCHS = IFMISC_DECODE( TEXT, NCHS, 2, RP, KP )
    	    IF( NCHS.EQ.0 ) GOTO 777
     	ENDIF

     	IF( IKEY.EQ.4 ) THEN		!GRAPH ORIGIN
    	    IF( KP(1).EQ.1 ) THEN
     		IF(RP(1).LT.0.0.OR.RP(1).GT.99.0) GOTO 777
     		XORG = RP(1)
    	    ENDIF
    	    IF( KP(2).EQ.1 ) THEN
     		IF(RP(2).LT.0.0.OR.RP(2).GT.99.0) GOTO 777
    	       	YORG = RP(2)
    	    ENDIF
     	ELSE IF( IKEY.EQ.5 ) THEN	!OVERALL SCALE FACTORS
    	    IF( KP(1).EQ.1 ) THEN
     		IF(RP(1).LT.0.1.OR.RP(1).GT.3.0) GOTO 777
    	       	XSCL = RP(1)
    	    ENDIF
    	    IF( KP(2).EQ.1 ) THEN
     		IF(RP(2).LT.0.1.OR.RP(2).GT.3.0) GOTO 777
    	       	YSCL = RP(2)
    	    ENDIF
     	ELSE IF( IKEY.EQ.6 ) THEN	!ANSI GRAPH FLAG
     	    ANSI = .FALSE.
     	    IF( TEXT(1:1).EQ.'Y' .OR. TEXT(1:1).EQ.'y'
     +     .OR. TEXT(1:1).EQ.'T' .OR. TEXT(1:1).EQ.'t' ) ANSI=.TRUE.
     	ELSE IF( IKEY.EQ.7 ) THEN	!SCREEN ERASE FLAG
     	    INIT = .TRUE.
     	    IF( TEXT(1:1).EQ.'N' .OR. TEXT(1:1).EQ.'n'
     +     .OR. TEXT(1:1).EQ.'F' .OR. TEXT(1:1).EQ.'f' ) INIT=.FALSE.
     	ELSE IF( IKEY.EQ.8 ) THEN	!AXIS COLOR
     	    IF(RP(1).LT.1.0.OR.RP(1).GT.8.0) GOTO 777
     	    IAXS = RP(1)
     	ELSE IF( IKEY.EQ.9 ) THEN
     	    IF( NCHS.LT.4 ) GOTO 777
     	    CALL IFMISC_UPPER(NCHS,TEXT)
     	    IF( TEXT(1:4).NE.'SIDE'.AND.TEXT(1:5).NE.'STACK') GOTO 777
     	    IKEY = SIDE
     	    IF( TEXT(1:4).EQ.'SIDE'  ) SIDE = 1
     	    IF( TEXT(1:5).EQ.'STACK' ) SIDE = 2
     	    IF( IKEY.NE.SIDE ) THEN
     		CALL BARPLT_SCALE( MNST, MNPT, %VAL(IYAR) )
     		CALL BARPLT_WIDTH(0)
     		CALL BARPLT_PARS(JSET)
     	    ENDIF
     	    RETURN
     	ELSE IF( IKEY.EQ.10 ) THEN
     	    IF( NCHS.LT.3 ) GOTO 777
     	    CALL IFMISC_UPPER(NCHS,TEXT)
     	    IF( TEXT(1:3).NE.'TOP' .AND. TEXT(1:4).NE.'SKIP'
     +    .AND. TEXT(1:6).NE.'BOTTOM' ) GOTO 777
     	    IF( TEXT(1:3).EQ.'TOP'    ) PBAR = 2
     	    IF( TEXT(1:4).EQ.'SKIP'   ) PBAR = 0
     	    IF( TEXT(1:6).EQ.'BOTTOM' ) PBAR = 1
     	ELSE IF( IKEY.EQ.11 ) THEN
     	    SPAC = RP(1)
     	    CALL BARPLT_WIDTH(1)
     	ELSE IF( IKEY.EQ.12 ) THEN
     	    BARD = RP(1)
     	    CALL BARPLT_WIDTH(1)
     	ELSE IF( IKEY.EQ.13 ) THEN
     	    IF(RP(1).LT.0.0.OR.RP(1).GT.2.0) GOTO 777
     	    DRAW = RP(1)
     	ELSE IF( IKEY.EQ.14 ) THEN
     	    IF( KP(1).EQ.1 ) THEN
     		IF( RP(1).LT.-9.0 .OR. RP(1).GT.99.0 ) GOTO 777
     		XLPS = RP(1)
    	    ENDIF
    	    IF( KP(2).EQ.1 ) THEN
     		IF( RP(2).LT.-9.0 .OR. RP(2).GT.99.0 ) GOTO 777
     		YLPS = RP(2)
    	    ENDIF
     	ELSE
     	    GOTO 777
     	ENDIF
     	CALL BARPLT_PARS_ALL(IKEY)
     	RETURN
777	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
     	RETURN
	END

	SUBROUTINE BARPLT_SET
C
C	THIS ROUTINE CHANGES DATA SET DRAWING PARAMETERS
C	IN COLUMN-RUN MODE.
C
    	INCLUDE		'BARPLT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/BARPLT_MENU/ JSET, IKEY, NCHS, TEXT
     	DIMENSION	KP(MNS), RP(MNS)
     	LOGICAL		REPEAT
C
C  CHECK TO SEE IF THERE IS ANY SPECIAL CHARACTER IN THE INPUT...
C
     	KSET = JSET				!ACTIVE SET NUMBER
     	REPEAT = .FALSE.
     	CALL IFMISC_UPPER(NCHS,TEXT)
     	I = INDEX( TEXT(1:NCHS), 'I' )		!JUMP TO SET "I"
     	IF( I.EQ.0 ) THEN
     	    I = INDEX( TEXT(1:NCHS), 'R' )	!REPEAT PARAMETERS
     	    IF( I.GT.0 ) REPEAT = .TRUE.
     	ENDIF
     	IF( I.EQ.NCHS ) NCHS = NCHS - 1
     	IF( I.GT.0 .AND. I.LT.NCHS ) THEN	!GET STARTING SET POINTER
     	    READ( TEXT(I+1:NCHS), 1000, ERR=777 ) KSET
     	    IF( KSET.LT.1 .OR. KSET.GT.NSET ) GOTO 777
     	    NCHS = I-1
     	ENDIF
1000	FORMAT(I)
C
C  DECODE THE INPUT...
C
     	I = IFMISC_DECODE( TEXT,NCHS, NSET-KSET+1, RP(KSET),KP(KSET) )
    	IF( I.EQ.0 ) GOTO 777	!ERROR IN INPUT
C
C  REPEAT ENTRIES FOR THE REST OF DATA SETS IF TRUE...
C
	IF( REPEAT ) THEN
    	    DO I=KSET, NSET
    	       IF( KP(I).EQ.0 ) GOTO 111
    	    ENDDO
111	    NCHS = I - 1
    	    IF( NCHS.LT.KSET ) GOTO 777
    	    DO J=I, NSET
    	       KP(J) = 1
    	       RP(J) = RP(J-(NCHS-KSET+1))
    	    ENDDO
    	ENDIF
C
C  STORE THE VALID PARAMETERS...
C
     	IF( IKEY.EQ.1 ) THEN
    	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) THEN
     		    J = RP(I)
     		    IF( J.LT.0 .OR. J.GT.16 ) GOTO 222
     		    IPEN(I) = J
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.2 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) THEN
     		    J = RP(I)
     		    IF( IABS(J).GT.99 ) GOTO 222
     		    IPAT(I) = J
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.3 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) THEN
     		    J = RP(I)
     		    IF( J.LT.1 .OR. J.GT.9 ) GOTO 222
     		    ILIN(I) = J
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.4 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) THEN
     		    J = RP(I)
     		    IF( J.LT.1 .OR. J.GT.9 ) GOTO 222
     		    IBOL(I) = J
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.5 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) THEN
     		    J = RP(I)
     		    IF( J.LT.1 .OR. J.GT.NSET ) GOTO 222
     		    KP(I) = J
     		ELSE
     		    KP(I) = ISEQ(I)
     		ENDIF
     	    ENDDO
     	    DO  I=KSET, NSET-1
     		DO  J=I+1,NSET
     		    IF( KP(I).EQ.KP(J) ) GOTO 777
     		ENDDO
     	    ENDDO
     	    DO  I=KSET, NSET
     		ISEQ(I) = KP(I)
     	    ENDDO
     	ELSE IF( IKEY.EQ.6 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) THEN
     		    P = RP(I)
     		    IF( P.LT.0.02 .OR. P.GT.5.0 ) GOTO 222
     		    BARW(I) = P
     		ENDIF
     	    ENDDO
     	    CALL BARPLT_WIDTH(1)
     	    CALL BARPLT_PARS_ALL(9)
     	    CALL BARPLT_PARS_ALL(10)
     	ELSE IF( IKEY.EQ.7 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) THEN
     		    P = ABS(RP(I))
     		    IF( P.GT.ABS(XLNS) ) GOTO 222
     		    XOFF(I) = RP(I)
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.8 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) THEN
     		    P = ABS(RP(I))
     		    IF( P.GT.ABS(YLNS) ) GOTO 222
     		    YOFF(I) = RP(I)
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.9 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) BARS(I) = RP(I)
     	    ENDDO
     	ELSE IF( IKEY.EQ.10 ) THEN
     	    IKEY = RP(1)
     	    I    = 1
     	    IF( IKEY.LT.1 .OR. IKEY.GT.NSET ) GOTO 222
     	    JSET = IKEY
     	    IKEY = 0
     	    GOTO 555
     	ENDIF
     	GOTO 333
C
C  PARAMETER VALUE OUT OF RANGE...
C
222	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
     	IF( I.EQ.KSET ) RETURN
C
C  DISPLAY NEW DATA SET LINE...
C
333	DO J= KSET, I-1
     	   IF( KP(J).NE.0 ) GOTO 444
     	ENDDO
     	GOTO 555
444	IF( J.NE.JSET ) THEN
     	    JSET = J
     	    IKEY = 0
     	ENDIF
555	CALL BARPLT_PARS_SET(JSET,IKEY)
     	RETURN
777	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
     	RETURN
	END

	SUBROUTINE BARPLT_AXIS_A
C
C	THIS ROUTINE CHANGES AXIS DRAWING PARAMETERS -- GROUP A
C
    	INCLUDE		'BARPLT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/BARPLT_MENU/ JSET, IKEY, NCHS, TEXT
     	DIMENSION	KP(5), RP(5)
C
C  DECODE THE PARAMETERS...
C
    	J = IFMISC_DECODE( TEXT, NCHS, 5, RP, KP )
    	IF( J.EQ.0 ) GOTO 777
C
C  STORE THE NEW PARAMETERS...
C
     	IF( KP(1).EQ.1 ) THEN
     	    J = RP(1)
     	    IF( J.LT.1 .OR. J.GT.2 ) GOTO 777
     	    LAXS = J
     	ENDIF

     	IF( KP(2).EQ.1 ) THEN
     	    J = RP(2)
     	    IF( J.EQ.0 .OR. IABS(J).GT.99 ) GOTO 777
     	    NTKS = J
     	ENDIF

     	IF( KP(3).EQ.1 ) THEN
     	    J = RP(3)
     	    IF( IABS(J).GT.99 ) GOTO 777
     	    MTKS = J
     	ENDIF

     	IF( KP(4).EQ.1 ) THEN
     	    J = RP(4)
     	    IF( IABS(J).GT.9 ) GOTO 777
     	    NDGS = J
     	ENDIF

     	IF( KP(5).EQ.1 ) THEN
     	    J = RP(5)
     	    IF( J.EQ.0 .OR. IABS(J).GT.44 ) GOTO 777
     	    IGDS = J
     	ENDIF

     	CALL BARPLT_PARS_AXIS(1)

     	IF( KP(1).EQ.1 ) THEN		!AUTO-SCALE ON
     	    J = BARPLT_SCALE( MNST, MNPT, %VAL(IYAR) )
     	    IF( J.EQ.0 ) CALL IFMISC_OOPS( 10, SLIN, SCOL, ' ' )
     	    CALL BARPLT_PARS_AXIS(3)
     	    GOTO 999
     	ENDIF

     	IF( KP(2).EQ.1 .AND. LAXS.EQ.1 ) THEN
     	    YINC = (YHIG-YLOW) / IABS(NTKS)
     	    CALL BARPLT_PARS_AXIS(3)
     	ENDIF
     	GOTO 999
777	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
999	RETURN
     	END

	SUBROUTINE BARPLT_AXIS_B
C
C	THIS ROUTINE CHANGES AXIS DRAWING PARAMETERS -- GROUP B
C
    	INCLUDE		'BARPLT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/BARPLT_MENU/ JSET, IKEY, NCHS, TEXT
     	DIMENSION	KP(3), RP(3)
C
C  DECODE THE PARAMETERS...
C
    	J = IFMISC_DECODE( TEXT, NCHS, 3, RP, KP )
    	IF( J.EQ.0 ) GOTO 777
C
C  STORE THE NEW PARAMETERS...
C
     	IF( KP(1).EQ.1 ) THEN
     	    P = RP(1)
     	    IF( ABS(P).LT.2.0 .OR. ABS(P).GT.99.0 ) GOTO 777
     	    XLNS = P
     	ENDIF

     	IF( KP(2).EQ.1 ) THEN
     	    P = RP(2)
     	    IF( ABS(P).LT.2.0 .OR. ABS(P).GT.99.0 ) GOTO 777
     	    YLNS = P
     	ENDIF

     	IF( KP(3).EQ.1 ) THEN
     	    P = RP(3)
     	    IF( P.LT.0.0 .OR. P.GT.ABS(YLNS)/3.0 ) GOTO 777
     	    OFFS = P
     	ENDIF
     	CALL BARPLT_PARS_AXIS(2)
     	GOTO 999
777	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
999	RETURN
     	END

	SUBROUTINE BARPLT_AXIS_C
C
C	THIS ROUTINE CHANGES AXIS DRAWING PARAMETERS -- GROUP C
C
    	INCLUDE		'BARPLT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/BARPLT_MENU/ JSET, IKEY, NCHS, TEXT
     	DIMENSION	KP(3), RP(3)
C
C  DECODE THE PARAMETERS...
C
    	J = IFMISC_DECODE( TEXT, NCHS, 3, RP, KP )
    	IF( J.EQ.0 ) GOTO 777
C
C  STORE THE NEW PARAMETERS...
C
     	IF( LAXS.EQ.1 ) THEN	!LINEAR TYPE OF AXIS
     	    IF( KP(1).EQ.0 ) RP(1) = YLOW
     	    IF( KP(2).EQ.0 ) RP(2) = YHIG
     	    IF( RP(1).EQ.RP(2) ) GOTO 777
     	    IF( KP(3).EQ.0 ) THEN
     		RP(3) = (RP(2)-RP(1))/IABS(NTKS)
     	    ELSE
     		IF( RP(3).EQ.0.0   ) GOTO 777
     		J = ABS((RP(2)-RP(1))/RP(3)) + 0.1
     		IF( J.LT.1 .OR. J.GT.99 ) GOTO 777
     		NTKS = J
     		RP(3) = (RP(2)-RP(1))/J
     		CALL BARPLT_PARS_AXIS(1)
     	    ENDIF
     	ELSE			!LOG10 TYPE OF AXIS
     	    IF( KP(1).EQ.0 ) RP(1) = YLOW
     	    IF( KP(2).EQ.0 ) RP(2) = YHIG
     	    IF( RP(1).LE.0.0 .OR. RP(2).LE.0.0 ) GOTO 777
     	    RP(1) = 10.0**INT(LOG10(RP(1)))
     	    RP(2) = 10.0**INT(LOG10(RP(2)))
     	    IF( RP(1).EQ.RP(2) ) GOTO 777
     	    RP(3) = LOG10(RP(2)/RP(1))
     	ENDIF
     	YLOW = RP(1)
     	YHIG = RP(2)
     	YINC = RP(3)
     	CALL BARPLT_PARS_AXIS(3)
     	GOTO 999
777	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
999	RETURN
	END

	SUBROUTINE BARPLT_LIST( JSET )
C
C	LIST OF ALL DATA SET PARAMETERS.
C
	INCLUDE 'BARPLT.CBS'

     	IF( MENU ) THEN
     	    CALL IFANSI_CURSOR(12,1)
     	    CALL IFANSI_CLEAR(2)
     	ELSE
     	    CALL IFINIT_LINE(24)
     	    CALL IFANSI_VIDEO(30)
     	    CALL IFANSI_TEXT( ' A LIST OF ALL DATA SET PARAMETERS ',
     +      35, 1, 22 )
     	    CALL IFANSI_VIDEO(47)
     	    CALL IFANSI_VIDEO(80)
     	    CALL IFANSI_VIDEO(90)
     	    WRITE(6,1)
 1	    FORMAT('  NO: PN  PT  LI  BL  SQ             WD    XO'
     +,'    YO                       YS     ')
     	ENDIF
     	CALL IFANSI_VIDEO(47)
	WRITE(6,1234) (I,IPEN(I),IPAT(I),ILIN(I),IBOL(I),ISEQ(I),
     +  BARW(I),XOFF(I),YOFF(I),BARS(I), I=1, NSET)
1234	FORMAT(6I4,10X,3F6.2,18X,G11.4)
     	CALL IFANSI_VIDEO(30)
	WRITE(6,1000)
1000	FORMAT(/' Press SPACEBAR to continue...',$)
     	CALL IFQIOW_KEY(I)
     	IF( MENU ) THEN
     	    CALL BARPLT_FORM(JSET)
     	ELSE
     	    CALL IFINIT_LINE(3)
     	ENDIF
	RETURN
	END

     	SUBROUTINE BARPLT_SAVE
C
C	THIS ROUTINE SAVES CURRENT PLOT SETUP IN A PARAMETER FILE.
C
     	INCLUDE		'BARPLT.CBS'
    	CHARACTER	TEXT*80, STRN*75
     	COMMON/BARPLT_MENU/  JSET, IKEY, NCHS, TEXT

     	NCHS = IFMISC_NEXT(TEXT)
     	IF( NCHS.EQ.0 ) THEN
     	    NCHS = IFMISC_PROMPT('_Filename:',TEXT,SLIN+1,9)
     	    IF( NCHS.EQ.0 ) GOTO 999
     	ENDIF
     	IF( NCHS.GT.32 ) THEN
     	    CALL IFMISC_OOPS( 7, SLIN, SCOL, TEXT )
     	    GOTO 999
     	ENDIF
     	IKEY = BARPLT_SETUP( 0, TEXT )
     	IF( IKEY.EQ.0 ) THEN
     	    CALL IFMISC_OOPS( 21, SLIN, SCOL, TEXT )
     	ELSE
     	    STRN = ' Current plot setup has been saved in'
     	    STRN(39:) = TEXT
     	    CALL BARPLT_OOPS( STRN )
     	ENDIF

999	RETURN
     	END

     	SUBROUTINE BARPLT_OOPS( TEXT )
     	INCLUDE 'BARPLT.CBS'
     	CHARACTER TEXT*(*)
     	NCHS = IFMISC_LENG(TEXT)
     	IF( SLIN.GT.0 .AND. SCOL.GT.0 ) THEN
     	    CALL BARPLT_CLEAR_OOPS
     	    CALL IFANSI_TEXT( TEXT, NCHS, SLIN, SCOL )
     	ELSE
     	    WRITE(6,1000) TEXT(1:NCHS)
1000	    FORMAT('_oops: ',A)
     	ENDIF
     	RETURN
     	END

     	SUBROUTINE BARPLT_CLEAR_OOPS
     	INCLUDE 'BARPLT.CBS'
     	IF( MENU ) THEN
     	    CALL IFANSI_CURSOR(SLIN,SCOL)
     	    CALL IFANSI_CLEAR(4)
     	ENDIF
     	RETURN
     	END

    	FUNCTION BARPLT_SCALE( MP, MS, Y )
C
C  PROGRAMMER: R.S. ZHOU,  ALFRED UNIVERSITY
C
C  	THIS ROUTINE SCALES INPUT DATA FOR HISTOGRAM PLOT.
C
C	RETURN WITH BARPLT_SCALE = 0.0 FOR SCALING FAILURE
C	RETURN WITH BARPLT_SCALE = 1.0 FOR OK SCALING.
C
    	INCLUDE 'BARPLT.CBS'
     	DIMENSION Y(MP,MS)
C
C  SEARCH FOR MINIMUM AND MAXIMUM Y VALUES IN THE DATA...
C
     	Y1 = 1.7E38
     	Y2 =-1.7E38
     	IF( SIDE.EQ.1 ) THEN
     	    DO  I = 1, NSET
     		SBAR = BARS(I)
     		IF( IPEN(I).NE.0 ) THEN
     		    DO  J = 1, NBAR
     			Y3 = SBAR*Y(J,I)
     			IF( Y3.LT.Y1 ) Y1 = Y3
     			IF( Y3.GT.Y2 ) Y2 = Y3
     		    ENDDO
     		ENDIF
     	    ENDDO
     	ELSE
     	    Y3 = Y1
     	    DO  J = 1, NBAR
     		Y4 = 0.0
     		Y5 = 0.0
     		DO  I = 1, NSET
     		    IF( IPEN(I).NE.0 ) THEN
     			SBAR = BARS(I)*Y(J,I)
     			IF( SBAR.GT.0.0 ) THEN
     			    Y4 = Y4 + SBAR
     			ELSE
     			    Y5 = Y5 + SBAR
     			ENDIF
     		    ENDIF
     		ENDDO
     		IF( Y4.LT.Y1 ) Y1 = Y4
     		IF( Y4.GT.Y2 ) Y2 = Y4
     		IF( Y5.LT.Y3 ) Y3 = Y5
     	    ENDDO
     	    IF( LAXS.EQ.1 ) Y1 = Y3
     	ENDIF
C
C  SCALE THE AXIS...
C
     	IF( LAXS.EQ.1 ) THEN
     	    IF( Y1.GT.0.0 ) Y1 = 0.0
     	    IF( Y2.LT.0.0 ) Y2 = 0.0
     	    I = IFAXIS_LINSCL( ABS(YLNS), Y1, Y2 )
     	    IF( Y1.GT.0.0 ) Y1 = 0.0
     	    IF( Y2.LT.0.0 ) Y2 = 0.0
     	    NTKS = I
     	    YLOW = Y1
     	    YHIG = Y2
     	    YINC = (Y2-Y1)/I
     	ELSE
     	    IF( Y1.LE.0.0 .OR. Y2.LE.0.0 ) GOTO 999
     	    I = IFAXIS_LOGSCL( Y1, Y2 )
     	    YLOW = Y1
     	    YHIG = Y2
     	    YINC = I
     	ENDIF
     	BARPLT_SCALE = 1.0
     	RETURN
C
C  SCALING FAILURE...
C
999	YLOW = 0.0
     	YHIG = 0.0
     	YINC = 0.0
     	BARPLT_SCALE = 0.0
     	RETURN
     	END

    	FUNCTION BARPLT_SETUP( IFLAG, FNAME )
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY
C
C	THIS ROUTINE WRITES/READS A PARAMETER/SETUP FILE FOR HISTOGRAM PLOT.
C
C	IFLAG --- 1 : READ IN THE PARAMETERS FROM "FNAME"
C	      --- 0 : WRITE THE PARAMETERS TO "FNAME"
C
C		RETURN WITH "0" FOR ERROR STATUS, "1" FOR OK.
C
C	FNAME --- PARAMETER/SETUP FILENAME	
C
    	INCLUDE		'BARPLT.CBS'
    	PARAMETER	NKS= 10, LUN= 13
    	CHARACTER	KWD(NKS)*4, KEY*4, REST*127, FNAME*(*)
    	DIMENSION	KP(20), RP(20), IRR(NKS)
C
C  PARAMETER GROUP KEYWORDS...
C
     	DATA KWD/ 'TITL', 'XLB1', 'YLB1', 'OVER',
     + 'YAX1', 'SETS', 'LABL', 'PAR1', 'PAR2', 'IDEN' /
C
C  NUMBER OF NUMERIC PARAMETERS IN EACH SETUP GROUP...
C
     	DATA IRR/ 0, 0, 0, 12, 11, 9, 0, 10, 10, 0 /
C
C  SET DEFAULT FILE EXTENTION TO .PAR ...
C
     	IF( FNAME.EQ.' ' ) RETURN
     	CALL IFMISC_DEFEXT( FNAME, '.PAR' )
    	IF( IFLAG.EQ.1 ) GOTO 5
C
C  WRITE THE SETUP FILE...
C
    	OPEN( UNIT=LUN, FILE=FNAME, STATUS='UNKNOWN',
     +        CARRIAGECONTROL='LIST', ERR=888 )

    	WRITE(LUN,1000,ERR=888) (TITL(I),I=1,3)
     +, IAXS, DRAW, SIDE, PBAR, SPAC, BARD
     +, XLPS, YLPS, XORG, YORG, XSCL, YSCL
     +, LAXS,NTKS,MTKS,NDGS,IGDS,XLNS,YLNS,OFFS,YLOW,YHIG,YINC
     +,(HPAR(I), I=1, 20), PLOTID

1000	FORMAT('%This is a GRAFIT parameter/setup file:'/
     +,'TITL=',A80,/,'XLB1=',A80,/,'YLB1=',A80,/,'OVER=',4I4,8F8.3,/
     +,'YAX1=',5I4,3F8.3,3G13.5,/,'PAR1=',10F7.2,/,'PAR2=',10F7.2,/
     +,'IDEN=',A32)

     	WRITE(LUN,1001,ERR=888) (IPEN(I),IPAT(I),ILIN(I),IBOL(I),
     +  ISEQ(I),BARW(I),XOFF(I),YOFF(I),BARS(I),LABL(I), I=1,NSET)

1001	FORMAT('SETS=',5I4,3F8.3,G13.5,/,'LABL=',A80)
    	GOTO 999
C
C  READ A SETUP FILE...
C
  5	OPEN( UNIT=LUN, FILE=FNAME, STATUS='OLD',
     +        CARRIAGECONTROL='LIST', READONLY, ERR=888 )
     	KSET = 0
C
C  READ KEYWORD LINES ONE BY ONE...
C
 111	READ(LUN,112,END=777) KEY,REST
 112	FORMAT(A4,X,A127)
     	IF( KEY.EQ.' ' .OR. REST.EQ.' ' ) GOTO 111
C
C  LOOK UP THE KEYWORD...
C
     	CALL IFMISC_UPPER(4,KEY)
     	DO I=1, NKS
     	   IF( KEY.EQ.KWD(I) ) GOTO 222
     	ENDDO
     	GOTO 111
C
C  YES, WE HAVE A VALID KEYOWRD...
C
 222	NCH = IFMISC_STRIP(REST)
     	IF( NCH.GT.0 .AND. IRR(I).GT.0 ) THEN
     	    NCH = IFMISC_DECODE( REST, NCH, IRR(I), RP, KP )
    	    IF( NCH.EQ.0 ) GOTO 111	!ERROR IN THE INPUT
     	ENDIF
C
C  SAVE THE PARAMETERS...
C
     	IF( I.LT.4 ) THEN	!GRAPH TITLE AND AXIS LABELS
     	    TITL(I) = REST
     	ELSE IF( I.EQ.4 ) THEN	!OVERALL GRAPH PARAMETERS
     	    IF( KP( 1).EQ.1 ) IAXS = RP( 1)
     	    IF( KP( 2).EQ.1 ) DRAW = RP( 2)
     	    IF( KP( 3).EQ.1 ) SIDE = RP( 3)
     	    IF( KP( 4).EQ.1 ) PBAR = RP( 4)
     	    IF( KP( 5).EQ.1 ) SPAC = RP( 5)
     	    IF( KP( 6).EQ.1 ) BARD = RP( 6)
     	    IF( KP( 7).EQ.1 ) XLPS = RP( 7)
     	    IF( KP( 8).EQ.1 ) YLPS = RP( 8)
     	    IF( KP( 9).EQ.1 ) XORG = RP( 9)
     	    IF( KP(10).EQ.1 ) YORG = RP(10)
     	    IF( KP(11).EQ.1 ) XSCL = RP(11)
     	    IF( KP(12).EQ.1 ) YSCL = RP(12)
     	ELSE IF( I.EQ.5 ) THEN		!AXIS DRAWING PARAMETERS
     	    IF( KP( 1).EQ.1 ) LAXS = RP( 1)
     	    IF( KP( 2).EQ.1 ) NTKS = RP( 2)
     	    IF( KP( 3).EQ.1 ) MTKS = RP( 3)
     	    IF( KP( 4).EQ.1 ) NDGS = RP( 4)
     	    IF( KP( 5).EQ.1 ) IGDS = RP( 5)
     	    IF( KP( 6).EQ.1 ) XLNS = RP( 6)
     	    IF( KP( 7).EQ.1 ) YLNS = RP( 7)
     	    IF( KP( 8).EQ.1 ) OFFS = RP( 8)
     	    IF( KP( 9).EQ.1 ) YLOW = RP( 9)
     	    IF( KP(10).EQ.1 ) YHIG = RP(10)
     	    IF( KP(11).EQ.1 ) YINC = RP(11)
     	ELSE IF( I.EQ.6 ) THEN	!DATA SET DRAWING PARAMETERS
     	    IF( KSET.EQ.MNST ) GOTO 111
     	    KSET = KSET + 1
     	    IF( KP( 1).EQ.1 ) IPEN(KSET) = RP( 1)
     	    IF( KP( 2).EQ.1 ) IPAT(KSET) = RP( 2)
     	    IF( KP( 3).EQ.1 ) ILIN(KSET) = RP( 3)
     	    IF( KP( 4).EQ.1 ) IBOL(KSET) = RP( 4)
     	    IF( KP( 5).EQ.1 ) ISEQ(KSET) = RP( 5)
     	    IF( KP( 6).EQ.1 ) BARW(KSET) = RP( 6)
     	    IF( KP( 7).EQ.1 ) XOFF(KSET) = RP( 7)
     	    IF( KP( 8).EQ.1 ) YOFF(KSET) = RP( 8)
     	    IF( KP( 9).EQ.1 ) BARS(KSET) = RP( 9)
     	ELSE IF( I.EQ.7 ) THEN	!DATA SET ID LABEL
     	    LABL(KSET) = REST
     	ELSE IF( I.EQ.8 ) THEN	!HARDCOPY SETUP PARAMETERS
     	    DO  I=1, 10
     		IF( KP(I).EQ.1 ) HPAR(I) = RP(I)
     	    ENDDO
     	ELSE IF( I.EQ.9 ) THEN	!HARDCOPY SETUP PARAMETERS
     	    DO  I=1, 10
     		IF( KP(I).EQ.1 ) HPAR(I+10) = RP(I)
     	    ENDDO
     	ELSE IF( I.EQ.10 ) THEN	!PLOT ID LABEL
     	    PLOTID = REST
     	ENDIF
     	GOTO 111
C
C  CHECK AXIS SCALE UNITS...
C
777	IF(YINC.EQ.0.0.OR.YLOW.EQ.YHIG) CALL BARPLT_SCALE( MNST,
     +  MNPT, %VAL(IYAR) )
     	GOTO 999
888	BARPLT_SETUP = 0.0
     	RETURN
999    	CLOSE(UNIT=LUN)
     	BARPLT_SETUP = 1.0
    	RETURN
    	END

     	SUBROUTINE BARPLT_VM
C
C	THIS ROUTINE ALLOCATES VIRTUAL MEMORY FOR DATA STORAGE.
C
     	INCLUDE 'BARPLT.CBS'
     	CHARACTER TEXT*80
     	COMMON/BARPLT_MENU/ JSET, IKEY, NCHS, TEXT
     	DIMENSION RP(2), KP(2)

     	NCHS = IFMISC_NEXT(TEXT)
     	IF( NCHS.EQ.0 ) THEN
     	NCHS=IFMISC_PROMPT('_Sets & bars/set (2I):',TEXT,SLIN+1,9)
     	IF( NCHS.EQ.0 ) RETURN
     	ENDIF
     	NCHS = IFMISC_DECODE( TEXT, NCHS, 2, RP, KP )
     	IF( NCHS.EQ.0 ) THEN
     	    CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
     	ELSE
     	    IF( KP(1).NE.0 ) THEN
     		KP(1) = RP(1)
     		IF( KP(1).LT.1 .OR. KP(1).GT.MNS ) GOTO 888
     	    ELSE
     		KP(1) = MNST
     	    ENDIF
     	    IF( KP(2).NE.0 ) THEN
     		KP(2) = RP(2)
     		IF( KP(2).LT.2 .OR. KP(2).GT.9999 ) GOTO 888
     	    ELSE
     		KP(2) = MNPT
     	    ENDIF
     	    CALL LIB$FREE_VM(IXAR(1),IXAR(2))
     	    CALL LIB$FREE_VM(4*MNST*MNPT,IYAR)
     	    MNST = KP(1)
     	    MNPT = KP(2)
     	    IXAR(1) = 8*MNPT
     	    IKEY = LIB$GET_VM( IXAR(1), IXAR(2) )
     	    IF( IKEY.EQ.0 ) GOTO 777
     	    IKEY = LIB$GET_VM( 4*MNST*MNPT, IYAR )
     	    IF( IKEY.EQ.0 ) GOTO 777
     	    JSET = 1
     	    NSET = 0
     	    NBAR = 0
     	    CALL BARPLT_INIT(1)
     	    CALL BARPLT_PARS_VM(MNST,MNPT)
     	    CALL BARPLT_PARS(JSET)
     	ENDIF
     	RETURN
777	CALL IFMISC_OOPS( 6, SLIN, SCOL, ' ' )
     	RETURN
888	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
     	RETURN
     	END

     	SUBROUTINE BARPLT_PLOT
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY
C
C	THIS ROUTINE CARRIES OUT THE PLOTTING FOR HISTOGRAM PLOT.
C
     	INCLUDE 'BARPLT.CBS'

     	NBYTES = 0
     	IF( YINC.EQ.0.0 ) THEN
     	    IF( IF_DCL_HARDCOPY() ) THEN
     		STOP '%BARPLT: data scaling failure.'
     	    ELSE
     		CALL IFMISC_OOPS( 10, 0, 0, ' ' )
     		RETURN
     	    ENDIF
     	ENDIF
C
C  INITIALIZE THE CRT...
C
     	CALL IFANSI_VIDEO(47)
     	CALL IFINIT_LINE( 3 )
     	IF( INIT ) THEN
     	    CALL IFINIT_PLOT( XORG, YORG, DATNAM )
     	ELSE
     	    CALL IFINIT_PLOT( XORG, YORG, '$OVERLAY' )
     	ENDIF
     	IF( IFCTRL_C() ) GOTO 999
C
C  OPEN A GRAPHICS SEGMENT TO SAVE THE PLOT...
C
     	IF( .NOT.IFINIT_SAVE() ) RETURN
     	CALL IFSCAL( XSCL, YSCL )
     	CALL IFANSI_ANSI( ANSI )
C
C  DRAW GRAPH TITLE IF ANY...
C
     	IF( TITL(1).NE.' ' ) THEN
     	    CALL IFSPEN(1)
     	    CALL IFTEXT_CENT(0.,ABS(XLNS),-1.,-1.,TITL(1),.15,.15)
     	ENDIF
C
C  DRAW THE Y-AXIS ...
C
     	IF( YLNS.GT.0.0 ) THEN
     	    CALL IFSPEN( IAXS )
     	    CALL IFAXIS( LAXS+3, ABS(XLNS), YLNS, TITL(3),
     +      YLOW, YINC, OFFS, NTKS, MTKS, NDGS, IGDS )
     	ENDIF
C
C  PUT ON THE BARS ...
C
     	IF( IFCTRL_C() ) GOTO 999
C
C  ALLOCATE SCRATCH ARRAYS...
C
     	NBYTES = 4*MNPT
     	JUNK = LIB$GET_VM( NBYTES, JXX )
     	IF( .NOT.JUNK ) GOTO 888
     	JUNK = LIB$GET_VM( NBYTES, JY1 )
     	IF( .NOT.JUNK ) GOTO 888
     	JUNK = LIB$GET_VM( NBYTES, JY2 )
     	IF( .NOT.JUNK ) GOTO 888
     	JUNK = LIB$GET_VM( NBYTES, JY3 )
     	IF( .NOT.JUNK ) GOTO 888
    	CALL BARPLT_DRAW( MNST, MNPT, IXAR, %VAL(IYAR),
     +       %VAL(JXX), %VAL(JY1), %VAL(JY2), %VAL(JY3) )
C
C  DRAW THE X-AXIS ...
C
     	IF( IFCTRL_C() ) GOTO 999
     	CALL BARPLT_XAXIS
C
C  CLOSE THE PLOT SESSION...
C
  555	CALL IFSTYL( 1, 1 )			!RESET PLOTTING STYLUS
     	IF( CRT.EQ.2 ) CALL IFSEG_OPEN( 0 ) 	!CLOSE THE SEGMENT
C
C  OVERLAY THE LAYOUT IF LAYOUT FILE EXISTS...
C
     	IF( IFCTRL_C() ) GOTO 999
    	IF( DESNAM.NE.' ' ) CALL LAYOUT_AUX(0,XORG,YORG,DESNAM)
  999	CALL IFINIT_PLOT_END
     	IF( NBYTES.GT.0 ) THEN
     	    CALL LIB$FREE_VM( NBYTES, JXX )
     	    CALL LIB$FREE_VM( NBYTES, JY1 )
     	    CALL LIB$FREE_VM( NBYTES, JY2 )
     	    CALL LIB$FREE_VM( NBYTES, JY3 )
     	ENDIF
     	RETURN
  888	IF( IF_DCL_HARDCOPY() ) THEN
     	    STOP 'BARPLT: Insufficient virtual memory to be allocated'
     	ELSE
     	    CALL IFMISC_OOPS( 6, 0, 0, ' ' )
     	ENDIF
     	RETURN
    	END

     	SUBROUTINE BARPLT_XAXIS
C
C	THIS ROUTINE DRAWS THE X-AXIS FOR HISTOGRAM PLOT,
C	WHICH IS POSITIONED AT Y=0.0 IF Y-AXIS SCALE ALLOWS.
C
     	INCLUDE 'BARPLT.CBS'
C
C  DRAW THE STRAIGHT LINE...
C
     	CALL IFSPEN( IAXS )
     	IF( LAXS.EQ.1 .AND. YLOW*YHIG.LT.0.0 ) THEN
     	    YPS = (YHIG-YLOW) / (ABS(YLNS)-2.0*OFFS)
     	    YPS = ABS(YLOW/YPS) + OFFS
     	    CALL IFPLOT(       0.0, YPS, 3 )
     	    CALL IFPLOT( ABS(XLNS), YPS, 2 )
     	    CALL IFPLOT(       0.0, YPS, 2 )
     	    IF( ANSI ) CALL IFAXIS_ANSI( 0.0, YPS, ABS(XLNS), YPS )
     	ENDIF
     	IF( XLNS.GT.0.0 ) THEN
     	    YPS = 0.0
     	    IF( ABS(YHIG).LT.ABS(YLOW) ) YPS = ABS(YLNS)
     	    CALL IFPLOT(  0.0, YPS, 3 )
     	    CALL IFPLOT( XLNS, YPS, 2 )
     	    CALL IFPLOT(  0.0, YPS, 2 )
     	    IF( ANSI ) CALL IFAXIS_ANSI( 0.0, YPS, XLNS, YPS )
     	    IF( YPS.EQ.0.0 ) THEN
     		YPS = -0.55
     	    ELSE
     		IF( PBAR.EQ.1 ) THEN
     		    YPS = YPS + 0.45
     		ELSE
     		    YPS = YPS + 0.25
     		ENDIF
     	    ENDIF
     	    IF( TITL(2).NE.' ' ) CALL IFTEXT_CENT(0.,XLNS,YPS,YPS,
     +      TITL(2),.12,.12)
     	ENDIF

     	RETURN
     	END

    	SUBROUTINE BARPLT_DRAW( MS, MP, X, Y, XPS, YPS, YSP, YMX )
C
C	THIS ROUTINE DRAWS THE BARS...
C
     	INCLUDE 'BARPLT.CBS'
     	CHARACTER X(MP)*8
     	DIMENSION Y(MP,MS), XPS(MP), YPS(MP), YSP(MP), YMX(MP)
     	COMMON/BARPLT_DRAW_ID/ XXX,YYY, LMX
C
C  GET Y-AXIS SCALE WINDOW...
C
     	YDL = BARPLT_LIMIT( YLO, YHI )
     	IF( LAXS.EQ.2 ) THEN
     	    YLOL = 10.0**YLO
     	    YHIL = 10.0**YHI
     	ENDIF
     	YRL = 0.0			!BAR REFERENCE LINE
     	IF( YLO*YHI.GT.0.0 ) THEN
     	    YRL = YLO
     	    IF( ABS(YHI).LT.ABS(YLO) ) YRL = YHI
     	ENDIF
C
C  OFFSET FROM ORIGIN IF SPECIFIED...
C
     	IF( BARD.GT.0.0 ) CALL IFPLOT( BARD, 0.0, -9 )
C
C  INITIALIZE CUMMULATIVE BAR POSITION RECORDS...
C
     	WBAR = BARW(1) + SPAC
     	IF( SIDE.EQ.1 ) THEN
     	    DO  I=2, NSET
     		WBAR = WBAR + BARW(I)
     	    ENDDO
     	ENDIF
     	BASE = (YRL-YLO)/YDL
     	IF( YDL.LT.0.0 ) BASE = ABS(YLNS)+BASE
     	DO  I=1, NBAR
     	    XPS(I) = (I-1)*WBAR
     	    YPS(I) = BASE
     	    YSP(I) = BASE
     	    YMX(I) = BASE
     	ENDDO
C
C  START THE DATA SET LOOP...
C
     	XXX = XLPS + 0.40 - BARD
     	YYY = YLPS + 0.15
     	LMX = 0
     	DO 888  IB=1, NSET
C
C  GET THE ACTUAL PLOT SEQUENCE OF THE DATA SET...
C
     	DO  IK=1, NSET
     	    IF( ISEQ(IK).EQ.IB ) GOTO 111
     	ENDDO
     	GOTO 888
 111	IF( IPEN(IK).EQ.0 ) GOTO 888
C
C  DRAW THIS SET OF BARS...
C
     	CALL IFSPEN( IPEN(IK) )
     	CALL IFSTYL( ILIN(IK), IBOL(IK) )
     	JPAT = IPAT(IK)
     	WBAR = BARW(IK)
     	OFFX = XOFF(IK)
     	OFFY = YOFF(IK)
     	SBAR = BARS(IK)
     	DO  IC=1, NBAR
     	IF( IFCTRL_C() ) RETURN
     	    BARH = Y(IC,IK)*SBAR
     	    IF( BARH.EQ.0.0 ) GOTO 777
     	    IF( LAXS.EQ.2 ) THEN
     		IF( BARH.LT.YLOL ) BARH = YLOL
     		IF( BARH.GT.YHIL ) BARH = YHIL
     		BARH = LOG10(BARH)
     	    ENDIF
     	    IF( BARH.LT.YLO ) BARH = YLO
     	    IF( BARH.GT.YHI ) BARH = YHI
     	    BARH = (BARH-YRL)/YDL
     	    HBAR = ABS(BARH)
     	    IF( HBAR.LT.0.02 ) GOTO 777
     		XPOS = OFFX + XPS(IC) + 0.5*WBAR
     	    IF( SIDE.EQ.1 ) THEN
     		YPOS = OFFY + YPS(IC) + 0.5*BARH
     	    ELSE
     		IF( BARH.GT.0.0 ) THEN
     		    YPOS = OFFY + YPS(IC) + 0.5*BARH
     		ELSE
     		    YPOS = OFFY + YSP(IC) + 0.5*BARH
     		ENDIF
     	    ENDIF
     	    IF( JPAT.NE.0 ) CALL IFFILL( JPAT )
     	    CALL IFBARS( XPOS, YPOS, WBAR, HBAR, 0.0, 0.0 )
     	    IF( JPAT.NE.0 ) CALL IFFILL( 0 )
     	    IF( ANSI ) CALL BARPLT_DRAW_ANSI( XPOS,YPOS,HBAR,JPAT )
  777	    IF( SIDE.EQ.1 ) THEN
     		XPS(IC) = XPS(IC)+WBAR
     		IF( PBAR.EQ.2 ) THEN
     		    HBAR = YPS(IC) + BARH
     		    IF(BARH.GT.0..AND.HBAR.GT.YMX(IC)) YMX(IC) = HBAR
     		    IF(BARH.LT.0..AND.HBAR.LT.YSP(IC)) YSP(IC) = HBAR
     		ENDIF
     	    ELSE
     		IF( BARH.GT.0.0 ) THEN
     		    YPS(IC) = YPS(IC) + BARH
     		ELSE
     		    YSP(IC) = YSP(IC) + BARH
     		ENDIF
     	    ENDIF
     	ENDDO
C
C  DRAW DATA SET LABEL...
C
     	IF( DRAW.GT.0 .AND. LABL(IK).NE.' ' ) CALL BARPLT_DRAW_ID(IK)
888	CONTINUE
C
C  DRAW GROUP BAR LABEL "X(I)"...
C
     	IF(PBAR.GT.0) CALL BARPLT_DRAW_LABEL( BASE,MNPT,
     +                IXAR,XPS,YPS,YSP,YMX)
     	IF(BARD.GT.0) CALL IFPLOT( -BARD, 0.0, -9 )
C
C  BOX THE DATA SET LABEL IF REQUIRED...
C
     	IF( DRAW.EQ.2 ) THEN
     	    WBAR = XLPS + LMX*0.1 + 0.9
     	    YYY  = YYY + 0.05
     	    CALL IFSPEN( IAXS )
     	    CALL IFPLOT( XLPS, YLPS, 3 )
     	    CALL IFPLOT( XLPS,  YYY, 2 )
     	    CALL IFPLOT( WBAR,  YYY, 2 )
     	    CALL IFPLOT( WBAR, YLPS, 2 )
     	    CALL IFPLOT( XLPS, YLPS, 2 )
     	ENDIF
     	
     	RETURN
     	END

     	SUBROUTINE BARPLT_DRAW_ID( IK )
C
C	THIS ROUTINE DRAWS DATA SET ID LABEL.
C
     	COMMON/BARPLT_DRAW_ID/ XXX,YYY, LMX
     	INCLUDE 'BARPLT.CBS'

     	JK  = IK
     	NCH = IFMISC_LENG( LABL(JK) )
     	IF( NCH.GT.LMX ) LMX = NCH
     	BARH = BARW(JK)
     	IF( BARH.GT.0.15 ) BARH = 0.15
     	JPAT = IPAT(JK)
     	IF( JPAT.NE.0 ) CALL IFFILL( JPAT )
     	CALL IFBARS( XXX, YYY+0.5*BARH, 0.5, BARH, 0.0, 0.0 )
     	IF( JPAT.NE.0 ) CALL IFFILL( 0 )
     	CALL IFTEXT_EXT(XXX+.4,YYY+.5*BARH-.05,LABL(JK),.1,.1,0.0)
     	YYY = YYY + 0.25

     	RETURN
     	END

     	SUBROUTINE BARPLT_DRAW_LABEL( BS, MP, X, XPS, YPS, YSP, YMX )
C
C	THIS ROUTINE DRAWS BAR GROUP LABEL "X(I)".
C
     	INCLUDE 'BARPLT.CBS'
     	CHARACTER X(MP)*8
     	DIMENSION XPS(MP), YPS(MP), YSP(MP), YMX(MP)

     	BASE = BS
     	IF( PBAR.EQ.2 ) THEN
     	    IF( SIDE.EQ.2 ) THEN
     		DO  I=1, NBAR
     		    IF( YSP(I).NE.BASE ) YMX(I) = YSP(I)
     		    IF( YPS(I).NE.BASE ) YMX(I) = YPS(I)
     		ENDDO
     	    ELSE
     		DO  I=1, NBAR
     		    IF( YMX(I).EQ.BASE ) YMX(I) = YSP(I)
     		ENDDO
     	    ENDIF
     	ENDIF
     	WBAR = BARW(1)
     	IF( SIDE.EQ.1 ) THEN
     	    DO  I=2, NSET
     		WBAR = WBAR + BARW(I)
     	    ENDDO
     	ENDIF
     	IF( PBAR.EQ.1 ) THEN
     	    IF( BASE.LT.ABS(YLNS)-0.1 ) THEN
     		BARH = -0.25
     	    ELSE
     		BARH = ABS(YLNS)+0.1
     	    ENDIF
     	ENDIF
     	CALL IFSPEN( IAXS )
     	DO  I=1, NBAR
     	    IF( X(I).NE.' ' ) THEN
     		IF( PBAR.EQ.2 ) THEN
     		    BARH = YMX(I)
     		    IF( BASE.LT.BARH ) THEN
     			BARH = BARH + 0.05
     		    ELSE
     			BARH = BARH - 0.15
     		    ENDIF
     		ENDIF
     		IF( SIDE.EQ.1 ) THEN
     		    XL = XPS(I) - WBAR - SPAC
     		    XR = XPS(I) + SPAC
     		ELSE
     		    XL = XPS(I) - SPAC
     		    XR = XPS(I) + WBAR + SPAC
     		ENDIF
     		CALL IFTEXT_CENT( XL, XR, BARH, BARH, X(I), 0.1, 0.1 )
     	    ENDIF
     	ENDDO
     	RETURN
     	END

    	FUNCTION BARPLT_LIMIT( YLO, YHI )
C
C	THIS ROUTINE CALCULATES SCALE WINDOW OF A HISTOGRAM PLOT
C	BECAUSE OF POSSIBLE OFFSETS OF THE 1ST MAJOR TICKMARKS.
C
C	YLO,YHI: WINDOW LIMIT ON Y-AXIS.
C	RETURN WITH AXIS SCALE INCREMENT PER INCH.
C
     	INCLUDE 'BARPLT.CBS'

     	IF( LAXS.EQ.1 ) THEN
     	    YDL = (YHIG-YLOW) / (ABS(YLNS)-2.0*OFFS)
     	    YLO = YLOW - YDL*OFFS
     	    YHI = YHIG + YDL*OFFS
     	ELSE
    	    YDL = LOG10(YHIG/YLOW) / (ABS(YLNS)-2.0*OFFS)
    	    YLO = LOG10(YLOW) - YDL*OFFS
    	    YHI = LOG10(YHIG) + YDL*OFFS
     	ENDIF
     	BARPLT_LIMIT = YDL
    	IF( YLO.GT.YHI ) THEN
    	    YDL = YLO
    	    YLO = YHI
    	    YHI = YDL
    	ENDIF

     	RETURN
    	END

     	SUBROUTINE BARPLT_DRAW_ANSI( XP, YP, BH, JP )
C
C	THIS ROUTINE DRAWS A BAR ON A VT100.
C
     	CHARACTER BAR*1

     	HB = 0.5*BH
     	IL3= IABS(JP)
     	IF( IL3.EQ.0 ) IL3 = 10		! *
     	IL3= IL3 + 32
     	IF( IL3.GT.125 ) IL3 = 125
     	BAR= CHAR(IL3)
     	CALL IFINIT_DIF(0)
     	CALL IFPLOT( XP, YP-HB, 3 )
     	CALL IFANSI_LAST( IL1, IC1 )
     	CALL IFPLOT( XP, YP+HB, 3 )
     	CALL IFANSI_LAST( IL2, IC1 )
     	CALL IFINIT_DIF(1)
     	IL3 = 1
     	IF( IL2.LT.IL1 ) IL3 = -1
     	DO I=IL1,IL2,IL3
     	   CALL IFANSI_TEXT( BAR, 1, I, IC1 )
     	ENDDO
     	RETURN
     	END

