    	SUBROUTINE IFTEXT( XOP,YOP,TEXT,WIDTH,HEIGHT,ANGLE )
C
C  PROGRAMMER: R.S. ZHOU	FEB-1986
C
C	THIS ROUTINE HANDLES GRAPHTEXT GENERATION.
C
C	XOP,YOP --- STARTING POSITION FOR DRAWING
C	TEXT    --- TEXT IN CHARACTER FORMAT
C	WIDTH   --- WIDTH OF TEXT IN INCHES
C	HEIGHT  --- HEIGHT OF TEXT IN INCHES
C	ANGLE   --- TEXT STRING SLANT ANGLES IN DEGREES
C
    	INCLUDE		'TEKLIB.CBS'
    	CHARACTER	TEXT*(*)
     	LOGICAL		BOLDFACE
    	DIMENSION	CSIZ(17)
C
C  'CSIZ' CONTAINS THE ACTUAL SIZES OF REGIS CHARACTER SET.
C  THUS, THESE ARE THE ONLY ALLOWABLE CHARACTER HEIGHTS.
C
    	DATA CSIZ/0.10,0.20,0.25,0.45,0.55,0.75,0.85,1.05,1.15,
    	1 1.35,1.40,1.65,1.80,1.85,2.05,2.25,2.35/

    	NCH = IFMISC_LENG( TEXT )
     	IF( NCH.EQ.0 ) GOTO 999
     	IWD = IDW
     	IDW = 0
     	IF( ITM.EQ.1 ) GOTO 888

     	WTH = WIDTH
    	HGT = HEIGHT
    	IAN = AMOD( ANGLE+XANG, 360.0 )
     	XPS = XOP
     	YPS = YOP
     	BOLDFACE = .FALSE.

    	IF( ITM.NE.2 ) GOTO 444
C
C  SET GRAPHTEXT ROTATION...
C
     	IF( IAN.NE.0 ) THEN
     	    IF( IPL.GT.NBS-IPK-7 ) CALL IFINIT_DUMP
    	    IPB(IPL+1) = 27		!<ESC>MR angle
    	    IPB(IPL+2) = 77
    	    IPB(IPL+3) = 82
    	    IPL = IPL + 3
    	    CALL IFPACK_TEKINT( IAN )
    	    IPL = IPL + 1
    	    IPB(IPL) = 48
     	ENDIF
C
C  SET GRAPHTEXT SIZE...
C
     	IF( IPL.GT.NBS-IPK-12 ) CALL IFINIT_DUMP
     	IPB(IPL+1) = 27		!<ESC>MC width,height,spacing
     	IPB(IPL+2) = 77
     	IPB(IPL+3) = 67
     	IPL = IPL + 3
     	CALL IFPACK_TEKINT( INT(FUNI*WTH*0.75*XSCL) )	!CHARACTER CELL WIDTH
     	CALL IFPACK_TEKINT( INT(FUNI*HGT*YSCL)      )	!CHARACTER CELL HEIGHT
     	CALL IFPACK_TEKINT( INT(FUNI*WTH*0.25*XSCL) )	!CHARACTER CELL SPACING
C
C  MOVE TO THE STARTING POINT...
C
111	CALL IFPLOT( XPS, YPS, 3 )
C
C  SEND GRAPHTEXT...
C
     	IF( IPL.GT.NBS-NCH-IPK-6 ) CALL IFINIT_DUMP
    	IPB(IPL+1) = 27		!<ESC>LT NCH,text
    	IPB(IPL+2) = 76
    	IPB(IPL+3) = 84
    	IPL = IPL + 3
    	CALL IFPACK_TEKINT( NCH )	!DELIMITER
    	DO I=1, NCH
    	   IPL = IPL + 1
    	   IPB(IPL) = ICHAR( TEXT(I:I) )
    	ENDDO
     	IF( IFN.NE.3 .OR. BOLDFACE ) GOTO 222
     	BOLDFACE = .TRUE.
     	XPS = XPS + 0.015*COS(IAN*D2R)
     	YPS = YPS + 0.015*SIN(IAN*D2R)
    	GOTO 111
222	IF( IAN.NE.0 ) THEN
     	    IF( IPL.GT.NBS-IPK-7 ) CALL IFINIT_DUMP
    	    IPB(IPL+1) = 27		!<ESC>MR angle
    	    IPB(IPL+2) = 77
    	    IPB(IPL+3) = 82
    	    IPL = IPL + 3
    	    CALL IFPACK_TEKINT( 0 )
    	    IPL = IPL + 1
    	    IPB(IPL) = 48
     	ENDIF
     	GOTO 888

444	IF( ITM.NE.3 ) GOTO 888
C
C  PLOT IN REGIS COMMANDS...
C
     	IAN = 45*(IAN/45)
    	WTH = WTH*XSCL
C
C  GET CHARACTER SIZE NUMBER...
C
    	DO K=1, 17
    	   IF( WTH.LE.CSIZ(K) ) GOTO 555
    	ENDDO
     	K = K-1
C
C  MOVE TO THE STARTING POINT...
C
555	XPS = XPS - 1.25*WTH*SIN(IAN*D2R)
     	YPS = YPS + 1.25*WTH*COS(IAN*D2R)
     	CALL IFPLOT( XPS, YPS, 3 )

     	IF( IPL.GT.NBS-IPK-19 ) CALL IFINIT_DUMP
     	IPB(IPL+1) = 'T'
C
C  THIS IS THE STRING SLANT...
C
     	IPB(IPL+2) = '('
    	IPB(IPL+3) = 'D'
    	IPL = IPL + 3
    	CALL IFPACK_REGIS( IAN )
    	IPL = IPL + 1
    	IPB(IPL) = ')'
C
C  THIS IS THE CHARACTER SIZE...
C
    	IPB(IPL+1) = '('
    	IPB(IPL+2) = 'S'
    	IPB(IPL+3) = 47+K
    	IPB(IPL+4) = ')'
    	IPL = IPL + 4
C
C  THIS IS THE CHARACTER SLANT...
C
     	IPB(IPL+1) = '('
    	IPB(IPL+2) = 'D'
    	IPL = IPL + 2
    	CALL IFPACK_REGIS( IAN )
    	IPL = IPL + 1
    	IPB(IPL) = ')'
C
C  LOAD THE TEXT INTO THE BUFFER USING (") AS DELIMITERS...
C
     	IF( IPL.GT.NBS-IPK-2-NCH ) CALL IFINIT_DUMP
    	IPL = IPL + 1
    	IPB(IPL) = '"'
    	DO I=1, NCH
    	   IPL = IPL + 1
    	   IPB(IPL) = ICHAR( TEXT(I:I) )
    	ENDDO
    	IPL = IPL + 1
    	IPB(IPL) = '"'
     	IF( IFN.NE.3 .OR. BOLDFACE ) GOTO 888
     	BOLDFACE = .TRUE.
     	XPS = XPS + 0.015*COS(IAN*D2R)
     	YPS = YPS + 0.015*SIN(IAN*D2R)
     	GOTO 555

888	IF( IWD.NE.0 ) THEN
     	    IF( NPPS.GT.0 ) CALL IFPLOT_DUMP
     	    IF( NCH.GT.80 ) NCH = 80
     	    WRITE(IDF,1000) NCH,XOP,YOP,WIDTH,HEIGHT,ANGLE,TEXT(1:NCH)
     	ENDIF
1000	FORMAT('TEXT:',I3,5F8.3,',',A<NCH>)
     	IDW = IWD

999	RETURN
    	END

    	SUBROUTINE IFTEXT_EXT(XO,YO,TEXT,WIDTH,HEIGHT,ANGLE)
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY	JAN-1986
C
C	THIS ROUTINE HANDLES EXTENDED GRAPHTEXT PLOTTING.
C
C	XO,YO  ----  THE STARTING POSITION OF THE TEXT LINE.
C	TEXT   ----  THE TEXT LINE TO BE PLOTTED.
C	WIDTH  ----  THE WIDTH OF THE TEXT LINE.
C	HEIGHT ----  THE HEIGHT OF THE TEXT LINE.
C	ANGLE  ----  THE SLANT ANGLE OF THE TEXT LINE.
C
C---------------------------------------------------------------------
C
C	CONTROLL SEQUENCES THAT CAN BE USED IN THE TEXT:
C
C	"{" --- CONVERT THE NEXT NON-BLANK CHARACTER TO SUPERSCRIPT
C	"}" --- CONVERT THE NEXT NON-BLANK CHARACTER TO SUBSCRIPT
C	\sTEXT_STRING^s  --- SLANT CHARS OF THE TEXT STRING.
C	\bTEXT_STRING^b  --- THE TEXT STRING AS BOLD FACE
C	\#TEXT_STRING^p  --- SET PEN # FOR THE TEXT STRING.
C
C---------------------------------------------------------------------
C
    	PARAMETER	D2R= 0.17453292E-1
    	CHARACTER	SYM*1, TEXT*(*)
     	BYTE		ITT, IFLAG
     	LOGICAL		IBL, IIB, IIS, IIP

    	NCH = IFMISC_LENG( TEXT )
     	IF( NCH.EQ.0 ) RETURN
     	XOP = XO
    	YOP = YO
     	ANG = ANGLE
    	WTH = WIDTH
    	HGT = HEIGHT
     	NCS = IFTEXT_FLAGS( TEXT )
     	IC  = 1
     	IBL = .FALSE.
     	IIB = .FALSE.
     	IIS = .FALSE.
     	IF( NCS.GT.0 ) GOTO 2
C
C  NO FUNCTION FLAGS FOUND...
C
   1	CALL IFTEXT( XOP, YOP, TEXT(IC:), WTH, HGT, ANG )
     	GOTO 999
C
C  INITIALIZATION...
C
   2	IC = 1				! COUNT FOR TRUE TEXT CHAR.!
     	CTH = COS( ANG*D2R )		! ROTATION CORRECTION !
    	STH = SIN( ANG*D2R )		! ROTATION CORRECTION !
     	CALL IFSCAL_NOW( XSF,YSF )
     	CALL IFSPEN_NOW( IPO )		! GET THE CURRENT PEN NUMBER
    	IFLAG = 0			! FLAG FOR CONTROLL SEQUENCE
C
C  LOOP THROUGH THE TEXTSTRING CHARACTER BY CHARACTER...
C
   3	IF( IFCTRL_C() ) RETURN
     	XPS = XOP
     	YPS = YOP
     	WWW = WTH
     	HHH = HGT
    	SYM = TEXT(IC:IC)
    	IF( SYM.EQ.' ' ) GOTO 666
     	IBL = .TRUE.
     	IF( SYM.NE.'{' ) GOTO 333
     	IF( TEXT(IC+1:IC+1).EQ.' ' ) GOTO 666
C
C  SUPERSCRIPT...
C
     	IC = IC + 1
     	SYM = TEXT(IC:IC)
     	XPS = XPS-0.7*WWW*STH	! X-OFFSET !
     	YPS = YPS+0.7*HHH*CTH	! Y-OFFSET !
     	WWW = 0.67*WWW
     	HHH = 0.67*HHH
    	GOTO 666

333	IF( SYM.NE.'}' ) GOTO 444
     	IF( TEXT(IC+1:IC+1).EQ.' ' ) GOTO 666
C
C  SUBSCRIPT...
C
     	IC = IC + 1
     	SYM = TEXT(IC:IC)
     	XPS = XPS+0.2*WWW*STH	! X-OFFSET !
     	YPS = YPS-0.2*HHH*CTH	! Y-OFFSET !
     	WWW = 0.67*WWW
     	HHH = 0.67*HHH
    	GOTO 666
C
C  START CONTROL SEQUENCE OF SOME KIND...
C
444	IF( SYM.NE.'\' ) GOTO 555		! NO FLAG !
    	IFLAG = IFLAG + 1
    	IC = IC + 1
    	SYM = TEXT(IC:IC)

     	IF( SYM.EQ.'S' .OR. SYM.EQ.'s' ) THEN
     	    CALL IFFONT( 2 )			!ITALIC FONT
     	    IIS = .TRUE.
     	    GOTO 777
     	ENDIF

     	IF( SYM.EQ.'B' .OR. SYM.NE.'b' ) THEN
     	    CALL IFFONT( 3 )			!BOLDFACE FONT
     	    IIB = .TRUE.
     	    GOTO 777
     	ENDIF
C
C  ATTEMPT TO CHANGE TEXT COLOR...
C
     	DECODE( 1, 445, SYM, ERR=777 ) NCS
445	FORMAT(I1)
    	IF( NCS.GT.0 .AND. NCS.LT.9 ) THEN
     	    CALL IFSPEN( NCS )
     	    IIP = .TRUE.
     	ENDIF
    	GOTO 777
C
C  STOP CONTROL SEQUENCE OF SOME KIND...
C
555	IF( SYM.NE.'^' .OR. IFLAG.EQ.0 ) GOTO 666
    	IFLAG = IFLAG -1
    	IC = IC + 1
    	SYM = TEXT(IC:IC)
     	IF( SYM.EQ.'S' .OR. SYM.EQ.'s' ) THEN
     	    CALL IFFONT( 1 )
     	    IIS = .FALSE.
     	    GOTO 777
     	ENDIF
     	IF( SYM.EQ.'B' .OR. SYM.EQ.'b' ) THEN
     	    CALL IFFONT( 1 )
     	    IIB = .FALSE.
     	    GOTO 777
     	ENDIF
     	IF( SYM.EQ.'P' .OR. SYM.EQ.'p' ) THEN
     	    CALL IFSPEN(IPO)
     	    IIP = .FALSE.
     	ENDIF
     	GOTO 777
C
C  DRAW THE CHARACTER...
C
666	IF(IBL) CALL IFTEXT( XPS, YPS, SYM, WWW, HHH, ANG )
C
C  UPDATE X,Y COORDINATES...
C
     	XOP = XOP + WTH*CTH
     	YOP = YOP + WTH*STH*XSF/YSF
C
C  GET THE NEXT CHARACTER...
C
777	IF( IC.GE.NCH ) GOTO 999
     	IC = IC + 1
     	NCS = IFTEXT_FLAGS( TEXT(IC:) )
     	IF( NCS.EQ.0 ) GOTO 1	!NO MORE CONTROLL SEQUENCE LEFT
     	GOTO 3
C
C  READY TO GET OUT...
C
999	IF( IIP ) CALL IFSPEN( IPO )
    	IF( IIB .OR. IIS ) CALL IFFONT( 1 )

     	RETURN
    	END

     	FUNCTION IFTEXT_FLAGS( TEXT )

	CHARACTER FLAGS(4)*1, TEXT*(*)
     	DATA FLAGS / '{', '}', '\', '^' /

     	K = IFMISC_LENG( TEXT )
	DO I= 1, K
     	   DO J=1, 4
     	      IF( TEXT(I:I) .EQ. FLAGS(J) ) GOTO 1
     	   ENDDO
     	ENDDO
     	IFTEXT_FLAGS = 0
     	RETURN
  1	IFTEXT_FLAGS = 1
     	RETURN
     	END

    	SUBROUTINE IFTEXT_MARK( XOP, YOP, HEIGHT, TEXT, ANGLE, NCHAR )
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY, MAY-1987
C
C	THIS ROUTINE IS HERE ONLY FOR CALCOMP CALL COMPATIBILITY
C
C	XOP,YOP --- STARTING POSITION FOR DRAWING
C	HEIGHT  --- HEIGHT OF TEXT IN INCHES
C	TEXT    --- TEXT IN CHARACTER FORMAT
C	ANGLE   --- TEXT STRING SLANT ANGLES IN DEGREES
C	NCHAR   --- NUMBER OF TEXT CHARACTERS TO BE PLOTTED
C
     	CHARACTER TEXT*(*)

     	NCH = NCHAR
     	IF( NCH.GT.0 ) THEN
     	    K = IFMISC_LENG(TEXT)
     	    IF( K.GT.NCH ) TEXT(NCH:) = ' '
     	    CALL IFTEXT_EXT(XOP,YOP,TEXT,HEIGHT,HEIGHT,ANGLE)
     	ELSE
     	    IF( NCH.EQ.-2 ) CALL IFPLOT(XOP,YOP,2)
     	    NCH = ICHAR(TEXT(1:1))
    	    CALL IFMARK(XOP,YOP,HEIGHT,ANGLE,NCH)
     	ENDIF

     	RETURN
    	END

     	SUBROUTINE IFTEXT_FPN( XPS, YPS, SIZE, FNUM, ANGLE, IDIG )
C
C  PROGRAMMER:  RONG-SHENG ZHOU
C		BOSTON COLLEGE, 9/1988
C
C	THIS ROUTINE DISPLAYS A FLOATING POINT NUMBER.
C
C	IDIG: NUMBER OF DIGITS AFTER THE DECIMAL POINTS.
C	IF IDIG.EQ.-1, ONLY THE INTEGER PART IS DISPLAYED.
C
     	CHARACTER TEXT*16

     	ENCODE( 16, 1000, TEXT ) FNUM
1000	FORMAT(F16.6)
     	DO IK= 1, 16
     	   IF( TEXT(IK:IK).NE.' ' ) GOTO 111
     	ENDDO
111	NCH = 10 + IDIG
     	IF( NCH.GT.16 ) NCH = 16
     	CALL IFTEXT( XPS, YPS, TEXT(IK:NCH), SIZE, SIZE, ANGLE )
     	RETURN
     	END

    	SUBROUTINE IFTEXT_CENT( XST,XED,YST,YED,TXT,WTH,HGT )
C
C	PROGRAMMER: R.S. ZHOU,		ALFRED UNIVERSITY
C
C	THIS ROUTINE CENTERS A TEXTSTRING.
C
C	XST,XED  ---  START AND ENDING X-COORDINATES IN INCHES.
C	YST,YED  ---   "     "    "    Y-     "       "    ".
C	TXT      ---  LABEL IN CHARACTER FORMAT.
C		      IF TXT(1).EQ.'!', TXT IS NOT CENTERED.
C	WTH      ---  WIDTH OF LABEL IN INCHES.
C	HGT      ---  HEIGHT OF LABEL IN INCHES.
C
    	CHARACTER TXT*(*)
    	DATA R2D / 57.29577952 /

     	NK = IFTEXT_STRIP( TXT )
     	IF( NK.EQ.0 ) RETURN
     	DIST = SQRT( (XED-XST)**2 + (YED-YST)**2 )
     	IF( DIST.EQ.0.0 ) RETURN
     	COSTH = (XED-XST) / DIST
     	SINTH = (YED-YST) / DIST
     	WITH  = WTH
     	IF( TXT(1:1).EQ.'!' ) THEN
     	    TXT = TXT(2:)
     	    XPS = XST
     	    YPS = YST
     	ELSE
     	    CALL IFSCAL_NOW( XPS, YPS )
     	    ANGLE = 1.0 + SINTH*(XPS/YPS-1.0)
     	    SPOS = DIST - NK * WITH * ANGLE
    	    IF( SPOS.LT.0.0 ) THEN
    		WITH = DIST / NK / ANGLE
     		IF( WITH.LT.0.05 ) WITH = 0.05
    		SPOS = DIST - NK * WITH * ANGLE
     	    ENDIF
     	    SPOS = 0.5 * SPOS
    	    XPS = XST + SPOS * COSTH
    	    YPS = YST + SPOS * SINTH
     	ENDIF
     	ANGLE = ASIN( SINTH ) * R2D
    	IF( COSTH.LT.0.0 ) ANGLE = 180.0-ANGLE
    	CALL IFTEXT_EXT( XPS, YPS, TXT, WITH, HGT, ANGLE )
     	RETURN
    	END

	FUNCTION IFTEXT_STRIP( TEXT )
C
C	THIS ROUTINE RETURNS THE LENGTH OF "TEXT" STRIPPED OF
C	ALL EMBEDDED CONTROL SEQUENCES ALLOWED IN "IFTEXT_EXT.FOR".
C
     	CHARACTER SYM*1, TEXT*(*)
     	LOGICAL   FLAG

    	NCH = IFMISC_LENG( TEXT )
     	MAX = NCH-1
    	FLAG= .FALSE.
	DO 5 I=1, MAX
    	SYM = TEXT(I:I)
     	IF( SYM.NE.'{' .AND. SYM.NE.'}' ) GOTO 3
     	IF( TEXT(I+1:I+1).EQ.' ' ) GOTO 5
     	NCH = NCH -1
     	GOTO 5
3    	IF( SYM.NE.'\' ) GOTO 4
    	FLAG= .TRUE.
    	NCH = NCH-2
    	GOTO 5
4	IF( SYM.NE.'^' .OR. .NOT.FLAG ) GOTO 5
    	FLAG= .FALSE.
    	NCH = NCH-2
5	CONTINUE
    	IF( NCH.LT.0 ) NCH = 0
    	IFTEXT_STRIP = NCH

    	RETURN
	END

