	SUBROUTINE DAO(NUMS,LUNF,LUNT)
C 
C	Direct Access Output routine
C 
C	Routine to output text information given the files created by
C	ININDX.  LUNF is the FROM lun; the lun to which the .DAX file
C	is assigned.
C	LUNT is the TO lun, normally assigned to a terminal.  All LUN
C	assignments must be made BEFORE calling this routine.
C 
C	This  routine will output to LUNT the  text associated with
C	reference number NUM in the original sequential text file.
C 
C	If NUMS was not found in the original file there will be no entry
C	for it in the .DAX file.  If NUM was not found in the original
C	text file, an error message will result.
C	NOTE:  If LUNT is unit 6, .C has no effect.
C 
	CHARACTER A*80,C*80,B,D
	DIMENSION IREF(40)
	READ(LUNF'1) IREF
	IF(NUMS.LT.1) GOTO 300
	IF(NUMS.GT.IREF(1)) GOTO 300 ! NUM OUTSIDE OF INDEX RANGE
	IPROM=0
	NUM=NUMS
	INUM=NUM-1
	NREF=INUM-INUM/40*40+1
	LINE=INUM/40+2
	READ(LUNF'LINE) IREF
	IREC=IREF(NREF)
	IF(IREC.EQ.0) GOTO 300  !  REFERENCE NUMBER DOES NOT EXIST
	READ(LUNF'IREC) C
C 
C	C(1:4) CONTAINS THE REFERENCE NUMBER (NUMS) IN STRING FORM
C 
2	READ(LUNF'IREC) A
	IREC=IREC+1
	B=A(1:1)
C 
	IF(B.EQ.'.') THEN
C 
C	   HAVE A DOT COMMAND:
	   D=A(2:2)  !  D IS THE COMMAND
	   IF(D.EQ.'E') GOTO 100  !  END OF D.A. TEXT FILE
11	   FORMAT(A1)
	   IF((D.EQ.'C'.OR.D.EQ.'c').AND.LUNT.NE.6) CALL TCS(1,0,0,0)
C	ABOVE LINE CLEARS SCREEN UNLESS WRITING TO UNIT 6
	   IF(D.EQ.'B'.OR.D.EQ.'b') WRITE(LUNT,13) "7 ! RING BELL
13	   FORMAT('+',$/'+',A1,$/'+',$)
	   IF(D.GT.'0'.AND.D.LE.'9') THEN  !  SKIP "D" LINES
	      K=ICHAR(D)-48
	      DO 14 I=1,K
	      WRITE(LUNT,15)
14	      CONTINUE
15	      FORMAT(' ')
	      END IF
	   IF(D.EQ.'W'.OR.D.EQ.'w') THEN
	      READ(LUNT,11,END=12) D  ! WAIT
	      IF(D.EQ.'X'.OR.D.EQ.'x') GOTO 100
	      END IF
	IF(D.EQ.'P'.OR.D.EQ.'p') IPROM=1
C 
	ELSE IF(B.GE.'0'.AND.B.LE.'9') THEN
C	      CHECK IF NEW NUMBER IS LESS OR GREATER THAN NUMS:
	      IF(A(1:4).GT.C(1:4)) GOTO 100  !  RETURN
C	      HAVE NUMERIC STRING LESS THAN OR EQUAL TO NUMS; DON'T PRINT
C	      IT OUT BUT CONTINUE TO READ D.A. TEXT FILE
C 
	ELSE  !   HAVE A NON-NUMERIC, NON-DOT STRING; WRITE TO LUNT.
	   CALL NUMBR(A,80,NPOS)
	   IF(NPOS.LT.1) NPOS=1
	   IF(IPROM.EQ.0) WRITE(LUNT,16) A(1:NPOS) ! MESSAGE
	   IF(IPROM.EQ.1) WRITE(LUNT,17) A(1:NPOS) ! PROMPT
	   IPROM=0
16	FORMAT(X,A)
17	FORMAT(X,A,$)
	END IF
	GOTO 2
12	WRITE(5,21) LUNT
21	FORMAT(' WARNING: Error or end of file during read from DAO'/
     C'         on a .W command; Logical unit',I3,' closed')
	CALL CLOSE(LUNT)
	GOTO 100
300	WRITE(5,301) NUMS
301	FORMAT(' DAO -- Reference number [',I6,'] not found')
100	RETURN
	END
