     	PROGRAM XYPLOT_MAIN
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY   JULY-1985
C
C	MAIN ROUTINE OF X,Y PLOT.
C
    	INCLUDE		'XYPLOT.CBS'
     	DIMENSION	RP(2)
C
C  INITIALIZE THE SESSION...
C
     	CALL IFINIT_SESSION
C
C  INITIALIZE PLOT PARAMETERS AND VIRTUAL MEMORY ALLOCATION...
C
     	CALL XYPLOT_INIT( 0 )
C
C  CHECK COMMAND LINE INPUT...
C
     	CALL XYPLOT_DCL( KEY )
     	IF( KEY.NE.0 ) GOTO 333
C
C  CONDUCT THE DIALOGUE...
C
  222	CALL XYPLOT_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 XYPLOT_PLOT
     	IF( CRT.EQ.1 ) THEN
     	    CALL IFANSI_CURSOR(1,1)
     	    CALL IFANSI_CLEAR(6)
     	ENDIF
     	WRITE(6,334)
  334	FORMAT(' XYPLOT> Please press a desired function key:')
C
C  PRESENT LOCAL COMMAND MENU...
C
  444	CALL IFANSI_VIDEO(47)
     	WRITE(6,445)
  445	FORMAT(' XYPLOT> 0>Exit  1/PF1>Hardcopy  2>Layout',
     +'  3/PF3>Dialogue  4>Zoom'/'         ?/PF2>Help  5>Cursor',
     +'    6>Redraw  $/PF4>DCL/VMS  CR>Dialog')
     	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 ) THEN		!HARDCOPY WITH PAGE SETUP
     	    CALL IFCOPY( HPAR(1), PLOTID )
     	    CALL XYPLOT_SETUP( 0, PARNAM )
     	    CALL IFINIT_LINE( -3 )
     	ELSE IF( KEY.EQ.-80 ) THEN	!PF1: HARDCOPY WITHOUT PAGE SETUP
     	    CALL IFANSI_LEDS(1)
     	    CALL IFFEED( HPAR(1), PLOTID, ' ' )
     	    CALL IFANSI_LEDS(0)
     	ELSE IF( KEY.EQ.50 ) 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 ) 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.52 ) THEN	!ZOOM
     	    KEY = XYPLOT_ZOOM()
     	    IF( KEY.NE.0 ) GOTO 333
     	ELSE IF( KEY.EQ.53 ) THEN	!GIN
     	    CALL XYPLOT_GIN( RP, RP )
     	ELSE IF( KEY.EQ.54 ) THEN
     	    GOTO 333				!REDRAW THE PLOT
     	ELSE IF( KEY.EQ.32 .OR. KEY.EQ.63 .OR. KEY.EQ.-81 ) THEN
     	    CALL IFMISC_HLP( 'XYPLOT', '$ 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	KEY = 4*MNST*MNPT
     	CALL LIB$FREE_VM(KEY,IXAR)
     	CALL LIB$FREE_VM(KEY,IYAR)
     	CALL IFINIT_EXIT
     	CALL EXIT
	END

     	SUBROUTINE XYPLOT_DCL( ICODE )
C
C	THIS ROUTINE CHECKS THE DCL COMMAND LINE INPUT.
C
     	INCLUDE 'XYPLOT.CBS'
C
C  IS THERE AN INPUT FILE IN THE LINE...
C
     	ICODE = 0
     	CALL IF_DCL_NFILE( NFLS )
     	IF( NFLS.EQ.0 ) RETURN
C
C  GET THE FIRST FILE...
C
     	SLIN = -1
     	SCOL = 0
     	CALL IF_DCL_FILE( 1, ADDNAM )
     	IERR = XYPLOT_DATA( ADDNAM, MNST, MNPT, MSET, NUMS,
     +                      %VAL(IXAR), %VAL(IYAR), LABL )
     	IF( IERR.NE.0 ) GOTO 555
C
C  YES, WE HAVE A NEW PLOT...
C
     	CALL XYPLOT_RANGE(1,MSET,MNST,MNPT,%VAL(IXAR),%VAL(IYAR))
     	DATNAM = ADDNAM
     	ADDNAM = ' '
     	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  GET THE REST OF THE DATA FILE(S) IF ANY...
C
     	IF( NFLS.EQ.2 ) THEN
     	    KSET = MSET+1
     	    CALL IF_DCL_FILE( 2, ADDNAM )
     	    IERR = XYPLOT_DATA( ADDNAM, MNST, MNPT, MSET, NUMS,
     +                          %VAL(IXAR), %VAL(IYAR), LABL )
     	    IF( IERR.NE.0 ) GOTO 555
     	CALL XYPLOT_RANGE(KSET,MSET,MNST,MNPT,%VAL(IXAR),%VAL(IYAR))
     	ENDIF
C
C  SCALE THE DATA...
C
     	CALL XYPLOT_INIT(1)
     	IERR = XYPLOT_SETUP( 1, PARNAM )
     	IF( IERR.EQ.0 ) THEN
     	    CALL XYPLOT_SCALE(1,MNST,MNPT,%VAL(IXAR),%VAL(IYAR))
     	    CALL XYPLOT_SCALE(2,MNST,MNPT,%VAL(IXAR),%VAL(IYAR))
     	ENDIF
     	ICODE = 1
C
C  MAKE THE HARDCOPY...
C
     	IF( IF_DCL_HARDCOPY() ) THEN
     	    CALL XYPLOT_PLOT
     	    CALL IFCOPY( HPAR(1), PLOTID )
     	ENDIF
     	GOTO 999
C
C  ERROR FROM READING A DATA_FILE...
C
555	IF( IERR.EQ.-1 ) THEN
     	    WRITE(6,556) ADDNAM
556	    FORMAT(' %XYPLOT: can not open file ',A32)
     	ELSE IF( IERR.EQ.-13 ) THEN
     	    WRITE(6,558) ADDNAM
558	    FORMAT(' %XYPLOT: no data found in file ',A32)
     	ELSE IF( IERR.GT.0 ) THEN
     	    WRITE(6,557) IERR, ADDNAM
557	    FORMAT(' %XYPLOT: error in record/line #',I5,
     +' of file ',A32)
     	ENDIF
999	IF( .NOT.IF_DCL_HARDCOPY() ) RETURN
     	CALL EXIT
     	END

     	SUBROUTINE XYPLOT_MENU( ICODE )
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY, FEB-1985
C
C  	INTERACTIVE DIALOGUE MENU FOR X,Y PLOT.
C	RETURN WITH "ICODE=1" IF QUITING.
C
    	INCLUDE		'XYPLOT.CBS'
     	PARAMETER	(NKS = 48)
     	CHARACTER	KWD(NKS)*2
    	CHARACTER	TEXT*80, KEY*2, SYM*1
     	EQUIVALENCE	(SYM,TEXT(3:3)), (KEY,TEXT(1:2))
     	COMMON/XYPLOT_MENU/ JSET, IKEY, NCHS, TEXT
C
C  2 LETTER ACCESS CODES TO GRAPH PARAMETERS...
C
     	DATA KWD / 'F1', 'F2', 'F3', 'F4', 'GT', 'L1', 'L2', 'L3',
     + 'L4', 'C1', 'C2', 'GO', 'BO', 'SF', 'VT', 'SE', 'MQ', 'NS',
     + 'T1', 'T2', 'T3', 'T4', 'X1', 'X2', 'X3', 'X4', 'S1', 'S2',
     + 'S3', 'S4', 'PN', 'SM', 'LI', 'PS', 'BC', 'BL', 'SS', 'XO',
     + 'YO', 'XS', 'YS', 'RL', 'PM', 'ID', 'LB', 'LM', 'LP', 'NO' /
C
C  PRESENT THE DIALOGUE MENU...
C
    	JSET = 1			!ACTIVE DATA SET POINTER
     	IF( MENU ) THEN
     	    SLIN = 21
     	    SCOL = 6
     	    CALL XYPLOT_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('_XYPLOT> 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('XYPLOT> ', 8, 22, 1 )
     	    CALL IFANSI_CLEAR(4)
     	ELSE
     	    WRITE(6,112)
112	    FORMAT(' XYPLOT> ',$)
     	ENDIF
     	IKEY = IFQIOW( NCHS, TEXT )	!INPUT VIA QIOW
     	IF( IKEY.EQ.26) GOTO 888	!CTRL/Z PRESSED
     	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 XYPLOT_CLEAR_OOPS
C
C  COMMAND INPUT...
C
     	IF( SYM.NE.'='  ) THEN
     	    CALL XYPLOT_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.5 ) THEN
     	    CALL XYPLOT_FILES
     	    GOTO 111
     	ELSE IF( IKEY.LT.10 ) THEN
     	    IKEY = IKEY-4
     	    TITL(IKEY) = TEXT
     	    CALL XYPLOT_PARS_ALL(IKEY)
     	ELSE IF( IKEY.LT.19 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-4
     	    CALL XYPLOT_OVERALL
     	ELSE IF( IKEY.LT.23 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-18
     	    CALL XYPLOT_AXIS_A
     	ELSE IF( IKEY.LT.27 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-22
     	    CALL XYPLOT_AXIS_B
     	ELSE IF( IKEY.LT.31 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-26
     	    CALL XYPLOT_AXIS_C
     	ELSE IF( IKEY.LT.43 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-30
     	    CALL XYPLOT_SET
     	ELSE IF( IKEY.EQ.43 ) THEN
     	    CALL XYPLOT_SET_PM
     	ELSE IF( IKEY.EQ.44 ) THEN
     	    LABL(LSET(1,JSET)) = TEXT
     	    CALL XYPLOT_PARS_SET(JSET,14)
     	ELSE
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-44
     	    CALL XYPLOT_LID
     	ENDIF
     	GOTO 111
C
C  ERROR TRANSFER...
C
666	CALL IFMISC_OOPS( 4, SLIN, SCOL, ' ' )  !MISSING INPUT PARAMETER
     	GOTO 111
777	CALL IFMISC_OOPS( 11, SLIN, SCOL, ' ' ) !NO DATA YET TO WORK ON
     	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 XYPLOT_SETUP( 0, PARNAM )
     	ICODE = 0
     	IF( .NOT.MENU ) CALL IFANSI_LEDS(0)
     	RETURN
    	END

     	SUBROUTINE XYPLOT_FORM( JSET )
C
C	THIS ROUTINE LAYOUTS THE DIALOGUE MENU FOR X,Y PLOT.
C
    	INCLUDE 'XYPLOT.CBS'
        CHARACTER TEXT*80
C
C  LAYOUT THE MENU...
C
     	IF( .NOT.MENU ) RETURN
     	CALL IFINIT_LINE(24)
     	TEXT(1:40) = 'GRAFIT: XY Plot (data storage allocated:'
        TEXT(41: ) = '    sets,       pts/set)'
     	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=',35X,'L2=',34X,'C1='/' L3=',35X,'L4=',34X,'C2=')
     	IF( CRT.NE.2 ) CALL IFANSI_VIDEO(90)
     	WRITE(6,1002)
1002	FORMAT(
     +' GO=',19X,'BO=',13X,'SF=',13X,'VT=    SE=    MQ=    NS=')

     	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     LENG TOFF XOFF  ROTA',
     +'        LOW        HIGH       STEP   ')
     	CALL IFANSI_VIDEO(47)
     	WRITE(6,2002)
2002	FORMAT(' T1=',16X,'X1=',22X,'S1='/
     +,' T2=',16X,'X2=',22X,'S2='/' T3=',16X,'X3=',22X,'S3=')
     	IF( CRT.NE.2 ) CALL IFANSI_VIDEO(90)
     	WRITE(6,2003)
2003	FORMAT(' T4=',16X,'X4=',22X,'S4=')

     	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  SM  LI  PS  BC  BL     SS    XO    YO'
     +,'     XS         YS          RL    ')
     	CALL IFANSI_VIDEO(47)
     	WRITE(6,3002)
3002	FORMAT(X,'   :'/'  PM=',9X,'ID=',37X,'LB=   LM=   LP=')
     	IF( CRT.NE.2 ) CALL IFANSI_VIDEO(90)
     	WRITE(6,3003)
3003	FORMAT(
     +' PTS:'6X'XL:'11X'XH:'11X'YL:'11X'YH:'11X'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=',17X,'F2=',17X,'F3=',17X,'F4=')
     	CALL IFANSI_VIDEO(90)
     	WRITE(6,4002)
4002	FORMAT(X,80(' '))
     	CALL IFANSI_VIDEO(20)
     	WRITE(6,5000)
5000	FORMAT(' oops:'//' Auxiliary: HELP/PF2, DCL/PF4, ALLOCATE,',
     +' MISC, DOWN_SET/PF1, UP_SET/PF3, LIST,   '/' _commands: GO,',
     +' READ, PLOT, OVERLAY, SETUP, LAYOUT, DELETE, RESET, REFRESH,',
     +' TIME ',$)
C
C  INSERT THE PARAMETERS...
C
     	CALL XYPLOT_PARS_VM(MNST,MNPT)
     	CALL XYPLOT_PARS(JSET)
     	RETURN
     	END

     	SUBROUTINE XYPLOT_PARS_VM( MS, MP )
     	INCLUDE 'XYPLOT.CBS'
     	IF( .NOT.MENU ) RETURN
     	CALL IFANSI_VIDEO(60)
     	CALL IFANSI_IFL( MS, 1, 'I3', 1, 41 )
     	CALL IFANSI_IFL( MP, 1, 'I5', 1, 51 )
     	RETURN
     	END

     	SUBROUTINE XYPLOT_PARS(JSET)
C
C	THIS ROUTINE INSERTS ALL GRAPH PARAMETERS.
C
     	INCLUDE 'XYPLOT.CBS'
     	IF( .NOT.MENU ) RETURN
     	CALL XYPLOT_PARS_ALL(0)		!OVERALL PLOT PARAMETER GROUP
     	CALL XYPLOT_PARS_AXIS(0,0)	!AXIS DRAWING PARAMETER GROUP
     	CALL XYPLOT_PARS_SET(JSET,0)	!DATA SET DRAWING PARAMETER GROUP
     	CALL XYPLOT_PARS_LID(0)		!DATA SET ID POSITION
     	CALL XYPLOT_PARS_NSET		!TOTAL NUMBER OF DATA SETS
     	CALL XYPLOT_PARS_FILE(0)	!I/O FILE GROUP
     	RETURN
    	END

     	SUBROUTINE XYPLOT_PARS_ALL( ICODE )
C
C	THIS ROUTINE DISPLAYS OVERALL PLOT PARAMETERS.
C
     	INCLUDE 'XYPLOT.CBS'
     	DIMENSION RP(2)
     	CHARACTER YES*3

     	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), 34, 4, 4 )
    	IF(I.EQ.0.OR.I.EQ.3) CALL IFANSI_TEXT( TITL(3), 33, 4, 42)
    	IF(I.EQ.0.OR.I.EQ.4) CALL IFANSI_TEXT( TITL(4), 34, 5, 4 )
    	IF(I.EQ.0.OR.I.EQ.5) CALL IFANSI_TEXT( TITL(5), 33, 5, 42)
    	IF(I.EQ.0.OR.I.EQ.6) CALL IFANSI_IFL( COL1, 1, 'I2', 4, 79 )
    	IF(I.EQ.0.OR.I.EQ.7) CALL IFANSI_IFL( COL2, 1, 'I2', 5, 79 )

    	IF(I.EQ.0.OR.I.EQ.8) THEN
     	   RP(1) = XORG
     	   RP(2) = YORG
     	   CALL IFANSI_FFL( RP, 2, '2F6.2', 6, 4 )
     	ENDIF
     	IF(I.EQ.0.OR.I.EQ.9) THEN
     	   RP(1) = XOFF
     	   RP(2) = YOFF
    	   CALL IFANSI_FFL( RP, 2, '2F6.2', 6, 26)
     	ENDIF
     	IF(I.EQ.0.OR.I.EQ.10) THEN
     	   RP(1) = XSCL
     	   RP(2) = YSCL
    	   CALL IFANSI_FFL( RP, 2, '2F6.3', 6, 42)
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.11) THEN
     	   YES = 'NO'
     	   IF( ANSI ) YES = 'YES'
     	   CALL IFANSI_TEXT( YES, 3, 6, 58 )
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.12) THEN
     	   YES = 'NO'
     	   IF( INIT ) YES = 'YES'
     	   CALL IFANSI_TEXT( YES, 3, 6, 65 )
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.13) THEN
     	   YES = 'NO'
     	   IF( QUAD.EQ.1 ) YES = 'YES'
     	   CALL IFANSI_TEXT( YES, 3, 6, 72 )
     	ENDIF
     	IF(I.EQ.0.OR.I.EQ.14) CALL IFANSI_IFL( NSDS,1,'I2',6,79 )

     	RETURN
     	END

     	SUBROUTINE XYPLOT_PARS_AXIS( ICODE, JCODE )
C
C	THIS ROUTINE DISPLAYS AXIS DRAWING PARAMETERS.
C
     	INCLUDE 'XYPLOT.CBS'
     	DIMENSION KP(5), RP(5)

     	IF( .NOT.MENU ) RETURN
     	CALL IFANSI_VIDEO(30)
     	I1 = 1
     	I2 = 4
     	IF( ICODE.GT.0 ) THEN
     	    I1 = ICODE
     	    I2 = ICODE
     	ENDIF
     	J = JCODE
     	DO  I=I1, I2
     	    IF( J.EQ.0 .OR. J.EQ.1 ) THEN
     		KP(1) = LAXS(I)
     		KP(2) = NTKS(I)
     		KP(3) = MTKS(I)
     		KP(4) = NDGS(I)
     		KP(5) = IGDS(I)
     		CALL IFANSI_IFL( KP, 5, '5I3', I+8, 4 )
     	    ENDIF
     	    IF( J.EQ.0 .OR. J.EQ.2 ) THEN
     		RP(1) = XLNS(I)
     		RP(2) = OFFS(I)
     		RP(3) = SOFF(I)
     		CALL IFANSI_FFL( RP, 3, '3F5.2', I+8, 23 )
     		CALL IFANSI_FFL( XANG(I), 1, 'F6.2', I+8, 38 )
     	    ENDIF
     	    IF( J.EQ.0 .OR. J.EQ.3 ) THEN
     		RP(1) = XLOW(I)
     		RP(2) = XHIG(I)
     		RP(3) = XINC(I)
     		CALL IFANSI_FFL( RP, 3, '3G11.4', I+8, 48 )
     	    ENDIF
     	ENDDO
     	RETURN
     	END

	SUBROUTINE XYPLOT_PARS_SET( ICODE, IPAR )
C
C	THIS ROUTINE DISPLAYS DATA SET DRAWING PARAMETERS.
C
    	INCLUDE  'XYPLOT.CBS'
     	CHARACTER PLOT*7

     	IF( .NOT.MENU ) RETURN
     	JSET = ICODE
     	I = IPAR
     	IF( I.EQ.0 ) THEN
     	    CALL IFANSI_VIDEO(47)
    	    CALL IFANSI_IFL( JSET, 1, 'I3', 15, 1 )
     	ENDIF
     	CALL IFANSI_VIDEO(30)
    	IF(I.EQ.0.OR.I.EQ.1) CALL IFANSI_IFL(IPEN(JSET),1,'I3',15,5)
    	IF(I.EQ.0.OR.I.EQ.2) CALL IFANSI_IFL(ISYM(JSET),1,'I3',15,9)
    	IF(I.EQ.0.OR.I.EQ.3) CALL IFANSI_IFL(ILIN(JSET),1,'I3',15,13)
    	IF(I.EQ.0.OR.I.EQ.4) CALL IFANSI_IFL(IDEN(JSET),1,'I3',15,17)
    	IF(I.EQ.0.OR.I.EQ.5) CALL IFANSI_IFL(ISET(JSET),1,'I3',15,21)
    	IF(I.EQ.0.OR.I.EQ.6) CALL IFANSI_IFL(IBOL(JSET),1,'I3',15,25)
    	IF(I.EQ.0.OR.I.EQ.7) CALL IFANSI_FFL(SSIZ(JSET),1,'F5.2',15,31)
    	IF(I.EQ.0.OR.I.EQ.8) CALL IFANSI_FFL(XSH(JSET),1,'F5.2',15,37)
    	IF(I.EQ.0.OR.I.EQ.9) CALL IFANSI_FFL(YSH(JSET),1,'F5.2',15,43)
    	IF(I.EQ.0.OR.I.EQ.10) CALL IFANSI_FFL(XSF(JSET),1,'G10.3',15,49)
    	IF(I.EQ.0.OR.I.EQ.11) CALL IFANSI_FFL(YSF(JSET),1,'G10.3',15,60)
    	IF(I.EQ.0.OR.I.EQ.12) CALL IFANSI_FFL(SRL(JSET),1,'G10.3',15,71)
     	IF(I.EQ.0.OR.I.EQ.13) THEN
     	    K = ISHD(JSET)
     	    PLOT = 'DEFAULT'
     	    IF( K.EQ. 1 ) PLOT = 'FILL'
     	    IF( K.EQ.-1 ) PLOT = 'LOOP'
     	    IF( K.EQ. 2 ) PLOT = 'STICK'
     	    IF( K.EQ. 3 ) PLOT = 'BAR'
    	    CALL IFANSI_TEXT( PLOT, 7, 16, 5 )
     	ENDIF
     	K = LSET(1,JSET)
     	IF(I.EQ.0.OR.I.EQ.14) CALL IFANSI_TEXT( LABL(K),31,16,17 )
     	IF( I.EQ.0 ) THEN
     	    CALL IFANSI_VIDEO(24)
     	    CALL IFANSI_VIDEO(80)
     	    CALL IFANSI_IFL( NUMS(K), 1, 'I5', 17, 5 )
     	    CALL IFANSI_VIDEO(60)
     	    CALL IFANSI_FFL( SRNG(1,K), 1, 'G10.3', 17, 14 )
     	    CALL IFANSI_FFL( SRNG(2,K), 1, 'G10.3', 17, 28 )
     	    CALL IFANSI_FFL( SRNG(3,K), 1, 'G10.3', 17, 42 )
     	    CALL IFANSI_FFL( SRNG(4,K), 1, 'G10.3', 17, 56 )
     	ENDIF

     	RETURN
	END

     	SUBROUTINE XYPLOT_PARS_LID( ICODE )
     	INCLUDE 'XYPLOT.CBS'
     	DIMENSION RP(2)

     	IF( .NOT.MENU ) RETURN
     	CALL IFANSI_VIDEO(30)
     	I = ICODE
     	IF(I.EQ.0.OR.I.EQ.1) CALL IFANSI_IFL( DRAW, 1, 'I2', 16, 57 )
     	IF(I.EQ.0.OR.I.EQ.2) CALL IFANSI_IFL( MARK, 1, 'I2', 16, 63 )
    	IF(I.EQ.0.OR.I.EQ.3) THEN
     	   RP(1) = XLPS
     	   RP(2) = YLPS
     	   CALL IFANSI_FFL( RP, 2, '2F6.2', 16, 69 )
     	ENDIF
     	RETURN
     	END

     	SUBROUTINE XYPLOT_PARS_FILE( ICODE )
C
C	THIS ROUTINE DISPLAYS FILENAMES.
C
     	INCLUDE 'XYPLOT.CBS'
     	CHARACTER DNAME*32

     	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, 16, 19, 4 )
     	ENDIF
     	IF( I.EQ.0 .OR. I.EQ.2 ) THEN
     	    DNAME = ADDNAM
     	    K = INDEX( DNAME, ']' )
     	    IF( K.GT.0 ) DNAME = DNAME(K+1:)
     	    CALL IFANSI_TEXT( DNAME, 16, 19, 24)
     	ENDIF
     	IF( I.EQ.0 .OR. I.EQ.3 ) THEN
     	    DNAME = PARNAM
     	    K = INDEX( DNAME, ']' )
     	    IF( K.GT.0 ) DNAME = DNAME(K+1:)
     	    CALL IFANSI_TEXT( DNAME, 16, 19, 44)
     	ENDIF
     	IF( I.EQ.0 .OR. I.EQ.4 ) THEN
     	    DNAME = DESNAM
     	    K = INDEX( DNAME, ']' )
     	    IF( K.GT.0 ) DNAME = DNAME(K+1:)
     	    CALL IFANSI_TEXT( DNAME, 17, 19, 64)
     	ENDIF

     	RETURN
     	END

     	SUBROUTINE XYPLOT_PARS_NSET
     	INCLUDE 'XYPLOT.CBS'
     	IF( .NOT.MENU ) RETURN
     	CALL IFANSI_VIDEO(24)
     	CALL IFANSI_VIDEO(80)
     	CALL IFANSI_IFL( NSET, 1, 'I3', 17, 78 )
     	RETURN
     	END

     	SUBROUTINE XYPLOT_COM
C
C	THIS ROUTINE IMPLEMENTS SOME DIALOGUE COMMANDS.
C
     	INCLUDE   'XYPLOT.CBS'
    	CHARACTER TEXT*80
     	COMMON/XYPLOT_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 XYPLOT_FILES
     		RETURN
     	    ENDIF
     	ENDIF
     	IF( TEXT(1:4).EQ.'DOWN'
     + .OR. (IKEY.EQ.27 .AND. TEXT(1:2).EQ.'OP') ) THEN
C
C  DOWN ONE ACTIVE-DATA-SET POINTER...
C
     	    IF( NSET.EQ.0 ) GOTO 888
     	    JSET = JSET + 1
     	    IF( JSET.GT.NSET ) JSET = 1
     	    CALL XYPLOT_PARS_SET(JSET,0)
     	ELSE IF( TEXT(1:2).EQ.'UP'
     + .OR. (IKEY.EQ.27 .AND. TEXT(1:2).EQ.'OR') ) THEN
C
C  UP ONE ACTIVE-DATA-SET POINTER...
C
     	    IF( NSET.EQ.0 ) GOTO 888
     	    JSET = JSET - 1
     	    IF( JSET.LT.1 ) JSET = NSET
     	    CALL XYPLOT_PARS_SET(JSET,0)
     	ELSE IF( TEXT(1:4).EQ.'LIST' ) THEN
C
C  LIST...
     	    IF( NSET.EQ.0 ) GOTO 888
     	    CALL XYPLOT_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( 'XYPLOT', TEXT, SLIN, SCOL )
     		IF( IKEY.EQ.0 ) CALL XYPLOT_FORM(JSET)
     	    ELSE
     		IKEY = IFMISC_HLP( 'XYPLOT', 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 XYPLOT_FORM(JSET)
     	ELSE IF( TEXT(1:5).EQ.'RESET' ) THEN
C
C  RESET...
     	    IF( NSET.EQ.0 ) GOTO 888
     	    CALL XYPLOT_RESET( JSET )
     	ELSE IF( TEXT(1:4).EQ.'SAVE' ) THEN
C
C  SAVE...
     	    IF( NSET.EQ.0 ) GOTO 888
     	    CALL XYPLOT_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 XYPLOT_FILES
     	ELSE IF( TEXT(1:4).EQ.'OVER' .OR. TEXT(1:3).EQ.'INC' ) THEN
C
C  OVERLAY...
     	    IKEY = 2
     	    NCHS = IFMISC_NEXT(TEXT)
     	    CALL XYPLOT_FILES
     	ELSE IF( TEXT(1:5).EQ.'SETUP' ) THEN
C
C  SETUP...
     	    IKEY = 3
     	    NCHS = IFMISC_NEXT(TEXT)
     	    CALL XYPLOT_FILES
     	ELSE IF( TEXT(1:6).EQ.'LAYOUT' ) THEN
C
C  LAYOUT...
     	    IKEY = 4
     	    NCHS = IFMISC_NEXT(TEXT)
     	    CALL XYPLOT_FILES
     	ELSE IF( TEXT(1:5).EQ.'WRITE' ) THEN
C
C  WRITE...
     	    IF( NSET.EQ.0 ) GOTO 888
     	    CALL XYPLOT_WRITE
     	ELSE IF( TEXT(1:3).EQ.'MIS' ) THEN
C
C  MISC...
     	    IF( NSET.EQ.0 ) GOTO 888
     	    CALL XYPLOT_MISC
     	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 XYPLOT_FORM(JSET)
     	ELSE IF( TEXT(1:3).EQ.'DEL' .OR. TEXT(1:3).EQ.'REM' ) THEN
C
C  REMOVE...
     	    IF( NSET.EQ.0 ) GOTO 888
     	    CALL XYPLOT_DELETE( MNST, MNPT, %VAL(IXAR), %VAL(IYAR) )
     	ELSE IF( TEXT(1:3).EQ.'ALL' ) THEN
C
C  ALLOCATE...
     	    CALL XYPLOT_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, ' ' )
     	RETURN
     	END

     	SUBROUTINE XYPLOT_RESET( JSET )
C
C	THIS ROUTINE RESETS THE PLOT.
C
     	INCLUDE 'XYPLOT.CBS'
     	IF( MENU ) CALL XYPLOT_CLEAR_OOPS
     	CALL XYPLOT_OOPS(' Resetting the plot...')
     	CALL XYPLOT_INIT(1)
     	CALL XYPLOT_SCALE( 1, MNST, MNPT, %VAL(IXAR), %VAL(IYAR) )
     	CALL XYPLOT_SCALE( 2, MNST, MNPT, %VAL(IXAR), %VAL(IYAR) )
     	IF( MENU ) THEN
     	    CALL XYPLOT_PARS(JSET)
     	    CALL XYPLOT_CLEAR_OOPS
     	ENDIF
     	RETURN
     	END

     	SUBROUTINE XYPLOT_FILES
C
C	THIS ROUTINE GETS INPUT DATA/PARAMETER/LAYOUT FILES.
C
     	INCLUDE		'XYPLOT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/XYPLOT_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 ) RETURN
     	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 ) !FILENAME TOO LONG
     	    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
     	KSET = 0
     	IKEY = XYPLOT_DATA( TEXT, MNST, MNPT, KSET, NUMS,
     +                      %VAL(IXAR), %VAL(IYAR), LABL )
     	IF( IKEY.NE.0 ) GOTO 555
C
C  YES, WE HAVE A NEW PLOT...
C
     	JSET = 1
     	NSET = 0
     	MSET = KSET
     	CALL XYPLOT_RANGE(1,KSET,MNST,MNPT,%VAL(IXAR),%VAL(IYAR))
     	ADDNAM = ' '
     	DATNAM = TEXT
     	PARNAM = DATNAM
     	CALL IFMISC_NAMEXT( PARNAM, '.PAR' )
     	DESNAM = ' '
     	IF( IFL3.EQ.0 ) THEN
     	    DESNAM = DATNAM
     	    CALL IFMISC_NAMEXT( DESNAM, '.DES' )
     	ENDIF
        CALL XYPLOT_NSET( NSET, DATNAM )
     	IF( IFL1.EQ.0 ) CALL XYPLOT_INIT(1)
     	IKEY = 0
     	IF( IFL2.EQ.0 ) IKEY = XYPLOT_SETUP( 1, PARNAM )
     	IF( IKEY.EQ.0 .AND. IFL1.EQ.0 ) THEN
     	    CALL XYPLOT_SCALE( 1, MNST, MNPT, %VAL(IXAR), %VAL(IYAR) )
     	    CALL XYPLOT_SCALE( 2, MNST, MNPT, %VAL(IXAR), %VAL(IYAR) )
     	ENDIF
     	IF( JKEY.GT.0 .AND. (IFL1.EQ.0.OR.IFL2.EQ.0) ) THEN
     	    CALL IFANSI_VIDEO(30)
     	    CALL XYPLOT_PARS(JSET)
     	ELSE
     	    IKEY = -999
     	ENDIF
     	GOTO 999

222	IF( IKEY.NE.2 ) GOTO 333
     	IF( MSET.EQ.MNST ) THEN
     	    CALL IFMISC_OOPS( 22, SLIN, SCOL, ' ' )
     	    GOTO 999
     	ENDIF
C
C  OVERLAY A DATA FILE...
C
     	KSET = MSET + 1
     	IKEY = XYPLOT_DATA( TEXT, MNST, MNPT, MSET, NUMS,
     +                      %VAL(IXAR), %VAL(IYAR), LABL )
     	IF( IKEY.NE.0 ) GOTO 555
C
C  YES, OVERLAY THE FILE...
C
     	IKEY = NSET
     	CALL XYPLOT_RANGE(KSET,MSET,MNST,MNPT,%VAL(IXAR),%VAL(IYAR))
     	CALL XYPLOT_PARS_NSET
     	KSET = NSET - IKEY
     	ADDNAM = TEXT
     	CALL XYPLOT_PARS_FILE(2)
        CALL XYPLOT_NSET( KSET, ADDNAM )
     	JSET = NSET
     	CALL XYPLOT_PARS_SET(JSET,0)
     	GOTO 999

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

444	IF( IKEY.NE.4 ) 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 XYPLOT_PARS_FILE(4)
     	GOTO 999
C
C  ERROR TRANSFER...
C
 555	IF( IKEY.LT.0 ) THEN
     	    CALL IFMISC_OOPS( -IKEY, SLIN, SCOL, TEXT )
     	ELSE
     	    TEXT = ' Error from reading data in record/line #'
     	    WRITE( TEXT(42:), 666 ) IKEY
 666	    FORMAT(I5)
     	    CALL XYPLOT_OOPS( TEXT )
     	ENDIF
 999	RETURN
     	END

      SUBROUTINE XYPLOT_NSET( NSET, FNAME )
      CHARACTER TEXT*80, FNAME*(*)
      WRITE( TEXT(1:4), 1 ) NSET
 1    FORMAT(I4)
      TEXT(5:)  = ' set(s) of data have been read from'
      TEXT(41:) = FNAME
      CALL XYPLOT_OOPS( TEXT )
      RETURN
      END

     	SUBROUTINE XYPLOT_RANGE( I1, I2, MS, MP, X, Y )
C
C	THIS ROUTINE GETS DATA RANGES FOR X,Y PLOT
C
     	INCLUDE 'XYPLOT.CBS'
     	DIMENSION X(MP,MS), Y(MP,MS)

     	DO  I = I1, I2
     	    NPTS = NUMS(I)
     	    IF( NPTS.NE.0 ) THEN	!NON-ERROR-BAR SET
     		NSET = NSET + 1
     		LSET(1,NSET) = I
     		IF( NPTS.GT.0 ) THEN
     		    LSET(2,NSET) = 0
     		ELSE
     		    NPTS = -NPTS
     		    NUMS(I) = NPTS
     		    LSET(2,NSET) = 1	!NEXT SET IS ERROR BAR
     		ENDIF
     		CALL IFMISC_RANGE( NPTS, X(1,I), Y(1,I), SRNG(1,I) )
     	    ENDIF
     	ENDDO

     	RETURN
     	END

    	SUBROUTINE XYPLOT_INIT( ICODE )
C
C	THIS ROUTINE INITIALIZES THE COMMON BLOCKS FOR X,Y PLOT.
C

    	INCLUDE 'XYPLOT.CBS'

     	IF( ICODE.EQ.0 ) THEN
     	    CRT = IFINIT_ITM(0)		!GET THE TYPE OF TERMINAL
     	    DATNAM = ' Data file here'
     	    ADDNAM = ' Additional file'
     	    PARNAM = ' Setup file'
     	    DESNAM = ' Layout file'
    	    DO I=1,5
     	       TITL(I) = ' '
    	    ENDDO
     	    DO I=1, MNS
     	       NUMS(I) = 0
     	       LSET(1,I) = I
     	       LSET(2,I) = 0
    	       LABL(I) = ' '
     	       DO J=1, 4
     		  SRNG(J,I) = 0.0
     	       ENDDO
     	    ENDDO
            DO I=1, 20
               HPAR(I) = 0.0
            ENDDO
     	    INIT = .TRUE.
     	    ANSI = .FALSE.
     	    MENU = .TRUE.
	    PLOTID = ' '
     	    NSET = 0
     	    MSET = 0
     	    MNST = 4
     	    MNPT = 256
     	    CALL IF_DCL_VM( COL1, COL2 )
     	    IF( COL1.GT.0 .AND. COL1.LE.MNS ) MNST = COL1
     	    IF( COL2.GT.1 .AND. COL2.LT.100000 ) MNPT = COL2
     	    I = 4*MNST*MNPT
     	    COL1 = LIB$GET_VM(I,IXAR)
     	    IF( .NOT.COL1 ) GOTO 888
     	    COL2 = LIB$GET_VM(I,IYAR)
     	    IF( .NOT.COL2 ) GOTO 888
     	ENDIF

     	DO I=1, 4
     	   LAXS(I) = 1
    	   NTKS(I) = 1
    	   MTKS(I) = 1
    	   NDGS(I) = 0
    	   IGDS(I) = 11
    	   OFFS(I) = 0.0
     	   SOFF(I) = 0.0
     	   XANG(I) = 0.0
     	   XLOW(I) = 0.0
     	   XHIG(I) = 0.0
     	   XINC(I) = 0.0
    	ENDDO
     	XLNS(1) = 6.0
     	XLNS(2) = 4.0
     	XLNS(3) = 6.0
     	XLNS(4) = 4.0

     	DO I=1, MNS
     	   QUAD = MOD(I,7)
     	   IF( QUAD.EQ.0 ) QUAD = 7
     	   IPEN(I) = QUAD
     	   ISYM(I) = 0
     	   ILIN(I) = 1
    	   ISET(I) = 1
    	   IDEN(I) = 1
    	   IBOL(I) = 1
    	   ISHD(I) = 0
    	   SSIZ(I) = 0.1
    	    XSH(I) = 0.0
    	    YSH(I) = 0.0
    	    XSF(I) = 1.0
    	    YSF(I) = 1.0
    	    SRL(I) = 0.0
    	ENDDO

    	BAND = .FALSE.
    	QUAD = 0
    	NSDS = 1
    	COL1 = 1
    	COL2 = 1
     	DRAW = 2
     	MARK = 1
     	XLPS = 0.5
     	YLPS = 0.5
     	XORG = 2.25
     	YORG = 2.25
     	XOFF = 0.00
     	YOFF = 0.00
     	XSCL = 1.00
     	YSCL = 1.00
    	RETURN
888	CALL IFMISC_OOPS( 6, 0, 0, ' ' )
     	CALL EXIT
    	END

	SUBROUTINE XYPLOT_OVERALL
C
C	THIS ROUTINE CHANGES OVREALL PLOT PARAMETERS.
C
    	INCLUDE		'XYPLOT.CBS'
     	CHARACTER	TEXT*80
     	DIMENSION	RP(2), KP(2)
     	COMMON/XYPLOT_MENU/ JSET, IKEY, NCHS, TEXT
C
C  DECODE THE PARAMETERS...
C
     	IF( IKEY.LT.11 .OR. IKEY.GT.13 ) THEN
     	    NCHS = IFMISC_DECODE( TEXT, NCHS, 2, RP, KP )
    	    IF( NCHS.EQ.0 ) GOTO 777
     	ENDIF

     	IF( IKEY.EQ.6 ) THEN		!1ST BAND AXIS COLOR
     	    IF(RP(1).LT.1.0.OR.RP(1).GT.8.0) GOTO 777
     	    COL1 = RP(1)
     	ELSE IF( IKEY.EQ.7 ) THEN	!2ND BAND AXIS COLOR
     	    IF(RP(1).LT.1.0.OR.RP(1).GT.8.0) GOTO 777
     	    COL2 = RP(1)
     	ELSE IF( IKEY.EQ.8 ) 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.9 ) THEN	!2ND BAND OFFSETS
    	    IF( KP(1).EQ.1 ) THEN
     		IF(RP(1).LT.-99.0.OR.RP(1).GT.99.0) GOTO 777
    	       	XOFF = RP(1)
    	    ENDIF
    	    IF( KP(2).EQ.1 ) THEN
     		IF(RP(2).LT.-99.0.OR.RP(2).GT.99.0) GOTO 777
    	       	YOFF = RP(2)
    	    ENDIF
     	ELSE IF( IKEY.EQ.10 ) 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.11 ) THEN	!ANSI GRAPH
     	    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.12 ) 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.13 ) THEN	!QUADRANT CODE
     	    QUAD = 0
     	    IF( TEXT(1:1).EQ.'Y' .OR. TEXT(1:1).EQ.'y'
     +     .OR. TEXT(1:1).EQ.'T' .OR. TEXT(1:1).EQ.'t' ) QUAD = 1
     	    IF( QUAD.NE.0 ) THEN
     		IF( BAND ) QUAD = 0
     		IF( LAXS(1).LT.0.AND.LAXS(2).LT.0) QUAD= 0
     		IF( IABS(LAXS(1)).NE.1.AND.IABS(LAXS(2)).NE.1) QUAD= 0
     	    ENDIF
     	ELSE IF( IKEY.EQ.14 ) THEN	!SD BAR PLOTTING CODE
     	    IF(RP(1).LT.0.0.OR.RP(1).GT.3.0) GOTO 777
     	    NSDS = RP(1)
     	ELSE
     	    GOTO 777
     	ENDIF
     	CALL XYPLOT_PARS_ALL(IKEY)
     	RETURN
777	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
     	RETURN
	END

	SUBROUTINE XYPLOT_SET
C
C	THIS ROUTINE CHANGES DATA SET DRAWING PARAMETERS
C	IN COLUMN-RUN MODE.
C
    	INCLUDE		'XYPLOT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/XYPLOT_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=888 ) KSET
     	    IF( KSET.LT.1 .OR. KSET.GT.NSET ) GOTO 888
     	    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 888	!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 888
    	    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
     		    ISYM(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.EQ.0 .OR. IABS(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.999 ) GOTO 222
     		    IF( J.GE.NUMS(LSET(1,I)) ) GOTO 222
     		    IDEN(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.3 ) GOTO 222
     		    ISET(I) = J
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.6 ) 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.7 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) THEN
     		    P = RP(I)
     		    IF( P.LT.0.02 .OR. P.GT.4.0 ) GOTO 222
     		    SSIZ(I) = P
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.8 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) THEN
     		    P = ABS(RP(I))
     		    IF( ISET(I).NE.2 .AND. P.GT.XLNS(1) ) GOTO 222
     		    IF( ISET(I).NE.1 .AND. P.GT.XLNS(3) ) GOTO 222
     		    XSH(I) = RP(I)
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.9 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) THEN
     		    P = ABS(RP(I))
     		    IF( ISET(I).NE.2 .AND. P.GT.XLNS(2) ) GOTO 222
     		    IF( ISET(I).NE.1 .AND. P.GT.XLNS(4) ) GOTO 222
     		    YSH(I) = RP(I)
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.10 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) XSF(I) = RP(I)
     	    ENDDO
     	ELSE IF( IKEY.EQ.11 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) YSF(I) = RP(I)
     	    ENDDO
     	ELSE IF( IKEY.EQ.12 ) THEN
     	    DO  I=KSET, NSET
     		IF( KP(I).NE.0 ) THEN
     		    J = XYPLOT_SRL( I, RP(I) )
     		    IF( J.EQ.0 ) GOTO 222
     		    SRL(I) = RP(I)
     		ENDIF
     	    ENDDO
     	ELSE
     	    GOTO 222
     	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
C
C  CHECK THE BAND CODE...
C
555	J = 0
     	REPEAT = BAND
     	BAND = .FALSE.
     	DO I=1, NSET
    	   IF( ISET(I).NE.2 ) J = 1
    	   IF( ISET(I).NE.1 ) BAND = .TRUE.
    	ENDDO
     	IF( J.EQ.0 ) THEN
     	    BAND = .FALSE.
     	    DO  I=1, NSET
     		ISET(I) = 1
     	    ENDDO
     	ENDIF
	CALL XYPLOT_PARS_SET(JSET,IKEY)
     	IF( .NOT.REPEAT .AND. BAND ) THEN	!SCALE 2ND BAND
     	    CALL IFANSI_VIDEO(30)
     	    J = XYPLOT_SCALE( 3, MNST, MNPT, %VAL(IXAR), %VAL(IYAR) )
     	    IF( J.EQ.0 ) CALL IFMISC_OOPS( 10, SLIN, SCOL, ' ' )
     	    CALL XYPLOT_PARS_AXIS(3,0)
     	    J = XYPLOT_SCALE( 4, MNST, MNPT, %VAL(IXAR), %VAL(IYAR) )
     	    IF( J.EQ.0 ) CALL IFMISC_OOPS( 10, SLIN, SCOL, ' ' )
     	    CALL XYPLOT_PARS_AXIS(4,0)
     	ENDIF
     	RETURN
888	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )	!INVALID PARAMETER
     	RETURN
	END

     	FUNCTION XYPLOT_SRL( I, P )
C
C	THIS ROUTINE MAKES SURE THAT SET PLOTTING REFERENCE
C	LINE IS WITHIN THE CURRENT Y-AXIS WINDOW.
C
     	INCLUDE 'XYPLOT.CBS'

     	PP = P
     	II = I
     	IF( ISET(II).NE.2 ) THEN
     	    CALL XYPLOT_LIMIT(1,YLO,YHI,YLO1,YHI1)
     	    YLO = YLO1
     	    YHI = YHI1
     	    LYY = IABS(LAXS(2))
     	ENDIF
     	IF( ISET(II).NE.1 ) THEN
     	    CALL XYPLOT_LIMIT(2,YLO,YHI,YLO2,YHI2)
     	    YLO = YLO2
     	    YHI = YHI2
     	    LYY = IABS(LAXS(4))
     	ENDIF
     	IF( ISET(II).EQ.3 ) THEN
     	    IF( YLO1.GT.YLO2 ) YLO = YLO1
     	    IF( YHI1.LT.YHI2 ) YHI = YHI1
     	    IF( YLO.GT.YHI ) THEN
     		YLO1 = YLO
     		YLO  = YHI
     		YHI  = YLO1
     	    ENDIF
     	ENDIF
     	IF( LYY.EQ.2 ) THEN
     	    IF( PP.LE.0.0 ) GOTO 777
     	    PP = LOG10(PP)
     	ENDIF
     	IF( LYY.EQ.3 ) THEN
     	    IF( PP.EQ.0.0 ) GOTO 777
     	    PP = 1.0/PP
     	ENDIF
     	IF( PP.LT.YLO .OR. PP.GT.YHI ) GOTO 777

     	XYPLOT_SRL = 1
     	RETURN
777	XYPLOT_SRL = 0
     	RETURN
     	END

     	SUBROUTINE XYPLOT_SET_PM
C
C	THIS ROUTINE GETS DATA SET PLOTTING MODE.
C
     	INCLUDE 'XYPLOT.CBS'
     	CHARACTER TEXT*80
     	COMMON/XYPLOT_MENU/ JSET, IKEY, NCHS, TEXT

     	IKEY = 0
     	IF( NCHS.GT.0 ) THEN
     	    IKEY = 9
     	    CALL IFMISC_UPPER(NCHS,TEXT)
     	    IF( TEXT(1:7).EQ.'DEFAULT' ) IKEY = 0
     	    IF( TEXT(1:4).EQ.'FILL' ) IKEY = 1
     	    IF( TEXT(1:4).EQ.'LOOP' ) IKEY =-1
     	    IF( TEXT(1:5).EQ.'STICK') IKEY = 2
     	    IF( TEXT(1:3).EQ.'BAR'  ) IKEY = 3
     	    IF( IKEY.EQ.9 ) THEN
     		CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
     		RETURN
     	    ENDIF
     	ENDIF
     	ISHD(JSET) = IKEY
     	CALL XYPLOT_PARS_SET(JSET,13)

     	RETURN
     	END

     	SUBROUTINE XYPLOT_LID
C
C	THIS ROUTINE CHANGES DATA SET LABEL POSITION.
C
    	INCLUDE 'XYPLOT.CBS'
     	CHARACTER TEXT*80
     	COMMON/XYPLOT_MENU/ JSET, IKEY, NCHS, TEXT
     	DIMENSION RP(2), KP(2)
C
C  DECODE THE PARAMETERS...
C
     	NCHS = IFMISC_DECODE( TEXT, NCHS, 2, RP, KP )
    	IF( NCHS.EQ.0 ) GOTO 777

     	IF( IKEY.EQ.1 ) THEN		!DRAW DATA SET LABELS
     	    IF(RP(1).LT.0.0.OR.RP(1).GT.2.0) GOTO 777
     	    DRAW = RP(1)
     	ELSE IF( IKEY.EQ.2 ) THEN	!DRAW DATA SET MARKERS
     	    IF(RP(1).LT.0.0.OR.RP(1).GT.1.0) GOTO 777
     	    MARK = RP(1)
     	ELSE IF( IKEY.EQ.3 ) THEN	!SET LABELING POSITION
    	    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 IF( IKEY.EQ.4 ) THEN	!ACTIVE DATA SET POINTER
     	    IKEY = RP(1)
     	    IF( IKEY.LT.1 .OR. IKEY.GT.NSET ) GOTO 777
     	    JSET = IKEY
     	    CALL IFANSI_VIDEO(30)
     	    CALL XYPLOT_PARS_SET(JSET,0)
     	    RETURN
     	ELSE
     	    GOTO 777
     	ENDIF
888	CALL XYPLOT_PARS_LID(IKEY)
     	RETURN
777	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
     	RETURN
     	END

	SUBROUTINE XYPLOT_AXIS_A
C
C	THIS ROUTINE CHANGES AXIS DRAWING PARAMETERS -- GROUP A
C
    	INCLUDE		'XYPLOT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/XYPLOT_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
     	IF( IKEY.GT.2 .AND. .NOT.BAND ) THEN
     	    CALL IFMISC_OOPS( 11, SLIN, SCOL, ' ' )
     	    GOTO 999
     	ENDIF
C
C  STORE THE NEW PARAMETERS...
C
     	IF( KP(1).EQ.1 ) THEN
     	    J = RP(1)
     	    IF( J.EQ.0 .OR. IABS(J).GT.3 ) GOTO 777
     	    LAXS(IKEY) = J
     	ENDIF

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

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

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

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

     	CALL XYPLOT_PARS_AXIS(IKEY,1)

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

     	IF( KP(2).EQ.1 .AND. IABS(LAXS(IKEY)).NE.2 ) THEN
     	    XINC(IKEY) = (XHIG(IKEY)-XLOW(IKEY)) / IABS(NTKS(IKEY))
     	    CALL XYPLOT_PARS_AXIS(IKEY,3)
     	ENDIF
     	GOTO 999
777	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
999	RETURN
     	END

	SUBROUTINE XYPLOT_AXIS_B
C
C	THIS ROUTINE CHANGES AXIS DRAWING PARAMETERS -- GROUP B
C
    	INCLUDE		'XYPLOT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/XYPLOT_MENU/ JSET, IKEY, NCHS, TEXT
     	DIMENSION	KP(4), RP(4)
C
C  DECODE THE PARAMETERS...
C
    	J = IFMISC_DECODE( TEXT, NCHS, 4, RP, KP )
    	IF( J.EQ.0 ) GOTO 777
     	IF( IKEY.GT.2 .AND. .NOT.BAND ) THEN
     	    CALL IFMISC_OOPS( 11, SLIN, SCOL, ' ' )
     	    GOTO 999
     	ENDIF
C
C  STORE THE NEW PARAMETERS...
C
     	IF( KP(1).EQ.1 ) THEN
     	    P = RP(1)
     	    IF( P.LT.2.0 .OR. P.GT.99.0 ) GOTO 777
     	    XLNS(IKEY) = P
     	ENDIF

     	IF( KP(2).EQ.1 ) THEN
     	    P = RP(2)
     	    IF( P.LT.0.0 .OR. P.GT.XLNS(IKEY)/3.0 ) GOTO 777
     	    OFFS(IKEY) = P
     	ENDIF

     	IF( KP(3).EQ.1 ) THEN
     	    P = RP(3)
     	    IF( P.LT.-9.99 .OR. P.GT.99.0 ) GOTO 777
     	    SOFF(IKEY) = P
     	ENDIF

     	IF( KP(4).EQ.1 ) THEN
     	    P = RP(4)
     	    IF( ABS(P).GT.80.0 ) GOTO 777
     	    XANG(IKEY) = P
     	ENDIF

     	CALL XYPLOT_PARS_AXIS(IKEY,2)
     	GOTO 999
777	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )	!PARAMETER OUT OF RANGE
999	RETURN
     	END

	SUBROUTINE XYPLOT_AXIS_C
C
C	THIS ROUTINE CHANGES AXIS DRAWING PARAMETERS -- GROUP C
C
    	INCLUDE		'XYPLOT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/XYPLOT_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
     	IF( IKEY.GT.2 .AND. .NOT.BAND ) THEN
     	    CALL IFMISC_OOPS( 11, SLIN, SCOL, ' ' )
     	    GOTO 999
     	ENDIF
C
C  STORE THE NEW PARAMETERS...
C
    	J = IABS(LAXS(IKEY))
     	IF( J.NE.2 ) THEN	!LINEAR TYPE OF AXIS
     	    IF( KP(1).EQ.0 ) RP(1) = XLOW(IKEY)
     	    IF( KP(2).EQ.0 ) RP(2) = XHIG(IKEY)
     	    IF( RP(1).EQ.RP(2) ) GOTO 777
     	    IF( KP(3).EQ.0 ) THEN
     		IF(J.EQ.3.AND.RP(1)*RP(2).LE.0.0) GOTO 777	!INVERSE AXIS
     		RP(3) = (RP(2)-RP(1))/IABS(NTKS(IKEY))
     	    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(IKEY) = J
     		RP(3) = (RP(2)-RP(1))/J
     		CALL XYPLOT_PARS_AXIS(IKEY,1)
     	    ENDIF
     	ELSE			!LOG10 TYPE OF AXIS
     	    IF( KP(1).EQ.0 ) RP(1) = XLOW(IKEY)
     	    IF( KP(2).EQ.0 ) RP(2) = XHIG(IKEY)
     	    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
     	XLOW(IKEY) = RP(1)
     	XHIG(IKEY) = RP(2)
     	XINC(IKEY) = RP(3)
     	CALL XYPLOT_PARS_AXIS(IKEY,3)
     	GOTO 999
777	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )	!OUT OF RANGE
999	RETURN
	END

	SUBROUTINE XYPLOT_LIST( JSET )
C
C	LIST OF ALL DATA SET PARAMETERS.
C
	INCLUDE 'XYPLOT.CBS'

     	IF( MENU ) THEN
     	    CALL IFANSI_CURSOR(15,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  SM  LI  DN  BC  BL     SS    XO    YO'
     +,'     XS         YS          RL    ')
     	ENDIF
     	CALL IFANSI_VIDEO(47)
	WRITE(6,1234) (I,IPEN(I),ISYM(I),ILIN(I),IDEN(I),ISET(I),
     +  IBOL(I),SSIZ(I),XSH(I),YSH(I),XSF(I),YSF(I),SRL(I), I=1,NSET)
1234	FORMAT(7I4,2X,3F6.2,3G11.3)
     	CALL IFANSI_VIDEO(30)
	WRITE(6,1000)
1000	FORMAT(/' Press SPACEBAR to continue...',$)
     	CALL IFQIOW_KEY(I)
     	IF( MENU ) THEN
     	    CALL XYPLOT_FORM(JSET)
     	ELSE
     	    CALL IFINIT_LINE(3)
     	ENDIF
	RETURN
	END

     	SUBROUTINE XYPLOT_MISC
C
C	THIS ROUTINE IMPLEMENTS THE FOLLOWING DATA
C	MANIPULATIONS ON ACTIVE DATA SET --- JSET:
C
C	(1) SWAP X,Y, COLUMNS OF INPUT DATA.
C	(2) SORT INPUT DATA IN ASCENDING ORDER IN X-COORDIANTES.
C	(3) SORT INPUT DATA IN ASCENDING ORDER IN Y-COORDIANTES.
C	(4) SMOOTH INPUT DATA BY A SAVITZKY-GOLAY FILTER.
C	(5) LEAST-SQUARE POLYNOMIAL REGRESSION.
C	(6) ADD/SUBTRACT/AVERAGE DATA SETS.
C	(7) WRITE OUT THE ACTIVE DATA SET.
C
     	INCLUDE		'XYPLOT.CBS'
    	CHARACTER	TEXT*80, ITEM(7)*30
     	COMMON/XYPLOT_MENU/ JSET, IKEY, NCHS, TEXT
     	DATA ITEM(1) / 'SWAP THE X,Y COLUMNS' /
     	DATA ITEM(2) / 'SORT ON X-COORDINATES' /
     	DATA ITEM(3) / 'SORT ON Y-COORDINATES' /
     	DATA ITEM(4) / 'DATA SMOOTHING' /
     	DATA ITEM(5) / 'LEAST-SQUARE POLYNOMIAL' /
     	DATA ITEM(6) / 'ADD/SUBTRACT/AVERAGE DATA SETS' /
     	DATA ITEM(7) / 'WRITE OUT THE ACTIVE DATA SET' /
C
C  DISPLAY THE MENU...
C
     	IKEY = 0
     	IF( .NOT.MENU ) CALL IFINIT_LINE(24)
     	CALL IFANSI_MARGIN(14,0)
     	CALL IFANSI_CURSOR(2,1)
     	CALL IFANSI_CLEAR(2)
     	CALL IFANSI_VIDEO(47)
     	CALL IFANSI_VIDEO(80)
     	CALL IFANSI_VIDEO(90)
     	TEXT(1:40) = '     M E N U   O F   D A T A   M A N I P'
        TEXT(41: ) = ' U L A T I O N   U T I L I T I E S      '
     	CALL IFANSI_TEXT( TEXT, 80, 3, 1 )
     	CALL IFANSI_VIDEO(47)
     	WRITE(6,1000)
1000	FORMAT(/
     + 10X,'1>',35X,' ACTIVE SET:'/,10X,'2>',35X,'DATA POINTS:'/
     + 10X,'3>',35X,'  X-MINIMUM:'/,10X,'4>',35X,'  X-MAXIMUM:'/
     + 10X,'5>',35X,'  Y-MINIMUM:'/,10X,'6>',35X,'  Y-MAXIMUM:'/
     + 10X,'7>'//
     +,10X'PF1> DOWN-ACTIVE-SET   PF3> UP-ACTIVE-SET   0> EXIT')
     	DO I=1, 7
     	   NCH = IFMISC_LENG(ITEM(I))
     	   CALL IFANSI_TEXT( ITEM(I), NCH, 4+I, 13 )
     	ENDDO
        TEXT = '               Please press a desired function code'
     	CALL IFANSI_VIDEO(30)
     	CALL IFANSI_TEXT( TEXT, 68, 14, 6 )

  111	CALL IFANSI_VIDEO(20)
     	CALL IFANSI_IFL( JSET, 1, 'I5', 5, 59 )
     	CALL IFANSI_TEXT('      ', 6, 5, 64 )
     	NCHS = LSET(1,JSET)
     	CALL IFANSI_IFL( NUMS(NCHS), 1, 'I5', 6, 59 )
     	CALL IFANSI_TEXT('      ', 6, 6, 64 )
     	CALL IFANSI_FFL( SRNG(1,NCHS), 1, 'G11.4', 7, 59 )
     	CALL IFANSI_FFL( SRNG(2,NCHS), 1, 'G11.4', 8, 59 )
     	CALL IFANSI_FFL( SRNG(3,NCHS), 1, 'G11.4', 9, 59 )
     	CALL IFANSI_FFL( SRNG(4,NCHS), 1, 'G11.4',10, 59 )

  333	IF( IKEY.GT.0 ) THEN
     	    CALL IFANSI_VIDEO(30)
     	    CALL IFANSI_TEXT(' ITS DONE ', 10, 12, 53 )
     	ENDIF

  222	CALL IFANSI_VIDEO(47)
     	CALL IFANSI_CURSOR(13,54)
     	CALL IFQIOW_KEY( KEY )
     	IF( KEY.EQ.32.OR.KEY.EQ.48.OR.KEY.EQ.26.OR.KEY.EQ.69 ) GOTO 999
C
C  GET THE OPTION...
C
     	CALL IFANSI_CURSOR(12,1)
     	CALL IFANSI_CLEAR(6)
     	CALL IFANSI_CURSOR(14,1)
     	CALL IFANSI_CLEAR(2)
     	IF( KEY.EQ.-80 ) THEN
     	    JSET = JSET + 1
     	    IF( JSET.GT.NSET ) JSET = 1
     	    IKEY = 0
     	    GOTO 111
     	ELSE IF( KEY.EQ.-82 ) THEN
     	    JSET = JSET - 1
     	    IF( JSET.LT.1 ) JSET = NSET
     	    IKEY = 0
     	    GOTO 111
     	ELSE IF( KEY.GT.48 .AND. KEY.LT.56 ) THEN
     	    KEY = KEY - 48
     	    IF( KEY.EQ.6 ) THEN
     		IF( MSET.EQ.MNST ) THEN
     		    CALL IFMISC_OOPS( 22, 12, 12, ' ' )
     		    GOTO 222
     		ENDIF
     		IF( NSET.EQ.1 ) THEN
     		    CALL IFMISC_OOPS( 11, 12, 12, ' ' )
     		    GOTO 222
     		ENDIF
     	    ENDIF
     	    NCH = IFMISC_LENG( ITEM(KEY) )
     	    CALL IFANSI_VIDEO(30)
     	    CALL IFANSI_TEXT( ITEM(KEY), NCH, KEY+4, 13 )
     	    CALL IFANSI_VIDEO(47)
     	    CALL IFANSI_CURSOR(14,1)
     	    IF( KEY.EQ.1 ) THEN
     		IKEY = XYPLOT_MISC_SWAP(JSET,MNST,MNPT,
     +                 %VAL(IXAR),%VAL(IYAR))
     	    ELSE IF( KEY.EQ.2 ) THEN
     		IKEY = XYPLOT_MISC_SORT( 'X', JSET, MNST, MNPT,
     +                 %VAL(IXAR), %VAL(IYAR) )
     	    ELSE IF( KEY.EQ.3 ) THEN
     		IKEY = XYPLOT_MISC_SORT( 'Y', JSET, MNST, MNPT,
     +                 %VAL(IXAR), %VAL(IYAR) )
     	    ELSE IF( KEY.EQ.4 ) THEN
     		IKEY = XYPLOT_MISC_SMOOTH( JSET, MNST, MNPT,
     +                 %VAL(IXAR), %VAL(IYAR) )
     	    ELSE IF( KEY.EQ.5 ) THEN
     		IKEY = XYPLOT_MISC_LSQ( JSET, MNST, MNPT,
     +                 %VAL(IXAR), %VAL(IYAR) )
     	    ELSE IF( KEY.EQ.6 ) THEN
     		IKEY = XYPLOT_MISC_ADD( JSET, MNST, MNPT,
     +                 %VAL(IXAR), %VAL(IYAR) )
     	    ELSE IF( KEY.EQ.7 ) THEN
     		IKEY = XYPLOT_MISC_OUT( JSET, MNST, MNPT,
     +                 %VAL(IXAR), %VAL(IYAR) )
     	    ENDIF
     	    CALL IFANSI_TEXT( ITEM(KEY), NCH, KEY+4, 13 )
     	    IF( KEY.EQ.1 ) GOTO 111
     	ELSE
     	    CALL IFMISC_OOPS( 5, 12, 12, ' ' )
     	    GOTO 222
     	ENDIF
     	GOTO 333
  999	CALL IFANSI_MARGIN(0,0)
     	IF( MENU ) THEN
     	    CALL XYPLOT_FORM(JSET)
     	ELSE
     	    CALL IFINIT_LINE(3)
     	ENDIF
     	RETURN
     	END

     	FUNCTION XYPLOT_MISC_SWAP( JSET, MS, MP, X, Y )
C
C	THIS ROUTINE SWAPPS THE X,Y COLUMNS OF DATA SET "JSET".
C
     	INCLUDE 'XYPLOT.CBS'
     	DIMENSION X(MP,MS), Y(MP,MS)

     	K = LSET(1,JSET)
     	DO  I=1, NUMS(K)
     	    TEMP = X(I,K)
     	    X(I,K) = Y(I,K)
     	    Y(I,K) = TEMP
     	ENDDO
     	TEMP = SRNG(1,K)
     	DUMY = SRNG(2,K)
     	SRNG(1,K) = SRNG(3,K)
     	SRNG(2,K) = SRNG(4,K)
     	SRNG(3,K) = TEMP
     	SRNG(4,K) = DUMY
     	XYPLOT_MISC_SWAP = 1

     	RETURN
     	END

     	FUNCTION XYPLOT_MISC_SORT( SYM, JSET, MS, MP, X, Y )
C
C	THIS ROUTINE SORTS ACTIVE DATA SET "JSET".
C
     	INCLUDE 'XYPLOT.CBS'
     	DIMENSION X(MP,MS), Y(MP,MS)
     	CHARACTER SYM*1

     	K = LSET(1,JSET)
     	J = LSET(2,JSET)	!ERROR BAR FLAG
     	IF( SYM.EQ.'X' ) THEN	!SORT ON X-COORDINATES
     	    IF( J.EQ.0 ) THEN
     		CALL IFMISC_SORT_ONE(NUMS(K),X(1,K),Y(1,K))
     	    ELSE
     		CALL IFMISC_SORT_TWO(NUMS(K),X(1,K),Y(1,K),Y(1,K+1))
     	    ENDIF
     	ELSE			!SORT ON Y-COORDINATES
     	    IF( J.EQ.0 ) THEN
     		CALL IFMISC_SORT_ONE(NUMS(K),Y(1,K),X(1,K))
     	    ELSE
     		CALL IFMISC_SORT_TWO(NUMS(K),Y(1,K),Y(1,K+1),X(1,K))
     	    ENDIF
     	ENDIF
     	XYPLOT_MISC_SORT = 1

     	RETURN
     	END

     	FUNCTION XYPLOT_MISC_SMOOTH( JSET, MS, MP, X, Y )
C
C	THIS ROUTINE SMOOTHS ACTIVE DATA SET "JSET"
C       USING A 5-POINTS CUBIC LEAST-SQUARE FIT.
C
     	INCLUDE		'XYPLOT.CBS'
     	DIMENSION	X(MP,MS), Y(MP,MS)
     	LOGICAL		PLOT
C
C  GET NUMBER OF FILTERING PASSES...
C
     	K    = LSET(1,JSET)
     	KSDS = LSET(2,JSET)
     	NPTS = NUMS(K)
        IF( NPTS.LT.5 ) THEN
            WRITE(6,111)
 111        FORMAT('_oops: min 5 data points required for smoothing.')
            GOTO 999
        ELSE
 221        WRITE(6,222)
 222        FORMAT(/' Enter number of filtering passes [1]: ',$)
            READ(5,333,ERR=221,END=999) NPASS
 333        FORMAT(I5)
            IF( NPASS.LT.1 .OR. NPASS.GT.99 ) NPASS = 1
        ENDIF
C
C  ALLOCATE SCRATCH ARRAY FOR SMOOTHING...
C
     	I = LIB$GET_VM( 4*NPTS, JYY )
     	IF( .NOT.I ) THEN
            CALL IFMISC_OOPS( 6, 0, 0, ' ' )
            GOTO 999
        ENDIF
C
C  IF STORAGE SPACE AVAILABLE, SAVE THE SMOOTHED DATA SET...
C
     	PLOT = .FALSE.
     	IF( MSET.LT.MNST ) THEN
     	    NSET = NSET + 1
     	    MSET = MSET + 1
     	    DO  I=1, NPTS
     		X(I,MSET) = X(I,K)
     		Y(I,MSET) = Y(I,K)
     	    ENDDO
     	    LSET(1,NSET) = MSET
     	    LSET(2,NSET) = 0
     	    K = MSET
     	    KSDS = 0
     	    PLOT = .TRUE.
     	ENDIF
        WRITE(6,444)
 444    FORMAT(/' DATA SMOOTHING using a moving 5-point cubic',
     +' least-square fit...',$)
     	CALL IFMISC_SMOOTH( NPTS, Y(1,K), %VAL(JYY), NPASS )
        CALL LIB$FREE_VM( 4*NPTS, JYY )
     	NUMS(K) = NPTS
     	CALL IFMISC_RANGE( NPTS, X(1,K), Y(1,K), SRNG(1,K) )
     	IF( PLOT ) WRITE(6,888) NSET
 888	FORMAT(' Smoothed data have been saved in data set #',I3,'.')
     	XYPLOT_MISC_SMOOTH = 1
     	RETURN
 999	XYPLOT_MISC_SMOOTH = 0
     	RETURN
     	END

     	FUNCTION XYPLOT_MISC_LSQ( JSET, MS, MP, X, Y )
C
C	THIS ROUTINE IMPLEMENTS A LINEAR LEAST-SQUARE PROCEDURE
C	FOR POLYNOMIAL REGRESSION.
C
     	INCLUDE		'XYPLOT.CBS'
     	DIMENSION	X(MP,MS), Y(MP,MS)
     	CHARACTER	XTYP*8, YTYP*8
    	REAL*8		XYPLOT_MISC_FIT, SDEV, SERR, RERR, COEF(10)
C
C  INFORM USER OF THE REGRESSION SPACE TO BE IN...
C
     	IF( ISET(JSET).NE.2 ) THEN
     	    MDEG = 1
     	    LXXX = IABS(LAXS(1))
     	    LYYY = IABS(LAXS(2))
     	ELSE
     	    MDEG = 2
     	    LXXX = IABS(LAXS(3))
     	    LYYY = IABS(LAXS(4))
     	ENDIF
     	IF( LXXX.EQ.1 ) THEN
     	    XTYP = 'LINEAR'
     	ELSE IF( LXXX.EQ.2 ) THEN
     	    XTYP = 'LOG10'
     	ELSE IF( LXXX.EQ.3 ) THEN
     	    XTYP = 'INVERSE'
     	ENDIF
     	IF( LYYY.EQ.1 ) THEN
     	    YTYP = 'LINEAR'
     	ELSE IF( LYYY.EQ.2 ) THEN
     	    YTYP = 'LOG10'
     	ELSE IF( LYYY.EQ.3 ) THEN
     	    YTYP = 'INVERSE'
     	ENDIF
C
C  ALLOCATE SCRATCH ARRAYS FOR CURVE FIT...
C
     	NBYTES = 4*(MNPT+3)
     	I = LIB$GET_VM( NBYTES, JXX )
     	IF( .NOT.I ) GOTO 9999
     	I = LIB$GET_VM( NBYTES, JYY )
     	IF( .NOT.I ) GOTO 9999
     	I = LIB$GET_VM( NBYTES, JYB )
     	IF( .NOT.I ) GOTO 9999
C
C  LOAD THE DATA SET...
C
     	NPTS = XYPLOT_LOAD( MDEG, JSET, MNST, MNPT, %VAL(IXAR),
     +         %VAL(IYAR), %VAL(JXX), %VAL(JYY), %VAL(JYB) )
     	MDEG = IFMISC_LENG(XTYP)
     	NDEG = IFMISC_LENG(YTYP)
     	WRITE(6,1002) XTYP(1:MDEG), YTYP(1:NDEG), NPTS
1002	FORMAT(' Note: Regression to be carried out in current axis',
     +' types (X-',A,', Y-',A,'),',/' scale window, and point',
     +' stride: ',I3,' data points sampled from the set.')
     	IF( NPTS.LT.3 ) THEN
     	    CALL IFMISC_OOPS( 11, 0, 0, ' ' )
     	    GOTO 999
     	ENDIF
C
C  GET FITTING POLYNOMIAL DEGREE...
C
     	WRITE(6,1000)
1000	FORMAT(/' Enter degree of fitting polynomial',
     +' (1-9,0>BEST-FIT) [0] ',$)
 111	CALL IFQIOW_KEY( NDEG )
     	IF( NDEG.EQ.26 ) GOTO 999
     	IF( NDEG.EQ.13 .OR. NDEG.EQ.32 ) NDEG = 48
     	IF( NDEG.LT.48 .OR. NDEG.GT.57 ) GOTO 111
     	NDEG = NDEG - 48
C
C  FIND THE BEST FIT POLYNOMIAL...
C
     	IF( NDEG.EQ.0 ) THEN
     	    MDEG = 9
     	    IF( MDEG.GT.(NPTS-2) ) MDEG = NPTS - 2
     	    NDEG = 1
     	    RMIN = 1.7E+38
     	    DO  I = 1, MDEG
     		SDEV=XYPLOT_MISC_FIT(NPTS,%VAL(JXX),%VAL(JYY),I,COEF)
     		IF( SDEV.EQ.0.0 ) GOTO 222
     		WRITE(6,1001) I, SDEV
     		IF( SDEV.LT.RMIN ) THEN
     		    RMIN = SDEV
     		    NDEG = I
     		ENDIF
     	    ENDDO
     	ELSE
     	    IF( NDEG.GT.(NPTS-2) ) NDEG = NPTS - 2
     	ENDIF
1001	FORMAT(' Polynomial degree> ',I1,' .... SD of fit> ',G12.5)

  222	SDEV = XYPLOT_MISC_FIT(NPTS,%VAL(JXX),%VAL(JYY),NDEG,COEF)
     	IF( SDEV.EQ.0.0 ) GOTO 777	!SINGULAR MATRIX
C
C  REPORT THE RESULTS...
C
     	WRITE(6,2000) NDEG
2000	FORMAT(/' Polynomial coefficients (degree=',I1,'):'/)
     	WRITE(6,2001) (COEF(I),I-1,I=1,NDEG+1)
2001	FORMAT(2(10X,G12.5,'*X**',I1))
     	WRITE(6,2002) SDEV
2002	FORMAT(/' Standard deviation of fit:',G12.5)
C
C  IF X,Y ARRAYS NOT FULL, STORE THE POLYNOMIAL FOR LATER PLOTTING...
C
     	IF( MSET.LT.MNST ) THEN
     	    NSET = NSET + 1
     	    MSET = MSET + 1
     	    LSET(1,NSET) = MSET
     	    LSET(2,NSET) = 0
     	    NPTS = 100
     	    NUMS(MSET) = NPTS
     	    PLOT = .TRUE.
     	    MDEG = LSET(1,JSET)
     	    STEP = (SRNG(2,MDEG)-SRNG(1,MDEG))/(NPTS-1)
     	    SDEV = SRNG(1,MDEG)-STEP
     	    DO  I=1, NPTS
     		YCAL = COEF(1)
     		RMIN = SDEV + STEP*I
     		IF( LXXX.EQ.2 ) RMIN = LOG10(RMIN)
     		IF( LXXX.EQ.3 ) RMIN = 1.0/RMIN
     		DO  J=1, NDEG
     		    YCAL = YCAL + COEF(J+1)*RMIN**J
     		ENDDO
     		IF( LXXX.EQ.2 ) RMIN = 10.0**RMIN
     		IF( LXXX.EQ.3 ) RMIN = 1.0/RMIN
     		X(I,MSET) = RMIN
     		RMIN = YCAL
     		IF( LYYY.EQ.2 ) RMIN = 10.0**RMIN
     		IF( LYYY.EQ.3 ) RMIN = 1.0/RMIN
     		Y(I,MSET) = RMIN
     	    ENDDO
     	    CALL IFMISC_RANGE(NPTS,X(1,MSET),Y(1,MSET),SRNG(1,MSET))
     	    WRITE(6,2003) NSET
     	ELSE
     	    WRITE(6,2004)
     	ENDIF
2003	FORMAT(' Polynomial have been saved in data set #',I3,'.')
2004	FORMAT(' Polynomial is not saved. Data sets full.')
     	XYPLOT_MISC_LSQ = 1.0
     	GOTO 999
888	XYPLOT_MISC_LSQ = 0.0
     	RETURN
777	WRITE(6,778)
778	FORMAT('_oops: Matrix singular. Run aborted.')
C
C  DEALLOCATE THE VIRTUAL MEMORY...
C
999	CALL LIB$FREE_VM( NBYTES, JXX )
     	CALL LIB$FREE_VM( NBYTES, JYY )
     	CALL LIB$FREE_VM( NBYTES, JYB )
     	RETURN
9999	CALL IFMISC_OOPS( 6, 0, 0, ' ' )
     	RETURN
     	END

     	REAL*8 FUNCTION XYPLOT_MISC_FIT(M,X,Y,N,B)
C
C	THIS FUNCTION CARRIES OUT AN NTH ORDER POLYNOMIAL
C	REGRESSION ON M DATA POINTS CONTAINED IN THE X AND Y ARRAYS.
C	THE FUNCTION NORMALLY RETURNS THE STANDARD DEVIATION SDEV OF
C	THE POINTS ABOUT THE REGRESSION CURVE.  THE REGRESSION
C	COEFFICIENTS ARE PLACED IN A AND B(1)...B(N).  HOWEVER, IF
C	THE SIMULTANEOUS EQUATION SOLVING ROUTINE ENCOUNTERS A
C	NEAR - SINGULAR MATRIX, THE FUNCTION RETURNS THE VALUE 0.0
C	THIS ROUTINE MUST HAVE MORE POINTS THAN DEGREE OF FIT.
C	IF REGLLS ENCOUNTERS LESS POINTS THAN DEGREE REQUESTED
C	NO PROCESSING OCCURS AND NO VALUES ARE RETURNED.
C
     	IMPLICIT REAL*8 (A-H, O-W)
     	REAL*8 XYPLOT_MISC_MATRIX
     	DIMENSION X(M),Y(M),B(N)
     	DIMENSION C(11,11),SX(20),SYX(10),CYX(10)
     	DATA EPS / 1.0E-20 /
C
C     ..... COMPUTE SUMS OF POWERS AND PRODUCTS .....
C
	NTWO = 2*N
	NP1 = N + 1
	SY = 0.0
	SYY = 0.0

	DO 1 I = 1,N
	NPI = N + I
	SX(I) = 0.0
	SX(NPI) = 0.0
  1	SYX(I) = 0.0

	DO 3 I = 1,M
     	YI = Y(I)
	SY = SY + YI
	SYY = SYY + YI**2
	DUM = 1.0
	DO 2 J = 1,N
     	XI = X(I)
	DUM = DUM*XI
	SX(J) = SX(J) + DUM
  2	SYX(J) = SYX(J) + YI*DUM
	DO 3 J = NP1,NTWO
	DUM = DUM*XI
  3	SX(J) = SX(J) + DUM
C
C     ..... COMPUTE COEFFICIENTS C(I,J) .....
C
	FM = M
	CYY = SYY - SY*SY/FM
	DO 4 I = 1,N
	CYX(I) = SYX(I) - SY*SX(I)/FM
	C(I,NP1) = CYX(I)
	DO 4 J = 1,N
	IPJ = I + J
  4	C(I,J) = SX(IPJ) - SX(I)*SX(J)/FM
C
C     ..... SOLVE SIMULTANEOUS EQUATIONS .....
C
	DET = XYPLOT_MISC_MATRIX(N,C,B,EPS,1,11)
	IF( DET.NE.0.0 )GO TO 6
	XYPLOT_MISC_FIT = 0.0
	RETURN
C
C     ..... COMPUTE INTERCEPT AND STANDARD DEVIATION SDEV .....
C
  6	DUM = SY
	DUMY = CYY
	DO 7 I = 1,N
	DUM = DUM - B(I)*SX(I)
  7	DUMY = DUMY - B(I)*CYX(I)
     	DO I=N,1,-1
     	   B(I+1) = B(I)
     	ENDDO
     	B(1) = DUM/FM
	DENOM = M - N - 1
	XYPLOT_MISC_FIT = DSQRT(DUMY/DENOM)
	RETURN
	END

     	REAL*8 FUNCTION XYPLOT_MISC_MATRIX(N,A,X,EPS,INDIC,NRC)
C
C	WHEN INDIC IS NEGATIVE, SIMULS COMPUTES THE INVERSE OF THE N
C	BY N MATRIX A IN PLACE.  WHEN INIC IS ZERO, SIMULS COMPUTES
C	THE N SOLUTIONS X(1)...X(N) CORRESPONDING TO THE SET OF LINEAR
C	EQUATIONS WITH AUGMENTED MATRIX OF COEFFICIENTS IN THE N BY
C	N + 1 ARRAY A AND IN ADDITION COMPUTES THE INVERSE OF THE
C	COEFFICIENT MATRIX IN PLACE AS ABOVE.  IF INDIC IS POSITIVE
C	THE SET OF LINEAR EQUATIONS IS SOLVED BUT THE INVERSE IS NOT
C	COMPUTED IN PLACE.  THE GAUSS - JORDEN COMPLETE ELIMINATION METHOD
C	IS EMPLOYED WITH THE MAXIMUM PIVOT STRATEGY.  ROW AND COLUMN
C	SUBSCRIPTS OF SUCCESSIVE PIVOT ELEMENTS ARE SAVED IN ORDER IN
C	THE IROW AND JCOL ARRAYS RESPECTIVELY.  K IS THE PIVOT COUNTER,
C	PIVOT THE ALGEBRAIC VALUE OF THE PIVOT ELEMENT, MAX
C	THE NUMBER OF COLUMNS IN A AND DETER THE DETERMINANT OF THE
C	COEFFICIENT MATRIX.  THE SOLUTIONS ARE COMPUTED IN THE (N + 1)TH
C	COLUMN OF A AND THEN UNSCRAMBLED AND PUT IN PROPER ORDER IN
C	X(1)...X(N) USING THE PIVOT SUBSCRIPT INFORMATION AVAILABLE
C	IN THE IROW AND JCOL ARRAYS,  THE SIGN OF THE DETERMINANT IS
C	ASJUSTED, IF NECESSARY, BY DETERIMINING IF AN ODD OR EVEN NUMBER
C	OF PAIRWISE INTERCHANGES IS REQUIRED TO PUT THE ELEMENTS OF THE
C	JORD ARRAY IN ASCENDING SEQUENCE WHERE JORD(IROW(I)) = JCOL(I).
C	IF THE INVERSE IS REQUIRED, IT IS UNSCRAMBLED IN PLACE USING
C	Y(1)...Y(N) AS TEMPORARY STORAGE.  THE VALUE OF THE DETERMINANT
C	IS RETURNED AS THE VALUE OF THE FUNCTION.  SHOULD THE POTENTIAL
C	PIVOT OF LARGEST MAGNITUDE BE SMALLER IN MAGNITUDE THAN EPS,
C	THE MATRIX IS CONSIDERED TO BE SINGULAR AND A TRUE ZERO IS
C	RETURNED AS THE VALUE OF THE FUNCTION.
C
     	IMPLICIT REAL*8 (A-H, O-Z)
     	DIMENSION IROW(11),JCOL(11),JORD(11),Y(11),A(NRC,NRC),X(N)

     	MAX = N
     	IF(INDIC.GE.0.0) MAX = N + 1
C
C     ..... BEGIN ELIMINATION PROCEDURE .....
C
	DETER = 1.0
	DO 18 K = 1,N
	KM1 = K - 1
C
C     ..... SEARCH FOR THE PIVOT ELEMENT .....
C
	PIVOT = 0.0
	DO 11 I = 1,N
	DO 11 J = 1,N
C
C     ..... SCAN IROW AND JCOL ARRAYS FOR INVALID PIVOT SUBSCRIPTS.....
C
	IF(K .EQ. 1)GO TO 9
	DO 8 ISCAN = 1,KM1
	DO 8 JSCAN = 1,KM1
	IF(I .EQ. IROW(ISCAN))GO TO 11
8	IF(J .EQ. JCOL(JSCAN))GO TO 11
9	IF(DABS(A(I,J)).LE.DABS(PIVOT))GO TO 11
	PIVOT = A(I,J)
	IROW(K) = I
	JCOL(K) = J
11	CONTINUE
C
C     ..... INSURE THAT SELECTED PIVOT IS LARGER THAN EPS .....
C
	IF(DABS(PIVOT).GT.EPS)GO TO 13
	XYPLOT_MISC_MATRIX = 0.0
	RETURN
C
C     ..... UPDATE THE DETERMINANT VALUE .....
C
13	IROWK = IROW(K)
	JCOLK = JCOL(K)
	DETER = DETER*PIVOT
C
C     ..... NORMALIZE PIVOT ROW ELEMENTS .....
C
	DO 14 J = 1,MAX
14	A(IROWK,J) = A(IROWK,J)/PIVOT
C
C     ..... CARRY OUT ELIMINATION AND CARRY OUT INVERSE .....
C
	A(IROWK,JCOLK) = 1.0/PIVOT
	DO 18 I = 1,N
	AIJCK = A(I,JCOLK)
	IF(I .EQ. IROWK)GO TO 18
	A(I,JCOLK) =  - AIJCK/PIVOT
	DO 17 J = 1,MAX
17	IF(J .NE. JCOLK) A(I,J) = A(I,J) - AIJCK*A(IROWK,J)
18	CONTINUE
C
C     ..... ORDER SOLUTION VALUES (IF ANY) AND CREATE JORD ARRAY .....
C
	DO 20 I = 1,N
	IROWI = IROW(I)
	JCOLI = JCOL(I)
	JORD(IROWI) = JCOLI
20	IF(INDIC.GE.0.0) X(JCOLI) = A(IROWI,MAX)
C
C     ..... ADJUST SIGN OF DETERMINANT .....
C
	INTCH = 0
	NM1 = N - 1
	DO 22 I = 1,NM1
	IP1 = I + 1
	DO 22 J = IP1,N
	IF(JORD(J).GE.JORD(I))GO TO 22
	JTEMP = JORD(J)
	JORD(J) = JORD(I)
	JORD(I) = JTEMP
	INTCH = INTCH + 1
22	CONTINUE
	IF(INTCH/2*2 .NE. INTCH) DETER =  - DETER
C
C     ..... IF INDIC IS POSITIVE RETURN WITH RESULTS .....
C
24	IF(INDIC.LE.0) GO TO 26
	XYPLOT_MISC_MATRIX = DETER
	RETURN
C
C     ..... IF INDIC IS ZERO OR NEGATIVE, UNSCRAMBLE THE INVERSE
C     FIRST BY ROWS .....
C
26	DO 28 J = 1,N
	DO 27 I = 1,N
	IROWI = IROW(I)
	JCOLI = JCOL(I)
27	Y(JCOLI) = A(IROWI,J)
	DO 28 I = 1,N
28	A(I,J) = Y(I)
C
C     ..... AND THEN BY COLUMNS .....
C
	DO 30 I = 1,N
	DO 29 J = 1,N
	IROWJ = IROW(J)
	JCOLJ = JCOL(J)
29	Y(IROWJ) = A(I,JCOLJ)
	DO 30 J = 1,N
30	A(I,J) = Y(J)
C
C     ..... RETURN FOR INDIC NEGATIVE OR ZERO .....
C
	XYPLOT_MISC_MATRIX = DETER
	RETURN
	END

     	SUBROUTINE XYPLOT_WRITE
C
C	THIS ROUTINE WRITES CURRENT DATA SETS INTO A FILE.
C
C	DEFAULT FILE FORMAT IS FORMAT NUMBER 1 --- ASCII.
C
     	INCLUDE		'XYPLOT.CBS'
    	CHARACTER	TEXT*80
     	COMMON/XYPLOT_MENU/ JSET, IKEY, NCHS, TEXT
C
C  PARSE DATA FORMAT QUALIFIER...
C
     	NCHS = IFMISC_NEXT(TEXT)
     	IF( NCHS.EQ.0 ) THEN
     	    NCHS = IFMISC_PROMPT('_Filename:',TEXT,SLIN+1,9)
     	    IF( NCHS.EQ.0 ) GOTO 999
     	ENDIF
     	IFOM = 1
     	ISLA = INDEX( TEXT(1:NCHS), '/' )
     	IF( ISLA.GT.0 ) THEN
     	    ISLA = INDEX( TEXT(1:NCHS), '/FORMAT=' )
     	    IF( ISLA.LT.2 ) GOTO 777
     	    READ( TEXT(ISLA+8:ISLA+8), 111, ERR=888 ) IFOM
C     	    DECODE( 1, 111, TEXT(ISLA+8:ISLA+8), ERR=888 ) IFOM
  111	    FORMAT(I1)
     	    IF( IFOM.LT.1 .OR. IFOM.GT.6 ) GOTO 888
     	    TEXT = TEXT(1:ISLA-1)
     	    NCHS = ISLA - 1
     	ENDIF
     	IF( NCHS.GT.32 ) THEN
     	    CALL IFMISC_OOPS( 7, SLIN, SCOL, TEXT )
     	    GOTO 999
     	ENDIF
C
C  WRITE THE FILE IN THE SPECIFIED FORMAT...
C
     	CALL XYPLOT_WRITE_DATA( TEXT, IFOM, MNST, MNPT,
     +                          %VAL(IXAR), %VAL(IYAR) )
     	GOTO 999
777	CALL XYPLOT_OOPS(' Invalid command qualifier.')
     	GOTO 999
888	CALL XYPLOT_OOPS(' Invalid data format number.')
999	RETURN
     	END

     	SUBROUTINE XYPLOT_WRITE_DATA( FNAME,IFOM, MS,MP,X,Y )
C
C	THIS ROUTINE WRITES OUT CURRENT DATA SETS.
C
     	INCLUDE 'XYPLOT.CBS'
     	DIMENSION X(MP,MS), Y(MP,MS)
     	CHARACTER TEXT*75, DNAME*32, FNAME*(*)

     	IFORM = IFOM
     	DNAME = FNAME
C
C  OPEN THE OUTPUT FILE...
C
     	IF( IFORM.LT.5 ) THEN
     	    OPEN( UNIT=13, FILE=DNAME, STATUS='NEW', FORM='FORMATTED',
     +            CARRIAGECONTROL='LIST', ERR=888 )
     	ELSE
     	    OPEN( UNIT=13, FILE=DNAME, STATUS='NEW', FORM='UNFORMATTED',
     +            ERR=888)
     	ENDIF
C
C  WRITE THE DATA SETS OUT...
C
     	IF( IFORM.EQ.1 ) THEN
     	    DO  I=1, NSET
     		K = LSET(1,I)
     		J = LSET(2,I)
     		NPTS = NUMS(K)
     		WRITE(13,1000,ERR=888) NPTS, LABL(K)
     		IF( J.EQ.0 ) THEN
     		    WRITE(13,1001,ERR=888) (X(N,K),Y(N,K),N=1,NPTS)
     		ELSE
     	WRITE(13,1002,ERR=888) (X(N,K),Y(N,K),Y(N,K+1),N=1,NPTS)
     		ENDIF
     	    ENDDO
1000	    FORMAT(I5,X,'!',A80)
1001	    FORMAT(2G13.5)
1002	    FORMAT(3G13.5)
     	ELSE IF( IFORM.EQ.2 ) THEN
     	    DO  I=1, NSET
     		K = LSET(1,I)
     		J = LSET(2,I)
     		NPTS = NUMS(K)
     		IF( J.EQ.0 ) THEN
     		    WRITE(13,1001,ERR=888) (X(N,K),Y(N,K),N=1,NPTS-1)
     		    WRITE(13,2001,ERR=888) X(NPTS,K),Y(NPTS,K),I,LABL(K)
     		ELSE
     	WRITE(13,1002,ERR=888) (X(N,K),Y(N,K),Y(N,K+1),N=1,NPTS-1)
     	WRITE(13,2002,ERR=888) X(NPTS,K),Y(NPTS,K),Y(NPTS,K+1),I,LABL(K)
     		ENDIF
     	    ENDDO
2001	    FORMAT(2G13.5,',,',I3,X,'!',A80)
2002	    FORMAT(3G13.5,I4,X,'!',A80)
     	ELSE IF( IFORM.EQ.3 ) THEN
     	    J = NSET
     	    IF( J.GT.9 ) J = 9
     	    WRITE(13,3001,ERR=888) -J
     	    WRITE(13,3002,ERR=888) (X(I,1),(Y(I,LSET(1,K)),K=1,J),
     +                              I=1,NUMS(1))
3001	    FORMAT(I5)
3002	    FORMAT(<J+1>G13.5)
     	ELSE IF( IFORM.EQ.4 ) THEN
     	    DO  I=1, NSET
     		K = LSET(1,I)
     		NPTS = NUMS(K)
     	WRITE(13,4001,ERR=888) X(1,K),X(NPTS,K),X(2,K)-X(1,K),LABL(K)
     		WRITE(13,4002,ERR=888) (Y(J,K),J=1,NPTS)
     	    ENDDO
4001	    FORMAT(3G13.5,X,'!',A80)
4002	    FORMAT(6G13.5)
     	ELSE IF( IFORM.EQ.5 ) THEN
     	    J = 1
     	    DO  I=1, NSET
     		K = LSET(1,I)
     		NPTS = NUMS(K)
     		WRITE(13,ERR=888) NPTS, J
     		WRITE(13,ERR=888) (X(N,K),N=1,NPTS)
     		WRITE(13,ERR=888) (Y(N,K),N=1,NPTS)
     	    ENDDO
     	ELSE IF( IFORM.EQ.6 ) THEN
     	    DO  I=1, NSET
     		K = LSET(1,I)
     		NPTS = NUMS(K)
     		WRITE(13,ERR=888) X(1,K),X(NPTS,K),X(2,K)-X(1,K)
     		WRITE(13,ERR=888) (Y(N,K),N=1,NPTS)
     	    ENDDO
     	ENDIF
     	TEXT = ' '
     	TEXT(2:) = DNAME
     	NPTS = IFMISC_LENG( DNAME )
     	TEXT(NPTS+3:) = 'written in data format # .'
     	WRITE( TEXT(NPTS+27:NPTS+27), 777 ) IFORM
C     	ENCODE( 1, 777, TEXT(NPTS+27:) ) IFORM
777	FORMAT(I1)
     	CALL XYPLOT_OOPS( TEXT )
     	GOTO 999

888	CALL IFMISC_OOPS( 21, SLIN, SCOL, DNAME )
999	CLOSE(UNIT=13)
     	RETURN
     	END

     	SUBROUTINE XYPLOT_SAVE
C
C	THIS ROUTINE SAVES CURRENT PLOT SETUP IN A PARAMETER FILE.
C
     	INCLUDE		'XYPLOT.CBS'
    	CHARACTER	TEXT*80, STRN*75
     	COMMON/XYPLOT_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 = XYPLOT_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 XYPLOT_OOPS( STRN )
     	ENDIF

999	RETURN
     	END

     	SUBROUTINE XYPLOT_OOPS( TEXT )
     	INCLUDE 'XYPLOT.CBS'
     	CHARACTER TEXT*(*)
     	NCHS = IFMISC_LENG( TEXT )
     	IF( SLIN.GT.0 .AND. SCOL.GT.0 ) THEN
     	    CALL XYPLOT_CLEAR_OOPS
     	    CALL IFANSI_TEXT( TEXT, NCHS, SLIN, SCOL )
     	ELSE
     	    WRITE(6,1000) TEXT(1:NCHS)
1000	    FORMAT('_oops: ',A)
     	ENDIF
     	RETURN
     	END

     	SUBROUTINE XYPLOT_CLEAR_OOPS
     	INCLUDE 'XYPLOT.CBS'
     	IF( MENU ) THEN
     	    CALL IFANSI_CURSOR(SLIN,SCOL)
     	    CALL IFANSI_CLEAR(4)
     	ENDIF
     	RETURN
     	END

    	SUBROUTINE XYPLOT_GIN( Z1, Z2 )
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY, JUNE-1986
C
C	THIS ROUTINE IMPLEMENTS GRAPHICS INPUT -- GIN FOR X,Y PLOT.
C
C	Z1,Z2: return the coordinates of last two cursor positions.
C
    	INCLUDE   'XYPLOT.CBS'
    	BYTE       ESC
     	DIMENSION  Z1(1), Z2(1)

     	Z1(1) = 0.0
     	Z1(2) = 0.0
     	Z2(1) = 0.0
     	Z2(2) = 0.0
     	IF( CRT.NE.2 ) THEN
     	    CALL IFMISC_OOPS( 17, 0, 0, 'GIN' )
     	    GOTO 999
     	ENDIF
C
C  GET THE SCALE UNITS...
C
     	CALL XYPLOT_VINCH( 1, XDL, YDL )
     	CALL XYPLOT_LIMIT( 1, XLO, XHI, YLO, YHI )
     	IF( XDL.LT.0.0 ) XLO = XHI
     	IF( YDL.LT.0.0 ) YLO = YHI
     	LXX = IABS(LAXS(1))
     	LYY = IABS(LAXS(2))
     	XLN = XLNS(1)
     	YLN = XLNS(2)
     	XXL = XLO
     	IF( LXX.EQ.2 ) XXL = 10.0**XXL
     	IF( LXX.EQ.3 ) XXL = 1.00/XXL
     	XXC = XXL
     	YYL = YLO
     	IF( LYY.EQ.2 ) YYL = 10.0**YYL
     	IF( LYY.EQ.3 ) YYL = 1.00/YYL
     	YYC = YYL
     	XPL = 0.0
     	YPL = 0.0
C
C  ENABLE GIN ...
C
     	ESC = 27
     	CALL IFINIT_DIF(0)	!DISABLE DI FILE OUTPUT
     	CALL IFINIT_LINE(3)
     	CALL IFSPEN(3)
    	CALL IFGIN_ABLE(2)
     	CALL IFSEG_MOVE( 0, 0.0, 0.0 )
    	CALL IFINIT_DUMP
     	WRITE(6,1000) ESC,ESC,ESC,ESC
1000	FORMAT(' XYPLOT_GIN> Press ',A1,'[43;30m SPACEBAR '
     +, A1,'[44;37m to enter point; ',A1,'[43;30m RETURN '
     +, A1,'[44;37m to exit...',$)

111	IF( IFGIN_REPORT(JUNK,XPS,YPS).EQ.0 ) GOTO 888
     	IF( XPS.EQ.XPL .AND. YPS.EQ.YPL ) GOTO 111
     	IF( XPS.LT.0.0.OR.XPS.GT.XLN.OR.YPS.LT.0.0.OR.YPS.GT.YLN ) THEN
     	    CALL IFMISC_OOPS( 19, 0, 0, ' ' )
     	    GOTO 111
     	ENDIF
C
C  MARK THE CURSOR POSITION ENTERED...
C
     	CALL IFPLOT( XPS-0.06, YPS, 3 )
     	CALL IFPLOT( XPS+0.06, YPS, 2 )
     	CALL IFPLOT( XPS, YPS-0.06, 3 )
     	CALL IFPLOT( XPS, YPS+0.06, 2 )
    	CALL IFINIT_DUMP
C
C  REPORT THE CURSOR POSITION ENTERED...
C
     	XHI = XLO + XPS*XDL
     	IF( LXX.EQ.2 ) XHI = 10.**XHI
     	IF( LXX.EQ.3 ) XHI = 1.0/XHI
     	YHI = YLO + YPS*YDL
     	IF( LYY.EQ.2 ) YHI = 10.**YHI
     	IF( LYY.EQ.3 ) YHI = 1.0/YHI
     	DIS1 = SQRT( (XPS-XPL)**2 + (YPS-YPL)**2 )
     	DIS2 = SQRT( (XHI-XXC)**2 + (YHI-YYC)**2 )
     	WRITE(6,2000) XPS,YPS, XHI,YHI, DIS1, DIS2
2000	FORMAT(' CURSOR AT ',2F7.3,'(INCHES), ',2G12.5
     +,'(AXIS UNITS).'/' DISTANCE FROM THE LAST: '
     +,F7.3,'(INCHES), ',G12.5,'(AXIS UNITS).')
     	XPL = XPS
     	YPL = YPS
     	XXL = XXC
     	YYL = YYC
     	XXC = XHI
     	YYC = YHI
     	GOTO 111
C
C  END OF THE SESSION...
C
888	CALL IFGIN_ABLE( 0 )
     	CALL IFINIT_DIF(1)		!ENABLE DI FILE OUTPUT
     	Z1(1) = XXL
     	Z2(1) = XXC
     	Z1(2) = YYL
     	Z2(2) = YYC
999	RETURN
    	END

    	FUNCTION XYPLOT_SCALE( IFLAG, MS, MP, X, Y )
C
C  PROGRAMMER: R.S. ZHOU,  ALFRED UNIVERSITY
C
C  	THIS ROUTINE SCALES INPUT DATA FOR X,Y PLOT.
C
C	IFLAG=1: SCALE THE INPUT DATA FOR X-AXIS OF THE 1ST GRAPH BAND.
C	IFLAG=2: SCALE THE INPUT DATA FOR Y-AXIS OF THE 1ST GRAPH BAND.
C	IFLAG=3: SCALE THE INPUT DATA FOR X-AXIS OF THE 2ND GRAPH BAND.
C	IFLAG=4: SCALE THE INPUT DATA FOR Y-AXIS OF THE 2ND GRAPH BAND.
C
C	RETURN WITH XYPLOT_SCALE = 0.0 FOR SCALING FAILURE
C	RETURN WITH XYPLOT_SCALE = 1.0 FOR OK SCALING.
C
    	INCLUDE 'XYPLOT.CBS'
     	DIMENSION X(MP,MS), Y(MP,MS)
C
C  SEARCH FOR MINIMUM AND MAXIMUM X,Y VALUES IN THE DATA...
C
     	IS = IFLAG
     	IT = 2
     	IF( IS.GT.2 ) IT = 1
     	X1 = 1.7E38
     	X2 =-1.7E38
     	DO  I = 1, NSET
    	    IF( IPEN(I).NE.0 .AND. ISET(I).NE.IT ) THEN
     		K = LSET(1,I)
     		IF( IS.NE.2*(IS/2) ) THEN
     		    SCL = XSF(I)
     		    DO  J = 1, NUMS(K), IDEN(I)
     			X3 = SCL*X(J,K)
     			IF( X3.LT.X1 ) X1 = X3
     			IF( X3.GT.X2 ) X2 = X3
     		    ENDDO
     		ELSE
     		    SCL = YSF(I)
     		    DO  J = 1, NUMS(K), IDEN(I)
     			X3 = SCL*Y(J,K)
     			IF( X3.LT.X1 ) X1 = X3
     			IF( X3.GT.X2 ) X2 = X3
     		    ENDDO
     		ENDIF
     	    ENDIF
     	ENDDO
C
C  SCALE THE AXIS...
C
     	IT = IABS(LAXS(IS))
     	IF( IT.NE.2 ) THEN
     	    IF( IT.EQ.3 .AND. X1*X2.LE.0.0 ) GOTO 999
     	    I = IFAXIS_LINSCL( XLNS(IS), X1, X2 )
     	    IF( IT.EQ.3 .AND. X1*X2.LE.0.0 ) GOTO 999
     	    NTKS(IS) = I
     	    XLOW(IS) = X1
     	    XHIG(IS) = X2
     	    XINC(IS) = (X2-X1)/I
     	ELSE
     	    IF( X1.LE.0.0 .OR. X2.LE.0.0 ) GOTO 999
     	    I = IFAXIS_LOGSCL( X1, X2 )
     	    XLOW(IS) = X1
     	    XHIG(IS) = X2
     	    XINC(IS) = I
     	ENDIF
     	XYPLOT_SCALE = 1.0
     	RETURN
C
C  SCALING FAILURE...
C
999	XLOW(IS) = 0.0
     	XHIG(IS) = 0.0
     	XINC(IS) = 0.0
     	XYPLOT_SCALE = 0.0
     	RETURN
     	END

    	SUBROUTINE XYPLOT_LIMIT( IFLAG, XLO,XHI, YLO,YHI )
C
C	THIS ROUTINE CALCULATES SCALE WINDOW OF A X,Y PLOT
C	BECAUSE OF POSSIBLE OFFSETS OF THE 1ST MAJOR TICKMARKS.
C
C	IFLAG=1: RETURN WINDOW OF 1ST GRAPH BAND.
C	IFLAG=2: RETURN WINDOW OF 2ND GRAPH BAND.
C
C	XLO,XHI: WINDOW LIMIT ON X-AXIS.
C	YLO,YHI: WINDOW LIMIT ON Y-AXIS.
C
     	INCLUDE 'XYPLOT.CBS'
C
C  GET THE SCALE UNITS PER INCH FIRST...
C
     	CALL XYPLOT_VINCH( IFLAG, XDL, YDL )
     	IF( IFLAG.EQ.1 ) THEN
     	    KSET = 1
     	ELSE
     	    KSET = 3
     	ENDIF
C
C  CALCULATE THE X-WINDOW ...
C
     	LTYPE = IABS(LAXS(KSET))
     	IF( LTYPE.EQ.1 ) THEN
    	    XLO = XLOW(KSET)
    	    XHI = XHIG(KSET)
    	ELSE IF( LTYPE.EQ.2 ) THEN
    	    XLO = LOG10(XLOW(KSET))
    	    XHI = LOG10(XHIG(KSET))
    	ELSE
     	    XLO = 1.0/XLOW(KSET)
     	    XHI = 1.0/XHIG(KSET)
    	ENDIF
     	XLO = XLO - XDL*OFFS(KSET)
     	XHI = XHI + XDL*OFFS(KSET)
    	IF( XLO.GT.XHI ) THEN
    	    XDL = XLO
    	    XLO = XHI
    	    XHI = XDL
    	ENDIF
C
C  CALCULATE THE Y-WINDOW ...
C
     	LTYPE = IABS(LAXS(KSET+1))
     	IF( LTYPE.EQ.1 ) THEN
    	    YLO = XLOW(KSET+1)
    	    YHI = XHIG(KSET+1)
    	ELSE IF( LTYPE.EQ.2 ) THEN
    	    YLO = LOG10(XLOW(KSET+1))
    	    YHI = LOG10(XHIG(KSET+1))
    	ELSE
     	    YLO = 1.0/XLOW(KSET+1)
     	    YHI = 1.0/XHIG(KSET+1)
    	ENDIF
     	YLO = YLO - YDL*OFFS(KSET+1)
     	YHI = YHI + YDL*OFFS(KSET+1)
    	IF( YLO.GT.YHI ) THEN
    	    YDL = YLO
    	    YLO = YHI
    	    YHI = YDL
    	ENDIF

     	RETURN
    	END

    	SUBROUTINE XYPLOT_VINCH( IFLAG, DELTAX, DELTAY )
C
C	THIS ROUTINE CALCULATES SCALE VALUE PER INCH FOR X,Y PLOT.
C
C	IFLAG=1: RETURN DELTAX AND DELTAY FOR 1ST GRAPH BAND.
C	IFLAG=2: RETURN DELTAX AND DELTAY FOR 2ND GRAPH BAND.
C
C	DELTAX = SCALE VALUE PER INCH OF X-AXIS.
C	DELTAY = SCALE VALUE PER INCH OF Y-AXIS.
C
     	INCLUDE 'XYPLOT.CBS'

     	IF( IFLAG.EQ.1 ) THEN
     	    KSET = 1
     	ELSE
     	    KSET = 3
     	ENDIF
C
C  CALCULATE DELTAX...
C
     	XLENG = XLNS(KSET) - 2.0*OFFS(KSET)
     	LTYPE = IABS(LAXS(KSET))
     	IF( LTYPE.EQ.1 ) THEN
     	    DELTAX = (XHIG(KSET)-XLOW(KSET)) / XLENG
     	ELSE IF( LTYPE.EQ.2 ) THEN
    	    DELTAX = LOG10(XHIG(KSET)/XLOW(KSET)) / XLENG
     	ELSE
     	    DELTAX = (1.0/XHIG(KSET)-1.0/XLOW(KSET)) / XLENG
     	ENDIF
C
C  CALCULATE DELTAY...
C
     	XLENG = XLNS(KSET+1) - 2.0*OFFS(KSET+1)
     	LTYPE = IABS(LAXS(KSET+1))
     	IF( LTYPE.EQ.1 ) THEN
     	    DELTAY = (XHIG(KSET+1)-XLOW(KSET+1)) / XLENG
     	ELSE IF( LTYPE.EQ.2 ) THEN
    	    DELTAY = LOG10(XHIG(KSET+1)/XLOW(KSET+1)) / XLENG
     	ELSE
     	    DELTAY = (1.0/XHIG(KSET+1)-1.0/XLOW(KSET+1)) / XLENG
     	ENDIF

    	RETURN
    	END

    	FUNCTION XYPLOT_SETUP( IFLAG, FNAME )
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY
C
C	THIS ROUTINE WRITES/READS A PARAMETER/SETUP FILE FOR X,Y 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		'XYPLOT.CBS'
    	PARAMETER	NKS= 15, 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', 'XLB2', 'YLB2',
     +            'OVER', 'XAX1', 'YAX1', 'XAX2', 'YAX2',
     +            'SETS', 'LABL', 'PAR1', 'PAR2', 'IDEN' /
C
C  NUMBER OF NUMERIC PARAMETERS IN EACH SETUP GROUP...
C
     	DATA IRR/ 0,0,0,0,0,14,12,12,12,12,13,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,5)
     +, DRAW, MARK, QUAD, NSDS, COL1, COL2
     +, XLPS, YLPS, XORG, YORG, XOFF, YOFF, XSCL, YSCL
     +,(LAXS(I), NTKS(I), MTKS(I), NDGS(I), IGDS(I)
     +, XLNS(I), OFFS(I), SOFF(I), XANG(I)
     +, XLOW(I), XHIG(I), XINC(I), I=1,4)
     +,(HPAR(I), I=1, 20), PLOTID

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

     	WRITE(LUN,1001,ERR=888) (IPEN(I), ISYM(I), ILIN(I), IDEN(I)
     +, ISET(I), IBOL(I), ISHD(I), SSIZ(I), XSH(I), YSH(I), XSF(I)
     +, YSF(I), SRL(I), LABL(I), I=1,NSET)

1001	FORMAT('SETS=',7I4,3F8.3,3G13.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.6 ) THEN	!GRAPH TITLE AND AXIS LABELS
     	    TITL(I) = REST
     	ELSE IF( I.EQ.6 ) THEN	!OVERALL GRAPH PARAMETERS
     	    IF( KP( 1).EQ.1 ) DRAW = RP( 1)
     	    IF( KP( 2).EQ.1 ) MARK = RP( 2)
     	    IF( KP( 3).EQ.1 ) QUAD = RP( 3)
     	    IF( KP( 4).EQ.1 ) NSDS = RP( 4)
     	    IF( KP( 5).EQ.1 ) COL1 = RP( 5)
     	    IF( KP( 6).EQ.1 ) COL2 = 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 ) XOFF = RP(11)
     	    IF( KP(12).EQ.1 ) YOFF = RP(12)
     	    IF( KP(13).EQ.1 ) XSCL = RP(13)
     	    IF( KP(14).EQ.1 ) YSCL = RP(14)
     	ELSE IF( I.LT.11 ) THEN		!AXIS DRAWING PARAMETERS
     	    I = I-6
     	    IF( KP( 1).EQ.1 ) LAXS(I) = RP( 1)
     	    IF( KP( 2).EQ.1 ) NTKS(I) = RP( 2)
     	    IF( KP( 3).EQ.1 ) MTKS(I) = RP( 3)
     	    IF( KP( 4).EQ.1 ) NDGS(I) = RP( 4)
     	    IF( KP( 5).EQ.1 ) IGDS(I) = RP( 5)
     	    IF( KP( 6).EQ.1 ) XLNS(I) = RP( 6)
     	    IF( KP( 7).EQ.1 ) OFFS(I) = RP( 7)
     	    IF( KP( 8).EQ.1 ) SOFF(I) = RP( 8)
     	    IF( KP( 9).EQ.1 ) XANG(I) = RP( 9)
     	    IF( KP(10).EQ.1 ) XLOW(I) = RP(10)
     	    IF( KP(11).EQ.1 ) XHIG(I) = RP(11)
     	    IF( KP(12).EQ.1 ) XINC(I) = RP(12)
     	ELSE IF( I.EQ.11 ) 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 ) ISYM(KSET) = RP( 2)
     	    IF( KP( 3).EQ.1 ) ILIN(KSET) = RP( 3)
     	    IF( KP( 4).EQ.1 ) IDEN(KSET) = RP( 4)
     	    IF( KP( 5).EQ.1 ) ISET(KSET) = RP( 5)
     	    IF( KP( 6).EQ.1 ) IBOL(KSET) = RP( 6)
     	    IF( KP( 7).EQ.1 ) ISHD(KSET) = RP( 7)
     	    IF( KP( 8).EQ.1 ) SSIZ(KSET) = RP( 8)
     	    IF( KP( 9).EQ.1 )  XSH(KSET) = RP( 9)
     	    IF( KP(10).EQ.1 )  YSH(KSET) = RP(10)
     	    IF( KP(11).EQ.1 )  XSF(KSET) = RP(11)
     	    IF( KP(12).EQ.1 )  YSF(KSET) = RP(12)
     	    IF( KP(13).EQ.1 )  SRL(KSET) = RP(13)
     	ELSE IF( I.EQ.12 ) THEN	!DATA SET ID LABEL
     	    LABL(LSET(1,KSET)) = REST
     	ELSE IF( I.EQ.13 ) THEN	!HARDCOPY SETUP PARAMETERS
     	    DO  I=1, 10
     		IF( KP(I).EQ.1 ) HPAR(I) = RP(I)
     	    ENDDO
     	ELSE IF( I.EQ.14 ) THEN	!HARDCOPY SETUP PARAMETERS
     	    DO  I=1, 10
     		IF( KP(I).EQ.1 ) HPAR(I+10) = RP(I)
     	    ENDDO
     	ELSE IF( I.EQ.15 ) THEN	!PLOT ID LABEL
     	    PLOTID = REST
     	ENDIF
     	GOTO 111
C
C  CHECK BAND CODE AND SCALE UNITS...
C
777	KSET = 0
     	BAND = .FALSE.
     	DO I=1, NSET
    	   IF( ISET(I).NE.2 ) KSET = 1
    	   IF( ISET(I).NE.1 ) BAND = .TRUE.
    	ENDDO
     	IF( KSET.EQ.0 ) THEN
     	    BAND = .FALSE.
     	    DO  I=1, NSET
     		ISET(I) = 1
     	    ENDDO
     	ENDIF
     	IF(XINC(1).EQ.0.0.OR.XLOW(1).EQ.XHIG(1)) THEN
     	   CALL XYPLOT_SCALE( 1, MNST, MNPT, %VAL(IXAR), %VAL(IYAR) )
     	ENDIF
     	IF(XINC(2).EQ.0.0.OR.XLOW(2).EQ.XHIG(2)) THEN
     	   CALL XYPLOT_SCALE( 2, MNST, MNPT, %VAL(IXAR), %VAL(IYAR) )
     	ENDIF
     	IF( BAND ) THEN
     	IF(XINC(3).EQ.0.0.OR.XLOW(3).EQ.XHIG(3)) THEN
     	   CALL XYPLOT_SCALE( 3, MNST, MNPT, %VAL(IXAR), %VAL(IYAR) )
     	ENDIF
     	IF(XINC(4).EQ.0.0.OR.XLOW(4).EQ.XHIG(4)) THEN
     	   CALL XYPLOT_SCALE( 4, MNST, MNPT, %VAL(IXAR), %VAL(IYAR) )
     	ENDIF
     	ENDIF
     	GOTO 999

888	XYPLOT_SETUP = 0
     	RETURN

999    	CLOSE(UNIT=LUN)
     	XYPLOT_SETUP = 1
    	RETURN
    	END

     	SUBROUTINE XYPLOT_DELETE( MS, MP, X, Y )
C
C	THIS ROUTINE DELETES OR REMOVES A SET OF DATA FOR X,Y PLOT.
C
     	INCLUDE 'XYPLOT.CBS'
     	DIMENSION X(MP,MS), Y(MP,MS)
     	CHARACTER TEXT*80
     	COMMON/XYPLOT_MENU/ JSET, IKEY, NCHS, TEXT
C
C  GET THE SET NUMBER TO REMOVE...
C
     	NCHS = IFMISC_NEXT(TEXT)
     	IF( NCHS.EQ.0 ) THEN
     	    CALL IFANSI_TEXT('_Data set #', 11, 22, 9 )
     	    READ(5,1001,END=888) TEXT
1001	    FORMAT(A)
     	    NCHS = IFMISC_STRIP(TEXT)
     	    IF( NCHS.EQ.0 ) GOTO 888
     	ENDIF
     	READ( TEXT(1:NCHS), 111, ERR=999 ) IKEY
C     	DECODE( NCHS, 111, TEXT, ERR=999 ) IKEY
111	FORMAT(I)
     	IF( IKEY.LT.1 .OR. IKEY.GT.NSET ) GOTO 999
C
C  REPACK THE LIST...
C
     	M = LSET(1,IKEY)-1
     	DO  I= IKEY, NSET-1
     	    M = M + 1
     	    J = I + 1
     	    K = LSET(1,J)
     	    N = LSET(2,J)
     	    LSET(1,I) = M
     	    LSET(2,I) = N
     	    NPTS = NUMS(K)
     	    NUMS(M) = NPTS
     	    LABL(M) = LABL(K)
     	    DO IJ = 1, 6
     		SRNG(IJ,M) = SRNG(IJ,K)
     	    ENDDO
     	    DO IJ = 1, NPTS
     		X(IJ,M) = X(IJ,K)
     		Y(IJ,M) = Y(IJ,K)
     		IF(N.GT.0) Y(IJ,M+1) = Y(IJ,K+1)
     	    ENDDO
     	    IF( N.GT.0 ) M = M + 1
     	    IPEN(I) = IPEN(J)
     	    ISYM(I) = ISYM(J)
     	    ILIN(I) = ILIN(J)
     	    IDEN(I) = IDEN(J)
     	    ISET(I) = ISET(J)
     	    IBOL(I) = IBOL(J)
     	    ISHD(I) = ISHD(J)
     	    SSIZ(I) = SSIZ(J)
     	     XSH(I) =  XSH(J)
     	     YSH(I) =  YSH(J)
     	     XSF(I) =  XSF(J)
     	     YSF(I) =  YSF(J)
     	     SRL(I) =  SRL(J)
     	ENDDO
     	NSET = NSET - 1
     	MSET = MSET - 1
     	CALL XYPLOT_PARS_NSET
     	IF( JSET.GT.NSET ) JSET = NSET
     	IF( JSET.GE.IKEY ) CALL XYPLOT_PARS_SET(JSET,0)
888	RETURN
999	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
     	RETURN
     	END

     	FUNCTION XYPLOT_MISC_ADD( JSET, MS, MP, X, Y )
C
C	THIS ROUTINE ADDS/SUBTRACTS/AVERAGES DATA SETS.
C
     	INCLUDE 'XYPLOT.CBS'
     	DIMENSION X(MP,MS), Y(MP,MS)
     	CHARACTER TEXT*16
     	DIMENSION RP(2), KP(2), IX(MNS), CX(MNS)

     	WRITE(6,1000)
1000	FORMAT(' Following formula is used to accomplish addition',
     +' or subtraction or averaging'/' of data sets:  SET(NEW) =',
     +' (SET(I)*C(I)+SET(J)*C(J)+SET(K)*C(K)+...) / N'/
     +' where C(I),C(J),... and N are user-specified constants.',
     +' The action is on the'/' Y-coordinates of data sets which',
     +' must have identical numbers of data points.'/' The resulting',
     +' data set takes the X-coordinates of the 1st set data selected.'/
     +' Enter DEL to delete the last OK input; CTRL/Z to exit.')
C
C  SELECT DATA SETS TO WORK ON...
C
     	KSET = 0
111	WRITE(6,1001)
1001	FORMAT(' Enter I and C(I) [0,1.0] ',$)
     	READ(5,1002,END=444) TEXT
1002	FORMAT(A)
     	IF( TEXT.EQ.' ' ) GOTO 111
     	NCHS = IFMISC_STRIP( TEXT )
     	IF( TEXT(1:3).EQ.'DEL' ) THEN
     	    IF( KSET.GT.0 ) KSET = KSET - 1
     	    GOTO 111
     	ENDIF
     	NCHS = IFMISC_DECODE( TEXT, NCHS, 2, RP, KP )
     	IF( NCHS.EQ.0 ) GOTO 222
     	NCHS = RP(1)
     	IF( NCHS.LT.1 .OR. NCHS.GT.NSET ) GOTO 222
     	DO  I= 1, KSET
     	    IF( NCHS.EQ.IX(I) ) GOTO 222
     	ENDDO
     	IF( KSET.EQ.1 ) NPTS = NUMS(LSET(1,IX(1)))
     	IF( KSET.GT.1 ) THEN
     	    IF( NUMS(LSET(1,NCHS)).NE.NPTS ) GOTO 222
     	ENDIF
     	KSET = KSET + 1
     	IX(KSET) = NCHS
     	CONS = RP(2)
     	IF( CONS.EQ.0.0 ) CONS = 1.0
     	CX(KSET) = CONS
     	IF( KSET.EQ.NSET ) GOTO 555
     	GOTO 111
222	CALL IFMISC_OOPS( 3, 0, 0, TEXT )
     	GOTO 111
C
C  GET THE VALUE OF "N"...
C
444	IF( KSET.LT.2 ) GOTO 999
555	WRITE(6,2000)
2000	FORMAT(' Enter N [1] ',$)
     	READ(5,2001,ERR=555,END=999) NCHS
2001	FORMAT(I)
     	IF( NCHS.EQ.0 ) NCHS = 1
C
C  CARRY OUT THE ACTION...
C
     	NSET = NSET + 1
     	MSET = MSET + 1
     	LSET(1,NSET) = MSET
     	LSET(2,NSET) = 0
     	NUMS(MSET) = NPTS
     	K = LSET(1,IX(1))
     	DO  I=1, NPTS
     	    X(I,MSET) = X(I,K)
     	    CONS = 0.0
     	    DO  J=1, KSET
     		CONS = CONS + CX(J)*Y(I,LSET(1,IX(J)))
     	    ENDDO
     	    Y(I,MSET) = CONS/NCHS
     	ENDDO
     	CALL IFMISC_RANGE(NPTS,X(1,MSET),Y(1,MSET),SRNG(1,MSET))
     	WRITE(6,888) NSET
888	FORMAT(' Resulting data set is saved as data set #',I3)
     	XYPLOT_MISC_ADD = 1
     	RETURN
999	XYPLOT_MISC_ADD = 0
     	RETURN
     	END

     	FUNCTION XYPLOT_MISC_OUT( JSET, MS, MP, X, Y )
C
C	THIS ROUTINE WRITES THE ACTIVE DATA SET TO A FILE.
C
     	INCLUDE		'XYPLOT.CBS'
     	DIMENSION	X(MP,MS), Y(MP,MS)
     	CHARACTER	FNAME*32
C
C  ALLOCATE SCRATCH ARRAYS...
C
     	NBYTES = 4*(MNPT+3)
     	I = LIB$GET_VM( NBYTES, JXX )
     	IF( .NOT.I ) GOTO 999
     	I = LIB$GET_VM( NBYTES, JYY )
     	IF( .NOT.I ) GOTO 999
     	I = LIB$GET_VM( NBYTES, JYB )
     	IF( .NOT.I ) GOTO 999
C
C  LOAD THE ACTIVE DATA SET...
C
     	IF( ISET(JSET).NE.2 ) THEN
     	    I = 1
     	ELSE
     	    I = 2
     	ENDIF
     	NPTS = XYPLOT_LOAD( I, JSET, MNST, MNPT, %VAL(IXAR),
     +         %VAL(IYAR), %VAL(JXX), %VAL(JYY), %VAL(JYB) )
     	WRITE(6,1000) NPTS
1000	FORMAT(X,I5,' data points have been sampled from the',
     +' active data set'/' within the current scale window using',
     +' the current point stride.')
     	IF( NPTS.EQ.0 ) THEN
     	    CALL IFMISC_OOPS( 11, 0, 0, ' ' )
     	    GOTO 888
     	ENDIF
     	WRITE(6,2000)
2000	FORMAT(/' Enter output filename [JUNK.DAT] ',$)
     	READ(5,2001,END=888) FNAME
2001	FORMAT(A32)
     	IF( FNAME.EQ.' ' ) FNAME = 'JUNK.DAT'
2004	WRITE(6,2005)
2005	FORMAT(' Enter file format number [1] ',$)
     	READ(5,2006,ERR=2004,END=888) I
2006	FORMAT(I)
     	IF( I.EQ.0 ) I = 1
     	IF( I.LT.1 .OR. I.GT.6 ) GOTO 2004
     	CALL XYPLOT_MISC_SET( FNAME, I, NPTS, %VAL(JXX), %VAL(JYY) )
C
C  DEALLOCATE THE VIRTUAL MEMORY...
C
888	CALL LIB$FREE_VM( NBYTES, JXX )
     	CALL LIB$FREE_VM( NBYTES, JYY )
     	CALL LIB$FREE_VM( NBYTES, JYB )
     	XYPLOT_MISC_OUT = 1.0
     	RETURN
999	CALL IFMISC_OOPS( 6, 0, 0, ' ' )
     	RETURN
     	END

     	SUBROUTINE XYPLOT_MISC_SET( FNAME, IFM, N, X, Y )
     	DIMENSION X(N), Y(N)
     	CHARACTER FNAME*(*)

     	IFORM = IFM
     	IF( IFORM.LT.5 ) THEN
     	    OPEN( UNIT=13, FILE=FNAME, STATUS='NEW', FORM='FORMATTED',
     +            CARRIAGECONTROL='LIST', ERR=888 )
     	ELSE
     	    OPEN( UNIT=13, FILE=FNAME, STATUS='NEW', FORM='UNFORMATTED',
     +            ERR=888 )
     	ENDIF
     	NPTS = N
     	IF( IFORM.LT.4 ) THEN
     	    IF( IFORM.EQ.1 ) WRITE(13,1000,ERR=888) NPTS
     	    WRITE(13,1001,ERR=888) (X(I),Y(I),I=1,NPTS)
1000	    FORMAT(I5)
1001	    FORMAT(2G13.5)
     	ELSE IF( IFORM.EQ.4 ) THEN
     	    WRITE(13,4001,ERR=888) X(1),X(NPTS),X(2)-X(1)
     	    WRITE(13,4002,ERR=888) (Y(I),I=1,NPTS)
4001	    FORMAT(3G13.5)
4002	    FORMAT(6G13.5)
     	ELSE IF( IFORM.EQ.5 ) THEN
     	    I = 1
     	    WRITE(13,ERR=888) NPTS, I
     	    WRITE(13,ERR=888) (X(I),I=1,NPTS)
     	    WRITE(13,ERR=888) (Y(I),I=1,NPTS)
     	ELSE IF( IFORM.EQ.6 ) THEN
     	    WRITE(13,ERR=888) X(1),X(NPTS),X(2)-X(1)
     	    WRITE(13,ERR=888) (Y(I),I=1,NPTS)
     	ENDIF
     	GOTO 999
888	CALL IFMISC_OOPS( 21, 0, 0, FNAME )
999	CLOSE(UNIT=13)
     	RETURN
     	END

     	FUNCTION XYPLOT_ZOOM()
C
C	THIS ROUTINE ZOOMS A X,Y PLOT.
C
     	INCLUDE 'XYPLOT.CBS'
     	DIMENSION Z1(2), Z2(2)

     	IF( BAND ) THEN
     	    WRITE(6,1234)
1234	    FORMAT('_oops: Zoom not supported for two band plot.')
     	    GOTO 999
     	ENDIF
C
C  INVOKE XYPLOT_GIN...
C
     	CALL XYPLOT_GIN( Z1, Z2 )
     	IF( Z1(1).EQ.Z2(1) .OR. Z1(2).EQ.Z2(2) ) GOTO 999
C
C  SCALE THE NEW PLOT WINDOW...
C
     	DO  I=1, 2
     	    IT = IABS(LAXS(I))
     	    X1 = Z1(I)
     	    X2 = Z2(I)
     	    IF( X1.GT.X2 ) THEN
     		X3 = X1
     		X1 = X2
     		X2 = X3
     	    ENDIF
     	    IF( IT.NE.2 ) THEN
     		IT = IFAXIS_LINSCL( XLNS(I), X1, X2 )
     		NTKS(I) = IT
     		XLOW(I) = X1
     		XHIG(I) = X2
     		XINC(I) = (X2-X1)/IT
     	    ELSE
     		IT = IFAXIS_LOGSCL( X1, X2 )
     		XLOW(I) = X1
     		XHIG(I) = X2
     		XINC(I) = IT
     	    ENDIF
     	ENDDO
     	XYPLOT_ZOOM = 1
     	RETURN
999	XYPLOT_ZOOM = 0
     	RETURN
     	END

     	FUNCTION XYPLOT_DATA(FNS,MNS,MNP,NST,NUM,X,Y,LABL)
C
C  PROGRAMMER:  RONG-SHENG ZHOU
C		ALFRED UNIVERSITY,  MARCH-1986
C
C       THIS ROUTINE READS A DATA FILE FOR X,Y PLOT.
C
C	FNS ---- NAME OF DATA FILE TO READ.
C	MNS ---- MAXIMUM NUMBER OF DATA SETS ALLOWED FROM THIS FILE.
C	MNP ---- MAXIMUM NUMBER OF DATA POINTS ALLOWED IN EACH SET.
C
C	NST ---- TOTAL NUMBER OF DATA SETS READ.
C	NUM ---- 1-D NUMBER OF DATA POINTS IN EACH SET READ.
C	X,Y ---- 2-D ARRAY THE STORING X,Y-COORDINATES.
C	LABL --- DATA SET CHARACTER ID.
C
C	XYPLOT_DATA=  0: FILE READ SUCCESSFUL.
C	XYPLOT_DATA= -1: FILE OPEN FAILURE.
C	XYPLOT_DATA=-13: NO DATA FOUND IN THE FILE.
C	XYPLOT_DATA>  0: ERROR IN FILE FORMAT IN RECORD/LINE
C			 NUMBER "XYPLOT_DATA".
C
    	PARAMETER	LUN= 13
    	CHARACTER	LABL(MNS)*80, FNS*(*)
    	DIMENSION	NUM(MNS), X(MNP,MNS), Y(MNP,MNS)
     	INTEGER		FORMAT

    	NCHS = IFMISC_LENG( FNS )
    	NDOT = INDEX( FNS(1:NCHS), ']' )
    	NDOT = INDEX( FNS(NDOT+1:NCHS), '.' )
     	IF( NDOT.GT.0 ) GOTO 333
    	IERR = 1
     	GOTO 222
C
C  OPEN FILE IN THE PRIORITY FROM *.PLT, *.DAT, *.RAW...
C
  111	CLOSE(LUN)
     	IF( NDOT.GT.0 ) THEN
     	    XYPLOT_DATA = -1.0
     	    RETURN
     	ENDIF
  222	IF( IERR.EQ.1 ) THEN
     	    FNS(NCHS+1: ) = '.PLT'
     	    IERR = 2
     	ELSE IF( IERR.EQ.2 ) THEN
    	    FNS(NCHS+1: ) = '.DAT'
    	    IERR = 3
     	ELSE IF( IERR.EQ.3 ) THEN
     	    FNS(NCHS+1: ) = '.RAW'
    	    NDOT = 1
     	ENDIF
C
C  OPEN THE FILE...
C
  333	FORMAT = XYPLOT_DATA_OPEN(LUN,FNS)
     	IF( FORMAT.EQ.0 ) GOTO 111
     	IF( .NOT.IF_DCL_HARDCOPY() .AND. MENU ) THEN
     	    CALL XYPLOT_OOPS(' Data acquisition in process...')
     	ENDIF
     	IF( FORMAT.GT.0 ) THEN		!FORMATTED FILE
     	    IERR = XYPLOT_DATA_ASCII(LUN,MNS,MNP,NST,NUM,X,Y,LABL)
     	ELSE				!UNFORMATTED FILE
     	    IERR = XYPLOT_DATA_BINARY(LUN,MNS,MNP,NST,NUM,X,Y)
     	ENDIF
  	CLOSE(LUN)
     	XYPLOT_DATA = FLOAT(IERR)
    	RETURN
    	END

     	FUNCTION XYPLOT_DATA_OPEN(LUN,FNAME)
C
C	THIS ROUTINE OPENS A FILE:
C
C	XYPLOT_DATA_OPEN=0: OPEN FAILURE
C	XYPLOT_DATA_OPEN>0: OPENED A FORMATTED FILE.
C	XYPLOT_DATA_OPEN<0: OPENED AN UNFORMATTED FILE.
C
     	CHARACTER FNAME*(*)
     	INTEGER   FORMAT
     	LOGICAL   YES
     	BYTE      TEST(32)

     	FORMAT = 0
     	INQUIRE( FILE=FNAME, EXIST=YES )
     	IF( .NOT.YES ) GOTO 999
     	OPEN(UNIT=LUN,FILE=FNAME,STATUS='OLD',FORM='FORMATTED',ERR=888)
     	READ(LUN,1000,ERR=222) TEST
1000	FORMAT(32A1)
     	DO I=1, 32
     	   IF( TEST(I).LT.7 ) GOTO 222
     	ENDDO
     	FORMAT = 1
     	REWIND(LUN)
     	GOTO 999
222	CLOSE(LUN)
     	OPEN(UNIT=LUN,FILE=FNAME,STATUS='OLD',FORM='UNFORMATTED',
     +       ERR=888)
     	FORMAT = -1
     	GOTO 999
888	CLOSE(LUN)
999	XYPLOT_DATA_OPEN = FORMAT
     	RETURN
     	END

     	FUNCTION XYPLOT_DATA_ASCII(LUN,MNS,MNP,NST,NUM,X,Y,LABL)
C
C	THIS ROUTINE READS AN ASCII DATA FILE.
C
    	CHARACTER	TEXT*132, ID*80, DATA*80, LABL(MNS)*80
    	DIMENSION	NUM(MNS), X(MNP,MNS), Y(MNP,MNS)
     	DIMENSION	RP(50), KP(50)
     	LOGICAL		BERR

     	IERR = 0
     	LINE = 0
     	NSET = NST
     	LUND = LUN
     	MNSS = MNS
     	MNPP = MNP
C
C  READ THE FIRST LINE TO PARSE FILE FORMAT...
C
 111	LINE = LINE + 1
     	READ(LUND,1000,ERR=888,END=999) DATA
    	IF( DATA.EQ.' ' ) GOTO 111
1000	FORMAT(A)

     	ID = ' '
    	N2 = IFMISC_STRIP( DATA )
     	N1 = INDEX( DATA(1:N2), '!' )
     	IF( N1.GT.0 ) THEN			!DATA SET ID
     	    ID = DATA(N1+1: )
     	    N2 = N1-1
     	    DATA = DATA(1:N2)
     	ENDIF
    	N3 = IFMISC_DECODE( DATA, N2, 4, RP, KP )
    	IF( N3.EQ.0 ) GOTO 888

    	N2 = RP(1)
     	BERR = .FALSE.
    	IF( KP(4).EQ.1) GOTO 4444	!FILE FORMAT #4
    	IF( KP(2).EQ.1) GOTO 2222	!FILE FORMAT #2
    	IF( N2.LT.0   ) GOTO 3333	!FILE FORMAT #3
    	IF( N2.EQ.0   ) GOTO 2222	!FILE FORMAT #2
C
C  FILE FORMAT #1...
C
 110	N1 = N2
    	IF( N1.GT.MNPP ) N1 = MNPP
	NSET = NSET + 1
    	DO  I=1, N1
 120	    LINE = LINE + 1
    	    READ(LUND,1000,ERR=888,END=190) DATA
     	    IF( DATA.EQ.' ' ) GOTO 120
     	    N3 = IFMISC_STRIP( DATA )
     	    N4 = IFMISC_DECODE( DATA, N3, 3, RP, KP )
     	    IF( N4.EQ.0 ) GOTO 888
     	    X(I,NSET) = RP(1)
     	    Y(I,NSET) = RP(2)
     	    IF( RP(3).GT.0.0 .AND. NSET.LT.MNSS ) THEN
     		Y(I,NSET+1)= RP(3)
     	        BERR = .TRUE.
     	    ENDIF
    	ENDDO
     	IF( ID.NE.' ' ) LABL(NSET) = ID
    	IF( .NOT.BERR ) THEN
     	    NUM(NSET) =  N1
     	ELSE
     	    NUM(NSET) = -N1
     	    NSET = NSET + 1
     	    NUM(NSET) = 0
     	ENDIF
	IF( NSET.EQ.MNSS ) GOTO 999
    	IF( N2.LE.MNPP ) GOTO 111
    	N2 = N2 - MNPP
     	BERR = .FALSE.
    	GOTO 110	!SPLITED SET
C
C  END OF FILE...
C
 190	IF( I.EQ.1 ) GOTO 888
     	I = I - 1
     	IF( ID.NE.' ' ) LABL(NSET) = ID
    	IF( .NOT.BERR ) THEN
     	    NUM(NSET) =  I
     	ELSE
     	    NUM(NSET) = -I
     	    NSET = NSET + 1
     	    NUM(NSET) = 0
     	ENDIF
    	GOTO 999
C
C  FILE FORMAT #2...
C
2222	I = 1
     	NSET = NSET + 1
     	GOTO 220
 210	LINE = LINE + 1
     	READ(LUND,1000,ERR=888,END=190) DATA
     	IF( DATA.EQ.' ' ) GOTO 210
     	N3 = IFMISC_STRIP( DATA )
     	N4 = IFMISC_DECODE( DATA, N3, 4, RP, KP )
     	IF( N4.EQ.0 ) GOTO 888
 220	X(I,NSET) = RP(1)
     	Y(I,NSET) = RP(2)
     	IF( RP(3).GT.0.0 .AND. NSET.LT.MNSS ) THEN
     	    Y(I,NSET+1)= RP(3)
     	    BERR = .TRUE.
     	ENDIF
     	IF( RP(4).NE.0.0 .OR. I.EQ.MNPP ) GOTO 250
    	I = I + 1
     	GOTO 210

 250	N3 = INDEX( DATA, '!' )
     	IF( N3.GT.0 ) ID = DATA(N3+1:)
     	IF( ID.NE.' ' ) LABL(NSET) = ID
     	IF( .NOT.BERR ) THEN
     	    NUM(NSET) = I
     	ELSE
     	    NUM(NSET) = -I
     	    NSET = NSET + 1
     	    NUM(NSET) = 0
     	ENDIF
     	IF( NSET.EQ.MNSS ) GOTO 999
     	IF( RP(4).NE.0.0 ) GOTO 111
     	I = 1
     	NSET = NSET + 1
     	BERR = .FALSE.
    	GOTO 210
C
C  FILE FORMAT #3...
C
3333	N1 = IABS(N2)
    	IF( N1+NSET.GT.MNSS ) N1 = MNSS - NSET
     	IF( N1.GT.49 ) N1 = 49
     	I = 1
 310	LINE = LINE + 1
     	READ(LUND,1000,ERR=888,END=350) TEXT
     	IF( TEXT.EQ.' ' ) GOTO 310
     	IF( TEXT(1:1).EQ.'!' ) GOTO 390
     	N3 = IFMISC_STRIP( TEXT )
     	N4 = IFMISC_DECODE( TEXT, N3, N1+1, RP, KP )
     	IF( N4.EQ.0 ) GOTO 888
     	DO J=1, N1
     	   X(I,NSET+J) = RP(1)
     	   Y(I,NSET+J) = RP(J+1)
     	ENDDO
     	I = I + 1
     	IF( I.GT.MNPP ) GOTO 350
     	GOTO 310

 350	IF( I.EQ.1 ) GOTO 888
     	I = I - 1
     	DO J=1, N1
    	   NSET = NSET + 1
    	   NUM(NSET) = I
    	ENDDO
    	GOTO 999
C
C  GET DATA SET ID IF AT ALL...
C
 360	IF( J.EQ.N1 ) GOTO 350
     	LINE = LINE + 1
     	READ(LUND,1000,ERR=888,END=350) DATA
     	IF( DATA(1:1).NE.'!' ) GOTO 360
     	J = J + 1
     	IF( DATA(2:).NE.' ' ) LABL(NSET+J) = DATA(2:)
     	GOTO 360
 390	J = 1
     	IF( TEXT(2:).NE.' ' ) LABL(NSET+J) = TEXT(2:)
     	GOTO 360
C
C  FILE FORMAT #4...
C
4444	N1 = RP(4)+0.1
    	IF( N1.LT.1 .OR. N1.GT.50 ) GOTO 888
     	X1 = RP(1)-RP(3)
     	X2 = RP(2)
     	X3 = RP(3)
    	IF( X3.EQ.0.0 ) GOTO 888
    	N2 = INT((X2-X1)/X3+0.5) + 1
    	IF( N2.LT.N1 ) GOTO 888
     	N3 = N2/N1
     	IF( N3*N1.LT.N2 ) N3 = N3 + 1
     	N5 = 0
     	N6 = 0
    	NSET = NSET + 1
    	DO  I=1, N3
 410	    LINE = LINE + 1
     	    READ(LUND,1000,ERR=888,END=888) TEXT
     	    IF( TEXT.EQ.' ' ) GOTO 410
     	    N4 = IFMISC_STRIP( TEXT )
     	    N4 = IFMISC_DECODE( TEXT, N4, N1, RP, KP )
    	    IF( N4.EQ.0 ) GOTO 888
     	    DO  J=1, N1
     		N5 = N5 + 1
    		N6 = N6 + 1
     		X(N5,NSET) = X1 + X3*N6
    		Y(N5,NSET) = RP(J)
     		IF( N6.EQ.N2 ) GOTO 490
     		IF( N5.EQ.MNPP ) THEN
     		    NUM(NSET) = N5
     		    IF( ID.NE.' ' ) LABL(NSET) = ID
     		    IF( NSET.EQ.MNSS ) GOTO 999
     		    NSET = NSET + 1
     		    N5 = 0
     		ENDIF
     	    ENDDO
    	ENDDO
 490	NUM(NSET) = N5
     	IF( ID.NE.' ' ) LABL(NSET) = ID
    	IF( NSET.EQ.MNSS ) GOTO 999
     	GOTO 111
C
C  ERROR TRANSFERS...
C
888	IERR = LINE
999	IF( NSET.GT.NST ) THEN
     	    NST = NSET
     	ELSE
     	    IERR = -13
     	ENDIF
     	XYPLOT_DATA_ASCII = FLOAT(IERR)
     	RETURN
     	END

     	FUNCTION XYPLOT_DATA_BINARY(LUN,MNS,MNP,NST,NUM,X,Y)
C
C	THIS ROUTINE READS A BINARY DATA FILE.
C
    	DIMENSION	NUM(MNS), X(MNP,MNS), Y(MNP,MNS)
     	DIMENSION	RP(10)

     	IERR = 0
     	LINE = 0
     	NSET = NST
     	LUND = LUN
     	MNSS = MNS
     	MNPP = MNP

111	LINE = LINE + 1
     	READ(LUND,ERR=222,END=777) RP(1), RP(2), RP(3)
    	GOTO 6666
222	REWIND( LUND )
     	LINE = 0
223	LINE = LINE + 1
    	READ(LUND,ERR=888,END=777) N3
C
C  FILE FORMAT #5...
C
    	IF( N3.LT.2 ) GOTO 888
     	N2 = 0
    	IF( N3.GT.MNPP ) THEN
     	    N2 = N3/MNPP
     	    IF( N2*MNPP.LT.N3 ) N2 = N2 + 1
     	    IF( N2.GT.10 ) N2 = 10
     	    N3 = N3/N2
     	    N2 = N2-1
     	ENDIF
    	NSET = NSET + 1
    	LINE = LINE + 1
    	READ(LUND,ERR=888,END=888) (X(I,NSET),(RP(J),J=1,N2),I=1,N3)
     	LINE = LINE + 1
     	READ(LUND,ERR=888,END=888) (Y(I,NSET),(RP(J),J=1,N2),I=1,N3)
     	NUM(NSET) = N3
     	IF( NSET.EQ.MNSS ) GOTO 999
    	GOTO 223
C
C  FILE FORMAT #6 ...
C
6666	IF( RP(3).EQ.0.0 ) GOTO 888
     	X1 = RP(1)
     	X2 = RP(2)
     	X3 = RP(3)
    	N3 = INT((X2-X1)/X3+0.5) + 1
    	IF( N3.LT.2 ) GOTO 888
     	N2 = 0
    	IF( N3.GT.MNPP ) THEN
     	    N2 = N3/MNPP
     	    IF( N2*MNPP.LT.N3 ) N2 = N2 + 1
     	    IF( N2.GT.10 ) N2 = 10
     	    N3 = N3/N2
     	    N2 = N2-1
     	ENDIF
    	NSET = NSET + 1
    	LINE = LINE + 1
    	READ(LUND,ERR=888,END=888) (Y(I,NSET),(RP(J),J=1,N2),I=1,N3)
     	N2 = N2 + 1
     	X1 = X1 - X3
     	DO I=1, N3*N2, N2
     	   X(I,NSET) = X1+X3*I
     	ENDDO
    	NUM(NSET) = N3
    	IF( NSET.EQ.MNSS ) GOTO 999
     	GOTO 111
C
C  ERROR TRANSFER...
C
777	IF( NSET.GT.NST ) GOTO 999
888	IERR = LINE
999	IF( NSET.GT.NST ) THEN
     	    NST = NSET
     	ELSE
     	    IERR = -13
     	ENDIF
     	XYPLOT_DATA_BINARY = FLOAT(IERR)
     	RETURN
     	END

     	SUBROUTINE XYPLOT_VM
C
C	THIS ROUTINE ALLOCATES VIRTUAL MEMORY FOR DATA STORAGE.
C
     	INCLUDE 'XYPLOT.CBS'
     	CHARACTER TEXT*80
     	COMMON/XYPLOT_MENU/ JSET, IKEY, NCHS, TEXT
     	DIMENSION RP(2), KP(2)

     	NCHS = IFMISC_NEXT(TEXT)
     	IF( NCHS.EQ.0 ) THEN
     	NCHS=IFMISC_PROMPT('_Sets & pts/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
     	    GOTO 888
     	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.99999 ) GOTO 888
     	    ELSE
     		KP(2) = MNPT
     	    ENDIF
     	    NCHS = 4*MNST*MNPT
     	    CALL LIB$FREE_VM(NCHS,IXAR)
     	    CALL LIB$FREE_VM(NCHS,IYAR)
     	    MNST = KP(1)
     	    MNPT = KP(2)
     	    NCHS = 4*MNST*MNPT
     	    IKEY = LIB$GET_VM( NCHS, IXAR )
     	    IF( IKEY.EQ.0 ) GOTO 777
     	    IKEY = LIB$GET_VM( NCHS, IYAR )
     	    IF( IKEY.EQ.0 ) GOTO 777
     	    JSET = 1
     	    NSET = 0
     	    MSET = 0
     	    CALL XYPLOT_INIT(1)
     	    CALL XYPLOT_PARS_VM(MNST,MNPT)
     	    CALL XYPLOT_PARS(JSET)
     	ENDIF
     	RETURN
777	CALL IFMISC_OOPS( 6, SLIN, SCOL, ' ' )
     	RETURN
888	CALL IFMISC_OOPS( 3, SLIN, SCOL, TEXT )
     	RETURN
     	END

     	SUBROUTINE XYPLOT_PLOT
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY
C
C	THIS ROUTINE CARRIES OUT THE PLOTTING FOR X,Y PLOT.
C
     	INCLUDE 'XYPLOT.CBS'
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
     	IF( .NOT.IFINIT_SAVE() ) RETURN
C
C  OPEN A GRAPHICS SEGMENT TO SAVE THE PLOT...
C
     	CALL IFSCAL( XSCL, YSCL )
     	CALL IFROTA( XANG(1), XANG(2) )
     	CALL IFANSI_ANSI( ANSI )
C
C  DRAW GRAPH TITLE IF ANY...
C
     	IF( TITL(1).NE.' ' ) THEN
     	    CALL IFSPEN(1)
    	    XLEN = XLNS(1)
    	    IF(BAND.AND.XOFF.GT.0.0.AND.YOFF.EQ.0.0) XLEN=XOFF+XLNS(3)
     	    CALL IFTEXT_CENT(0.,XLEN,-1.,-1.,TITL(1),.15,.15)
     	ENDIF
C
C  DRAW THE AXES OF THE 1ST GRAPH BAND ...
C
     	IF( IFCTRL_C() ) GOTO 999
     	IF( XINC(1).EQ.0.0 .OR. XINC(2).EQ.0.0 ) THEN
     	    IF( .NOT.IF_DCL_HARDCOPY() ) THEN
     		CALL IFMISC_OOPS( 10, 0, 0, ' ' )
     		GOTO 222
     	    ELSE
     		STOP '%XYPLOT: data scaling failure.'
     	    ENDIF
     	ENDIF
     	CALL IFSPEN( COL1 )
     	IF( LAXS(1).GT.0 ) CALL XYPLOT_AXIS( 1 )
     	IF( IFCTRL_C() ) GOTO 999
     	IF( LAXS(2).GT.0 ) CALL XYPLOT_AXIS( 2 )
C
C  DRAW DATA SETS THAT BELONG TO THE 1ST GRAPH BAND...
C
     	IF( IFCTRL_C() ) GOTO 999
    	CALL XYPLOT_DRAW( 1 )
C
C  DRAW THE 2ND GRAPH BAND IF ANY...
C
  222	IF( IFCTRL_C() ) GOTO 999
     	IF( BAND ) THEN
     	    IF( XINC(3).EQ.0.0 .OR. XINC(4).EQ.0.0 ) THEN
     		IF( .NOT.IF_DCL_HARDCOPY() ) THEN
     		CALL IFMISC_OOPS( 10, 0, 0, ' ' )
     		GOTO 555
     		ELSE
     		STOP '%XYPLOT: data scaling failure.'
     		ENDIF
     	    ENDIF
     	    CALL IFROTA( XANG(3), XANG(4) )
     	    IF(XOFF.NE.0.0.OR.YOFF.NE.0.0) CALL IFPLOT(XOFF,YOFF,-3)
     	    CALL IFSPEN( COL2 )
     	    IF( LAXS(3).GT.0 ) CALL XYPLOT_AXIS( 3 )
     	IF( IFCTRL_C() ) GOTO 999
     	    IF( LAXS(4).GT.0 ) CALL XYPLOT_AXIS( 4 )
     	IF( IFCTRL_C() ) GOTO 999
    	    CALL XYPLOT_DRAW( 2 )
     	    IF(XOFF.NE.0.0.OR.YOFF.NE.0.0) CALL IFPLOT(-XOFF,-YOFF,-3)
     	    CALL IFROTA( XANG(1), XANG(2) )
     	ENDIF
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
     	IF( IFCTRL_C() ) GOTO 999
    	IF( DESNAM.NE.' ' ) CALL LAYOUT_AUX(0,XORG,YORG,DESNAM)
  999	CALL IFINIT_PLOT_END
     	RETURN
    	END

     	SUBROUTINE XYPLOT_AXIS( ICODE )
C
C	THIS ROUTINE PLOTS AN AXIS FOR X,Y PLOT.
C
     	INCLUDE 'XYPLOT.CBS'
C
C  GET TYPE OF AXIS TO PLOT...
C
     	ICD = ICODE
     	ITY = LAXS(ICD)
     	IF( ICD.EQ.2 .OR. ICD.EQ.4 ) ITY = 3 + ITY
C
C  OFFSET THE AXIS IF MULTI-QUADRANT PLOT OR 2ND BAND IS DESIRED...
C
     	XPS = 0.0
    	YPS = 0.0
    	IF( QUAD.EQ.1 ) THEN
     	    IF( ITY.LT.4 ) YPS = XYPLOT_CROSS(1)
     	    IF( ITY.GT.3 ) XPS = XYPLOT_CROSS(2)
     	ENDIF
     	IF( ICD.LT.3 ) THEN
     	    XLN = XLNS(1)
     	    YLN = XLNS(2)
     	ELSE
     	    XLN = XLNS(3)
     	    YLN = XLNS(4)
     	    IF( XOFF.EQ.0.0 .AND. YOFF.EQ.0.0 ) THEN
     		IF( ICD.EQ.3 ) YPS = YLN
     		IF( ICD.EQ.4 ) XPS = XLN
     	    ENDIF
     	ENDIF
     	IF( YPS.GT.0.5*YLN ) XLN = -XLN
     	IF( XPS.GT.0.5*XLN ) YLN = -YLN
     	NTICKS = NTKS(ICD)
     	IF( NTICKS.LT.0 ) THEN
     	    IF( ITY.LT.4 ) XLN = -XLN
     	    IF( ITY.GT.3 ) YLN = -YLN
     	    NTICKS = -NTICKS
     	ENDIF
C
C  DRAW THE AXIS...
C
     	XOF = 0.0
     	YOF = 0.0
     	IF( ITY.LT.4 ) THEN
     	    YOF = SOFF(ICD)
     	ELSE
     	    XOF = SOFF(ICD)
     	ENDIF
     	CALL IFPLOT( XPS+XOF, YPS+YOF, -3 )
     	JGDS = IGDS(ICD)
     	IF( IABS(JGDS).GT.10 ) THEN
     	    IF( ITY.LT.4 .AND. (YPS+YOF).NE.0.0 ) JGDS = JGDS/10
     	    IF( ITY.GT.3 .AND. (XPS+XOF).NE.0.0 ) JGDS = JGDS/10
     	    IF( BAND .AND. ICD.GT.2 .AND. IABS(JGDS).GT.10 ) THEN
     		IF( XOFF.EQ.0.0 .AND. YOFF.EQ.0.0 ) JGDS = JGDS/10
     	    ENDIF
     	    IGDS(ICD) = JGDS
     	ENDIF
     	CALL IFAXIS( ITY,XLN,YLN,TITL(ICD+1),XLOW(ICD),XINC(ICD),
     +  OFFS(ICD), NTICKS, MTKS(ICD), NDGS(ICD), JGDS )
     	CALL IFPLOT( -XPS-XOF, -YPS-YOF, -3 )

     	RETURN
	END

     	FUNCTION XYPLOT_CROSS( ICODE )
C
C	THIS ROUTINE CALCULATES X,Y AXIS ORIGIN INTERSECTION.
C
     	INCLUDE 'XYPLOT.CBS'

     	CALL XYPLOT_VINCH( 1, DELTAX, DELTAY )
     	XPS = 0.0
     	YPS = 0.0
     	X11 = ABS(XLOW(1)/DELTAX) + OFFS(1)
     	X22 = ABS(XHIG(1)/DELTAX) + OFFS(1)
     	XLN = XLNS(1) - OFFS(1)
     	IF( X11.LT.XLN .AND. X22.LT.XLN ) XPS = X11
     	X11 = ABS(XLOW(2)/DELTAY) + OFFS(2)
     	X22 = ABS(XHIG(2)/DELTAY) + OFFS(2)
     	XLN = XLNS(2) - OFFS(2)
     	IF( X11.LT.XLN .AND. X22.LT.XLN ) YPS = X11
     	IF( XPS.EQ.0.0 .AND. YPS.EQ.0.0 ) GOTO 999
     	IF( XPS.NE.0.0 .AND. YPS.NE.0.0 ) GOTO 999
     	IF( XPS.NE.0.0 ) THEN
     	    IF( ABS(XHIG(2)).LT.ABS(XLOW(2)) ) YPS = XLNS(2)
     	ELSE
     	    IF( ABS(XHIG(1)).LT.ABS(XLOW(1)) ) XPS = XLNS(1)
     	ENDIF

999	IF( ICODE.EQ.1 ) XYPLOT_CROSS = YPS
     	IF( ICODE.EQ.2 ) XYPLOT_CROSS = XPS

     	RETURN
     	END

    	SUBROUTINE XYPLOT_DRAW( ICODE )
C
C	THIS ROUTINE DRAWS THE DATA SETS.
C
C	ICODE=1: DRAW THE DATA SETS ON THE 1ST GRAPH BAND.
C	ICODE=2: DRAW THE DATA SETS ON THE 2ND GRAPH BAND.
C
    	INCLUDE	'XYPLOT.CBS'
     	COMMON/XYPLOT_DRAW/ XPOS, YPOS, LMAX
C
C  PLOT OFFSETS (1ST MAJOR TICKMARK OFFSETS) IF SPECIFIED...
C
     	ICD = ICODE
     	IF( ICD.EQ.1 ) THEN
     	    ITT = 2
     	    XOF = OFFS(1)
     	    YOF = OFFS(2)
     	    XPOS= XLPS - XOF + 0.15
    	    YPOS= YLPS - YOF + 0.15
     	    LMAX= 0
     	ELSE
     	    ITT = 1
     	    XOF = OFFS(3)
     	    YOF = OFFS(4)
     	    IF( XOFF.NE.0.0 .OR. YOFF.NE.0.0 ) THEN
     		XPOS = XLPS - XOF + 0.15
     		YPOS = YLPS - YOF + 0.15
     		LMAX= 0
     	    ENDIF
     	ENDIF
     	IF( XOF.GT.0.0 .OR. YOF.GT.0.0 ) CALL IFPLOT( XOF, YOF, -3 )
C
C  ALLOCATE SCRATCH ARRAYS FOR PLOTTING A SET OF DATA...
C
     	NBYTES = 4*(MNPT+3)
     	I = LIB$GET_VM( NBYTES, JXX )
     	IF( .NOT.I ) GOTO 888
     	I = LIB$GET_VM( NBYTES, JYY )
     	IF( .NOT.I ) GOTO 888
     	I = LIB$GET_VM( NBYTES, JYB )
     	IF( .NOT.I ) GOTO 888
C
C  START DRAWING DATA SET BY SET...
C
     	OFFX = 0.0	!INDIVIDUAL DATA SET OFFSETS
     	OFFY = 0.0
     	IF(CRT.EQ.2) CALL IFFILL_PANEL(0)	!DISABLE FILL NEW-PANEL CHECK
    	DO  999 I = 1, NSET
     	IF( IFCTRL_C() ) GOTO 9999
C
C  SKIP THE SET IF PEN_CODE=0 .OR. BAND_CODE=ITT ...
C
     	IF( IPEN(I).EQ.0 .OR. ISET(I).EQ.ITT ) GOTO 999
C
C  OFFSETS THIS SET OF DATA IF SPECIFIED...
C
     	OFFX = OFFX + XSH(I)
     	OFFY = OFFY + YSH(I)
C
C  LOAD THE X,Y COORDINATES...
C
     	NPTS = XYPLOT_LOAD( ICD, I, MNST, MNPT, %VAL(IXAR),
     +         %VAL(IYAR), %VAL(JXX), %VAL(JYY), %VAL(JYB) )
C
C  SKIP IF THE ALL DATA POINTS ARE SCALED OUT OF PLOT WINDOW...
C
     	IF( NPTS.EQ.0 ) GOTO 999
     	IF( OFFX.NE.0.0 .OR. OFFY.NE.0.0 ) CALL IFPLOT(OFFX,OFFY,-3)
C
C  SET THE DRAWING COLOR FOR THIS SET...
C
     	CALL IFSPEN( IPEN(I) )
C
C  DRAW THE DATA SET...
C
     	IF( ILIN(I).LT.0 ) NPTS = -NPTS
     	CALL IFSTYL( IABS(ILIN(I)), IBOL(I) )
     	IF( IFCTRL_C() ) GOTO 9999
     	CALL IFLINE(ISYM(I),SSIZ(I),ISHD(I),NPTS,%VAL(JXX),%VAL(JYY))
     	IF( IFCTRL_C() ) GOTO 9999
C
C  PLOT ERROR BARS IF ANY...
C
    	IF( NSDS.GT.0 .AND. LSET(2,I).EQ.1 ) THEN
     	    CALL XYPLOT_SBAR( ICD, I, IABS(NPTS), %VAL(JXX),
     +                        %VAL(JYY), %VAL(JYB) )
     	ENDIF
     	IF( OFFX.NE.0.0 .OR. OFFY.NE.0.0 ) CALL IFPLOT(-OFFX,-OFFY,-3)
C
C  DRAW THE SET ID LABEL...
C
    	IF( DRAW.GT.0 .AND. LABL(LSET(1,I)).NE.' ' ) THEN
    	    IF( ITT.NE.1 .OR. ISET(I).NE.3 ) CALL XYPLOT_DRAW_ID(I)
     	ENDIF
C
C  GET THE NEXT SET OF DATA...
C
  999	CONTINUE
C
C  RESET PLOTTING STYLUS...
C
     	CALL IFSTYL( 1, 1 )
     	IF(CRT.EQ.2) CALL IFFILL_PANEL(1)	!ENABLE FILL NEW-PANEL CHECK
C
C  RESTORE THE ORIGINS...
C
    	IF( XOF.GT.0.0.OR.YOF.GT.0.0 ) CALL IFPLOT(-XOF,-YOF,-3)
C
C  DRAW THE SET ID LABEL BOX IF SPECIFIED...
C
     	IF( IFCTRL_C() ) GOTO 9999
     	IF( DRAW.EQ.2 .AND. LMAX.GT.0 ) CALL XYPLOT_DRAW_BOX(ICD)
C
C  DEALLOCATE THE VIRTUAL MEMORY...
C
9999	CALL LIB$FREE_VM( NBYTES, JXX )
     	CALL LIB$FREE_VM( NBYTES, JYY )
     	CALL LIB$FREE_VM( NBYTES, JYB )
     	RETURN
888	IF( IF_DCL_HARDCOPY() ) THEN
     	    STOP '%XYPLOT: insufficient virtual memory to be allocated'
     	ELSE
     	    CALL IFMISC_OOPS( 6, 0, 0, ' ' )
     	ENDIF
     	RETURN
    	END

     	FUNCTION XYPLOT_LOAD(IC,KSET,MS,MP,X,Y,XDAT,YDAT,YBAR)
C
C	THIS ROUTINE LOADS A SET OF DATA FOR PLOTTING.
C
C	KSET: DATA SET POINTER.
C	NPTS: NUMBER OF DATA POINTS LOADED.
C
     	INCLUDE	'XYPLOT.CBS'
     	DIMENSION X(MP,MS),Y(MP,MS),XDAT(MP+3),YDAT(MP+3),YBAR(MP+3)

     	ICD = IC
     	IF( ICD.EQ.1 ) THEN
     	    LXX  = IABS(LAXS(1))
     	    LYY  = IABS(LAXS(2))
     	ELSE
     	    LXX  = IABS(LAXS(3))
     	    LYY  = IABS(LAXS(4))
     	ENDIF
     	CALL XYPLOT_LIMIT( ICD, X1, X2, Y1, Y2 )
     	CALL XYPLOT_VINCH( ICD, XDL, YDL )
     	NPTS = 0
     	IT1  = KSET
     	IT2  = LSET(1,IT1)
     	IT3  = LSET(2,IT1)
     	XSC  = XSF(IT1)
     	YSC  = YSF(IT1)
        CALL XYPLOT_OFFSET( ICD, IT1, XOF, YOF )
        IF( XOF.NE.0.0 ) THEN
            XOF = XOF*XDL
            X1  = X1 - XOF
            X2  = X2 - XOF
        ENDIF
        IF( YOF.NE.0.0 ) THEN
            YOF = YOF*YDL
            Y1  = Y1 - YOF
            Y2  = Y2 - YOF
        ENDIF
     	DO  I= 1, NUMS(IT2), IDEN(IT1)
    	    XIJ = XSC*X(I,IT2)
    	    YIJ = YSC*Y(I,IT2)
     	    IF( LXX.EQ.2 ) XIJ = LOG10( XIJ )
    	    IF( LXX.EQ.3 ) XIJ = 1.0/XIJ
    	    IF( LYY.EQ.2 ) YIJ = LOG10( YIJ )
    	    IF( LYY.EQ.3 ) YIJ = 1.0/YIJ
     	    IF( XIJ.GE.X1 .AND. XIJ.LE.X2 .AND. YIJ.GE.Y1 .AND.
     +          YIJ.LE.Y2 ) THEN
     		NPTS = NPTS + 1
     		XDAT(NPTS) = XIJ
     		YDAT(NPTS) = YIJ
     		IF(IT3.EQ.1) YBAR(NPTS) = YSC*Y(I,IT2+1)
     	    ENDIF
     	ENDDO
     	IF( NPTS.GT.0 ) THEN
     	    IF( ICD.EQ.1 ) THEN
     		XIJ = XLOW(1)
     		YIJ = XLOW(2)
     	    ELSE
     		XIJ = XLOW(3)
     		YIJ = XLOW(4)
     	    ENDIF
     	    IF( LXX.EQ.2 ) XIJ = LOG10( XIJ )
    	    IF( LXX.EQ.3 ) XIJ = 1.0/XIJ
    	    IF( LYY.EQ.2 ) YIJ = LOG10( YIJ )
    	    IF( LYY.EQ.3 ) YIJ = 1.0/YIJ
     	    XDAT(NPTS+1) = XIJ
     	    YDAT(NPTS+1) = YIJ
            XDAT(NPTS+2) = XDL
            YDAT(NPTS+2) = YDL
     	    IF( ISHD(IT1).NE.0 ) THEN	!PLOT REFERENCE LINE ON
     		YIJ = SRL(IT1)
     		IF( LYY.EQ.2 ) THEN
     		    IF( YIJ.LE.0.0 ) THEN
     			YIJ = Y1
     		    ELSE
     			YIJ = LOG10( YIJ )
     		    ENDIF
     		ENDIF
     		IF( LYY.EQ.3 ) THEN
     		    IF( YIJ.EQ.0.0 ) THEN
     			YIJ = Y1
     		    ELSE
     			YIJ = 1.0/YIJ
     		    ENDIF
     		ENDIF
     		YDAT(NPTS+3) = YIJ
     	    ENDIF
     	ENDIF
     	XYPLOT_LOAD = FLOAT(NPTS)
     	RETURN
     	END

      SUBROUTINE XYPLOT_OFFSET( ICD, IT1, XOF, YOF )
C
C     THIS ROUTINE RETURNS THE TOTAL OFFSETS IN XOF,YOF
C     FOR DATA SET IT1.
C
      INCLUDE 'XYPLOT.CBS'

      ITT = 1
      IF( ICD.EQ.1 ) ITT = 2
      XOF = 0.0
      YOF = 0.0
      DO I=1, IT1
     	 IF( IPEN(I).NE.0 .AND. ISET(I).NE.ITT ) THEN
             XOF = XOF + XSH(I)
             YOF = YOF + YSH(I)
         ENDIF
      ENDDO
      RETURN
      END

     	SUBROUTINE XYPLOT_SBAR( ICD, KSET, NPTS, XDAT, YDAT, YBAR )
C
C	THIS ROUTINE DRAWS THE ERROR BARS FOR X,Y PLOT.
C
     	INCLUDE 'XYPLOT.CBS'
     	DIMENSION XDAT(NPTS), YDAT(NPTS), YBAR(NPTS)

     	NP = NPTS
     	IT = ICD
     	IF( IT.EQ.1 ) LY = IABS(LAXS(2))
     	IF( IT.EQ.2 ) LY = IABS(LAXS(4))
     	XLO = XDAT(NP+1)
     	XDL = 1.0/XDAT(NP+2)
     	YLO = YDAT(NP+1)
     	YDL = 1.0/YDAT(NP+2)
     	SIZ = SSIZ(KSET)
     	IF( ISYM(KSET).EQ.0 ) SIZ = 0.0
    	DO 999 I= 1, NP
     	IF( IFCTRL_C() ) RETURN
    	    YBR = ABS(YBAR(I))
    	    IF( YBR.EQ.0.0 ) GOTO 999
     	    YPT = YDAT(I)
     	    YBR = NSDS*YBR
    	    IF( LY.EQ.1 ) THEN
     		YTP = YDL*(YPT+YBR-YLO)
     		YBB = YDL*(YPT-YBR-YLO)
    	    ENDIF
    	    IF( LY.EQ.2 ) THEN
     		YTP = YDL*(LOG10(10.0**YPT+YBR)-YLO)
     		YBB = YDL*(LOG10(10.0**YPT-YBR)-YLO)
    	    ENDIF
    	    IF( LY.EQ.3 ) THEN
     		YTP = YDL*(1.0/(1.0/YPT+YBR)-YLO)
     		YBB = YDL*(1.0/(1.0/YPT-YBR)-YLO)
    	    ENDIF
     	    IF( (YTP-YBB).LE.SIZ ) GOTO 999	!TOO SHORT TO DRAW
     	    XXX = XDL*(XDAT(I)-XLO)
     	    XBL = XXX - 0.025
     	    XBR = XXX + 0.025
    	    CALL IFPLOT(XBL,YTP,3)
    	    CALL IFPLOT(XBR,YTP,2)
    	    CALL IFPLOT(XXX,YTP,3)
     	    IF( SIZ.GT.0.0 ) THEN		!BYPASS THE SYMBOL
     		YBR = YDL*(YPT-YLO)
     		CALL IFPLOT(XXX,YBR+0.5*SIZ,2)
     		CALL IFPLOT(XXX,YBR-0.5*SIZ,3)
     	    ENDIF
   	    CALL IFPLOT(XXX,YBB,2)
    	    CALL IFPLOT(XBL,YBB,3)
    	    CALL IFPLOT(XBR,YBB,2)
999	CONTINUE

     	RETURN
     	END

     	SUBROUTINE XYPLOT_DRAW_ID( KSET )
C
C 	THIS ROUTINE DRAWS THE DATA SET LABELS.
C
     	INCLUDE 'XYPLOT.CBS'
     	COMMON/XYPLOT_DRAW/ XPOS, YPOS, LMAX

     	ITT = KSET
     	XPS = XPOS
     	YPS = YPOS
     	YIN = 0.25
     	IF( MARK.EQ.0 ) GOTO 222		!SKIP THE MARKER
C
C  DRAW THE PREFIX-MARKER...
C
     	IFL = IABS(ISHD(ITT))
     	ISM = ISYM(ITT)
     	SIZ = SSIZ(ITT)
     	IF( SIZ.GT.0.4 ) SIZ = 0.4
     	IF( SIZ.GT.0.1 ) THEN
     	    YPS = YPS + 0.5*SIZ
     	    YIN = SIZ + 0.15
     	ELSE
     	    YPS = YPS + 0.05
     	ENDIF
     	IF( IFL.EQ.0 .OR. IFL.EQ.2 ) THEN	!NORMAL/STICK PLOT
     	    IF( ISM.EQ.0 ) THEN
     		CALL IFPLOT( XPS, YPS, 3 )
     		CALL IFPLOT( XPS+0.6, YPS, 2 )
     	    ELSE
     		IF( ISM.GT.0 ) THEN
     		    CALL IFPLOT( XPS, YPS, 3 )
     		    CALL IFPLOT( XPS+0.3-0.5*SIZ, YPS, 2 )
     		ENDIF
     		CALL IFMARK( XPS+0.3, YPS, SIZ, 0.0, IABS(ISM) )
     		IF( ANSI ) THEN
     		    CALL IFINIT_DIF(0)
     		    CALL IFPLOT( XPS+1.0, YPS, 3 )
     		    CALL IFINIT_DIF(1)
     		    CALL IFANSI_DRAW(IABS(ISM))
     		ENDIF
     		IF( ISM.GT.0 ) THEN
     		    CALL IFPLOT( XPS+0.3+0.5*SIZ, YPS, 3 )
     		    CALL IFPLOT( XPS+0.6, YPS, 2 )
     		ENDIF
     	    ENDIF
     	ENDIF
     	IF( IFL.EQ.3 ) THEN		!BAR PLOT
     	    IF( ISM.NE.0 ) CALL IFFILL( IABS(ISM) )
     	    CALL IFBARS( XPS+0.3, YPS, 0.6, SIZ, 0.0, 0.0 )
     	    IF( ISM.NE.0 ) CALL IFFILL( 0 )
     	ENDIF
     	IF( IFL.EQ.1 ) THEN		!AREA FILL
     	    IF( ISM.EQ.0 ) ISM = 1
     	    CALL IFFILL( ISM )
     	    CALL IFBARS( XPS+0.3, YPS, 0.6, SIZ, 0.0, 0.0 )
     	    CALL IFFILL(  0  )
     	ENDIF
     	YPS = YPS - 0.05
     	XPS = XPS + 0.7
C
C  DRAW THE ID LABEL...
C
222	IFL = IFMISC_LENG( LABL(LSET(1,ITT)) )
     	IF( IFL.GT.LMAX ) LMAX = IFL
     	CALL IFTEXT_EXT(XPS,YPS,LABL(LSET(1,ITT)),0.1,0.1,0.0)
     	YPOS = YPOS + YIN

     	RETURN
     	END

     	SUBROUTINE XYPLOT_DRAW_BOX(ICODE)
C
C	THIS ROUTINE DRAWS THE BOX AROUND SET ID LABELS.
C
     	INCLUDE 'XYPLOT.CBS'
     	COMMON/XYPLOT_DRAW/ XPOS, YPOS, LMAX

     	ICD = ICODE
     	ITT = 0
     	IF( .NOT.BAND ) THEN
     	    ITT = 2
     	ELSE
     	    IF( ICD.EQ.1 ) THEN
     		IF( XOFF.NE.0.0 .OR. YOFF.NE.0.0 ) ITT = 2
     	    ELSE
     		ITT = 4
     		IF( XOFF.EQ.0.0 .AND. YOFF.EQ.0.0 ) ITT = 2
     	    ENDIF
     	ENDIF
     	IF( ITT.GT.0 ) THEN
     	    XPOS = 0.1
     	    IF( CRT.EQ.2 ) XPOS = 0.12
     	    IF( CRT.EQ.3 ) XPOS = 0.14
     	    XPOS = XLPS + 1.0 + XPOS*LMAX
     	    IF( MARK.EQ.0 ) XPOS = XPOS - 0.7
     	    YPOS = YPOS + OFFS(ITT)
     	    IF( ITT.EQ.2 ) CALL IFSPEN(COL1)
     	    IF( ITT.EQ.4 ) CALL IFSPEN(COL2)
     	    CALL IFPLOT( XLPS, YLPS, 3 )
     	    CALL IFPLOT( XLPS, YPOS, 2 )
     	    CALL IFPLOT( XPOS, YPOS, 2 )
     	    CALL IFPLOT( XPOS, YLPS, 2 )
     	    CALL IFPLOT( XLPS, YLPS, 2 )
     	ENDIF

     	RETURN
     	END

