C-----------------------------------------------------------------------
C  Find the Coarse setting for 2-Theta
C-----------------------------------------------------------------------
      SUBROUTINE TFIND (TIM)
      INCLUDE 'COMDIF'
      DIMENSION TCOUNT(NSIZE)
      EQUIVALENCE (ACOUNT(9*NSIZE+1),TCOUNT(1))
      STEPM = 0.01
      SENSE = -1.0
      TSTEP = 0.25
      NATT = 0
      NPTS = 10
100   THEOFF = THETA
      OMEOFF = OMEGA
      CALL ANGSET (THETA,OMEGA,CHI,PHI,NATT,ICOL)
      ICOUNT = 0
      MCOUNT = 0
      DO 110 I = 1,NPTS
        CALL CCTIME (TIM,TCOUNT(I))
        IF (TCOUNT(I) .GT. MCOUNT) THEN
          MCOUNT = TCOUNT(I)
          ICOUNT = I
        ENDIF
        THETA = THETA + SENSE*TSTEP
        OMEGA = OMEGA - SENSE*TSTEP*0.5
        CALL ANGSET (THETA,OMEGA,CHI,PHI,NATT,ICOL)
  110 CONTINUE
      IF (ICOUNT .EQ. 1) THEN
        SENSE = -SENSE
        THETA = THEOFF + 9.0*SENSE*TSTEP
        OMEGA = OMEOFF - 9.0*SENSE*TSTEP/2
        GO TO 100
      ENDIF
      IF (ICOUNT .EQ. 10) THEN
        THETA = THEOFF - 3.0*SENSE*TSTEP
        OMEGA = OMEOFF + 3.0*SENSE*TSTEP/2
        GO TO 100
      ENDIF
      THETA = THEOFF +     (ICOUNT - 2.25)*SENSE*TSTEP
      OMEGA = OMEOFF - 0.5*(ICOUNT - 2.25)*SENSE*TSTEP
      TIM = 500.0*TIM/TCOUNT(ICOUNT)
      IF (TIM .LT. 10000.0) THEN
        IF (TIM .LT. 1000.) TIM = 1000.
        TSTEP = TSTEP/4.0
        IF (TSTEP .GT. STEPM) GO TO 100
      ENDIF
      THETA = THEOFF + ICOUNT*SENSE*TSTEP
      OMEGA = OMEOFF - ICOUNT*SENSE*TSTEP/2
      RETURN
      END
