	SUBROUTINE IFINTE( DANG, COUNTS, TIME)
C
C  Jim Walker, Aug 1987 for Diffrac-500 with a Radix Databox.
C  Integrate from the current position to the specified 2-theta angle.
C
	INCLUDE '[102,2]INP.COM/NOLIST'	
	INCLUDE '[102,2]IOBLK.COM/NOLIST'
	INCLUDE '[102,2]ERRBLK.COM/NOLIST'	
	INCLUDE '[102,2]RAWDES.COM/NOLIST'	
	INCLUDE 'INTERFACE.COM'
	REAL*4 DANG, COUNTS, TIME
	INTEGER*4 ISTAT, ITIME, NCHAR, I, J, K, ISTAT2
	PARAMETER CR=CHAR(13)
	CHARACTER BUFFER*255
C
	IERR(5)=0
D	ISTAT2=0
C
C  Setup command: Calibrate mode, Integrate to angle.
	WRITE(BUFFER,4) 13, CURANG+DANG
4	FORMAT('C',a1,'I',F8.4)
C
C  Put in leading zeros so the interface doesn't get mad.
	DO 7,I=4,8
	   IF(BUFFER(I:I).EQ.' ') BUFFER(I:I)='0'
7	CONTINUE
C
C  Send command to interface.
D	ISTAT2=1
	CALL NULL(BUFFER, 11, ISTAT)
	IF(ISTAT.NE.1) GOTO 9000
C
C  Carriage return will start it running.
D	ISTAT2=2
	TIME = SECNDS(0.0)
	CALL ECHO(CHAR(13), 1, ISTAT)
	IF(ISTAT.NE.-2) GOTO 9000
C
C  Wait for completion (shouldn't take any longer than 2 sec per degree)
	ITIME = INT( ABS(DANG)) * 2 + 2
10	CALL READ(BUFFER, NCHAR, ISTAT, ITIME)
D	ISTAT2=3
	IF(ISTAT.EQ.-1) GOTO 10
	IF(ISTAT.NE.-2) GOTO 9000
	TIME = SECNDS( TIME )
C
C  Read total counts.
D	ISTAT2=4
	CALL READ(BUFFER, NCHAR, ISTAT, 99)
	IF(ISTAT.NE.-2) GOTO 9000
C  Find beginning of counts
	DO 74, J=J,NCHAR
	IF(BUFFER(J:J).GE.'0' .AND. BUFFER(J:J).LE.'9') GOTO 75
74	CONTINUE
C  Didn't find anything, bail out.
D	ISTAT2=5
	GOTO 9000
C  Find end of counts
75	DO 76, K=J,NCHAR
	IF(BUFFER(K:K).LT.'0' .OR. BUFFER(K:K).GT.'9') GOTO 77
76	CONTINUE
C  Didn't find anything, bail out (this can't happen)
D	ISTAT2=6
	GOTO 9000
77	BUFFER(K:K)='.'
	READ(BUFFER(J:K), '(G)') COUNTS
C
C  Echo the data to the terminal if required.
	IF(IDSPLY.GT.0) THEN
	   IDSPLY = IDSPLY - 1
	   IF(IDIF.EQ.0) IDIF=6
	   WRITE(IDIF,79) CURANG, CURANG+DANG, COUNTS/TIME
79	   FORMAT(' Range =',2F8.3,'   Counts/sec =',F10.2)
C  If we are done typing, close the listing device
	   IF(IDSPLY.EQ.0 .AND. IDIF.NE.6) CLOSE(UNIT=IDIF)
	ENDIF
C
C  Read rest of junk.
D	ISTAT2=7
	CALL READ(BUFFER, NCHAR, ISTAT, 99)
C	IF(ISTAT.NE.1) GOTO 9000
C
C  Remember where we are now.
	CURANG=CURANG+DANG
C
C  Get back to monitor mode
D	ISTAT2=8
	CALL NULL('E'//CHAR(13), 2, ISTAT)
	IF(ISTAT.NE.1) GOTO 9000
	GOTO 9999
C
C  Error return
9000	IERR(5)=127	! interface error
D	IF(ISTAT.LT.0 .AND. ISTAT.GT.-99) ISTAT=ISTAT-100*ISTAT2
	IERR(4)=ISTAT
	CALL ERRMSG('IFINTE',RAWFIL,1,BUFFER)
C
9999	RETURN
	END
