     	SUBROUTINE LAYOUT_MAIN( ICODE, XORG, YORG, FNAME )
C
C  PROGRAMMER:	RONG-SHENG ZHOU
C		ALFRED UNIVERSITY, MARCH-1987
C
C	THIS ROUTINE IMPLEMENTS AN INTERACTIVE TWO-DIMENSIONAL
C	LAYOUT ON A TEK-4100 SEGMENT-GRAPHICS TERMINAL.
C
C	ICODE ---- FUNCTION CODE:
C
C		 0 = ENTER TO PLOT "FNAME" AND QUIT.
C     		 1 = ENTER AS A STANDALONE LAYOUT SESSION.
C		     LAYOUT IS SAVED IN "FNAME" UPON EXIT.
C		 2 = ENTER AS A AUXILIARY LAYOUT SESSION.
C		     LAYOUT IS SAVED IN "FNAME" UPON EXIT.
C
C	XORG,YORG ---- LAYOUT ORIGIN(X,Y).
C	FNAME -------- FILE TO STORE AND/OR TO PLOT A LAYOUT.
C
     	CHARACTER FNAME*(*)
     	ID = LAYOUT_START(ICODE,XORG,YORG,FNAME)
     	IF(ID.EQ.0) CALL LAYOUT_DIALOG
     	RETURN
     	END

     	FUNCTION LAYOUT_START(ICODE,XO,YO,FNAME)
C
C	THIS ROUTINE INITIALIZES A LAYOUT SESSION.
C
     	INCLUDE  'LAYOUT.CBS'
     	CHARACTER FNAME*(*)
     	LOGICAL   YES

    	MODE  = ICODE
     	XORG  = XO
     	YORG  = YO
     	LOFILE= FNAME
     	IF( MODE.EQ.0 ) THEN	!LAYOUT OVERLAY ONLY
     	    CALL LAYOUT_INIT
     	    INQUIRE( FILE=LOFILE, EXIST=YES )
     	    IF(YES) CALL LAYOUT_IO( 1, LOFILE )
     	    LAYOUT_START = 1
     	    RETURN
     	ENDIF
C
C  INTERACTIVE LAYOUT SESSION...
C
     	CALL IFANSI_CLEAR(2)	!CLEAR BOTTOM SCREEN
     	CRT = IFINIT_ITM(0)	!GET THE TYPE OF TERMINAL
     	TEK = IFINIT_ITK(0)
    	IF( MODE.EQ.1 .AND. CRT.GT.1 ) THEN
     	    CALL IFINIT_LINE(3)
     	    ISCP = IFMISC_DIGITS( MNN )
     	    MAXS = IFMISC_DIGITS( MNT )
     	    MIXS = IFMISC_DIGITS( MNC )
     	    MAYS = IFMISC_DIGITS( MNP )
     	    MIYS = IFMISC_DIGITS( MNF )
     	    WRITE(6,1234) MNN, MNT, MNC, MNP, MNF
1234	FORMAT(' PROGRAM LIMITS: ',I<ISCP>,' OVERALL ENTRIES; '
     +,I<MAXS>,' TEXT STRINGS;'/17X,I<MIXS>,' CURVES; ',I<MAYS>
     +,' POINTS/CURVE; ',I<MIYS>,' FILL GROUPS.')
     	    CALL IFINIT_PLOT( XORG, YORG, LOFILE )
    	    CALL LAYOUT_INIT
    	ELSE
     	    CALL IFINIT_LINE(-3)
     	    IF( INI.NE.999 ) CALL LAYOUT_INIT
     	ENDIF
     	IF( CRT.EQ.2 ) THEN
     	    CALL IFMAC_MACROS(1)
     	    CALL IFINIT_FKEYS( 'VISION', 'RELEASE', 'REFRESH',
     +     'GIN-FLIP', 'MOVE', 'ROTATE', 'ZOOM', 'COLOR' )
     	ENDIF
     	IF( MODE.EQ.1 ) CALL LAYOUT_DCL
     	LAYOUT_START = 0
     	RETURN
     	END

     	SUBROUTINE LAYOUT_DIALOG
C
C	THIS ROUTINE CARRIES ON A LAYOUT SESSION.
C
    	INCLUDE  'LAYOUT.CBS'
    	CHARACTER KEY*4, KYE*2, TEXT*80
     	INTEGER   ERR
    	EQUIVALENCE (TEXT(1:4),KEY), (TEXT(1:2),KYE)
C
C  START THE INTERACTIVE LOOP...
C
    	IQQ = 0		!TRANSFORMATION CODE
     	JQQ = 0		!0=COMMAND MODE, >0=ENTRY MODE
     	ERR = 0		!INPUT ERROR CODE
    	NCH = 0
111	IF( JQQ.EQ.0 ) THEN
     	    WRITE(6,1000)
1000	    FORMAT('$LAYOUT_COM> ')
     	ELSE
     	    IF( JQQ.EQ.1 ) WRITE(6,1101)
     	    IF( JQQ.EQ.2 ) WRITE(6,1102)
     	    IF( JQQ.EQ.3 ) WRITE(6,1103)
     	    IF( JQQ.EQ.4 ) WRITE(6,1104)
     	    IF( JQQ.EQ.5 ) WRITE(6,1105)
     	    IF( JQQ.EQ.6 ) WRITE(6,1106)
     	    IF( JQQ.EQ.7 ) WRITE(6,1107)
     	ENDIF
1101	FORMAT(' FORMAT: PEN,X,Y,LENGTH,HEIGHT,BORDER,ROTATE,FILL'/
     +,'$LAYOUT_ENTRY_BAR> ')
1102	FORMAT(' FORMAT: PEN,X,Y,LENGTH,HEIGHT,BORDER,ROTATE,FILL'/
     +,'$LAYOUT_ENTRY_BOX> ')
1103	FORMAT(' FORMAT: PEN,X,Y,R1,R2,BORDER,ROTATE,ANGLE1,ANGLE2,FILL'/
     +,'$LAYOUT_ENTRY_ARC> ')
1104	FORMAT(' FORMAT: PEN,X,Y,D1,D2,BORDER,ROTATE,FILL'/
     +,'$LAYOUT_ENTRY_OBLIQUE> ')
1105	FORMAT(' FORMAT: PEN,X,Y,SIZE,BORDER,ROTATE,EDGES,FILL'/
     +,'$LAYOUT_ENTRY_POLYGON> ')
1106	FORMAT(' FORMAT: PEN,X,Y,LENGTH,HEIGHT,HEAD,ROTATE,TYPE'/
     +,'$LAYOUT_ENTRY_ARROWHEAD> ')
1107	FORMAT(' FORMAT: PEN,X,Y,SIZE,ROTATE,NUMBER'/
     +,'$LAYOUT_ENTRY_SYMBOL> ')

     	IOP = IFQIOW( IDUM, TEXT )
     	IF( IOP.EQ.26 ) GOTO 888
     	IF( NCH.LT.0 ) CALL IFINIT_LINE(-3)
    	IF( IDUM.EQ.0 ) THEN
     	    JQQ = 0
     	    NCH = 0
     	    GOTO 111
     	ENDIF
    	NCH = IFMISC_STRIP( TEXT )
    	CALL  IFMISC_UPPER( TEXT )
     	IF( JQQ.GT.0 ) GOTO 555
C
C  	-----	COMMAND INPUT    ---------
C
     	ERR = 1
     	IF( NCH.EQ.1 ) GOTO 333
     	IF( KYE.EQ.'EX' .OR. KYE.EQ.'QU' ) GOTO 888

     	IF( KEY.EQ.'HELP' .OR. (IOP.EQ.27.AND.KYE.EQ.'OQ') ) THEN
     	    CALL LAYOUT_HELP( TEXT )
     	    NCH = -1
     	    GOTO 111
     	ENDIF
C
C  CHECK FOR ENTRY MODE...
C
     	IF( KEY.EQ.'ENTR' ) THEN
     	    ERR = 8
     	    IF( CRT.EQ.1 ) GOTO 777
     	    JQQ = LAYOUT_MODE( TEXT )
     	    IF( JQQ.GT.0 ) THEN
     		IQQ = 0
     		IF( NLG.GT.0 ) CALL LAYOUT_SET_BLINK(0)
     		NLCOLD = NLC
    	    ENDIF
     	    GOTO 111
     	ENDIF
C
C  CHECK FOR SOME LAYOUT COMMANDS...
C
     	IQQ = 0
     	IDUM= LAYOUT_COM( IOP, TEXT )
    	IF( IDUM.NE.0 ) GOTO 111
C
C  CHECK FOR TRANSFORM KEYWORDS...
C
     	IF( KEY.EQ.'CODE' ) THEN
     	    IQQ = 1
     	    GOTO 222
     	ELSE IF( KEY.EQ.'COLO' .OR. KYE.EQ.'F8' ) THEN
     	    IQQ = 2
     	    GOTO 222
     	ELSE IF( KEY.EQ.'FILL' ) THEN
     	    IQQ = 3
     	    GOTO 222
     	ELSE IF( KEY.EQ.'MOVE' .OR. KYE.EQ.'F5' ) THEN
     	    IQQ = 4
     	    GOTO 222
     	ELSE IF( KEY.EQ.'ROTA' .OR. KYE.EQ.'F6' ) THEN
     	    IQQ = 5
     	    GOTO 222
     	ELSE IF( KEY.EQ.'ZOOM' .OR. KYE.EQ.'F7' ) THEN
     	    IQQ = 6
     	    GOTO 222
     	ELSE IF( KEY.EQ.'VISI' .OR. KYE.EQ.'F1' ) THEN
     	    IQQ = 7
     	    GOTO 222
     	ENDIF
     	ERR = 1				!INVALID COMMAND
     	GOTO 777

222	ERR = 8
     	IF( CRT.NE.2 ) GOTO 777		!INVALID TERMINAL
     	ERR = 5
     	IF( NLC.EQ.0 ) GOTO 777		!NOTHING ON THE SCREEN
     	ERR = 6
     	IF( NLG.EQ.0 ) GOTO 777		!NO PICKED ENTRIES
     	IF( IQQ.EQ.7 ) THEN		!FLIP VISIBILITY
     	    CALL LAYOUT_SET_VISS
     	    GOTO 111
     	ENDIF
C
C  DECODE COMMAND PARAMETERS IF AT ALL...
C
     	NCH = IFMISC_NEXT( TEXT )
     	IF( NCH.EQ.0 ) GOTO 111
     	IDUM = LAYOUT_TRAN( TEXT, PF1, PF2, PF3, PF4 )
     	IF( IDUM.EQ.0 ) GOTO 111	!ERROR PARAMETERS
     	GOTO 444
C
C  TRANSFORM BIT BY BIT...
C
333	IF( IQQ.EQ.0 ) GOTO 777
     	DECODE( 1, 334, TEXT(1:1), ERR=777 ) IOP
334	FORMAT(I1)
     	IF( IQQ.LT.4 ) THEN
     	    PF1 = IOP
     	ELSE
     	    IF( IQQ.EQ.4 ) CALL LAYOUT_MOVE_WHERE( IOP, PF1, PF2 )
     	    IF( IQQ.EQ.5 ) CALL LAYOUT_ROTATE_ANGLE( IOP, PF1 )
     	    IF( IQQ.EQ.6 ) CALL LAYOUT_ZOOM_SCALE( IOP, PF1, PF2 )
     	    IF( IOP.EQ.0 .OR. IOP.EQ.5 ) GOTO 111
     	ENDIF
C
C  PERFORM THE TRANSFORMATION SPECIFIED PREVIOUSLY...
C
444	IF( IQQ.EQ.1 ) THEN
     	    CALL LAYOUT_CODE( INT(PF1) )
     	ELSE IF( IQQ.EQ.2 ) THEN
     	    CALL LAYOUT_COLOR( INT(PF1) )
     	ELSE IF( IQQ.EQ.3 ) THEN
     	    CALL LAYOUT_FILL( INT(PF1) )
     	ELSE IF( IQQ.EQ.4 ) THEN
     	    CALL LAYOUT_MOVE( PF1, PF2 )
     	ELSE IF( IQQ.EQ.5 ) THEN
     	    CALL LAYOUT_ROTATE( PF1, PF2+XORS, PF3+YORS )
     	ELSE IF( IQQ.EQ.6 ) THEN
     	    CALL LAYOUT_ZOOM( PF1, PF2, PF3+XORS, PF4+YORS )
     	ENDIF
    	GOTO 111
C
C  	------    ENTRY INPUT	 -------
C
555	IF( KYE.EQ.'EX' ) THEN
     	    JQQ = 0
     	    GOTO 111
     	ENDIF

     	IF( KYE.EQ.'F6' .OR. KEY.EQ.'HELP' ) THEN
     	    CALL LAYOUT_HELP_ENTRY( JQQ )
     	    NCH = -1
     	    GOTO 111
     	ENDIF

     	IF( KYE.EQ.'F4' .OR. KEY(1:3).EQ.'DEL' ) THEN
     	    IF( NLC.GT.NLCOLD ) THEN
     		CALL IFSEG_OPEN( -NSN(NLC) )
     		CALL IFINIT_DUMP
     		NLC = NLC - 1
     		GOTO 111
     	    ENDIF
     	ENDIF

     	ERR = 12
     	IF( NLC.EQ.MNN ) GOTO 777	!MAX ENTRY COUNT HIT
C
C  ADD AN ENTRY ...
C
     	CALL LAYOUT_ENTRY( TEXT, JQQ )
     	GOTO 111
C
C  ERROR INPUT ...
C
777	CALL LAYOUT_ERROR( ERR )
     	IF( ERR.EQ.12 ) JQQ = 0
    	GOTO 111
C
C  EXIT FROM LAYOUT...
C
888	IF( JQQ.GT.0 ) THEN
     	    JQQ = 0
     	    GOTO 111
     	ENDIF
     	IF( NLC.GT.0 .AND. KYE.EQ.'QU' ) THEN
     	    WRITE(6,3000)
3000	    FORMAT('$Abort the layout? (Y/N) [Y] ')
     	    READ(5,3001,END=889) KYE
3001	    FORMAT(A)
     	    IF( KYE(1:1).EQ.'N' .OR. KYE(1:1).EQ.'n' ) GOTO 111
     	ELSE
     	    KYE = 'EX'
     	ENDIF
889	IF( NLG.GT.0 ) CALL LAYOUT_SET_BLINK(0)
     	IF( NLC.EQ.0 .OR. CRT.EQ.1 .OR. KYE.NE.'EX' ) GOTO 999
C
C  SAVE THE LAYOUT...
C
     	IF( MODE.EQ.1 ) THEN
     	    TEXT = 'SAVE'
     	ELSE
     	    TEXT = 'SAVE '
     	    TEXT(6:) = LOFILE
     	ENDIF
     	CALL LAYOUT_SAVE( TEXT )
999	IF( CRT.EQ.2 ) CALL IFSEG_OPEN(-4)
     	CALL IFMAC_MACROS(0)
     	RETURN
    	END

    	SUBROUTINE LAYOUT_INIT
C
C	THIS ROUTINE INITIALIZES THE COMMON BLACKS FOR LAYOUT.
C
    	INCLUDE 'LAYOUT.CBS'

     	INI = 999
    	NLC = 0
     	KSG = NSG
    	NLG = 0
     	NFG = 0
     	NTX = 0
     	NCU = 0
     	LTYP = 1
     	LWID = 1
     	FKEYS = 1
     	BLINK = 1
     	FRAME = 1
     	LVISS = 1
    	ISCP = 0
    	MAXS = 10
     	MIXS = 10
     	MAYS = 10
     	MIYS = 10
    	XORS = 0.0
    	YORS = 0.0
     	CHORD = 10.0
     	PLOTID = ' '

999	RETURN
    	END

    	FUNCTION LAYOUT_TRAN( TEXT, PF1, PF2, PF3, PF4 )
C
C  PROGRAMMER: R.S. ZHOU	MAY-1986
C
C	THIS ROUTINE DECODES THE TRANSFORMATION PARAMETERS FOR LAYOUT.
C
    	CHARACTER KEY*3, KWD(7)*3, TEXT*(*)
    	DIMENSION KP(4), RP(4)
     	DATA KWD/ 'WHI', 'RED', 'GRE', 'BLU', 'CYA', 'PUR', 'YEL' /

    	PF1 = 0.0
    	PF2 = 0.0
    	PF3 = 0.0
    	PF4 = 0.0
     	NCH = IFMISC_DECODE( TEXT, 4, RP, KP )
     	IF( NCH.GT.0 ) THEN
     	    IF( KP(1).EQ.1 ) PF1 = RP(1)
     	    IF( KP(2).EQ.1 ) PF2 = RP(2)
     	    IF( KP(3).EQ.1 ) PF3 = RP(3)
     	    IF( KP(4).EQ.1 ) PF4 = RP(4)
     	ELSE
     	    KEY = TEXT(1:3)
     	    DO  IK = 1, 7
     		IF( KEY.EQ.KWD(IK) ) GOTO 111
     	    ENDDO
     	    LAYOUT_TRAN = 0
     	    CALL LAYOUT_ERROR(2)
     	    RETURN
111	    PF1 = IK
    	ENDIF

999	LAYOUT_TRAN = 1
     	RETURN
    	END

     	FUNCTION LAYOUT_MODE( TEXT )
C
C	THIS ROUTINE CHECKS FOR ENTRY MODE CHANGE FOR LAYOUT.
C
     	CHARACTER KEY*3, TEXT*(*)

     	MODE = 0
     	NCHS = IFMISC_NEXT( TEXT )
     	IF( NCHS.EQ.0 ) THEN
     	    WRITE(6,1000)
1000	FORMAT(' Keyword menu: BAR, BOX, ARC, POLYGON, OBLIQUE,',
     +' ARROWHEAD, SYMBOL.'/'$Enter keyword: ')
     	    READ(5,1001,END=999) KEY
1001	FORMAT(A)
     	    IF( KEY.EQ.' ' ) GOTO 999
     	ELSE
     	    KEY = TEXT(1:3)
     	ENDIF
     	IF( KEY .EQ. 'BAR' ) MODE = 1
     	IF( KEY .EQ. 'BOX' ) MODE = 2
     	IF( KEY .EQ. 'ARC' ) MODE = 3
     	IF( KEY .EQ. 'OBL' ) MODE = 4
     	IF( KEY .EQ. 'POL' ) MODE = 5
     	IF( KEY .EQ. 'ARR' ) MODE = 6
     	IF( KEY .EQ. 'SYM' ) MODE = 7
     	IF( MODE.EQ.0 ) CALL LAYOUT_ERROR(2)

999	LAYOUT_MODE = MODE
     	RETURN
     	END

     	SUBROUTINE LAYOUT_ENTRY( TEXT, ICODE )
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY, MARCH-1987
C
C	THIS ROUTINE ADDS A LAYOUT ENTRY.
C
     	INCLUDE 'LAYOUT.CBS'

     	CHARACTER KEY*3, KCS(7)*3, TEXT*(*)
     	DIMENSION K(MNS+1), R(MNS+1)
     	DATA KCS / 'WHI', 'RED', 'GRE', 'BLU', 'CYA', 'PUR', 'YEL' /
C
C  INITIALIZE R...
C
     	DO I=1, MNS+1
     	   R(I) = 0.0
     	ENDDO
C
C  CHECK FOR COLOR KEYWORD FIRST...
C
     	I1 = 0
     	I2 = 1
     	ICD = ICODE
     	KEY = TEXT(1:3)
     	DO IK = 1, 7
     	   IF( KEY.EQ.KCS(IK) ) GOTO 111
     	ENDDO
     	GOTO 222
111	I1 = 1
     	I2 = 2
     	R(1) = IK
     	NCH = IFMISC_NEXT( TEXT )
     	IF( NCH.EQ.0 ) GOTO 888
222	NCH = IFMISC_DECODE( TEXT, MNS-I1, R(I2), K(I2) )
    	IF( NCH.EQ.0 ) GOTO 888
C
C  CHECK PEN CODE...
C
     	IF( R(1).LT.0.0 .OR. R(1).GT.8.0 ) GOTO 888
C
C  CONVERT TO ABSOLUTE COORDINATES...
C
     	R(2) = R(2) + XORS
     	R(3) = R(3) + YORS
C
C  CHECK THE REST OF THE PARAMETERS...
C
     	IF( ICD.LT.3 ) THEN	!BAR ENTRY...
     	    IF( R(4).LT.0.01 .OR. R(4).GT.10.0 ) GOTO 888
     	    IF( R(5).LT.0.01 .OR. R(5).GT.10.0 ) GOTO 888
     	    IF( R(6).LT.0.00 .OR. R(6).GT.10.0 ) GOTO 888
     	    R(7) = AMOD( R(7), 360.0 )
     	    IF( ABS(R(8)).GT.99.0 ) GOTO 888
     	    R(9) = LTYP
     	    R(10)= LWID
     	    GOTO 555
     	ENDIF

     	IF( ICD.EQ.3 ) THEN	!ARC ENTRY...
     	    IF( R(4).LT.0.01 .OR. R(4).GT.5.0 ) GOTO 888
     	    IF( R(5).LT.0.01 .OR. R(5).GT.5.0 ) GOTO 888
     	    IF( R(6).LT.0.00 .OR. R(6).GT.5.0 ) GOTO 888
     	    R(7) = AMOD( R(7), 360.0 )
     	    R(8) = AMOD( R(8), 360.0 )
     	    R(9) = AMOD( R(9), 360.0 )
     	    IF( ABS(R(10)).GT.99.0 ) GOTO 888
     	    R(11) = LTYP
     	    R(12) = LWID
     	    GOTO 555
     	ENDIF

     	IF( ICD.EQ.4 ) THEN	!OBLIQUE ENTRY...
     	    IF( R(4).LT.0.01 .OR. R(4).GT.5.0 ) GOTO 888
     	    IF( R(5).LT.0.01 .OR. R(5).GT.5.0 ) GOTO 888
     	    IF( R(6).LT.0.00 .OR. R(6).GT.5.0 ) GOTO 888
     	    R(7) = AMOD( R(7), 360.0 )
     	    IF( ABS(R(8)).GT.99.0 ) GOTO 888
     	    R(9) = LTYP
     	    R(10)= LWID
     	    GOTO 555
     	ENDIF

     	IF( ICD.EQ.5 ) THEN	!POLYGON ENTRY...
     	    IF( R(4).LT.0.01 .OR. R(4).GT.5.0 ) GOTO 888
     	    IF( R(5).LT.0.00 .OR. R(5).GT.5.0 ) GOTO 888
     	    R(6) = AMOD( R(6), 360.0 )
     	    IF( R(7).LT.3.0 .OR. R(7).GT.360.0 ) GOTO 888
     	    IF( ABS(R(8)).GT.99.0 ) GOTO 888
     	    R(9) = LTYP
     	    R(10)= LWID
     	    GOTO 555
     	ENDIF

     	IF( ICD.EQ.6 ) THEN	!ARROWHEAD ENTRY...
     	    IF( R(4).LT.0.01 .OR. R(4).GT.10.0 ) GOTO 888
     	    IF( R(5).LT.0.01 .OR. R(5).GT.10.0 ) GOTO 888
     	    IF( R(6).LT.0.01 .OR. R(6).GT.10.0 ) GOTO 888
     	    R(7) = AMOD( R(7), 360.0 )
     	    IF( R(8).LT.1.0 ) GOTO 888
     	    GOTO 555
     	ENDIF

     	IF( ICD.EQ.7 ) THEN	!MARKER SYMBOL ENTRY...
     	    IF( R(4).LT.0.01 .OR. R(4).GT.5.0 ) GOTO 888
     	    R(5) = AMOD( R(5), 360.0 )
     	    IF( R(6).LT.1.0 ) GOTO 888
     	    GOTO 555
     	ENDIF
     	GOTO 888
C
C  STORE THE ENTRY PARAMETERS...
C
555	NLC = NLC + 1
     	NID(NLC) = ICD
     	PEN(NLC) = R(1)
     	DO I=1, MNS
     	   P00(I,NLC) = R(I+1)
     	ENDDO
     	NFL(NLC) = 0
C
C  DISPLAY THE ENTRY...
C
     	CALL LAYOUT_DRAW( NLC, 1 )
     	CALL IFINIT_DUMP
     	RETURN
888	CALL LAYOUT_ERROR(4)
     	RETURN
     	END

    	SUBROUTINE LAYOUT_ERROR( ICODE )
C
C  PROGRAMMER: R.S. ZHOU		MARCH-1987
C
C	THIS ROUTINE DISPLAYS ERROR MESSAGES FOR LAYOUT.
C
     	BYTE BELL
     	DATA BELL / 7 /

     	ID = ICODE
    	CALL IFANSI_VIDEO(70)
    	IF( ID.EQ.1 )  THEN
     		WRITE(6,1) BELL
     	ELSE IF( ID.EQ.2 )  THEN
     		WRITE(6,2) BELL
     	ELSE IF( ID.EQ.3 )  THEN
     		WRITE(6,3) BELL
     	ELSE IF( ID.EQ.4 )  THEN
     		WRITE(6,4) BELL
     	ELSE IF( ID.EQ.5 )  THEN
     		WRITE(6,5) BELL
     	ELSE IF( ID.EQ.6 )  THEN
     		WRITE(6,6) BELL
     	ELSE IF( ID.EQ.7 )  THEN
     		WRITE(6,7) BELL
     	ELSE IF( ID.EQ.8 )  THEN
     		WRITE(6,8) BELL
     	ELSE IF( ID.EQ.9 )  THEN
     		WRITE(6,9) BELL
     	ELSE IF( ID.EQ.10 )  THEN
     		WRITE(6,10) BELL
     	ELSE IF( ID.EQ.11 )  THEN
     		WRITE(6,11) BELL
     	ELSE IF( ID.EQ.12 )  THEN
     		WRITE(6,12) BELL
     	ELSE IF( ID.EQ.13 )  THEN
     		WRITE(6,13) BELL
     	ELSE IF( ID.EQ.14 )  THEN
     		WRITE(6,14) BELL
     	ELSE IF( ID.EQ.15 )  THEN
     		WRITE(6,15) BELL
     	ELSE IF( ID.EQ.16 )  THEN
     		WRITE(6,16) BELL
     	ELSE IF( ID.EQ.17 )  THEN
     		WRITE(6,17) BELL
     	ELSE IF( ID.EQ.18 )  THEN
     		WRITE(6,18) BELL
     	ELSE IF( ID.EQ.19 )  THEN
     		WRITE(6,19) BELL
     	ELSE IF( ID.EQ.20 )  THEN
     		WRITE(6,20) BELL
     	ENDIF
     	CALL IFANSI_VIDEO(47)

1	FORMAT(X,A1,'oops: Undefined command.')
2	FORMAT(X,A1,'oops: Invalid command parameters.')
3	FORMAT(X,A1,'oops: Missing command parameters.')
4	FORMAT(X,A1,'oops: Invalid or out of range parameter.')
5	FORMAT(X,A1,'oops: No entry yet to work on.')
6	FORMAT(X,A1,'oops: No picked entries to work on.')
7	FORMAT(X,A1,'oops: Can not open the file.')
8	FORMAT(X,A1,'oops: Terminal incapable of the command.')
9	FORMAT(X,A1,'oops: Input is not a layout file.')
10	FORMAT(X,A1,'oops: Invalid cursor position.')
11	FORMAT(X,A1,'oops: Improper key pressed.')
12	FORMAT(X,A1,'oops: Max layout entry count hit.')
13	FORMAT(X,A1,'oops: Max line point count hit.')
14	FORMAT(X,A1,'oops: Max text character count hit.')
15	FORMAT(X,A1,'oops: Max text entry count hit.')
16	FORMAT(X,A1,'oops: Max line entry count hit.')
17	FORMAT(X,A1,'oops: Max fill group count hit.')
18	FORMAT(X,A1,'oops: Invalid entry ID.')
19	FORMAT(X,A1,'oops: Can not find the file.')
20	FORMAT(X,A1,'oops: Filename too long (max 32 characters).')

     	RETURN
     	END

     	SUBROUTINE LAYOUT_DCL
C
C	THIS ROUTINE CHECKS INPUT DCL COMMAND LINE.
C
     	INCLUDE 'LAYOUT.CBS'

     	CALL IF_DCL_FILE( 1, LOFILE )
     	IF( LOFILE.EQ.' ' ) RETURN
     	IF( CRT.EQ.1 ) THEN
     	    CALL LAYOUT_INIT
     	    CALL IFINIT_PLOT( XORG, YORG, LOFILE )
     	ENDIF
     	IERR = LAYOUT_IO( 1, LOFILE )
     	IF( IERR.GT.0 ) THEN
     	    IF( IF_DCL_HARDCOPY() ) CALL IFCOPY( HPAR(1), PLOTID )
     	ELSE IF( IERR.EQ.0 ) THEN
     	    WRITE(6,1000) LOFILE
1000	FORMAT(' %LAYOUT_DCL: can not open file ',A32)
     	ELSE
     	    IERR = IFMISC_LENG( LOFILE )
     	    WRITE(6,1001) LOFILE(1:IERR)
1001	FORMAT(' %LAYOUT_DCL: ',A<IERR>,' is not a layout file.')
     	ENDIF
     	IF( .NOT.IF_DCL_HARDCOPY() ) RETURN
     	CALL EXIT
     	END

