	Integer Function TPU$CallUser (N, Str, Return_Descr)
C 		Inputs are an integer, a string, and a string descriptor
C 		Very little error checking is done - captive routine.
C 
C   N		Action of this routine
C  ===	       ========================
C   1		Set logical TPU$POSITION to value of STR
C   2		Delete logical TPU$POSITION
C   3		Set Terminal NO_LINE_EDITING
C   4		Set Terminal LINE_EDITING
C   Other	Just return
	
C ======================================================================
C	29-SEP-1988	Version 5.001
C	
C	Dale E. Coy				Phone: (505) 667-3270/665-0145
C	Los Alamos National Laboratory
C	CRM-2, MS/B270, PO Box 1663
C	Los Alamos, NM 87544
C ======================================================================
	
	Implicit Integer*4 (a-z)
	
	Include '($SSDEF)'
       	Include '($IODEF)'
       	Include '($TTDEF)'
       	Include '($TT2DEF)'
	
	Character*(*) Str
	Character*100 Str2	! Can't trim in place
	Integer N, Return_Descr(2)
	Integer*2 StrLen
	
	Integer*4 Stat
	Logical Have_Channel /.FALSE./
	
	Integer*2 TT_Channel, IOSB(4)
	Integer*4 TChar_Buf (3), TT_Width_Type_Class,
	1	TT_Char, TT2_Char

	Equivalence (TChar_Buf (1), TT_Width_Type_Class)
	Equivalence (TChar_Buf (2), TT_Char)
	Equivalence (TChar_Buf (3), TT2_Char)

	Parameter (TChar_Buf_Length = 12)
	
C ======================================================================
	
	Call Str$Trim (Str2, Str, StrLen)
	GoTo (100, 200, 300, 400) N
	GoTo 5000
	
100	Continue	! Set Logical
	Call Lib$Set_Logical ('TPU_POSITION',STR(:StrLen))
	GoTo 5000
	
200	Continue	! Delete Logical
	Call Lib$Delete_Logical ('TPU_POSITION')
	GoTo 5000
	
300	Continue	! NO_LINE_EDITING
	If (.NOT. Have_Channel) then
	       	Stat = SYS$Assign('TT', TT_Channel,,)
       		If (.not. Stat) Call Lib$Stop(%Val(Stat))
		Have_Channel = .TRUE.
	End If
	
	Stat = Sys$QIOW(,%Val(TT_Channel),%VAL(IO$_SENSEMODE),
	1   %Ref(IOSB),,,%Ref(TChar_Buf),
	2   %Val(TChar_Buf_Length),,,,)
	If (.not. Stat) Call Lib$Stop(%Val(Stat))
	
	TT2_Char = IBClr ( TT2_Char, TT2$V_Editing)
	Stat = Sys$QIOW(,%Val(TT_Channel),%VAL(IO$_SETMODE),
	1       %Ref(IOSB),,,%Ref(TChar_Buf),
	2       %Val(TChar_Buf_Length),,,,)
	If (.not. Stat) Call Lib$Stop(%Val(Stat))
	
	GoTo 5000
	
400	Continue	! LINE_EDITING
	If (.NOT. Have_Channel) then
	       	Stat = SYS$Assign('TT', TT_Channel,,)
      		If (.not. Stat) Call Lib$Stop(%Val(Stat))
		Have_Channel = .TRUE.
	End If
	
	Stat = Sys$QIOW(,%Val(TT_Channel),%VAL(IO$_SENSEMODE),
	1	   %Ref(IOSB),,,%Ref(TChar_Buf),
	2	   %Val(TChar_Buf_Length),,,,)
	If (.not. Stat) Call Lib$Stop(%Val(Stat))

	TT2_Char = IBSet ( TT2_Char, TT2$V_Editing)
	Stat = Sys$QIOW(,%Val(TT_Channel),%VAL(IO$_SETMODE),
	1          %Ref(IOSB),,,%Ref(TChar_Buf),
	2          %Val(TChar_Buf_Length),,,,)
    	If (.not. Stat) Call Lib$Stop(%Val(Stat))

        Stat = SYS$DAssgn (%Val(TT_Channel))
        If (.not. Stat) Call Lib$Stop(%Val(Stat))
	Have_Channel = .FALSE.

	GoTo 5000
	
	
5000	Continue	! All routines exit this way
C 		Repeat the input string back to the output (descriptor)
	Call Lib$SGet1_DD (StrLen, Return_Descr)
	Call Lib$SCopy_DXDX (Str, Return_Descr)
	
	TPU$CallUser = SS$_NORMAL
	Return
	End

