     	SUBROUTINE PIEPLT_MAIN
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY   JULY-1985
C
C	MAIN ROUTINE OF PIE-CHART PLOT.
C
    	INCLUDE		'PIEPLT.CBS'
C
C  INITIALIZE PLOT PARAMETERS...
C
     	CALL PIEPLT_INIT(0)
C
C  CHECK THE INPUT COMMAND LINE...
C
     	CALL PIEPLT_DCL( KEY )
     	IF( KEY.NE.0 ) GOTO 333
C
C  CONDUCT THE DIALOGUE...
C
  222	CALL PIEPLT_MENU( KEY )
     	IF( KEY.NE.0 ) GOTO 999
C
C  CARRY OUT THE PLOTTING...
C
  333	CALL PIEPLT_PLOT
C
C  PRESENT LOCAL COMMAND MENU...
C
  444	CALL IFANSI_VIDEO(30)
     	WRITE(6,555)
  555	FORMAT(' PIEPLT_MENU (Please press a desired function code): ')
     	CALL IFANSI_VIDEO(47)
     	WRITE(6,556)
  556	FORMAT(' 0>Exit 1>Hardcopy 2>Layout 3>Dialog',
     +' 6>Redraw ?>Help $>DCL_prompt ...')
     	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 PIEPLT_DATA( 0, DATNAM )
     	    CALL IFINIT_LINE( -3 )
     	ELSE IF( KEY.EQ.80 ) THEN	!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.54 ) THEN
     	    GOTO 333				!REDRAW THE PLOT
     	ELSE IF( KEY.EQ.63 .OR. KEY.EQ.81 ) THEN
     	    KEY = IFMISC_TYPE('GRAFIT$HLP:PIEPLT_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 PIEPLT_DCL( ICODE )
C
C	THIS ROUTINE CHECKS INPUT DCL COMMAND LINE.
C
     	INCLUDE 'PIEPLT.CBS'
C
C  IS THERE A FILE IN THE LINE...
C
     	ICODE = 0
     	CALL IF_DCL_FILE( 1, DATNAM )
     	IF( DATNAM.EQ.' ' ) THEN
     	    DATNAM = 'JUNK.PIE'
     	    RETURN
     	ENDIF
     	IERR = PIEPLT_DATA( 1, DATNAM )
     	IF( IERR.GT.0 ) GOTO 999
C
C  YES, WE HAVE A NEW PLOT...
C
     	CALL IF_DCL_LAYOUT( DESNAM )
     	IF( DESNAM.EQ.' ' ) THEN
     	    DESNAM = DATNAM
     	    CALL IFMISC_NAMEXT( DESNAM, '.DES' )
     	ENDIF
     	ICODE = 1
     	IF( .NOT.IF_DCL_HARDCOPY() ) RETURN
C
C  MAKE THE HARDCOPY...
C
     	CALL PIEPLT_PLOT
     	CALL IFCOPY( HPAR(1), PLOTID )
     	GOTO 888
C
C  ERROR FROM READING THE DATA FILE...
C
999	IF( IERR.EQ.1 ) WRITE(6,1001) DATNAM
1001	FORMAT(' %PIEPLT_DCL: can not open file ',A32)
     	IF( IERR.EQ.2 ) WRITE(6,1002) DATNAM
1002	FORMAT(' %PIEPLT_DCL: no pie found in file ',A32)
     	IF( .NOT.IF_DCL_HARDCOPY() ) RETURN
888	CALL EXIT
     	END

