     	SUBROUTINE LAYOUT_GIN( TEXT )
C
C  THIS ROUTINE ENABLES GRAPHICS INPUT (GIN) IN LAYOUT.
C
     	INCLUDE 'LAYOUT.CBS'
     	CHARACTER KEY*3, KWD(7)*3, TEXT*(*)
     	DATA KWD/ 'WHI','RED','GRE','BLU','CYA','PUR','YEL' /
C
C  GET THE CURSOR COLOR...
C
     	IK = 2
     	NCH = IFMISC_NEXT( TEXT )
    	IF( NCH.GT.0 ) THEN
     	    KEY = TEXT(1:3)
     	    DO IK=1, 7
     	       IF( KEY.EQ.KWD(IK) ) GOTO 111
     	    ENDDO
    	    NCH = IFMISC_DECODE( TEXT, 1, RP, KP )
     	    IF( NCH.EQ.0 ) THEN
     		CALL LAYOUT_ERROR(2)
     		GOTO 999
     	    ENDIF
     	    IK = 2
     	    IF( RP.GT.0 .AND. RP.LT.8.0 ) IK = RP
    	ENDIF
C
C  ENABLE GIN...
C
111	IF( NLG.GT.0 ) THEN
     	    IF(LVISS.LT.0) CALL LAYOUT_SET_VISS	!VISIBLE ENTRIES
     	    CALL LAYOUT_SET_BLINK( 0 )		!RELEASE THEM
     	ENDIF
     	CALL IFMAC_MACROS( 2 )			!GIN KEY MACROS
    	CALL IFGIN_ABLE( IK )			!ENABLE GIN
     	CALL IFSEG_MOVE( 0, 0.0, 0.0 )		!MOVE CURSOR TO ORIGIN
     	CALL IFINIT_DUMP
     	CALL LAYOUT_GIN_IN( IK )		!ENTER GIN LAYOUT
     	CALL IFGIN_ABLE( 0 )			!DISABLE GIN
     	IF( FKEYS.GT.0 ) THEN
     	    CALL IFMAC_MACROS(1)		!COMMAND MACROS
     	ELSE
     	    CALL IFMAC_MACROS(0)		!ERASE GIN MACROS
     	ENDIF

999	RETURN
     	END

      	SUBROUTINE LAYOUT_GIN_IN( IPN )
C
C  PROGRAMMER:  RONG-SHENG ZHOU
C		ALFRED UNIVERSITY, JUNE-1986
C
C	THIS ROUTINE IMPLEMENTS GIN LAYOUT.
C
C		IPN: GIN CURSOR COLOR CODE
C
    	INCLUDE		'LAYOUT.CBS'
     	PARAMETER	NKS= 23
    	INTEGER		IR(NKS), ESC, CODE, FILL
     	COMMON/LAYOUT_GIN/ IGIN,LINE,FILL,NPTS,SIZE,XPOS,YPOS
C
C  "IR" ARRAY CONTAINS THE ASCII CODES OF ALL DEFINED GIN KEYS...
C
     	DATA IR / 96, 84, 68, 46, 45, 32,126, 67, 77, 76, 70,
     +        80, 73, 74, 75, 88, 66, 82, 71, 79, 86, 63, 83 /
C
C  INITIALIZE...
C
     	IGIN = IPN		!GIN CURSOR COLOR
     	LINE = 1		!LINE TYPE: SOLID, SPLINE OFF
    	NPTS = 0		!NUMER OF LINE POINTS
    	FILL = 0		!LINE AREA FILL OFF
    	SIZE = 0.12		!LETTERING SIZE
    	CODE = 0		!ENTRY TRANSFORM OFF
     	IPAT = 0		!ENTRY ID OFF
    	X1ST = 0.0		!X-COORDINATE OF THE 1ST PICKED ENTRY
    	Y1ST = 0.0		!Y-COORDINATE OF THE 1ST PICKED ENTRY
     	XOLD = 99.0
     	YOLD = 99.0
C
C  START THE GIN LOOP...
C
     	ESC = 27
     	WRITE(6,1234) ESC, ESC
1234	FORMAT(' LAYOUT_GIN> WARNING:',A1,'[43;30m Keyboard could',
     +' easily be jammed by QUICK key strokes! ',A1,'[44;37m'/
     +' LAYOUT_GIN> Press ? if you need any help.')
C
C  READ A GIN REPORT FROM TERMINAL...
C
1111	WRITE(6,1112)
1112	FORMAT('$LAYOUT_GIN> ')
     	KEY = IFGIN_REPORT( NSEG, XPOS, YPOS )
      	IF( KEY.EQ.0 ) GOTO 999
C
C  IF INPUT IS LOWERCASE, CONVERT TO UPPERCASE ...
C
    	IF( KEY.GT.96 .AND. KEY.LT.123 ) KEY= KEY-32
     	DO IKEY=1, NKS
     	   IF( KEY.EQ.IR(IKEY) ) GOTO 2222
     	ENDDO
     	IERR = 11
     	IF( KEY.LT.48 .OR. KEY.GT.57 ) GOTO 777
     	KEY = KEY - 48
     	IF( CODE.GT.0 .AND. NLG.GT.0 ) GOTO 200
C
C  SET LETTERING SIZE/FILL PATTERN/ENTRY ID/LINE TYPE (0-9)...
C
    	IF( NPTS.EQ.0 ) THEN
     	    FILL = KEY
    	    IPAT = KEY
    	    IF( KEY.GT.0 ) SIZE = 0.04*KEY
     	ENDIF
    	IF( NPTS.GT.1 ) THEN
     	    IF( KEY.EQ.0 ) KEY = 10
     	    LINE = KEY*LINE
     	    GOTO 125
     	ENDIF
     	GOTO 1111
C
C  FLIP GIN MODE IF NECESSARY...
C
2222	IF( IKEY.EQ.6 .OR. IKEY.EQ.7 ) THEN
     	    IF( IGIN.GT.0 ) THEN
     		IGIN = -IGIN		!ENABLE GIN PICKER
     		CALL IFGIN_ABLE( 0 )
     		CALL IFGIN_ABLE( IGIN )
     		GOTO 1111
     	    ENDIF
     	ELSE
     	    IF( IGIN.LT.0 ) THEN
     		IGIN = -IGIN		!ENABLE GIN LOCATOR
     		CALL IFGIN_ABLE( 0 )
     		CALL IFGIN_ABLE( IGIN )
     	    ENDIF
     	ENDIF
C
C  BRANCH TO THE DESIRED ACTION...
C
     	GOTO (100,100,110,120,121,130,140,150,160,170,170,170,
     +        170,170,170,220,230,250,260,270,300,900,123), IKEY
     	IERR = 11
     	GOTO 777
C
C  START LETTERING ON THE SCREEN ( <ENTER> .OR. <T> )...
C
100	IERR = 12			!MAX ENTRY COUNT HIT
     	IF( NLC.EQ.MNN ) GOTO 777
     	IERR = 15
     	IF( NTX.EQ.MNT ) GOTO 777
     	CALL LAYOUT_GIN_TEXT
    	GOTO 1111
C
C  DRAW AN ENTRY OF ID ( D )...
C
110	IERR = 12
     	IF( NLC.EQ.MNN ) GOTO 777
    	CALL LAYOUT_GIN_ENTRY( IPAT, XPOS, YPOS )
    	GOTO 1111
C
C  ENTER A POINT FOR DRAWING A LINE ( . )...
C
120	IERR = 13			!MAX POINT COUNT HIT
     	IF( NPTS.EQ.MNP ) GOTO 777
     	IF( NPTS.EQ.0 .OR. XPOS.NE.XOLD .OR. YPOS.NE.YOLD ) THEN
    	    NPTS = NPTS + 1
    	    CALL LAYOUT_GIN_LINE( 0 )
     	    XOLD = XPOS
     	    YOLD = YPOS
     	ENDIF
    	GOTO 1111
C
C  SIGNIFY A SMOOTHED LINE OR A SINGLE ARROWHEAD LINE ( - )....
C
121	IERR = 11
     	IF( NPTS.LT.2 ) GOTO 777
    	LINE = -1
    	GOTO 1111
C
C  SELECT ENTRIES IN A BOX ( S ).
C
123	IERR = 11
     	IF( NPTS.NE.2 ) GOTO 777
	LINE = 99
	IKEY = NLG
C
C  DRAW THE LINE OR PICK ENTRIES...
C
125	IF( LINE.NE.99 ) THEN
     	    IERR = 12
     	    IF( NLC.EQ.MNN ) GOTO 777
     	ENDIF
     	CALL LAYOUT_GIN_LINE( 1 )
C
C  IF IN BOX SELECT MODE, FIND (X1ST,Y1ST)...
C
	IF( LINE.EQ.99 .AND. IKEY.EQ.0 .AND. NLG.GT.0 ) THEN
	    X1ST = XPOS
	    Y1ST = YPOS
	ENDIF
     	NPTS = 0
     	FILL = 0
     	LINE = 1
    	GOTO 1111
C
C  PICK FOR TRANSFORM ( SPACEBAR )...
C
130	IERR = 10
     	NSEG = IFGIN_NSEG( NSEG )
    	IF( NSEG.LE.NSG ) GOTO 777
    	IF( NLG.EQ.0 ) THEN
    	    X1ST = XPOS
    	    Y1ST = YPOS
    	ENDIF
    	CALL LAYOUT_PICK_SEG( NSEG )
    	GOTO 1111
C
C  PICK FOR DELETE( <DEL> )...
C
140	IERR = 10
     	NSEG = IFGIN_NSEG( NSEG )
    	IF( NSEG.LE.NSG ) GOTO 777
    	CALL LAYOUT_DELETE_SEG( NSEG )
    	GOTO 1111
C
C  COPY( C )...
C
150	IERR = 6
     	IF( NLG.EQ.0 ) GOTO 777
    	XPOS = XPOS - X1ST
    	YPOS = YPOS - Y1ST
    	CALL LAYOUT_COPY_ONE( XPOS, YPOS, 0.0, 0.0 )
    	GOTO 1111
C
C  MOVE ( M )...
C
160	IERR = 6
     	IF( NLG.EQ.0 ) GOTO 777
    	X1ST = XPOS - X1ST
    	Y1ST = YPOS - Y1ST
    	CALL LAYOUT_MOVE( X1ST, Y1ST )
    	X1ST = XPOS
    	Y1ST = YPOS
    	GOTO 1111
C
C  SET FOR COLOR_CHANGE(F8)/AREA_FILL(F)/CODE_CHANGE(P)/
C          MOVE(F5)/ROTATE(F6)/ZOOM(F7)...
C
170	IERR = 6
     	IF( NLG.EQ.0 ) GOTO 777
    	CODE = IKEY - 9
    	GOTO 1111
C
C  TRANSFORM THE PICKED ENTRIES ( NUMBER KEYS )...
C
200	IKEY = KEY
     	IF( CODE.EQ.1 ) THEN
     	     CALL LAYOUT_COLOR( IKEY )		!CHANGE COLOR
     	ELSE IF( CODE.EQ.2 ) THEN
     	     CALL LAYOUT_FILL( IKEY )		!POLYGON FILL
     	ELSE IF( CODE.EQ.3 ) THEN
     	     CALL LAYOUT_CODE( IKEY )		!CODE CHANGE
     	ELSE IF( CODE.EQ.4 ) THEN
     	     CALL LAYOUT_MOVE_WHERE( IKEY, XFT, YFT )
     	     IF(KEY.NE.0.AND.KEY.NE.5) CALL LAYOUT_MOVE(XFT,YFT)
     	ELSE IF( CODE.EQ.5 ) THEN
     	     CALL LAYOUT_ROTATE_ANGLE( IKEY, ANG )
    	IF(KEY.NE.0.AND.KEY.NE.5) CALL LAYOUT_ROTATE(ANG,XPOS,YPOS)
     	ELSE IF( CODE.EQ.6 ) THEN
     	     CALL LAYOUT_ZOOM_SCALE( IKEY, XFT, YFT )
     	IF(KEY.NE.0.AND.KEY.NE.5) CALL LAYOUT_ZOOM(XFT,YFT,XPOS,YPOS)
     	ENDIF
    	GOTO 1111
C
C  RELEASE PICKED ENTRIES( F2 )...
C
220	IF( NLG.GT.0 ) CALL LAYOUT_SET_BLINK( 0 )
    	CODE = 0
    	GOTO 1111
C
C  FLIP-FLOP BLINKING FEATURE ( B )...
C
230	IF( NLG.GT.0 ) CALL LAYOUT_SET_BLINK( 1 )
    	GOTO 1111
C
C  REFRESH THE SCREEN( F3 )...
C
250	CALL IFINIT_FRESH
    	GOTO 1111
C
C  FLIP-FLOP BACKGROUND SCALE ( G )...
C
260	IF( ISCP.EQ.0 ) THEN	!FLIP ON
     	    ISCP = 1
     	ELSE			!FLIP OFF
    	    ISCP = 0
    	ENDIF
     	CALL LAYOUT_SET_RULER
    	CALL IFINIT_DUMP
    	GOTO 1111
C
C  REORIGIN ( O )...
C
270	XORS = XPOS
     	YORS = YPOS
    	CALL IFSEG_MOVE( 3, XORS, YORS )
     	IF( ISCP.GT.0 ) CALL LAYOUT_SET_RULER
     	CALL IFINIT_DUMP
     	GOTO 1111
C
C  SET PICKED ENTRY VISIBILITY ( F1 )...
C
300	IERR = 6
     	IF( NLG.EQ.0 ) GOTO 777
     	CALL LAYOUT_SET_VISS
     	GOTO 1111
C
C  DISPLAY HELP MENU( ? )...
C
900	CALL LAYOUT_GIN_HELP
     	GOTO 1111
C
C  ERROR TRANSFER...
C
777	CALL LAYOUT_ERROR( IERR )
     	GOTO 1111
999	RETURN
    	END

    	SUBROUTINE LAYOUT_GIN_TEXT
C
C  PROGRAMMER: R.S. ZHOU		MARCH-1986
C
C	THIS ROUTINE IMPLEMENTS GIN LETTERING.
C
    	INCLUDE		'LAYOUT.CBS'
    	CHARACTER	TEXT*75
     	INTEGER		FILL
     	COMMON/LAYOUT_GIN/ IGIN,LINE,FILL,NPTS,SIZE,XPOS,YPOS

    	CALL IFSPEN( 3 )
     	CALL IFPLOT( XPOS-0.05, YPOS, 3 )
     	CALL IFPLOT( XPOS+0.05, YPOS, 2 )
     	CALL IFPLOT( XPOS, YPOS-0.05, 3 )
     	CALL IFPLOT( XPOS, YPOS+0.05, 2 )
     	CALL IFMAC_KEYEXP( 0 )
     	CALL IFGIN_ABLE( 0 )
111	WRITE(6,1000)
1000	FORMAT('$LAYOUT_TEXT> ')
     	READ(5,1001,ERR=111,END=999) TEXT
1001	FORMAT(A75)
C
C  ENTER A TEXT LINE...
C
     	IF( TEXT.NE.' ' ) THEN
     	    CALL IFMISC_STRIP(TEXT)
     	    NLC = NLC + 1
     	    NTX = NTX + 1
     	    LDT(NTX) = NLC
     	    TXT(NTX) = TEXT
     	    NFL(NLC) = 0
     	    NID(NLC) = 8
     	    PEN(NLC) = 1
     	    P00(1,NLC) = XPOS
    	    P00(2,NLC) = YPOS
    	    P00(3,NLC) = SIZE
     	    P00(4,NLC) = SIZE
     	    P00(5,NLC) = 0.0
     	    CALL LAYOUT_DRAW( NLC, 1 )
     	ENDIF
999	CALL IFGIN_ABLE( IGIN )
     	CALL IFSEG_MOVE( 0, XPOS, YPOS )
     	CALL IFMAC_KEYEXP( 1 )
     	CALL IFINIT_DUMP
     	RETURN
    	END

     	SUBROUTINE LAYOUT_GIN_LINE( ICODE )
C
C  PROGRAMMER: R.S. ZHOU		MARCH-1986
C
C	THIS ROUTINE IMPLEMENTS GIN LINE/CURVE
C	OR PICK LAYOUT ENTRIES IN BOX MODE.
C
C	ICODE=0: STORE A POINT
C	ICODE=1: TERMINATE THE LINE.
C
    	INCLUDE		'LAYOUT.CBS'
     	INTEGER		FILL
     	COMMON/LAYOUT_GIN/ IGIN,LINE,FILL,NPTS,SIZE,XPOS,YPOS
     	SAVE		XPS, YPS

     	IF( ICODE.NE.0 ) GOTO 111
C
C  ADD A POINT...
C
     	IF( NPTS.EQ.1 ) THEN
     	    XPS = XPOS
     	    YPS = YPOS
     	ENDIF
     	XSC(NPTS,NCU+1) = XPOS-XPS
    	YSC(NPTS,NCU+1) = YPOS-YPS
    	CALL IFSPEN( 3 )
     	CALL IFPLOT( XPOS-0.05, YPOS, 3 )
     	CALL IFPLOT( XPOS+0.05, YPOS, 2 )
     	CALL IFPLOT( XPOS, YPOS-0.05, 3 )
     	CALL IFPLOT( XPOS, YPOS+0.05, 2 )
    	CALL IFINIT_DUMP
    	GOTO 999

111	IF( LINE.NE.99 ) GOTO 222
C
C  PICK ENTRIES THAT FALL IN THE BOX...
C
     	X11 = XPS
    	Y11 = YPS
    	X22 = XPS+XSC(2,NCU+1)
    	Y22 = YPS+YSC(2,NCU+1)
     	IF( X22.LT.X11 ) THEN
     	    XPOS= X11
     	    X11 = X22
     	    X22 = XPOS
     	ENDIF
     	IF( Y22.LT.Y11 ) THEN
     	    XPOS= Y11
     	    Y11 = Y22
     	    Y22 = XPOS
     	ENDIF
     	DO  I=1, NLC
     	    IF( P00(1,I).GT.X11 .AND. P00(1,I).LT.X22
     1    .AND. P00(2,I).GT.Y11 .AND. P00(2,I).LT.Y22 ) THEN
     		CALL LAYOUT_PICK_SEG( NSN(I) )
     	    ENDIF
     	ENDDO
     	XPOS = XPS
     	YPOS = YPS
	GOTO 999
C
C  ADD A NEW ENTRY...
C
222	IF( NPTS.NE.2 .OR. LINE.GT.0 ) GOTO 333
C
C  ADD AN ARROWHEAD...
C
     	LINE = 1
     	IF( FILL.GT.0 )  LINE = 11	!DOUBLE ARROWHEAD
     	NLC = NLC + 1
     	NID(NLC) = 6
     	X22 = XSC(2,NCU+1)
     	Y22 = YSC(2,NCU+1)
     	X11 = SQRT( X22**2 + Y22**2 )
     	Y11 = ASIN( Y22/X11 )/D2R
     	IF( X22.LT.0.0 ) Y11 = 180.0-Y11
     	P00(1,NLC) = X22+XPS
     	P00(2,NLC) = Y22+YPS
     	P00(3,NLC) = X11
     	P00(4,NLC) = 0.03
     	P00(5,NLC) = 0.10
     	P00(6,NLC) = Y11
     	P00(7,NLC) = LINE
     	GOTO 444
C
C  ADD A LINE...
C
333	IF( NPTS.NE.2 .AND. NCU.EQ.MNC ) THEN
     	    CALL LAYOUT_ERROR(16)
     	    GOTO 999
     	ENDIF
     	IF( NPTS.EQ.2 ) FILL = 0
     	IF( LINE.LT.0 ) THEN
     	    NPTS = -NPTS
     	    LINE = -LINE
     	ENDIF
     	NLC = NLC + 1
     	NID(NLC) = 9
     	P00(1,NLC) = XPS
     	P00(2,NLC) = YPS
     	P00(3,NLC) = NPTS
     	P00(4,NLC) = 1.0
     	P00(5,NLC) = 1.0
     	P00(6,NLC) = 0.0
     	P00(7,NLC) = FILL
     	P00(8,NLC) = LINE
     	P00(9,NLC) = LWID
     	IF( NPTS.EQ.2 ) THEN
     	    P00(10,NLC) = XSC(2,NCU+1)
     	    P00(11,NLC) = YSC(2,NCU+1)
     	ELSE
     	    NCU = NCU + 1
     	    LID(NCU) = NLC
     	ENDIF

444	PEN(NLC) = 1
     	NFL(NLC) = 0
     	CALL LAYOUT_DRAW( NLC, 1 )
     	CALL IFINIT_DUMP

999    	RETURN
    	END

    	SUBROUTINE LAYOUT_GIN_ENTRY( IT, XP, YP )
C
C  PROGRAMMER: R.S. ZHOU		MARCH-1986
C
C	THIS ROUTINE ADDS A SIMPLE LAYOUT ENTRY.
C
    	INCLUDE 'LAYOUT.CBS'

    	ID = IT
     	IF( ID.LT.1 .OR. ID.GT.7 ) GOTO 888
C
C  GENERATE A DEFAULT ENTRY....
C
    	NLC = NLC + 1
     	NID(NLC) = ID
     	NFL(NLC) = 0
     	PEN(NLC) = 1
     	P00(1,NLC) = XP
     	P00(2,NLC) = YP
     	DO I=3, MNS
     	   P00(I,NLC) = 0.0
     	ENDDO
     	IF( ID.LT.3 ) THEN		!BAR
     	    P00(3,NLC) = 1.0
     	    P00(4,NLC) = 1.0
     	    P00(8,NLC) = LTYP
     	    P00(9,NLC) = LWID
     	ENDIF
     	IF( ID.EQ.3 ) THEN		!ARC
     	    P00(3,NLC) = 0.5
     	    P00(4,NLC) = 0.5
     	    P00(10,NLC)= LTYP
     	    P00(11,NLC)= LWID
     	ENDIF
     	IF( ID.EQ.4 ) THEN		!OBLIQUE
     	    P00(3,NLC) = 1.0
     	    P00(4,NLC) = 0.5
     	    P00(8,NLC) = LTYP
     	    P00(9,NLC) = LWID
     	ENDIF
     	IF( ID.EQ.5 ) THEN		!POLIGON
     	    P00(3,NLC) = 1.0
     	    P00(6,NLC) = 3.0
     	    P00(8,NLC) = LTYP
     	    P00(9,NLC) = LWID
     	ENDIF
     	IF( ID.EQ.6 ) THEN		!ARROWHEAD
     	    P00(3,NLC) = 0.5
     	    P00(4,NLC) = 0.5
     	    P00(5,NLC) = 0.3
     	    P00(7,NLC) = 3.0
     	ENDIF
     	IF( ID.EQ.7 ) THEN		!SYMBOL
     	    P00(3,NLC) = 0.1
     	    P00(5,NLC) = 1.0
     	ENDIF
     	CALL LAYOUT_DRAW( NLC, 1 )
     	CALL IFINIT_DUMP
     	GOTO 999

888	CALL LAYOUT_ERROR(18)		!INVALID ENTRY ID
999	RETURN
    	END

     	SUBROUTINE LAYOUT_GIN_HELP
C
C	THIS ROUTINE DISPLAYS ON-LINE HELP ON GIN LAYOUT.
C
     	INTEGER		FILL
     	COMMON/LAYOUT_GIN/ IGIN,LINE,FILL,NPTS,SIZE,XPOS,YPOS

     	CALL IFGIN_ABLE( 0 )			!DISABLE GIN
     	IKEY = IFMISC_TYPE( 'GRAFIT$HLP:LAYOUT_GIN.HLP', ' ', 21 )
     	IF( IKEY.GT.0 ) THEN
     	    CALL IFANSI_VIDEO(70)
     	    WRITE(6,1000)
1000	    FORMAT('_oops: Help file is not available.')
     	    CALL IFANSI_VIDEO(47)
     	ENDIF
    	CALL IFGIN_ABLE( IGIN )			!ENABLE GIN
     	CALL IFSEG_MOVE( 0, XPOS, YPOS )	!MOVE CURSOR TO ORIGIN
     	CALL IFINIT_LINE(3)
    	RETURN
    	END

