     	PROGRAM 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 THE SESSION...
C
     	CALL IFINIT_SESSION
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 ) THEN
     	    IF( .NOT.IFINIT_DIFF() ) GOTO 999
     	    GOTO 444
     	ENDIF
C
C  CARRY OUT THE PLOTTING...
C
  333	CALL PIEPLT_PLOT
     	IF( CRT.EQ.1 ) THEN
     	    CALL IFANSI_CURSOR(1,1)
     	    CALL IFANSI_CLEAR(6)
     	ENDIF
     	WRITE(6,334)
  334	FORMAT(' PIEPLT> Please press a desired function key:')
C
C  PRESENT LOCAL COMMAND MENU...
C
  444	CALL IFANSI_VIDEO(47)
     	WRITE(6,445)
  445	FORMAT(' PIEPLT> ?>Help 0>Exit 1>Hardcopy 2>Layout 3>Dialog',
     +' 6>Redraw $>DCL_prompt ...')
     	CALL IFANSI_CURSOR(0,8)
     	CALL IFQIOW_KEY( KEY )

     	IF( KEY.EQ.26 .OR. KEY.EQ.48 .OR. KEY.EQ.69 ) GOTO 999
     	IF( KEY.EQ.49 .OR.KEY.EQ.72 ) THEN	!HARDCOPY WITH PAGE SETUP
     	    CALL IFCOPY( HPAR(1), PLOTID )
     	    CALL PIEPLT_DATA( 0, DATNAM )
     	    CALL IFINIT_LINE( -3 )
     	ELSE IF( KEY.EQ.-80 ) THEN	!HARDCOPY WITHOUT PAGE SETUP
     	    CALL IFANSI_CURSOR(0,14)
     	    CALL IFANSI_LEDS(1)
     	    CALL IFFEED( HPAR(1), PLOTID, ' ' )
     	    CALL IFANSI_LEDS(0)
     	ELSE IF( KEY.EQ.50 .OR. KEY.EQ.76 ) THEN	!LAYOUT
     	    IF( DESNAM.EQ.' ' ) THEN
     		DESNAM = DATNAM
     		CALL IFMISC_NAMEXT( DESNAM, '.DES' )
     	    ENDIF
     	    CALL LAYOUT_AUX( 2, XORG, YORG, DESNAM )
     	ELSE IF( KEY.EQ.51 .OR. KEY.EQ.68 .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.54 .OR. KEY.EQ.82 ) THEN
     	    GOTO 333				!REDRAW THE PLOT
     	ELSE IF( KEY.EQ.32 .OR. KEY.EQ.63 .OR. KEY.EQ.-81 ) THEN
     	    CALL IFMISC_HLP( 'PIEPLT', '$ 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  RETURN TO THE MAIN MENU...
C
  999	CALL IFINIT_EXIT
     	CALL EXIT
	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
     	SLIN = -1
     	SCOL = 0
     	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
C
C  MAKE THE HARDCOPY...
C
     	IF( IF_DCL_HARDCOPY() ) THEN
     	    CALL PIEPLT_PLOT
     	    CALL IFCOPY( HPAR(1), PLOTID )
     	ENDIF
     	GOTO 888
C
C  ERROR FROM READING THE DATA FILE...
C
999	IF( IERR.EQ.1 ) WRITE(6,1001) DATNAM
     	IF( IERR.EQ.2 ) WRITE(6,1002) DATNAM
1001	FORMAT(' %PIEPLT: can not open file ',A32)
1002	FORMAT(' %PIEPLT: no pie found in file ',A32)
888	IF( .NOT.IF_DCL_HARDCOPY() ) RETURN
     	CALL EXIT
     	END

     	SUBROUTINE PIEPLT_MENU( ICODE )
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY, FEB-1985
C
C  	INTERACTIVE DIALOGUE MENU FOR PIE-CHART PLOT.
C	RETURN WITH "ICODE=1" IF QUITING.
C
    	INCLUDE		'PIEPLT.CBS'
     	PARAMETER	(NKS = 18)
     	CHARACTER	KWD(NKS)*2
    	CHARACTER	TEXT*80, KEY*2, SYM*1
     	EQUIVALENCE	(SYM,TEXT(3:3)), (KEY,TEXT(1:2))
     	COMMON/PIEPLT_MENU/  JSET, IKEY, NCHS, TEXT
C
C  ACCESS 2 LETTER CODES TO GRAPH PARAMETERS...
C
     	DATA KWD / 'F1', 'F4', 'GT', 'TP', 'TC', 'GO', 'SF', 'SE',
     + 'PA', 'PD', 'NO', 'LP', 'PI', 'PN', 'PT', 'LI', 'CO', 'ID' /
C
C  PRESENT THE DIALOGUE MENU...
C
    	JSET = 1			!ACTIVE SLICE POINTER
     	IF( MENU ) THEN
     	    SLIN = 21
     	    SCOL = 6
     	    CALL PIEPLT_FORM( JSET )
     	    CALL IFANSI_VIDEO(47)
        CALL IFANSI_TEXT( ' Type HELP (or press PF2) if you need any',
     +      42, SLIN, SCOL+10 )
     	ELSE
     	    SLIN = -1
     	    SCOL = 0
     	    CALL IFANSI_LEDS(3)
     	    WRITE(6,1)
  1	    FORMAT('_PIEPLT> 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('PIEPLT> ', 8, 22, 1 )
     	    CALL IFANSI_CLEAR(4)
     	ELSE
     	    WRITE(6,112)
112	    FORMAT(' PIEPLT> ',$)
     	ENDIF
     	IKEY = IFQIOW( NCHS, TEXT )
     	IF( IKEY.EQ.26) GOTO 888
     	IF( NCHS.EQ.0 ) GOTO 111
     	NCHS = IFMISC_STRIP(TEXT)
     	CALL   IFMISC_UPPER(2,KEY)
     	IF( KEY.EQ.'QU' .OR. KEY.EQ.'EX' ) GOTO 888
     	IF( NCHS.EQ.2  .AND. KEY.EQ.'GO' ) GOTO 999
     	IF( MENU ) CALL PIEPLT_CLEAR_OOPS
C
C  COMMAND INPUT...
C
     	IF( SYM.NE.'='  ) THEN
     	    CALL PIEPLT_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	TEXT = TEXT(4:)
     	NCHS = NCHS-3
     	IF( IKEY.LT.3 ) THEN
     	    CALL PIEPLT_FILES
     	    GOTO 111
     	ELSE IF( IKEY.EQ.3 ) THEN
     	    TITL = TEXT
     	    CALL PIEPLT_PARS_ALL(1)
     	ELSE IF( IKEY.LT.11 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-2
     	    CALL PIEPLT_OVERALL
     	ELSE IF( IKEY.LT.18 ) THEN
     	    IF( NCHS.EQ.0 ) GOTO 666
     	    IKEY = IKEY-10
     	    CALL PIEPLT_SET
     	ELSE
     	    LABL(JSET) = TEXT
     	    CALL PIEPLT_PARS_SET(JSET,8)
     	ENDIF
     	GOTO 111
666	CALL IFMISC_OOPS(4,SLIN,SCOL,' ')
     	GOTO 111
888	ICODE = 1		!QUIT FROM THE DIALOGUE
     	CALL IFANSI_CLEAR(2)
     	IF( .NOT.MENU ) CALL IFANSI_LEDS(0)
     	RETURN
999	IF( NPIE.EQ.0 ) GOTO 888
     	CALL PIEPLT_DATA(0,DATNAM)
     	ICODE = 0
     	IF( .NOT.MENU ) CALL IFANSI_LEDS(0)
     	RETURN
    	END

     	SUBROUTINE PIEPLT_FORM(JSET)
C
C	THIS ROUTINE LAYOUTS THE DIALOGUE MENU FOR PIE-CHART PLOT.
C
    	INCLUDE 'PIEPLT.CBS'
C
C  LAYOUT THE MENU...
C
     	IF( .NOT.MENU ) RETURN
     	CALL IFINIT_LINE(24)
     	CALL IFANSI_TITLE('GRAFIT: Pie-Chart Plot (max    slices)')
     	CALL IFANSI_VIDEO(60)
     	CALL IFANSI_IFL( MNP, 1, 'I2', 1, 29 )

     	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='/' TP=',8X,'TC=',4X,'GO=',14X,'SF='
     +,15X,'SE=',6X,'PA=',6X,'PD=')

     	CALL IFANSI_VIDEO(90)
     	WRITE(6,1002)
1002	FORMAT(X,80(' '))
     	IF( CRT.EQ.2 ) THEN
     	    CALL IFANSI_VIDEO(50)
     	ELSE
     	    CALL IFANSI_VIDEO(47)
     	    CALL IFANSI_VIDEO(90)
     	ENDIF
     	WRITE(6,2000)
2000	FORMAT('    * * * * *   S L I C E   D R A W I N G'
     +,'   P A R A M E T E R S   * * * * *      ')
     	CALL IFANSI_VIDEO(47)
     	WRITE(6,2001)
2001	FORMAT(' NO=',5X,'NP:',7X,'ID=',44X,'LP='/
     +' PI=',19X,'%',16X,'PN=',6X,'PT=',6X,'LI=',5X,'CO=')

     	CALL IFANSI_VIDEO(90)
     	WRITE(6,1002)
     	IF( CRT.EQ.2 ) THEN
     	    CALL IFANSI_VIDEO(50)
     	ELSE
     	    CALL IFANSI_VIDEO(90)
     	ENDIF
     	WRITE(6,3000)
3000	FORMAT('     * * * * * * * *   I N P U T  &  O U T P U T'
     +,'   F I L E S   * * * * * * *     ')
     	CALL IFANSI_VIDEO(47)
     	WRITE(6,3001)
3001	FORMAT(' F1=',38X,'F4=')

     	CALL IFANSI_VIDEO(90)
     	CALL IFANSI_TEXT( ' ', 80, 20, 1 )
     	CALL IFANSI_VIDEO(20)
     	WRITE(6,4000)
4000	FORMAT(' oops:'//' Auxiliary: HELP/PF2, DCL/PF4,',
     +' DOWN_SLICE/PF1, UP_SLICE/PF3, LIST, REFRESH,      '/
     +' _commands: GO, EXIT, READ, PLOT, LAYOUT, SAVE,',
     +' RESET, DELETE, TIME ...',9X,' ',$)
C
C  INSERT THE PARAMETERS...
C
     	CALL PIEPLT_PARS(JSET)
     	RETURN
     	END

     	SUBROUTINE PIEPLT_PARS(JSET)
C
C	THIS ROUTINE INSERTS ALL GRAPH PARAMETERS.
C
     	INCLUDE 'PIEPLT.CBS'
     	IF( MENU ) THEN
     	    CALL PIEPLT_PARS_ALL(0)	!OVERALL PLOT PARAMETER GROUP
     	    CALL PIEPLT_PARS_SET(JSET,0)!SLICE DRAWING PARAMETER GROUP
     	    CALL PIEPLT_NPIE		!TOTAL NUMBER OF SLICES ENTERED
     	    CALL PIEPLT_PARS_FILE(0)	!I/O FILE GROUP
     	ENDIF
     	RETURN
    	END

     	SUBROUTINE PIEPLT_PARS_ALL( ICODE )
C
C	THIS ROUTINE DISPLAYS OVERALL PLOT PARAMETERS.
C
     	INCLUDE 'PIEPLT.CBS'
     	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, 77, 3, 4 )
    	IF(I.EQ.0.OR.I.EQ.2) THEN
     	   IF( PTIT.EQ.1 ) CALL IFANSI_TEXT( 'BOTTOM', 6, 4, 4 )
     	   IF( PTIT.EQ.2 ) CALL IFANSI_TEXT( 'TOP   ', 6, 4, 4 )
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.3) CALL IFANSI_IFL( CTIT,1,'I2',4,15 )
    	IF(I.EQ.0.OR.I.EQ.4) CALL IFANSI_FFL( XORG,2,'2F6.2',4,22 )
     	IF(I.EQ.0.OR.I.EQ.5) CALL IFANSI_FFL( XSCL,2,'2F6.3',4,39 )
     	IF(I.EQ.0.OR.I.EQ.6) THEN
     	   YES = 'YES'
     	   IF( .NOT.INIT ) YES = 'NO'
     	   CALL IFANSI_TEXT( YES, 3, 4, 57 )
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.7) CALL IFANSI_IFL( PANG, 1, 'I4', 4, 66 )
    	IF(I.EQ.0.OR.I.EQ.8) CALL IFANSI_FFL( PIED, 1, 'F6.2', 4, 75 )

     	RETURN
     	END

	SUBROUTINE PIEPLT_PARS_SET( ICODE, IPAR )
C
C	THIS ROUTINE DISPLAYS SLICE DRAWING PARAMETERS.
C
    	INCLUDE 'PIEPLT.CBS'

     	IF( .NOT.MENU ) RETURN
     	CALL IFANSI_VIDEO(30)
     	JSET = ICODE
     	I = IPAR-1
     	IF( I.LT.0 ) I = 0
     	IF(I.EQ.0) CALL IFANSI_IFL( JSET, 1, 'I2', 7, 4 )
    	IF(I.EQ.0.OR.I.EQ.7) CALL IFANSI_TEXT(LABL(JSET), 42, 7, 22 )
     	IF(I.EQ.0.OR.I.EQ.1)
     +    CALL IFANSI_FFL(XLPS(1,JSET),2,'2F6.2',7,69)
    	IF(I.EQ.0.OR.I.EQ.2) THEN
     	   CALL IFANSI_FFL( PIES(JSET),1,'G12.5',8,4 )
    	   CALL IFANSI_FFL( PERC(JSET),1,'F6.2',8,17)
     	ENDIF
    	IF(I.EQ.0.OR.I.EQ.3) CALL IFANSI_IFL(IPEN(JSET),1,'I3',8,43)
    	IF(I.EQ.0.OR.I.EQ.4) CALL IFANSI_IFL( IPAT(JSET),1,'I3',8,52)
    	IF(I.EQ.0.OR.I.EQ.5) CALL IFANSI_IFL( ILIN(JSET),1,'I3',8,61)
    	IF(I.EQ.0.OR.I.EQ.6)
     +     CALL IFANSI_FFL(XOFF(1,JSET),2,'2F6.2',8,69)

     	RETURN
	END

     	SUBROUTINE PIEPLT_NPIE
     	INCLUDE 'PIEPLT.CBS'
     	IF( .NOT.MENU ) RETURN
     	CALL IFANSI_VIDEO(24)
     	CALL IFANSI_VIDEO(80)
     	CALL IFANSI_IFL( NPIE, 1, 'I3', 7, 12 )
        CALL IFANSI_VIDEO(30)
     	RETURN
     	END

     	SUBROUTINE PIEPLT_PARS_FILE( ICODE )
C
C	THIS ROUTINE DISPLAYS FILENAMES.
C
     	INCLUDE 'PIEPLT.CBS'

     	IF( .NOT.MENU ) RETURN
     	I = ICODE
     	CALL IFANSI_VIDEO(20)
     	IF( I.LT.2 ) CALL IFANSI_TEXT( DATNAM, 36, 11, 4 )
     	IF( I.NE.1 ) CALL IFANSI_TEXT( DESNAM, 36, 11, 45)
     	RETURN
     	END

     	SUBROUTINE PIEPLT_COM
C
C	THIS ROUTINE IMPLEMENTS SOME DIALOGUE COMMANDS.
C
C	LIST OF COMMANDS:
C
C	HELP   : display help information.
C	REFRESH: re-layout the dialogue menu.
C	SAVE   : save graph parameters.
C	RESET  : reset plot setup.
C	READ   : read a data file to start a new plot.
C	PLOT   : read and plot a data file to start a new plot.
C	LAYOUT : use another layout file.
C	DELETE : delete a slice from input list.
C	LIST   : list all slice parameters.
C	DCL    : spawn a system subprocess.
C	DOWN   : step slice pointer down by one.
C	UP     : step slice pointer back by one.
C
     	INCLUDE		'PIEPLT.CBS'
    	CHARACTER	TEXT*80
     	COMMON/PIEPLT_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 PIEPLT_FILES
     		RETURN
     	    ENDIF
     	ENDIF
     	IF( TEXT(1:4).EQ.'DOWN'
     + .OR. (IKEY.EQ.27 .AND. TEXT(1:2).EQ.'OP') ) THEN
C
C  DOWN...
     	    JSET = JSET + 1
     	    IF( JSET.GT.MNP ) JSET = 1
     	    CALL PIEPLT_PARS_SET(JSET,0)
     	ELSE IF( KEY.EQ.'UP'
     + .OR. (IKEY.EQ.27 .AND. TEXT(1:2).EQ.'OR') ) THEN
C
C  UP...
     	    JSET = JSET - 1
     	    IF( JSET.LT.1 ) JSET = MNP
     	    CALL PIEPLT_PARS_SET(JSET,0)
     	ELSE IF( TEXT(1:4).EQ.'LIST' ) THEN
C
C  LIST...
     	    IF( NPIE.EQ.0 ) GOTO 888
     	    CALL PIEPLT_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( 'PIEPLT', TEXT, SLIN, SCOL )
     		IF( IKEY.EQ.0 ) CALL PIEPLT_FORM(JSET)
     	    ELSE
     		IKEY = IFMISC_HLP( 'PIEPLT', 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 PIEPLT_FORM(JSET)
     	ELSE IF( TEXT(1:4).EQ.'SAVE' ) THEN
C
C  SAVE...
     	    IF( NPIE.EQ.0 ) GOTO 888
     	    CALL PIEPLT_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 PIEPLT_FILES
     	ELSE IF( TEXT(1:6).EQ.'LAYOUT' ) THEN
C
C  LAYOUT...
     	    IKEY = 2
     	    NCHS = IFMISC_NEXT(TEXT)
     	    CALL PIEPLT_FILES
     	ELSE IF( TEXT(1:3).EQ.'DEL' ) THEN
C
C  DELETE...
     	    IF( NPIE.EQ.0 ) GOTO 888
     	    NCHS = IFMISC_NEXT(TEXT)
     	    CALL PIEPLT_DELPIE
     	ELSE IF( TEXT(1:5).EQ.'RESET' ) THEN
C
C  RESET...
     	    CALL PIEPLT_RESET( JSET )
     	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 PIEPLT_FORM(JSET)
     	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 PIEPLT_RESET( JSET )
C
C	THIS ROUTINE RESETS THE PLOT.
C
     	INCLUDE 'PIEPLT.CBS'
     	IF( MENU ) CALL PIEPLT_CLEAR_OOPS
     	CALL PIEPLT_OOPS(' Resetting the plot...')
     	CALL PIEPLT_INIT(1)
     	IF( MENU ) THEN
     	    CALL PIEPLT_PARS(JSET)
     	    CALL PIEPLT_CLEAR_OOPS
     	ENDIF
     	RETURN
     	END

     	SUBROUTINE PIEPLT_FILES
C
C	THIS ROUTINE GETS INPUT DATA/LAYOUT FILES.
C
     	INCLUDE		'PIEPLT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/PIEPLT_MENU/  JSET, IKEY, NCHS, TEXT

     	JKEY = IKEY
     	IKEY = IABS(IKEY)
     	IF( NCHS.EQ.0  ) THEN
     	    NCHS = IFMISC_PROMPT('_Filename:',TEXT,SLIN+1,9)
     	    IF( NCHS.EQ.0 ) GOTO 999
     	ENDIF
     	IF( NCHS.GT.32 ) THEN
     	    CALL IFMISC_OOPS(7,SLIN,SCOL,TEXT)
     	    GOTO 999
     	ENDIF
     	CALL IFMISC_UPPER(NCHS,TEXT)
     	IF( IKEY.NE.1 ) GOTO 222
C
C  START A NEW PLOT WITH A NEW DATA FILE...
C
     	IKEY = PIEPLT_DATA(1,TEXT)
     	IF( IKEY.GT.0 ) THEN
     	    IF( IKEY.EQ.1 ) THEN
     		CALL IFMISC_OOPS(1,SLIN,SCOL,TEXT)
     	    ELSE
     		CALL IFMISC_OOPS(13,SLIN,SCOL,TEXT)
     		GOTO 999
     	    ENDIF
     	ENDIF
C
C  YES, WE HAVE A NEW FILE...
C
     	DATNAM = TEXT
     	DESNAM = DATNAM
     	CALL IFMISC_NAMEXT( DESNAM, '.DES' )
     	IF( IKEY.EQ.0 ) THEN
     	    JSET = 1
     	    TEXT = ' '
     	    WRITE( TEXT(1:), 1000 ) NPIE
1000	    FORMAT(I4)
     	    TEXT(5:) = ' slices have been read from'
     	    TEXT(33:) = DATNAM
     	    CALL IFANSI_VIDEO(20)
     	    CALL PIEPLT_OOPS( TEXT )
     	    IF( JKEY.GT.0 ) THEN
     		CALL IFANSI_VIDEO(30)
     		CALL PIEPLT_PARS(JSET)
     	    ELSE
     		IKEY = -999
     	    ENDIF
     	ELSE
     	    CALL PIEPLT_PARS_FILE(0)
     	ENDIF
     	GOTO 999

222	IF( IKEY.NE.2 ) 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 PIEPLT_PARS_FILE(2)

999	RETURN
     	END

     	FUNCTION PIEPLT_DATA( ICODE, FNAME )
C
C	THIS ROUTINE READS/WRITES A PIE-CHART DATA FILE.
C
     	INCLUDE        'PIEPLT.CBS'
    	PARAMETER	LUN= 13
    	CHARACTER	KEY*4, REST*127, FNAME*(*)
    	DIMENSION	KP(20), RP(20)
     	LOGICAL         YES

     	IF( FNAME.EQ.' ' ) RETURN
C
C  SET DEFAULT FILE EXT TO .PIE...
C
     	CALL IFMISC_DEFEXT( FNAME, '.PIE' )
     	IF( ICODE.NE.0 ) GOTO 1234
C
C  WRITE THE DATA FILE...
C
    	OPEN( UNIT=LUN, FILE=FNAME, STATUS='UNKNOWN',
     +        CARRIAGECONTROL='LIST', ERR=666 )

    	WRITE(LUN,1000,ERR=666) TITL, PTIT, CTIT, PANG, PIED
     +, XORG, XSCL, (HPAR(I), I=1, 20), PLOTID
1000	FORMAT('%This is a GRAFIT pie-chart data file:'/
     +,'TITL=',A80,/,'OVER=',3I5,5F8.3,/,'PAR1=',10F7.2,/
     +,'PAR2=',10F7.2,/'IDEN=',A32)

     	DO I=1, MNP
     	   IF( PIES(I).GT.0.0 ) WRITE(LUN,1001,ERR=666) PIES(I),
     +     IPEN(I), IPAT(I), ILIN(I), XOFF(1,I),XOFF(2,I),
     +     XLPS(1,I),XLPS(2,I), LABL(I)
     	ENDDO
1001	FORMAT('PIES=',G13.5,3I4,4F8.3,',',A32)
     	PIEPLT_DATA = 0.0
    	GOTO 999
C
C  READ A PIE-CHART DATA FILE...
C
1234	INQUIRE( FILE=FNAME, EXIST=YES )
     	IF( .NOT.YES ) GOTO 666
     	OPEN( UNIT=LUN, FILE=FNAME, STATUS='OLD',
     +        CARRIAGECONTROL='LIST', READONLY, ERR=666 )
C
C  READ KEYWORD LINES ONE BY ONE...
C
     	MPIE = 0
 111	READ(LUN,112,END=555) KEY,REST
 112	FORMAT(A4,X,A127)
     	IF( KEY.EQ.' ' .OR. REST.EQ.' ' ) GOTO 111
     	NCH = IFMISC_STRIP(REST)
     	CALL  IFMISC_UPPER(4,KEY)
     	IF( KEY.EQ.'TITL' ) THEN	!GRAPH TITLE
     	    TITL = REST
     	ELSE IF( KEY.EQ.'OVER' ) THEN	!OVERALL GRAPH PARAMETERS
     	    NCH = IFMISC_DECODE( REST, NCH, 8, RP, KP )
    	    IF( NCH.EQ.0 ) GOTO 111	!ERROR IN THE INPUT
     	    IF( KP(1).EQ.1 ) PTIT = RP(1)
     	    IF( KP(2).EQ.1 ) CTIT = RP(2)
     	    IF( KP(3).EQ.1 ) PANG = RP(3)
     	    IF( KP(4).EQ.1 ) PIED = RP(4)
     	    IF( KP(5).EQ.1 ) XORG(1) = RP(5)
     	    IF( KP(6).EQ.1 ) XORG(2) = RP(6)
     	    IF( KP(7).EQ.1 ) XSCL(1) = RP(7)
     	    IF( KP(8).EQ.1 ) XSCL(2) = RP(8)
     	ELSE IF( KEY.EQ.'PAR1' ) THEN	!HARDCOPY SETUP PARAMETERS
     	    NCH = IFMISC_DECODE( REST, NCH, 10, RP, KP )
    	    IF( NCH.EQ.0 ) GOTO 111	!ERROR IN THE INPUT
     	    DO  I=1, 10
     		IF( KP(I).EQ.1 ) HPAR(I) = RP(I)
     	    ENDDO
     	ELSE IF( KEY.EQ.'PAR2' ) THEN	!HARDCOPY SETUP PARAMETERS
     	    NCH = IFMISC_DECODE( REST, NCH, 10, RP, KP )
    	    IF( NCH.EQ.0 ) GOTO 111	!ERROR IN THE INPUT
     	    DO  I=1, 10
     		IF( KP(I).EQ.1 ) HPAR(I+10) = RP(I)
     	    ENDDO
     	ELSE IF( KEY.EQ.'PIES' ) THEN	!PIE DRAWING PARAMETERS
     	    IF( MPIE.EQ.MNP ) GOTO 111
     	    NCH = IFMISC_DECODE( REST, NCH, 8, RP, KP )
    	    IF( NCH.EQ.0 ) GOTO 111	!ERROR IN THE INPUT
     	    IF( RP(1).LE.0.0 ) GOTO 111
     	    MPIE = MPIE + 1
     	    PIES(MPIE) = RP(1)
     	    IF( KP(2).EQ.1 ) IPEN(MPIE) = RP(2)
     	    IF( KP(3).EQ.1 ) IPAT(MPIE) = RP(3)
     	    IF( KP(4).EQ.1 ) ILIN(MPIE) = RP(4)
     	    IF( KP(5).EQ.1 ) XOFF(1,MPIE) = RP(5)
     	    IF( KP(6).EQ.1 ) XOFF(2,MPIE) = RP(6)
     	    IF( KP(7).EQ.1 ) XLPS(1,MPIE) = RP(7)
     	    IF( KP(8).EQ.1 ) XLPS(2,MPIE) = RP(8)
     	    LABL(MPIE) = REST(NCH:)
     	ELSE IF( KEY.EQ.'IDEN' ) THEN	!PLOT ID LABEL
     	    PLOTID = REST
     	ENDIF
     	GOTO 111
555	IF( MPIE.GT.0 ) GOTO 888
     	PIEPLT_DATA = 2.0		!NO PIE FOUND
     	GOTO 999
666	IERR = 1
     	PIEPLT_DATA = 1.0		!FILE NOT FOUND
     	GOTO 999
888	NPIE = MPIE
     	CALL PIEPLT_SCALE
     	PIEPLT_DATA = 0.0
999	CLOSE(UNIT=LUN)
     	RETURN
     	END

    	SUBROUTINE PIEPLT_INIT( ICODE )
C
C	THIS ROUTINE INITIALIZES THE COMMON BLOCKS FOR PIE-CHART PLOT.
C
    	INCLUDE 'PIEPLT.CBS'

     	IF( ICODE.EQ.0 ) THEN
     	    CRT = IFINIT_ITM(0)		!GET THE TYPE OF TERMINAL
     	    DATNAM = 'JUNK.PIE'
     	    DESNAM = 'JUNK.DES'
     	    TITL = ' '
     	    DO I=1, MNP
     	       PIES(I) = 0.0
     	       PERC(I) = 0.0
    	       LABL(I) = ' '
     	    ENDDO
     	    NPIE = 0
     	    INIT = .TRUE.
     	    MENU = .TRUE.
	    PLOTID = ' '
     	ENDIF

     	CTIT = 3
     	PANG = 0.0
     	PIED = 4.0
     	XORG(1) = 5.0
     	XORG(2) = 4.0
     	XSCL(1) = 1.0
     	XSCL(2) = 1.0
     	PTIT = 1
     	DO I=1, MNP
     	   IPEN(I) = PTIT
     	   PTIT = PTIT + 1
     	   IF( PTIT.GT.7 ) PTIT = 1
     	   IPAT(I) = 1
     	   ILIN(I) = 1
    	   XOFF(1,I) = 0.0
    	   XOFF(2,I) = 0.0
    	   XLPS(1,I) = 0.0
    	   XLPS(2,I) = 0.0
    	ENDDO
     	PTIT = 1

    	RETURN
    	END

	SUBROUTINE PIEPLT_OVERALL
C
C	THIS ROUTINE CHANGES OVREALL PLOT PARAMETERS.
C
    	INCLUDE		'PIEPLT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/PIEPLT_MENU/ JSET, IKEY, NCHS, TEXT
     	DIMENSION	RP(2), KP(2)
C
C  DECODE THE PARAMETERS...
C
     	IF( IKEY.NE.2 .AND. IKEY.NE.6 ) THEN
     	    NCHS = IFMISC_DECODE( TEXT, NCHS, 2, RP, KP )
    	    IF( NCHS.EQ.0 ) GOTO 777
     	ENDIF
     	IF( IKEY.EQ.2 ) THEN
     	    IF( NCHS.LT.3 ) GOTO 777
     	    CALL IFMISC_UPPER(NCHS,TEXT)
     	    IF( TEXT(1:3).NE.'TOP'.AND.TEXT(1:6).NE.'BOTTOM' ) GOTO 777
     	    PTIT = 1
     	    IF( TEXT(1:3).EQ.'TOP' ) PTIT = 2
     	ELSE IF( IKEY.EQ.3 ) THEN
     	    IF( RP(1).LT.1.0 .OR. RP(1).GT.8.0 ) GOTO 777
     	    CTIT = RP(1)
     	ELSE IF( IKEY.EQ.4 ) THEN		!GRAPH ORIGIN
     	    DO I=1,2
     		IF( KP(I).EQ.1 ) THEN
     		IF(RP(I).LT.0.0.OR.RP(I).GT.99.0) GOTO 777
     		XORG(I) = RP(I)
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.5 ) THEN		!OVERALL SCALE FACTORS
     	    DO I=1,2
     		IF( KP(I).EQ.1 ) THEN
     		IF(RP(I).LT.0.1.OR.RP(I).GT.3.0) GOTO 777
    	       	XSCL(I) = RP(I)
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.6 ) THEN		!SCREEN ERASE FLAG
     	    INIT = .TRUE.
     	    IF( TEXT(1:1).EQ.'N' .OR. TEXT(1:1).EQ.'n'
     +     .OR. TEXT(1:1).EQ.'F' .OR. TEXT(1:1).EQ.'f' ) INIT=.FALSE.
     	ELSE IF( IKEY.EQ.7 ) THEN		!1ST PIE ANGULER OFFSET
     	    IF( ABS(RP(1)).GE.360.0 ) GOTO 777
     	    PANG = RP(1)
     	ELSE IF( IKEY.EQ.8 ) THEN		!PIE DIAMETER IN INCHES
     	    IF(RP(1).LT.1.0.OR.RP(1).GT.99.0) GOTO 777
     	    PIED = RP(1)
     	ELSE
     	    GOTO 777
     	ENDIF
     	CALL PIEPLT_PARS_ALL(IKEY)
     	RETURN
777	CALL IFMISC_OOPS(3,SLIN,SCOL,TEXT)
     	RETURN
	END

	SUBROUTINE PIEPLT_SET
C
C	THIS ROUTINE CHANGES PIE DRAWING PARAMETERS
C	IN COLUMN-RUN MODE.
C
    	INCLUDE		'PIEPLT.CBS'
     	CHARACTER	TEXT*80
     	COMMON/PIEPLT_MENU/ JSET, IKEY, NCHS, TEXT
     	DIMENSION	KP(2), RP(2)
C
C  DECODE THE INPUT...
C
     	IF( IKEY.NE.2 ) THEN
     	    J = IFMISC_DECODE( TEXT, NCHS, 2, RP, KP )
    	    IF( J.EQ.0 ) GOTO 777
     	ENDIF
C
C  STORE THE VALID PARAMETERS...
C
     	IF( IKEY.EQ.1 ) THEN
     	    J = RP(1)
     	    IF( J.LT.1 .OR. J.GT.MNP ) GOTO 777
     	    JSET = J
     	    IKEY = 0
     	ELSE IF( IKEY.EQ.2 ) THEN
     	    DO J=1, 2
     		IF( KP(J).EQ.1 ) THEN
     		    IF( ABS(RP(J)).GT.99.0 ) GOTO 777
     		    XLPS(J,JSET) = RP(J)
     		ENDIF
     	    ENDDO
     	ELSE IF( IKEY.EQ.3 ) THEN
     	    IF( RP(1).LT.0.0 ) GOTO 777
     	    PIES(JSET) = RP(1)
     	    CALL PIEPLT_SCALE
     	ELSE IF( IKEY.EQ.4 ) THEN
     	    J = RP(1)
     	    IF( J.LT.0 .OR. J.GT.16 ) GOTO 777
     	    IPEN(JSET) = J
     	ELSE IF( IKEY.EQ.5 ) THEN
     	    J = RP(1)
     	    IF( IABS(J).GT.99 ) GOTO 777
     	    IPAT(JSET) = J
     	ELSE IF( IKEY.EQ.6 ) THEN
     	    J = RP(1)
     	    IF( J.LT.1 .OR. J.GT.9 ) GOTO 777
     	    ILIN(JSET) = J
     	ELSE IF( IKEY.EQ.7 ) THEN
     	    DO J=1, 2
     		IF( KP(J).EQ.1 ) THEN
     		    IF( ABS(RP(J)).GT.9.0 ) GOTO 777
     		    XOFF(J,JSET) = RP(J)
     		ENDIF
     	    ENDDO
     	ELSE
     	    GOTO 777
     	ENDIF
     	CALL PIEPLT_PARS_SET(JSET,IKEY)
     	RETURN
777	CALL IFMISC_OOPS(3,SLIN,SCOL,TEXT)
     	RETURN
	END

	SUBROUTINE PIEPLT_LIST( JSET )
C
C	LIST OF ALL PIE PARAMETERS.
C
	INCLUDE 'PIEPLT.CBS'

     	IF( MENU ) THEN
     	    CALL IFANSI_CURSOR(7,1)
     	    CALL IFANSI_CLEAR(2)
     	ELSE
     	    CALL IFINIT_LINE(24)
     	ENDIF
     	CALL IFANSI_VIDEO(47)
     	CALL IFANSI_VIDEO(80)
     	CALL IFANSI_VIDEO(90)
     	WRITE(6,1)
  1	FORMAT(' NO  PIE-SIZE       %   PEN PAT LIN OFFSET(X,Y)',
     +' LABELS(X,Y)       ID             ')
     	CALL IFANSI_VIDEO(47)
     	DO I=1, MNP
     	   IF( PIES(I).GT.0.0 ) WRITE(6,1234) I, PIES(I), PERC(I),
     +     IPEN(I), IPAT(I), ILIN(I), XOFF(1,I), XOFF(2,I),
     +     XLPS(1,I), XLPS(2,I), LABL(I)
     	ENDDO
1234	FORMAT(X,I2,G13.5,F7.2,3I4,4F6.2,X,A20)
     	CALL IFANSI_VIDEO(30)
	WRITE(6,1000)
1000	FORMAT(/' Press SPACEBAR to continue...',$)
     	CALL IFQIOW_KEY(I)
     	IF( MENU ) THEN
     	    CALL PIEPLT_FORM(JSET)
     	ELSE
     	    CALL IFINIT_LINE(3)
     	ENDIF
	RETURN
	END

     	SUBROUTINE PIEPLT_SAVE
C
C	THIS ROUTINE SAVES CURRENT PLOT IN A FILE.
C
     	INCLUDE		'PIEPLT.CBS'
    	CHARACTER	TEXT*80, STRN*75
     	COMMON/PIEPLT_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 = PIEPLT_DATA( 0, TEXT )
     	IF( IKEY.EQ.0 ) THEN
     	    CALL IFMISC_OOPS(21,SLIN,SCOL,TEXT)
     	ELSE
     	    STRN = ' Current plot has been saved in'
     	    STRN(39:) = TEXT
     	    CALL PIEPLT_OOPS( STRN )
     	ENDIF

999	RETURN
     	END

     	SUBROUTINE PIEPLT_OOPS( TEXT )
     	INCLUDE 'PIEPLT.CBS'
     	CHARACTER TEXT*(*)
     	NCHS = IFMISC_LENG(TEXT)
     	IF( SLIN.GT.0 .AND. SCOL.GT.0 ) THEN
     	    CALL PIEPLT_CLEAR_OOPS
     	    CALL IFANSI_TEXT( TEXT, NCHS, SLIN, SCOL )
     	ELSE
     	    WRITE(6,1000) TEXT(1:NCHS)
1000	    FORMAT('_oops: ',A)
     	ENDIF
     	RETURN
     	END

     	SUBROUTINE PIEPLT_CLEAR_OOPS
     	INCLUDE 'PIEPLT.CBS'
     	IF( MENU ) THEN
     	    CALL IFANSI_CURSOR(SLIN,SCOL)
     	    CALL IFANSI_CLEAR(4)
     	ENDIF
     	RETURN
     	END
 
     	SUBROUTINE PIEPLT_SCALE
C
C	THIS ROUTINE SCALES AND REPACKS PIE LIST.
C
     	INCLUDE 'PIEPLT.CBS'

     	NPIE = 0
     	SUMP = 0.0
     	DO  I=1, MNP
     	    P = PIES(I)
     	    IF( P.GT.0.0 ) THEN
     		NPIE = NPIE + 1
     		SUMP = SUMP + P
     	    ENDIF
     	ENDDO
     	CALL PIEPLT_NPIE
     	IF( NPIE.GT.0 ) THEN
     	    DO  I=1, MNP
     		P = PIES(I)
     		IF( P.GT.0.0 ) PERC(I) = 100.0*P/SUMP
     	    ENDDO
     	ENDIF
     	RETURN
     	END

     	SUBROUTINE PIEPLT_DELPIE
C
C	THIS ROUTINE DELETES A VALID PIE FROM INPUT LIST.
C
     	INCLUDE		'PIEPLT.CBS'
    	CHARACTER	TEXT*80
     	COMMON/PIEPLT_MENU/  JSET, IKEY, NCHS, TEXT

     	IF( NCHS.EQ.0 ) THEN
     	    NCHS = IFMISC_PROMPT('_Slice #',TEXT,SLIN+1,9)
     	    IF( NCHS.EQ.0 ) GOTO 999
     	ENDIF
C     	DECODE( NCHS, 1000, TEXT, ERR=666 ) IKEY
     	READ( TEXT(1:NCHS), 1000, ERR=666 ) IKEY
1000	FORMAT(I)
     	IF( IKEY.LT.1 .OR. IKEY.GT.MNP ) GOTO 666
     	IF( PIES(IKEY).GT.0.0 ) THEN
     	    PIES(IKEY) = 0.0
     	    PERC(IKEY) = 0.0
     	    CALL PIEPLT_SCALE
     	    CALL PIEPLT_PARS_SET(JSET,0)
     	ENDIF
     	GOTO 999
666	CALL IFMISC_OOPS(3,SLIN,SCOL,TEXT)
999	RETURN
     	END

     	SUBROUTINE PIEPLT_PLOT
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY
C
C	THIS ROUTINE CARRIES OUT THE PLOTTING FOR PIE-CHART PLOT.
C
     	INCLUDE 'PIEPLT.CBS'

     	IF( NPIE.EQ.0.0 ) THEN
     	    IF( IF_DCL_HARDCOPY() ) THEN
     		STOP '%PIEPLT: no data yet to proceed'
     	    ELSE
     		CALL IFMISC_OOPS( 12, 0, 0, ' ' )
     		RETURN
     	    ENDIF
     	ENDIF
C
C  INITIALIZE THE CRT...
C
     	CALL IFANSI_VIDEO(47)
     	CALL IFINIT_LINE( 3 )
     	IF( INIT ) THEN
     	    CALL IFINIT_PLOT( XORG(1), XORG(2), DATNAM )
     	ELSE
     	    CALL IFINIT_PLOT( XORG(1), XORG(2), '$OVERLAY' )
     	ENDIF
     	IF( IFCTRL_C() ) GOTO 999
C
C  OPEN A GRAPHICS SEGMENTS TO SAVE THE PLOT...
C
     	IF( .NOT.IFINIT_SAVE() ) RETURN
     	CALL IFSCAL( XSCL(1), XSCL(2) )
C
C  DRAW GRAPH TITLE IF ANY...
C
     	IF( TITL.NE.' ' ) THEN
     	    CALL IFSPEN(CTIT)
     	    YPS = -0.5*PIED-0.65
     	    IF( PTIT.NE.1 ) YPS = -YPS
     	    CALL IFTEXT_CENT(-XORG(1),10.0-XORG(1),YPS,YPS,TITL,.12,.12)
     	ENDIF
C
C  DRAW THE PIES...
C
     	IF( IFCTRL_C() ) GOTO 999
    	CALL PIEPLT_DRAW
C
C  CLOSE THE PLOT SESSION...
C
  555	CALL IFSTYL( 1, 1 )			!RESET PLOTTING STYLUS
     	IF( CRT.EQ.2 ) CALL IFSEG_OPEN( 0 ) 	!CLOSE THE SEGMENT
C
C  OVERLAY THE LAYOUT IF LAYOUT FILE EXISTS...
C
     	IF( IFCTRL_C() ) GOTO 999
    	IF(DESNAM.NE.' ') CALL LAYOUT_AUX(0,XORG(1),XORG(2),DESNAM)
  999	CALL IFINIT_PLOT_END
     	RETURN
    	END

    	SUBROUTINE PIEPLT_DRAW
C
C	THIS ROUTINE DRAWS THE PIES...
C
     	INCLUDE    'PIEPLT.CBS'

     	ANG0 = FLOAT(PANG)
     	PRAD = 0.5*PIED
     	DO 1234 I=1, MNP
     	IF( IFCTRL_C() ) RETURN
     	    IF( PERC(I).LT.1.0 ) GOTO 1234
     	    ANGL = 3.6*PERC(I)
     	    CALL IFSPEN( IPEN(I) )
     	    CALL IFSTYL( ILIN(I), 1 )
     	    IF( IPAT(I).NE.0.0 ) CALL IFFILL( IPAT(I) )
     	    CALL IFARCS( XOFF(1,I), XOFF(2,I), PRAD, PRAD, PRAD,
     +                   0.0, ANG0, ANGL, 1.0 )
     	    IF( IPAT(I).NE.0.0 ) CALL IFFILL( 0 )
     	    ANG0 = ANG0 + ANGL
     	    IF( LABL(I).NE.' ' ) THEN
     		XPS = XLPS(1,I)
     		YPS = XLPS(2,I)
     		ANGL= ANG0 - 0.5*ANGL
     		IF( ANGL.LT.0.0 ) ANGL = 360.0+ANGL
     		IF( XPS.EQ.0.0 .AND. YPS.EQ.0.0 ) THEN
     		    XPS = (PRAD+0.25)*COSD(ANGL)
     		    YPS = (PRAD+0.25)*SIND(ANGL)
     		    IF( ANGL.GT.90.0.AND.ANGL.LT.270.0 ) THEN
     			XPS = XPS-0.1*IFMISC_LENG(LABL(I))
     		    ENDIF
     		    XLPS(1,I) = XPS
     		    XLPS(2,I) = YPS
     		ENDIF
     		XPS = XPS + XOFF(1,I)
     		YPS = YPS + XOFF(2,I)
     		CALL IFTEXT_EXT(XPS,YPS,LABL(I),0.1,0.1,0.0)
     	    ENDIF
1234	CONTINUE
     	RETURN
     	END

