     	FUNCTION LAYOUT_COM( IK, TEXT )
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY,  JUN-1986
C
C	THIS ROUTINE IMPLEMENTS SOME LAYOUT COMMANDS.
C
    	INCLUDE		'LAYOUT.CBS'
    	CHARACTER	KEY*3, TEXT*(*)

     	IOP = IK	!TERMINATOR CHARACTER
C
C  ENABLE GIN...
C
    	KEY = TEXT(1:3)
     	IF( KEY.EQ.'GIN' .OR. KEY.EQ.'F4' ) THEN
     	    IF( TEK.LT.4106 ) GOTO 555
     	    CALL LAYOUT_GIN( TEXT )
C
C  PLOT A NEW LAYOUT ...
C
     	ELSE IF( KEY.EQ.'PLO' ) THEN
     	    IF( MODE.EQ.2 ) GOTO 666
     	    CALL LAYOUT_PLOT( TEXT )
C
C  OVERLAY ANOTHER PLOT FILE...
C
     	ELSE IF( KEY.EQ.'OVE' .OR. KEY.EQ.'INC' ) THEN
     	    IF( CRT.EQ.1 ) GOTO 555
     	    CALL LAYOUT_OVERLAY( TEXT )
C
C  PICK ENTRIES...
C
     	ELSE IF( KEY.EQ.'PIC' .OR. KEY.EQ.'SEL' ) THEN
     	    IF( TEK.LT.4106 ) GOTO 555
     	    IF( NLC.EQ.0 ) GOTO 777
     	    CALL LAYOUT_PICK( TEXT )
C
C  REFRESH THE SCREEN...
C
     	ELSE IF( KEY.EQ.'REF' .OR. KEY.EQ.'F3' ) THEN
     	    IF( TEK.LT.4106 ) GOTO 555
     	    CALL IFINIT_FRESH
C
C  RELEASE THE PICKED ENTRIES...
C
     	ELSE IF( KEY.EQ.'REL' .OR. KEY.EQ.'F2' ) THEN
     	    IF( TEK.LT.4106 ) GOTO 555
     	    IF( NLG.EQ.0 ) GOTO 444
     	    CALL LAYOUT_SET_BLINK( 0 )
C
C  SAVE THE PLOT INTO A FILE...
C
     	ELSE IF( KEY.EQ.'SAV' .OR. (IOP.EQ.27.AND.KEY.EQ.'OP') ) THEN
     	    IF( CRT.EQ.1 ) GOTO 555
     	    IF( NLC.EQ.0 ) GOTO 777
     	    CALL LAYOUT_SAVE( TEXT )
C
C  CLEAR THE SCREEN...
C
     	ELSE IF( KEY.EQ.'CLE' ) THEN
     	    IF( CRT.EQ.1 ) GOTO 555
     	    IF( MODE.EQ.2 ) GOTO 666
     	    CALL IFINIT_PLOT( XORG, YORG, LOFILE )
     	CALL IFINIT_FKEYS( 'VISION', 'RELEASE', 'REFRESH',
     + 'GIN-FLIP', 'MOVE', 'ROTATE', 'ZOOM', 'COLOR' )
    	    CALL LAYOUT_INIT
C
C  MAKE MULTIPLE COPIES OF THE PICKED ENTRIES...
C
     	ELSE IF( KEY.EQ.'COP' ) THEN
     	    IF( TEK.LT.4106 ) GOTO 555
     	    IF( NLG.EQ.0 ) GOTO 444
     	    CALL LAYOUT_COPY( TEXT )
C
C  DELETE ENTRIES...
C
     	ELSE IF( KEY.EQ.'DEL' ) THEN
     	    IF( TEK.LT.4106 ) GOTO 555
     	    IF( NLG.EQ.0 ) GOTO 444
     	    CALL LAYOUT_DELETE
C
C  MAKE A HARDCOPY...
C
     	ELSE IF( KEY.EQ.'HAR' ) THEN
     	    IF( CRT.EQ.1 ) GOTO 555
     	    IF( NLC.EQ.0 ) GOTO 777
     	    CALL IFCOPY( HPAR(1), PLOTID )
     	ELSE IF( IOP.EQ.27 .AND. KEY.EQ.'OR' ) THEN
     	    IF( CRT.EQ.1 ) GOTO 555
     	    IF( NLC.EQ.0 ) GOTO 777
     	    WRITE(6,1234)
 1234	    FORMAT('$Working...')
     	    CALL IFFEED( HPAR(1), PLOTID, ' ' )
C
C  SET LAYOUT ATTRIBUTES...
C
     	ELSE IF( KEY.EQ.'SET' ) THEN
     	    IF( CRT.EQ.1 ) GOTO 555
     	    CALL LAYOUT_SET( TEXT )
C
C  SPAWN A SYSTEM SUBPROCESS...
C
     	ELSE IF( KEY.EQ.'DCL' .OR. (IOP.EQ.27.AND.KEY.EQ.'OS') ) THEN
     	    CALL IFMISC_SPAWN( TEXT, 0 )
     	    CALL IFINIT_LINE( -3 )
C
C  NOT IN THE COMMAND LIST...
C
     	ELSE
     	    IF( IOP.EQ.27 ) THEN
     		CALL IFANSI_VIDEO(70)
     		WRITE(6,1000)
1000		FORMAT('_oops: Undefined function key.')
     		CALL IFANSI_VIDEO(47)
     		GOTO 999
     	    ELSE
     		GOTO 666
     	    ENDIF
     	ENDIF
     	GOTO 999

444	CALL LAYOUT_ERROR(6)		!NO PICKED ENTRIES YET
     	GOTO 999
555	CALL LAYOUT_ERROR(8)		!INVALID TERMINAL TYPE
     	GOTO 999
777	CALL LAYOUT_ERROR(5)		!NOTHING TO WORK ON
999	LAYOUT_COM = 1
     	RETURN
666	LAYOUT_COM = 0			!NOT IN THE LIST
     	RETURN
    	END

    	SUBROUTINE LAYOUT_PLOT( TEXT )
C
C  PROGRAMMER: R.S. ZHOU		MAY-1986
C
C  	THIS ROUTINE DRAWS A LAYOUT.
C
    	INCLUDE		'LAYOUT.CBS'
    	CHARACTER	SNAME*32, TEXT*(*)
     	LOGICAL		YES

    	NCH = IFMISC_NEXT( TEXT )
    	IF( NCH.GT.0 ) GOTO 111
     	WRITE(6,100)
100	FORMAT('$Filename [.DES] ')
    	READ(5,101,ERR=999,END=999) SNAME
101	FORMAT(A)
    	IF( SNAME.EQ.' ' ) GOTO 999
    	GOTO 222
111	IF( NCH.GT.32 ) THEN
     	    CALL LAYOUT_ERROR(20)
     	    GOTO 999
     	ENDIF
     	SNAME = TEXT
222	CALL IFMISC_DEFEXT( SNAME, '.DES' )
C
C  CHECK IF THE FILE EXIST...
C
     	INQUIRE( FILE=SNAME, EXIST=YES )
     	IF( .NOT.YES ) THEN
     	    CALL LAYOUT_ERROR( 19 )
     	    GOTO 999
     	ENDIF
C
C  FILE EXISTS. PLOT IT...
C
     	IF( LOFILE.EQ.' ' ) LOFILE = SNAME
     	CALL LAYOUT_INIT
     	CALL IFINIT_PLOT( XORG, YORG, LOFILE )
     	CALL IFINIT_FKEYS( 'VISION', 'RELEASE', 'REFRESH',
     + 'GIN-FLIP', 'MOVE', 'ROTATE', 'ZOOM', 'COLOR' )
    	NCH = LAYOUT_IO( 1, SNAME )
     	IF( NCH.GT.0 ) THEN
     	    IF( CRT.EQ.1 ) CALL IFCOPY( HPAR(1), PLOTID )
     	ELSE
     	    IF( NCH.EQ.0 ) CALL LAYOUT_ERROR( 7 )
     	    IF( NCH.LT.0 ) CALL LAYOUT_ERROR( 9 )
     	ENDIF

999	RETURN
    	END

    	SUBROUTINE LAYOUT_OVERLAY( TEXT )
C
C  PROGRAMMER: R.S. ZHOU		MAY-1986
C
C  	THIS ROUTINE OVERLAYS A LAYOUT PLOT.
C
    	INCLUDE		'LAYOUT.CBS'
    	CHARACTER	SNAME*32, TEXT*(*)
     	LOGICAL		YES

    	NCH = IFMISC_NEXT( TEXT )
    	IF( NCH.GT.0 ) GOTO 111
     	WRITE(6,100)
100	FORMAT('$Filename [.DES] ')
    	READ(5,101,ERR=999,END=999) SNAME
101	FORMAT(A)
     	IF( SNAME.EQ.' ' ) GOTO 999
    	GOTO 222

111	IF( NCH.GT.32 ) THEN
     	    CALL LAYOUT_ERROR(20)
     	    GOTO 999
     	ENDIF
     	SNAME = TEXT
C
C  CHECK IF THE FILE EXIST...
C
222	CALL IFMISC_DEFEXT( SNAME, '.DES' )
     	INQUIRE( FILE=SNAME, EXIST=YES )
     	IF( .NOT.YES ) THEN
     	    CALL LAYOUT_ERROR( 19 )
     	    GOTO 999
     	ENDIF
C
C  FILE EXISTS. PLOT IT...
C
     	IF( LOFILE.EQ.' ' ) LOFILE = SNAME
    	NCH = LAYOUT_IO( 1, SNAME )
     	IF( NCH.GT.0 ) THEN
     	    IF( CRT.EQ.1 ) CALL IFCOPY( HPAR(1), PLOTID )
     	ELSE
     	    IF( NCH.EQ.0 ) CALL LAYOUT_ERROR( 7 )
     	    IF( NCH.LT.0 ) CALL LAYOUT_ERROR( 9 )
     	ENDIF

999	RETURN
    	END

    	SUBROUTINE LAYOUT_SAVE( TEXT )
C
C   PROGRAMMER: R.S. ZHOU	MAY-1986
C
C  	THIS ROUTINE SAVES THE CURRENT LAYOUT IN A FILE.
C
    	INCLUDE 'LAYOUT.CBS'
    	CHARACTER PNAME*32, SNAME*32, TEXT*(*)

    	NCH = IFMISC_NEXT( TEXT )
    	IF( NCH.GT.32 ) THEN
     	    CALL LAYOUT_ERROR(20)
     	    GOTO 999
     	ENDIF
     	SNAME = TEXT
     	IF( NCH.GT.0 ) GOTO 111
C
C  GET THE FILENAME...
C
    	SNAME = 'JUNK.DES'
    	IF( LOFILE.NE.' ' ) SNAME = LOFILE
    	NCH = IFMISC_LENG( SNAME )
    	WRITE(6,1000) SNAME
1000	FORMAT('$Save layout in [',A<NCH>,'] ')
    	READ(5,1001,ERR=999,END=999) PNAME
1001	FORMAT(A)
    	IF( PNAME.NE.' ' ) SNAME = PNAME

111	NCH = LAYOUT_IO( 0, SNAME )
    	IF( LOFILE.EQ.' ' ) LOFILE = SNAME

999	RETURN
    	END

