	SUBROUTINE OUTFIL(ICHAR,ITRANS,INOUT)
	COMMON/OUTFIL/ ILINE(512),IPOS,IOTSUM,IONYBL,NOREC,IFLGO,LENO
	COMMON/DOTCNT/ IDOT
	LOGICAL*1 ILINE,IMSG(20),IBUF(512)
	INTEGER IBUFER(2),PTR
	DATA IMSG/"15,"12,'R','e','c','e','i','v','e',' ','c','o','m',
     C		'p','l','e','t','e',"15,"12/
	DATA IPOS/0/,IFLG/0/,IDOT/0/
C	  CHECK FOR TERMINATION OF INPUT
	IF(INOUT.EQ.3) GOTO 200
C	  CHECK IF IN BINARY TRANSFER MODE
	IF((ITRANS.AND."100).NE.0) GOTO 30
C
C	  IF CALLED FROM 1ST SPOT IN MAIN AND NOT IN COPY MODE
C	    AND NO CHARACTER AVAILABLE THEN RETURN
C
	IF(ICHAR.LT.0) RETURN
	IF(INOUT.EQ.1.AND.(ITRANS.AND."20).EQ.0) RETURN
C
C	  IGNORE RUBOUTS AND NULLS IN ASCII 7-BIT MODE
C
	IF((ITRANS.AND."40).NE.0) GOTO 5
	I=(ICHAR.AND."177)
	IF(I.EQ."177.OR.I.EQ.0) RETURN
C
C	  CHECK FOR LINE-FEEDS - DON'T PLACE IN FILE
C
	IF(ICHAR.EQ."12) GOTO 8
C
C	  CHECK FOR CARRIAGE-RETURN
C	  MUST WRITE TO OUTPUT FILE IF WE HAVE CARRIAGE RETURN
C
	IF(ICHAR.NE."15) GOTO 5
C
C	  IF THIS LINE IS NULL (IPOS=0) PUT A NULL IN 1ST CHAR
C
	IF(IPOS.EQ.0) ILINE(1)=0
C
C	  WRITE A LINE OF OUTPUT TO FILE
C
 3	WRITE(7,7) (ILINE(I),I=1,IPOS)
 7	FORMAT(4(128A1))
	IPOS=0
	GOTO 8
C
 5	IPOS=IPOS+1
	ILINE(IPOS)=ICHAR
C	  IF IN ECHO MODE THEN ECHO THIS CHAR
 8	IF((INOUT.EQ.2.AND.(ITRANS.AND."4).NE.0))
     C		CALL ENQUE(ICHAR.AND."177)
	IF((IPOS/100)*100.EQ.IPOS) GOTO 20
	IF(IPOS.LT.512) RETURN
C
C	  IF SEQUENTIAL FILE FOR OUTPUT, LINES MUST BE LESS THAN 512
C	  CHARACTERS IN LENGTH
C
	IF((ITRANS.AND."140).EQ.0) GOTO 3
C
 10	WRITE(7'NOREC) ILINE
 15	IPOS=0
 20	IF((ITRANS.AND.4).NE.0.OR.INOUT.EQ.4) RETURN
C
C	  SKIP PRINTING DOTS IF OPTION IS SET
 25	IFLG=IFLG+1
	IF(IFLG.NE.2) RETURN
	IFLG=0
	IDOT=IDOT+1
	CALL ENQUE('.')
	IF(IDOT.NE.50) RETURN
	CALL ENQUE("15)
	CALL ENQUE("12)
	IDOT=0
	RETURN
C
C	  IN BINARY MODE - DECODE THIS STUFF AND PUT IN FILE
 30	TYPE *,'NOT YET SUPPORTED'
	RETURN
 32	IF(INOUT.EQ.1) GOTO 100
C	  IF ILLEGAL CHARACTER RECEIVED IGNORE IT WHEN B/4 COL. 73
	IF((ICHAR.AND."160).EQ.0.AND.IPOS.LT.37) RETURN
	IF(ICHAR.EQ."15) GOTO 50
	IOTSUM=IOTSUM+(ICHAR.AND."17)
	IF(IONYBL.EQ.2) GOTO 35
	IPOS=IPOS+1
	IONYBL=2
	ILINE(IPOS)=(ICHAR.AND."17)*16
	GOTO 40
 35	IONYBL=1
	ILINE(IPOS)=ILINE(IPOS)+(ICHAR.AND."17)
	IF(IPOS.EQ.512) GOTO 10
C
C
	READ(7'(IADDR/1024+1),ERR=39) ILINE
 36	DO 38 I=MOD(IADDR,512)+1,LEN
	J=I/2
	IF((I.AND.1).EQ.0) GOTO 37
	ILINE(J)=(ILINE(J).AND."177400) + IBUF(I)
	GOTO 38
 37	ILINE(J)=(ILINE(J).AND."377) + IBUF(J)*"400
 38	CONTINUE
	WRITE(7'(IADDR/1024+1))
C*****   39 IS USED TO INITIALIZE THE ILINE ARRAY FOR WRITING BINARY
C*****	 DATA (ILINE(I)=0 I=1 TO 512
 39	CONTINUE
C
C
C	  BUFFER IS FULL - WRITE IN OUT
 40	RETURN
C
C	  WE GOT A <CR> - SET UP RESPONSE MESSAGE
 50	IBUFER(2)="15
	PTR=1
	IF((IOTSUM.AND."17).NE.0) GOTO 55
	IBUFER(1)='A'
	RETURN
 55	IBUFER(1)='N'
	IPOS=ISTRT
C******	MUST BACKSPACE FILE TO PROPER POSITION(SOMETIMES)
	RETURN
C
C	  SEND A(CKNOWLEDGE) OR N(ACK) 
C
 100	IF(PTR.EQ.0) RETURN
	ICHAR=IBUFER(PTR)
	PTR=PTR+1
	IF(PTR.EQ.3) PTR=0
	RETURN
C
C	  TERMINATE A TRANSMISSION
C
 200	IF((ITRANS.AND.1).EQ.0) RETURN
	CALL CLSFIL(1,ITRANS)
	DO 210 I=1,20
	IFLG=IMSG(I)
 210	CALL ENQUE(IFLG)
	RETURN
	END
