     	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 = 30
     	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',
     + '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
     	CALL BARPLT_FORM( JSET )
     	IF( NSET.EQ.0 ) CALL BARPLT_OOPS(' Enter a data filename
     + to start a plot. Type HELP if you need any.')
C
C  START THE DIALOGUE LOOP...
C
111	CALL IFANSI_VIDEO(47)
     	CALL IFANSI_TEXT('BARPLT> ', 8, 18, 1 )
     	CALL IFANSI_CLEAR(4)
     	IKEY = IFQIOW( NCHS, TEXT )
     	IF( IKEY.EQ.26) GOTO 888
     	IF( NCHS.EQ.0 ) GOTO 999
     	NCHS = IFMISC_STRIP(TEXT)
     	CALL   IFMISC_UPPER(KEY)
     	IF( KEY.EQ.'QU' ) GOTO 888
     	IF( KEY.EQ.'EX' ) GOTO 999
     	CALL BARPLT_CLEAR_OOPS
C
C  COMMAND INPUT...
C
     	IF( SYM.NE.'='  ) THEN
     	    CALL BARPLT_COM
     	    IF( IKEY.EQ.-1 ) GOTO 999
     	    GOTO 111
     	ENDIF
C
C  PARAMETER INPUT...
C
     	DO IKEY = 1, NKS
     	   IF( KEY.EQ.KWD(IKEY) ) GOTO 222
     	ENDDO
     	CALL BARPLT_ERROR(1)	!INVALID KEYWORD
     	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.17 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-3
     	    CALL BARPLT_OVERALL
     	ELSE IF( IKEY.EQ.17 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-16
     	    CALL BARPLT_AXIS_A
     	ELSE IF( IKEY.EQ.18 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-17
     	    CALL BARPLT_AXIS_B
     	ELSE IF( IKEY.EQ.19 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-18
     	    CALL BARPLT_AXIS_C
     	ELSE IF( IKEY.LT.30 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-19
     	    CALL BARPLT_SET
     	ELSE
     	    LABL(JSET) = TEXT
     	    CALL BARPLT_PARS_SET(JSET,10)
     	ENDIF
     	GOTO 111
C
C  ERROR TRANSFER...
C
666	CALL IFANSI_VIDEO(70)
     	CALL BARPLT_OOPS(' Missing input parameters.')
     	GOTO 111
777	CALL BARPLT_ERROR(6)	!NO DATA YET TO WORK ON
     	GOTO 111
888	ICODE = 1		!QUIT FROM THE DIALOGUE
     	RETURN
999	IF( NSET.EQ.0 ) GOTO 888
     	CALL BARPLT_SETUP( 0, PARNAM )
     	ICODE = 0
     	RETURN
    	END

     	SUBROUTINE BARPLT_FORM( JSET )
C
C	THIS ROUTINE LAYOUTS THE DIALOGUE MENU FOR HISTOGRAM PLOT.
C
    	INCLUDE 'BARPLT.CBS'
C
C  LAYOUT THE MENU...
C
     	CALL IFINIT_LINE(24)
     	CALL IFANSI_TITLE('GRAFIT: Histogram Plot (limits:    data sets,
     +     bars/set)')
     	CALL IFANSI_VIDEO(60)
     	CALL IFANSI_IFL( MNS, 1, 2, 1, 33 )
     	CALL IFANSI_IFL( MNP, 1, 3, 1, 47 )

     	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='
     +, 44X,'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=',26X,'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)
     	WRITE(6,4002)
4002	FORMAT(X,80(' '))
     	CALL IFANSI_VIDEO(47)
     	WRITE(6,5000)
5000	FORMAT(' oops:'//' Auxiliary: HELP/PF2, DCL/PF4,',
     +' DOWN_SET/PF1, UP_SET/PF3, LIST, REFRESH,'/
     +' _commands: EXIT, QUIT, READ, PLOT, SAVE,',
     +' RESET, SETUP, LAYOUT, ...')
C
C  INSERT THE PARAMETERS...
C
     	CALL BARPLT_PARS(JSET)
     	RETURN
     	END

     	SUBROUTINE BARPLT_PARS(JSET)
C
C	THIS ROUTINE INSERTS ALL GRAPH PARAMETERS.
C
     	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

     	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)

     	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, 6.2, 5, 4 )
     	ENDIF
     	IF(I.EQ.0.OR.I.EQ.5) THEN
     	   RP(1) = XSCL
     	   RP(2) = YSCL
    	   CALL IFANSI_FFL( RP, 2, 6.3, 5, 24)
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.6) THEN
     	   PLOT = 'YES'
     	   IF( .NOT.INIT ) PLOT = 'NO'
     	   CALL IFANSI_TEXT( PLOT, 3, 5, 71)
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.7) CALL IFANSI_IFL( IAXS, 1, 2, 5, 79 )
    	IF(I.EQ.0.OR.I.EQ.8) THEN
     	   PLOT = 'SIDE'
     	   IF( SIDE.EQ.2 ) PLOT = 'STACK'
     	   CALL IFANSI_TEXT( PLOT, 8, 6, 4 )
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.9) 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.10) CALL IFANSI_FFL( SPAC, 1, 6.2, 6, 30 )
    	IF(I.EQ.0.OR.I.EQ.11) CALL IFANSI_FFL( BARD, 1, 6.2, 6, 41 )
     	IF(I.EQ.0.OR.I.EQ.12) CALL IFANSI_IFL( DRAW, 1, 2, 6, 62 )
    	IF(I.EQ.0.OR.I.EQ.13) THEN
     	   RP(1) = XLPS
     	   RP(2) = YLPS
     	   CALL IFANSI_FFL( RP, 2, 6.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)

     	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, 3, 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, 6.2, 9, 23 )
     	ENDIF
     	IF( I.EQ.0. OR. I.EQ.3 ) THEN
     	    RP(1) = YLOW
     	    RP(2) = YHIG
     	    RP(3) = YINC
     	    CALL IFANSI_GFL( RP, 3, 12.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'

     	JSET = ICODE
     	I = IPAR
     	IF( I.EQ.0 ) THEN
     	    CALL IFANSI_VIDEO(47)
    	    CALL IFANSI_IFL( JSET, 1, 3, 12, 1 )
     	ENDIF
     	CALL IFANSI_VIDEO(30)
    	IF(I.EQ.0.OR.I.EQ.1) CALL IFANSI_IFL(IPEN(JSET),1,3,12,5)
    	IF(I.EQ.0.OR.I.EQ.2) CALL IFANSI_IFL(IPAT(JSET),1,3,12,9)
    	IF(I.EQ.0.OR.I.EQ.3) CALL IFANSI_IFL(ILIN(JSET),1,3,12,13)
    	IF(I.EQ.0.OR.I.EQ.4) CALL IFANSI_IFL(IBOL(JSET),1,3,12,17)
    	IF(I.EQ.0.OR.I.EQ.5) CALL IFANSI_IFL(ISEQ(JSET),1,3,12,21)
    	IF(I.EQ.0.OR.I.EQ.6) CALL IFANSI_FFL(BARW(JSET),1,6.2,12,34)
    	IF(I.EQ.0.OR.I.EQ.7) CALL IFANSI_FFL(XOFF(JSET),1,5.2,12,41)
    	IF(I.EQ.0.OR.I.EQ.8) CALL IFANSI_FFL(YOFF(JSET),1,5.2,12,47)
    	IF(I.EQ.0.OR.I.EQ.9) CALL IFANSI_GFL(BARS(JSET),1,12.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, 3, 13, 34 )
     	   CALL IFANSI_GFL( SRNG(1,JSET), 1, 11.4, 13, 41 )
     	   CALL IFANSI_GFL( SRNG(2,JSET), 1, 11.4, 13, 56 )
     	ENDIF

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

     	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'
     	CALL IFANSI_VIDEO(24)
     	CALL IFANSI_VIDEO(80)
     	CALL IFANSI_IFL( NSET, 1, 2, 13, 79 )
     	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(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...
     	    CALL BARPLT_MENU_HELP
     	ELSE IF( TEXT(1:3).EQ.'REF' ) THEN
C
C  REFRESH...
     	    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( IKEY.NE.27 ) THEN
     		CALL BARPLT_ERROR(2)	!UNDEFINED COMMAND
     	    ELSE
     		CALL IFANSI_VIDEO(70)
     		CALL BARPLT_OOPS(' Undefined function key.')
     	    ENDIF
     	ENDIF
     	RETURN
888	CALL BARPLT_ERROR(6)	!NO DATA YET TO WORK ON
     	RETURN
     	END

     	SUBROUTINE BARPLT_RESET( JSET )
C
C	THIS ROUTINE RESETS THE PLOT.
C
     	CALL BARPLT_CLEAR_OOPS
     	CALL BARPLT_OOPS(' Resetting the plot...')
     	CALL BARPLT_INIT(1)
     	CALL BARPLT_SCALE()
     	CALL BARPLT_WIDTH(0)
     	CALL BARPLT_PARS(JSET)
     	CALL BARPLT_CLEAR_OOPS

     	RETURN
     	END

     	SUBROUTINE BARPLT_FILES
C
C	THIS ROUTINE GETS INPUT DATA/PARAMETER/LAYOUT FILES.
C
     	INCLUDE		'BARPLT.CBS'
     	CHARACTER	TEXT*80, TERR*75
     	COMMON/BARPLT_MENU/  JSET, IKEY, NCHS, TEXT

     	JKEY = IKEY
     	IKEY = IABS(IKEY)
     	IF( NCHS.EQ.0  ) THEN
     	    NCHS = BARPLT_NEXT(TEXT)
     	    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 BARPLT_ERROR(8)	!FILENAME TOO LONG TO HANDLE
     	    GOTO 999
     	ENDIF
     	CALL IFMISC_UPPER(TEXT)
     	IF( IKEY.NE.1 ) GOTO 222
C
C  START A NEW PLOT WITH A NEW DATA FILE...
C
     	IKEY = BARPLT_DATA( TEXT )
     	IF( IKEY.GT.0 ) THEN
     	    CALL IFANSI_VIDEO(70)
     	IF(IKEY.EQ.1) CALL BARPLT_OOPS(' Can not find/open the file.')
     	IF(IKEY.EQ.2) CALL BARPLT_OOPS(' No data found in the file.')
     	IF(IKEY.EQ.3) CALL BARPLT_OOPS(' Invalid data format in the
     + file.')
     	    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 = ' '
     	IKEY = IFMISC_DIGITS(NSET)+1
     	ENCODE( IKEY, 1000, TEXT ) NSET
1000	FORMAT(I<IKEY>)
     	TEXT(IKEY+2:) = 'set(s) of data have been read from'
     	TEXT(IKEY+37:) = 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()
     	IF( JKEY.GT.0 .AND. (IFL1.EQ.0.OR.IFL2.EQ.0) ) THEN
     	    CALL IFANSI_VIDEO(30)
     	    CALL BARPLT_PARS(JSET)
     	ELSE
     	    IKEY = JKEY
     	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 IFANSI_VIDEO(70)
     	    TERR = ' can not find setup file'
     	    TERR(26:) = TEXT
     	    CALL BARPLT_OOPS( TERR )
     	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 )
C
C	THIS ROUTINE READS A HISTOGRAM DATA FILE.
C
     	INCLUDE  'BARPLT.CBS'
     	CHARACTER TEXT*132, FNAME*(*)
     	DIMENSION RP(MNS), KP(MNS)
     	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), MNS, RP, KP )
     	IF( ICOM.EQ.0 ) GOTO 888
     	NDOT = NDOT + 1
     	X(NDOT) = TEXT(1:ISPC-2)
     	DO I=1, MNS
     	   Y(NDOT,I) = RP(I)
     	ENDDO
     	IF( NDOT.LT.MNP ) 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, MNS
     	    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 = 2
     	GOTO 999
888	IERR = 3
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.
     	    PLOTID = ' '
     	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
    	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.8 .AND. IKEY.NE.9 ) THEN
     	    NCHS = IFMISC_DECODE( TEXT, 2, RP, KP )
    	    IF( NCHS.EQ.0 ) THEN
     		CALL BARPLT_ERROR(3)
     		RETURN
     	    ENDIF
     	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
     	    GOTO 888
     	ENDIF

     	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
     	    GOTO 888
     	ENDIF

     	IF( IKEY.EQ.6 ) 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.
     	    GOTO 888
     	ENDIF

     	IF( IKEY.EQ.7 ) THEN		!AXIS COLOR
     	    IF(RP(1).LT.1.0.OR.RP(1).GT.8.0) GOTO 777
     	    IAXS = RP(1)
     	    GOTO 888
     	ENDIF

     	IF( IKEY.EQ.8 ) THEN
     	    IF( NCHS.LT.4 ) GOTO 777
     	    CALL IFMISC_UPPER(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()
     		CALL BARPLT_WIDTH(0)
     		CALL BARPLT_PARS(JSET)
     	    ENDIF
     	    GOTO 999
     	ENDIF

     	IF( IKEY.EQ.9 ) THEN
     	    IF( NCHS.LT.3 ) GOTO 777
     	    CALL IFMISC_UPPER(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
     	    GOTO 888
     	ENDIF

     	IF( IKEY.EQ.10 ) THEN
     	    SPAC = RP(1)
     	    CALL BARPLT_WIDTH(1)
     	    GOTO 888
     	ENDIF

     	IF( IKEY.EQ.11 ) THEN
     	    BARD = RP(1)
     	    CALL BARPLT_WIDTH(1)
     	    GOTO 888
     	ENDIF

     	IF( IKEY.EQ.12 ) THEN
     	    IF(RP(1).LT.0.0.OR.RP(1).GT.2.0) GOTO 777
     	    DRAW = RP(1)
     	    GOTO 888
     	ENDIF

     	IF( IKEY.EQ.13 ) 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
     	    GOTO 888
     	ENDIF
777	CALL BARPLT_ERROR(4)
     	RETURN
888	CALL BARPLT_PARS_ALL(IKEY)
999	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 THE LAST CHARACTER IN "TEXT"...
C
     	REPEAT = .FALSE.
     	IF( TEXT(NCHS:NCHS).EQ.'R'.OR.TEXT(NCHS:NCHS).EQ.'r' ) THEN
     	    REPEAT=.TRUE.
     	    NCHS = NCHS - 1
     	ENDIF
C
C  DECODE THE INPUT...
C
     	I = IFMISC_DECODE( TEXT(1:NCHS), NSET, RP, KP )
    	IF( I.EQ.0 ) GOTO 777
C
C  REPEAT ENTRIES FOR THE REST OF DATA SETS ...
C
	IF( REPEAT ) THEN
    	    DO I=1, NSET
    	       IF( KP(I).EQ.0 ) GOTO 111
    	    ENDDO
111	    NCHS = I - 1
    	    DO J=I, NSET
    	       KP(J) = 1
    	       RP(J) = RP(J-NCHS)
    	    ENDDO
    	ENDIF
C
C  STORE THE VALID PARAMETERS...
C
     	IF( IKEY.EQ.1 ) THEN
    	    DO  I=1, 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
     	    GOTO 333
     	ENDIF

     	IF( IKEY.EQ.2 ) THEN
     	    DO  I=1, NSET
     		IF( KP(I).NE.0 ) THEN
     		    J = RP(I)
     		    IF( IABS(J).GT.99 ) GOTO 222
     		    IPAT(I) = J
     		ENDIF
     	    ENDDO
     	    GOTO 333
     	ENDIF

     	IF( IKEY.EQ.3 ) THEN
     	    DO  I=1, 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
     	    GOTO 333
     	ENDIF

     	IF( IKEY.EQ.4 ) THEN
     	    DO  I=1, 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
     	    GOTO 333
     	ENDIF

     	IF( IKEY.EQ.5 ) THEN
     	    DO  I=1, 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=1, NSET-1
     		DO  J=I+1,NSET
     		    IF( KP(I).EQ.KP(J) ) GOTO 777
     		ENDDO
     	    ENDDO
     	    DO  I=1, NSET
     		ISEQ(I) = KP(I)
     	    ENDDO
     	    GOTO 333
     	ENDIF

     	IF( IKEY.EQ.6 ) THEN
     	    DO  I=1, 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)
     	    GOTO 333
     	ENDIF

     	IF( IKEY.EQ.7 ) THEN
     	    DO  I=1, NSET
     		IF( KP(I).NE.0 ) THEN
     		    P = ABS(RP(I))
     		    IF( P.GT.ABS(XLNS) ) GOTO 222
     		    XOFF(I) = RP(I)
     		ENDIF
     	    ENDDO
     	    GOTO 333
     	ENDIF

     	IF( IKEY.EQ.8 ) THEN
     	    DO  I=1, NSET
     		IF( KP(I).NE.0 ) THEN
     		    P = ABS(RP(I))
     		    IF( P.GT.ABS(YLNS) ) GOTO 222
     		    YOFF(I) = RP(I)
     		ENDIF
     	    ENDDO
     	    GOTO 333
     	ENDIF

     	IF( IKEY.EQ.9 ) THEN
     	    DO  I=1, NSET
     		IF( KP(I).NE.0 ) BARS(I) = RP(I)
     	    ENDDO
     	    GOTO 333
     	ENDIF

     	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
C
C  PARAMETER VALUE OUT OF RANGE...
C
222	CALL BARPLT_ERROR(4)
     	IF( I.EQ.1 ) RETURN
C
C  DISPLAY NEW DATA SET LINE...
C
333	DO J= 1, 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 BARPLT_ERROR(3)	!INVALID PARAMETER
     	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, 5, RP, KP )
    	IF( J.EQ.0 ) THEN
     	    CALL BARPLT_ERROR(3)	!ERROR IN INPUT
     	    GOTO 999
     	ENDIF
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()
     	    IF( J.EQ.0 ) CALL BARPLT_ERROR(7)
     	    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 BARPLT_ERROR(4)	!PARAMETER OUT OF RANGE
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, 3, RP, KP )
    	IF( J.EQ.0 ) THEN
     	    CALL BARPLT_ERROR(3)	!ERROR IN INPUT
     	    GOTO 999
     	ENDIF
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 BARPLT_ERROR(4)	!PARAMETER OUT OF RANGE
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, 3, RP, KP )
    	IF( J.EQ.0 ) THEN
     	    CALL BARPLT_ERROR(3)	!ERROR IN INPUT
     	    GOTO 999
     	ENDIF
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 ) THEN
     		    CALL BARPLT_ERROR(4)
     		    GOTO 999
     		ENDIF
     		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 BARPLT_ERROR(7)	!OUT OF RANGE
999	RETURN
	END

	SUBROUTINE BARPLT_LIST( JSET )
C
C	LIST OF ALL DATA SET PARAMETERS.
C
	INCLUDE 'BARPLT.CBS'

	CALL IFANSI_CURSOR(12,1)
	CALL IFANSI_CLEAR(2)
     	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)

	WRITE(6,1000)
1000	FORMAT('$Press SPACEBAR to continue...')
     	CALL IFQIOW_KEY(I)
     	CALL BARPLT_FORM(JSET)
	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 = BARPLT_NEXT(TEXT)
     	    IF( NCHS.EQ.0 ) GOTO 999
     	ENDIF
     	IF( NCHS.GT.32 ) THEN
     	    CALL BARPLT_ERROR(8)
     	    GOTO 999
     	ENDIF
     	IKEY = BARPLT_SETUP( 0, TEXT )
     	IF( IKEY.EQ.0 ) THEN
     	    CALL IFANSI_VIDEO(70)
     	CALL BARPLT_OOPS(' Error during writing the setup file.')
     	ELSE
     	    STRN = ' Current plot setup has been saved in'
     	    STRN(39:) = TEXT
     	    CALL BARPLT_OOPS( STRN )
     	ENDIF

999	RETURN
     	END

     	SUBROUTINE BARPLT_ERROR( IERR )
C
C	THIS ROUTINE DISPLAYS DIALOGUE ERROR MESSAGE.
C
     	CHARACTER TEXT*75

     	I = IERR
     	IF(I.EQ.1) TEXT=' Undefined access-code.'
     	IF(I.EQ.2) TEXT=' Undefined command.'
     	IF(I.EQ.3) TEXT=' Invalid parameters.'
     	IF(I.EQ.4) TEXT=' Parameter value out of range.'
     	IF(I.EQ.5) TEXT=' Can not find/open the file.'
     	IF(I.EQ.6) TEXT=' No data yet to work on.'
     	IF(I.EQ.7) TEXT=' Invalid axis scale specification.'
     	IF(I.EQ.8) TEXT=' Filename too long (max. 32 characters).'
     	CALL IFANSI_VIDEO(70)
     	CALL BARPLT_OOPS( TEXT )

999	RETURN
     	END

     	SUBROUTINE BARPLT_OOPS( TEXT )
     	CHARACTER TEXT*(*)
     	NCHS = IFMISC_LENG(TEXT)
     	CALL BARPLT_CLEAR_OOPS
     	CALL IFANSI_TEXT( TEXT, NCHS, 17, 6 )
     	RETURN
     	END

     	SUBROUTINE BARPLT_CLEAR_OOPS
     	CALL IFANSI_CURSOR(17,6)
     	CALL IFANSI_CLEAR(4)
     	RETURN
     	END

    	FUNCTION BARPLT_SCALE()
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'
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
     	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, 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
     	    GOTO 111
     	ENDIF

     	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)
     	    GOTO 111
     	ENDIF

     	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)
     	    GOTO 111
     	ENDIF

     	IF( I.EQ.6 ) THEN	!DATA SET DRAWING PARAMETERS
     	    IF( KSET.EQ.MNS ) 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)
     	    GOTO 111
     	ENDIF

     	IF( I.EQ.7 ) THEN	!DATA SET ID LABEL
     	    LABL(KSET) = REST
     	    GOTO 111
     	ENDIF

     	IF( I.EQ.8 ) THEN	!HARDCOPY SETUP PARAMETERS
     	    DO  I=1, 10
     		IF( KP(I).EQ.1 ) HPAR(I) = RP(I)
     	    ENDDO
     	    GOTO 111
     	ENDIF
     	IF( I.EQ.9 ) THEN	!HARDCOPY SETUP PARAMETERS
     	    DO  I=1, 10
     		IF( KP(I).EQ.1 ) HPAR(I+10) = RP(I)
     	    ENDDO
     	    GOTO 111
     	ENDIF

     	IF( I.EQ.10 ) THEN	!PLOT ID LABEL
     	    PLOTID = REST
     	    GOTO 111
     	ENDIF
     	GOTO 111
C
C  CHECK AXIS SCALE UNITS...
C
777	IF(YINC.EQ.0.0.OR.YLOW.EQ.YHIG) CALL BARPLT_SCALE()
     	GOTO 999
888	BARPLT_SETUP = 0.0
     	RETURN
999    	CLOSE(UNIT=LUN)
     	BARPLT_SETUP = 1.0
    	RETURN
    	END

     	SUBROUTINE BARPLT_MENU_HELP
C
C	THIS ROUTINE DISPLAYS ON-LINE HELP FOR HISTOGRAM.
C
     	CHARACTER TEXT*80, KEY*4
     	COMMON/BARPLT_MENU/ JSET, IKEY, NCHS, TEXT

     	NCHS = IFMISC_NEXT(TEXT)
     	IF( NCHS.EQ.2 ) THEN
     	    IKEY=IFMISC_HELP('GRAFIT$HLP:BARPLT_LINE.HLP',TEXT,17,6)
     	ELSE
     	    IF( NCHS.EQ.0 ) THEN
     		KEY = 'HELP'
     	    ELSE 
     		KEY  = TEXT
     		IKEY = INDEX( TEXT(1:NCHS), '/ALL' )
     		IF( IKEY.EQ.0 )	IKEY =INDEX( TEXT(1:NCHS), '/MORE' )
     		IF( IKEY.EQ.0 )	IKEY =INDEX( TEXT(1:NCHS), '/FULL' )
     		IF( IKEY.GT.1 ) KEY  =TEXT(1:IKEY-1)
     	    ENDIF
     	    IKEY = IFMISC_TYPE('GRAFIT$HLP:BARPLT_HELP.HLP',KEY,21)
     	    IF( IKEY.GT.0 ) GOTO 888
     	    CALL BARPLT_FORM(JSET)
     	ENDIF
     	RETURN
C
C  ERROR TRANSFER...
C
888	CALL IFANSI_VIDEO(70)
     	IF(IKEY.EQ.1) THEN
     	   CALL BARPLT_OOPS(' Help file is not available.')
     	ELSE
     	   CALL BARPLT_OOPS(' No help found for the keyword.')
     	ENDIF
     	RETURN
     	END

     	FUNCTION BARPLT_NEXT(TEXT)
     	CHARACTER FNAME*64, TEXT*(*)
     	CALL IFANSI_TEXT('_Filename: ', 11, 18, 9 )
     	READ(5,1001,END=999) FNAME
1001	FORMAT(A)
     	NCHS = 0
     	IF( FNAME.NE.' ' ) THEN
     	    CALL   IFMISC_STRIP(FNAME)
     	    NCHS = IFMISC_UPPER(FNAME)
     	    TEXT = FNAME
     	ENDIF
     	BARPLT_NEXT = NCHS
     	RETURN
999	BARPLT_NEXT = 0
     	RETURN
     	END

