c calculates the matsubara cuf-off when the needed accuracy according to 
c the pure gap equation is given
c input:
c   temp= temperature/Tc
c   accur= allowed error in the gap/Tc
c output:
c   nfreq= number of positive matsubara energies needed to achieve
c          the desired accuracy (assuming that all higher energies are
c          simply omitted from the sum in the gap equation)
      subroutine cutoff(temp,accur,nfreq)
      implicit none
      integer nfreq
      double precision temp, gap, fprime, err
      double precision pi, zeta37, eps, sqterm
      double precision acc, accur,small
      parameter (pi = 3.141592654,small=.000001)
      parameter (zeta37 = 1.2020569*7.)
      if(accur.ge.0.5)then
        nfreq=int(accur+small)
      else
        acc = accur/(2*pi*temp)
        gap = 1.7638*sqrt(1. - temp)/(2*pi*temp)
        fprime = 0.
        err = zeta37
        nfreq = 0
80      nfreq = nfreq + 1
        eps = float(nfreq) - 0.5
        err = err - 1./eps**3
        sqterm = sqrt(eps**2 + gap**2)
c seuraava 2:nen tulee koska virhe itse asiassa on gap**2*err/2
        fprime = fprime + 2./sqterm**3
        if (gap*err/fprime .gt. acc) goto 80
      end if
      return
      end

