     	SUBROUTINE 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 PLOT PARAMETERS...
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 ) GOTO 999
C
C  CARRY OUT THE PLOTTING...
C
  333	CALL XYPLOT_PLOT
C
C  PRESENT LOCAL COMMAND MENU...
C
  444	CALL IFANSI_VIDEO(30)
     	WRITE(6,555)
  555	FORMAT(' XYPLOT_MENU (Please press a desired function code): ')
     	CALL IFANSI_VIDEO(47)
     	WRITE(6,556)
  556	FORMAT(' 0>Exit 1>Hardcopy 2>Layout 3>Dialog',
     +' 4>Zoom 5>Cursor 6>Redraw ?>Help ...')
     	CALL IFANSI_CURSOR(0,27)
  445	CALL IFQIOW_KEY( KEY )

     	IF( KEY.EQ.26 .OR. KEY.EQ.48 ) GOTO 999
     	IF( KEY.EQ.13 ) KEY = 51
     	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_CURSOR(0,-20)
     	    CALL IFFEED( HPAR(1), PLOTID, ' ' )
     	ELSE IF( KEY.EQ.50 ) THEN		!LAYOUT
     	    IF( DESNAM.EQ.' ' ) THEN
     		DESNAM = DATNAM
     		CALL IFMISC_NAMEXT( DESNAM, '.DES' )
     	    ENDIF
     	    CALL LAYOUT_MAIN( 2, XORG, YORG, DESNAM )
     	ELSE IF( KEY.EQ.51 .OR. KEY.EQ.82 ) THEN
     	    GOTO 222				!DIALOGUE MENU
     	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.63 .OR. KEY.EQ.81 ) THEN
     	    KEY = IFMISC_TYPE('GRAFIT$HLP:XYPLOT_HELP.HLP','MENU',-2)
     	    IF( KEY.GT.0 ) THEN
     		CALL IFANSI_VIDEO(70)
     		WRITE(6,777)
  777		FORMAT('_oops: Help file is not available.')
     		CALL IFANSI_VIDEO(47)
     	    ENDIF
     	ELSE IF( KEY.EQ.36 .OR. KEY.EQ.83 ) THEN	!SPAWN
     	    CALL IFMISC_SPAWN( '$', 0 )
     	    CALL IFINIT_LINE( -3 )
     	ELSE
     	    GOTO 445
     	ENDIF
    	GOTO 444
C
C  RETURN TO THE MAIN MENU...
C
  999	RETURN
	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
     	CALL IF_DCL_FILE( 1, ADDNAM )
     	KSET = -1
     	IERR = XYPLOT_DATA( ADDNAM, MNS, MNP, KSET, NUMS, X, Y, LABL )
     	IF( IERR.EQ.1 ) GOTO 555
     	IF( IERR.EQ.2 ) GOTO 666
     	IF( KSET.EQ.0 ) GOTO 777
C
C  YES, WE HAVE A NEW PLOT...
C
     	NSET = 0
     	MSET = KSET
     	CALL XYPLOT_RANGE( 1, KSET )
     	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
     	DO  I=2, NFLS
     	    CALL IF_DCL_FILE( I, ADDNAM )
     	    KSET = -1
     	    IERR = MSET + 1
     	    IERR = XYPLOT_DATA( ADDNAM, MNS-MSET, MNP, KSET,
     +             NUMS(IERR), X(1,IERR), Y(1,IERR), LABL(IERR) )
     	    IF( IERR.EQ.1 ) GOTO 555
     	    IF( IERR.EQ.2 ) GOTO 666
     	    IF( KSET.EQ.0 ) GOTO 777
     	    CALL XYPLOT_RANGE( MSET+1, MSET+KSET )
     	    MSET = MSET + KSET
     	ENDDO
C
C  SCALE THE DATA...
C
     	CALL XYPLOT_INIT(1)
     	IERR = XYPLOT_SETUP( 1, PARNAM )
     	IF( IERR.EQ.0 ) THEN
     	    CALL XYPLOT_SCALE(1)
     	    CALL XYPLOT_SCALE(2)
     	ENDIF
     	ICODE = 1
     	IF( .NOT.IF_DCL_HARDCOPY() ) RETURN
C
C  MAKE THE HARDCOPY...
C
     	CALL XYPLOT_PLOT
     	CALL IFCOPY( HPAR(1), PLOTID )
     	GOTO 998
C
C  ERROR FROM READING A DATA_FILE...
C
555	WRITE(6,556) ADDNAM
556	FORMAT(' %XYPLOT_DCL: can not open file ',A32)
     	GOTO 999
666	WRITE(6,667) ADDNAM
667	FORMAT(' %XYPLOT_DCL: error from reading file ',A32)
     	GOTO 999
777	WRITE(6,778) ADDNAM
778	FORMAT(' %XYPLOT_DCL: no data found in file ',A32)
999	IF( .NOT.IF_DCL_HARDCOPY() ) RETURN
998	CALL EXIT
     	END

