    	SUBROUTINE IFANSI_TEXT( STR, N, IL, IC )
C
C	PROGRAMMER: R.S. ZHOU		FEB-1986
C
C	THIS ROUTINE OUTPUTS N CHARACTERS OF STR AT LINE --- IL
C	AND COLUMN --- IC
C
C		IC<0 : DISPLAY IN DOUBLE HEIGHT LINE
C		IL<0 : DISPLAY IN DOUBLE WIDTH LINE
C
     	INCLUDE 'TEKLIB.CBS'
    	BYTE TEXT(8), DLIN(3)
     	CHARACTER LINE*132, STR*(*)
     	DATA TEXT / 27, 91, 0, 0, 59, 0, 0, 72 /
    	DATA DLIN / 27, 35, 54 /
C
C  TEXT = <ESC>[00;00H
C  DLIN = <ESC>#6
C
     	N0 = IABS(N)
    	ICD = 0
    	IF( IL.LT.0 ) ICD = 1
    	IF( IC.LT.0 ) ICD = 2
    	ILL = IABS(IL)
    	ICC = IABS(IC)
     	IL0 = ILL/10
     	IL1 = ILL-10*IL0
     	IC0 = ICC/10
     	IC1 = ICC-10*IC0
    	TEXT(3) = 48 + IL0
    	TEXT(4) = 48 + IL1
    	TEXT(6) = 48 + IC0
    	TEXT(7) = 48 + IC1
     	LINE = STR
     	IF( ICD.EQ.0 ) THEN
     	    WRITE(LUN,1) TEXT, LINE(1:N0)
  1	    FORMAT(8A1,A<N0>)
     	ELSE IF( ICD.EQ.1 ) THEN
     	    WRITE(LUN,2) TEXT,DLIN, LINE(1:N0)
  2	    FORMAT(8A1,3A1,A<N0>)
     	ELSE
     	    DLIN(3) = 51
    	    WRITE(LUN,2) TEXT,DLIN, LINE(1:N0)
    	    DLIN(3) = 52
    	    ILL = ILL+1
     	    IL0 = ILL/10
     	    IL1 = ILL-10*IL0
    	    TEXT(3) = 48 + IL0
    	    TEXT(4) = 48 + IL1
    	    WRITE(LUN,2) TEXT,DLIN, LINE(1:N0)
    	ENDIF
    	RETURN
     	END

    	SUBROUTINE IFANSI_IFL( KP, IE, IT, IL, IC )
C
C	PROGRAMMER: R.S. ZHOU		FEB-1986
C
C	THIS ROUTINE OUTPUTS "IE" INTEGERS CONTAINED IN INTEGER
C	ARRAY -- KP(IE) IN FIELD LENGTH DESIGNATED BY "IT" AT
C	LINE "IL" AND COLUMN "IC".
C	
     	INCLUDE 'TEKLIB.CBS'
    	BYTE TEXT(8)
    	DIMENSION KP(1)
     	DATA TEXT / 27, 91, 0, 0, 59, 0, 0, 72 /
C
C  TEXT = <ESC>[00;00H
C
     	IR = IE
    	IFL = IT
     	IL0=IL/10
     	IL1=IL-10*IL0
     	IC0=IC/10
     	IC1=IC-10*IC0
    	TEXT(3) = 48 + IL0
    	TEXT(4) = 48 + IL1
    	TEXT(6) = 48 + IC0
    	TEXT(7) = 48 + IC1
     	WRITE(LUN,1) TEXT, (KP(I),I=1,IR)
1	FORMAT(8A1,<IR>I<IFL>)
    	RETURN
     	END

    	SUBROUTINE IFANSI_FFL( RP, IE, FL, IL, IC )
C
C	PROGRAMMER: R.S. ZHOU		FEB-1986
C
C	THIS ROUTINE OUTPUTS "IE" REAL NUMBERS CONTAINED IN THE
C	ARRAY -- RP(IE) IN FIELD FORMAT DESIGNATED BY "FL" AT
C	LINE NUMBER "IL" AND COLUMN NUMBER "IC" IN THE DIALOGUE
C	AREA, WHERE "FL" IS SPECIFIED IN "m.n" FOR FIXED POINT
C	REAL DATA FIELD "Fm.n".
C
     	INCLUDE 'TEKLIB.CBS'
    	BYTE TEXT(8)
    	DIMENSION RP(1)
     	DATA TEXT / 27, 91, 0, 0, 59, 0, 0, 72 /
     	PARAMETER FM= 10.0
C
C  TEXT = <ESC>[00;00H
C
     	J   = INT(FL)
     	K   = FM*(FL-FLOAT(J))+0.1
     	IR  = IE
     	IL0 = IL/10
     	IL1 = IL-10*IL0
     	IC0 = IC/10
     	IC1 = IC-10*IC0
    	TEXT(3) = 48 + IL0
    	TEXT(4) = 48 + IL1
    	TEXT(6) = 48 + IC0
    	TEXT(7) = 48 + IC1
     	WRITE(LUN,1) TEXT, (RP(I),I=1,IR)
1	FORMAT(8A1,<IR>F<J>.<K>)
    	RETURN
     	END

    	SUBROUTINE IFANSI_GFL( RP, IE, FL, IL, IC )
C
C	PROGRAMMER: R.S. ZHOU		FEB-1986
C
C	THIS ROUTINE OUTPUTS "IE" REAL NUMBERS CONTAINED IN THE
C	ARRAY -- RP(IE) IN FIELD FORMAT DESIGNATED BY "FL" AT
C	LINE NUMBER "IL" AND COLUMN NUMBER "IC" IN THE DIALOGUE
C	AREA, WHERE "FL" IS SPECIFIED IN "m.n" FOR FLOATING POINT
C	REAL DATA FIELD "Gm.n".
C
     	INCLUDE 'TEKLIB.CBS'
    	BYTE TEXT(8)
    	DIMENSION RP(1)
     	DATA TEXT / 27, 91, 0, 0, 59, 0, 0, 72 /
     	PARAMETER FM= 10.0
C
C  TEXT = <ESC>[00;00H
C
     	J   = INT(FL)
     	K   = FM*(FL-FLOAT(J))+0.1
     	IR  = IE
     	IL0 = IL/10
     	IL1 = IL-10*IL0
     	IC0 = IC/10
     	IC1 = IC-10*IC0
    	TEXT(3) = 48 + IL0
    	TEXT(4) = 48 + IL1
    	TEXT(6) = 48 + IC0
    	TEXT(7) = 48 + IC1
     	WRITE(LUN,1) TEXT, (RP(I),I=1,IR)
1	FORMAT(8A1,<IR>G<J>.<K>)
    	RETURN
     	END

    	SUBROUTINE IFANSI_CLEAR( IC )
C
C   PROGRAMMER: R.S. ZHOU,	FEB-1986
C
C	THIS ROUTINE ERASES THE SCREEN AREA SPECIFIED BY "IC"
C	BY USING THE STANDARD ANSI COMMANDS.
C
C	IC = 0: ERASE THE ENTIRE SCREEN AND CURSOR HOME AT (1,1)
C	IC = 1: ERASE THE ENTIRE SCREEN AND CURSOR DOES NOT MOVE
C	IC = 2: ERASE FROM THE CURRENT CURSOR TO THE END OF SCREEN
C	IC = 3: ERASE FROM THE CURRENT CURSOR TO THE TOP OF SCREEN
C	IC = 4: ERASE FROM THE CURRENT CURSOR TO THE END OF LINE
C	IC = 5: ERASE FROM THE CURRENT CURSOR TO THE START OF LINE
C	IC = 6: ERASE THE ENTIRE LINE OF CURRENT CURSOR.
C
     	INCLUDE 'TEKLIB.CBS'
    	BYTE TEXT(7)
    	DATA TEXT / 27, 91, 0, 0, 27, 91, 72 /

     	IF( IF_DCL_HARDCOPY() ) RETURN

    	II = IC
    	TEXT(4) = 74
    	IF( II.GT.3 ) TEXT(4) = 75
    	TEXT(3) = 50
    	IF( II.EQ.2 .OR. II.EQ. 4 ) TEXT(3) = 48
    	IF( II.EQ.3 .OR. II.EQ. 5 ) TEXT(3) = 49
    	IE = 4
    	IF( II.EQ.0 ) IE = 7
     	WRITE(LUN,1) (TEXT(I),I=1,IE)
1	FORMAT(<IE>A1)

    	RETURN
     	END

    	SUBROUTINE IFANSI_CURSOR( IL, IC )
C
C	PROGRAMMER: R.S. ZHOU		FEB-1986
C
C	THIS ROUTINE POSITIONS THE ALPHA CURSOR
C
C		AT SCREEN   LINE --- IL
C		AT SCREEN COLUMN --- IC
C
C	IN DIALOGUE AREA BY ANSI CURSOR COMMANDS.
C
C		1<=IL<=30,     1<=IC<=80
C
C	IF IL=0, IC SPECIFIES CURSOR RIGHTWARD/LEFTWARD MOTION;
C	IF IC=0, IL SPECIFIES CURSOR UP/DOWN MOTION:
C
C		POSITIVE NUMBER ===> DOWN/RIGHTWARD
C		NEGATIVE NUMBER ===> UP/LEFTWARD
C
     	INCLUDE 'TEKLIB.CBS'
    	BYTE CUR1(8), CUR2(5)
    	DATA CUR1/ 27, 91, 0, 0, 59, 0, 0, 72 /	!<ESC>[00;00H (POSITION)
    	DATA CUR2/ 27, 91, 0, 0, 0 /		!<ESC>[000    (POSITION)

     	IF( IF_DCL_HARDCOPY() ) RETURN

     	ILL = IABS(IL)
     	IF( ILL.NE.0 ) THEN
     	    IF( ILL.GT.24 ) ILL = 24
     	    IL0 = ILL/10
     	    IL1 = ILL-10*IL0
     	ENDIF
     	ICC = IABS(IC)
     	IF( ICC.NE.0 ) THEN
     	    IF( ICC.GT.80 ) ICC = 80
     	    IC0 = ICC/10
     	    IC1 = ICC-10*IC0
     	ENDIF
     	IF( ILL.NE.0 .AND. ICC.NE.0 ) THEN
     	    CUR1(3) = IL0+48
     	    CUR1(4) = IL1+48
     	    CUR1(6) = IC0+48
     	    CUR1(7) = IC1+48
     	    WRITE(LUN,1) CUR1
  1	    FORMAT(8A1)
     	ELSE IF( ILL.EQ.0 ) THEN
     	    CUR2(3) = IC0+48
     	    CUR2(4) = IC1+48
     	    CUR2(5) = 68
     	    IF( IC.GT.0 ) CUR2(5) = 67
     	    WRITE(LUN,1) (CUR2(I),I=1,5)
     	ELSE
     	    CUR2(3) = IL0+48
     	    CUR2(4) = IL1+48
     	    CUR2(5) = 65
     	    IF( IL.GT.0 ) CUR2(5) = 66
     	    WRITE(LUN,1) CUR2
     	ENDIF
    	RETURN
     	END

    	SUBROUTINE IFANSI_VIDEO( IC )
C
C	PROGRAMMER: R.S. ZHOU		FEB-1986
C
C	THIS ROUTINE IMPLEMENTS THE STANDARD ANSI GRAPHICS RENDITIONS
C
C	IC=#*, # = background color 0 to 7
C	       * = character color  0 to 7
C
C	If IC<0, reverse video is on, otherwise off.
C	If *=9 blink on (e.g. IC=9 just blinking)
C	If #=9 underscore on (.e.g. IC=90 just underscore)
C	If #=8 bold display on (.e.g. IC=80 just bold)
C
     	INCLUDE 'TEKLIB.CBS'
     	LOGICAL REVERSE
     	INTEGER CRT
    	BYTE TEXT(5)
    	DATA TEXT / 27, 91, 0, 0, 109 /

     	IF( IF_DCL_HARDCOPY() ) RETURN
C
C   GET TERMINAL ID REPORT...
C
     	CRT = IFINIT_ITM(0)
C
C   TEXT = <ESC>[00m
C
    	IC0 = IC
     	REVERSE = .FALSE.
     	IF( IC0.LT.0 ) REVERSE = .TRUE.
     	IC1 = IABS(IC0)
     	IC0 = IC1/10
     	IC1 = IC1 - IC0*10
     	IF( CRT.NE.2.AND.IC0.NE.4.AND.IC0.LT.8 ) REVERSE = .TRUE.

    	IF( IC0.LT.8 .AND. IC1.LT.8 ) THEN
    	    TEXT(3) = 48
    	    TEXT(4) = 48
     	    WRITE(LUN,1) TEXT  		!ALL ATTRIBUTES OFF
    	ENDIF

     	IF( REVERSE ) THEN
    	    TEXT(3) = 48
    	    TEXT(4) = 55
     	    WRITE(LUN,1) TEXT		!REVERSE VIDEO ON
     	ENDIF

     	IF( CRT.NE.2 .AND. IC0.EQ.8 ) THEN
     	    TEXT(3) = 0
     	    TEXT(4) = 49
     	    WRITE(LUN,1) TEXT		!BOLD PRINT ON
     	ENDIF

     	IF( IC0.EQ.9 ) THEN
     	    TEXT(3) = 0
     	    TEXT(4) = 52
     	    WRITE(LUN,1) TEXT		!UNDERSCORE ON
     	ENDIF

     	IF( IC0.LT.8 .AND. CRT.EQ.2 ) THEN
     	    TEXT(3) = 52
     	    TEXT(4) = 48 + IC0		!BACKGROUND COLOR
     	    WRITE(LUN,1) TEXT
     	ENDIF

     	IF( IC0.GT.7 .AND. IC1.EQ.0 ) GOTO 9

     	IF( IC1.EQ.9 ) THEN
     	    TEXT(3) = 0
     	    TEXT(4) = 53
     	    WRITE(LUN,1) TEXT		!BLINK ON
     	ELSE IF( CRT.EQ.2 ) THEN
     	    TEXT(3) = 51
     	    TEXT(4) = 48 + IC1
     	    WRITE(LUN,1) TEXT		!CHARACTER COLOR
     	ENDIF

1	FORMAT(5A1)
9    	RETURN
     	END

    	SUBROUTINE IFANSI_MARGIN( ITOP,IBOT )
C
C  PROGRAMMER: R.S. ZHOU
C
C  	THIS ROUTINE SETS TOP AND BOTTOM MARGINS OF SCREEN
C	FOR DIALOG IN ANSI MODE.
C
     	INCLUDE 'TEKLIB.CBS'
    	BYTE TEXT(8)
     	DATA TEXT/ 27, 91, 0, 0, 59, 0, 0, 114 /	!0<ESC>[00;00r

     	IF( IF_DCL_HARDCOPY() ) RETURN

    	IT = ITOP
    	IB = IBOT
    	IF( IT.LT.1 ) IT = 1
    	IF( IT.GT.24) IT = 24
    	IF( IB.LT.1 ) IB = 24
    	IF( IB.GT.24) IB = 24
    	IF( IT.GT.(IB-2)) IT = IB-2
     	IT0 = IT/10
     	IT1 = IT-10*IT0
     	IB0 = IB/10
     	IB1 = IB-10*IB0
     	TEXT(3) = IT0+48
     	TEXT(4) = IT1+48
     	TEXT(6) = IB0+48
     	TEXT(7) = IB1+48
     	WRITE(LUN,1) TEXT
 1	FORMAT(8A1)
    	RETURN
    	END    	

     	SUBROUTINE IFANSI_TITLE( TITLE )
C
C	THIS ROUTINE DISPLAYS A SCREEN PAGE TITLE.
C
     	CHARACTER HEADER*80, TITLE*(*)

     	HEADER = TITLE
     	CALL DATE( HEADER(63:71) )
     	CALL TIME( HEADER(73:80) )
     	CALL IFANSI_VIDEO(12)
     	CALL IFANSI_VIDEO(80)
     	CALL IFANSI_TEXT( HEADER, 80, 1, 1 )
     	CALL IFANSI_VIDEO(47)

     	RETURN
     	END

