anchor.diff:  !! Select a scattering type (elastic, sd, inelastic, ...)
   !<
   integer function k2coll_ichoix(ma)
  +
     use mod_ranlux
     use coll_materials
  -  integer ma,i
  -  real(kind=fPrec) aran
  -  aran=real(rndm4(),fPrec)
  -  i=1
  -10 if( aran.gt.cprob(i,ma) ) then
  -    i=i+1
  +
  +  integer, intent(in) :: ma
  +  integer i
  +
  +  i = 1
  +10 continue
  +  if(rndm4() > cprob(i,ma)) then
  +    i = i+1
       goto 10
     end if
  -  k2coll_ichoix=i
  +
  +  k2coll_ichoix = i
  +
   end function k2coll_ichoix
   
   !>
  
positive.code:   use mathlib_bouncer
    use coll_materials
  
    implicit none
  
    real(kind=fPrec) t,cnorm,cnform
    parameter(cnorm=2.607e-5_fPrec,cnform=0.8561e3_fPrec) ! DM: changed 2.607d-4 to 2.607d-5 to fix Rutherford bug
  
    k2coll_ruth=(cnorm*exp_mb(((-one*real(t,fPrec))*cnform)*emr(mcurr)**2))*(zatom(mcurr)/real(t,fPrec))**2
  end function k2coll_ruth
  
  !>
  
negative.code: !! Note: For single-diffractive scattering the vector p of momentum
  !! is modified (energy loss is applied)
  !<
  real(kind=fPrec) function k2coll_gettran(inter, xmat, p)
  
    use mathlib_bouncer
    use mod_ranlux
    use mod_funlux
    use coll_materials
  
    integer,          intent(in)    :: inter
    integer,          intent(in)    :: xmat
    real(kind=fPrec), intent(inout) :: p
  
    real(kind=fPrec) t,xm2,bsd,truth,xran(1)
    integer length
  
    ! Neither if-statements below have an else, so defaulting function return to zero.
    k2coll_gettran = zero
  
  #ifndef MERLINSCATTER
    select case(inter)
    case(2) ! Nuclear Elastic
      k2coll_gettran = (-one*log_mb(rndm4()))/bn(xmat)
  
    case(3) ! pp Elastic
      k2coll_gettran = (-one*log_mb(rndm4()))/bpp
  
    case(4) ! Single Diffractive
      xm2 = exp_mb(rndm4() * xln15s)
      p   = p * (one - xm2/ecmsq)
      if(xm2 < two) then
        bsd = two * bpp
      else if(xm2 >= two .and. xm2 <= five) then
        bsd = ((106.0_fPrec - 17.0_fPrec*xm2)*bpp )/36.0_fPrec
      else
        bsd = (seven*bpp)/12.0_fPrec
      end if
      k2coll_gettran = (-one*log_mb(rndm4()))/bsd
  
    case(5) ! Coulomb
      length = 1
      call funlux(cgen(1,mat), xran, length)
      truth = xran(1)
      t = truth
      k2coll_gettran = t
    end select
  #else
    select case(inter)
    case(2)
      k2coll_gettran = (-one*log_mb(rndm4()))/bn(xmat)
    case(3)
      call merlinscatter_get_elastic_t(k2coll_gettran)
    case(4)
      call merlinscatter_get_sd_xi(xm2)
      call merlinscatter_get_sd_t(k2coll_gettran)
      p = p * (one - (xm2/ecmsq))
    case(5)
      length = 1
      call funlux(cgen(1,mat), xran, length)
      truth = xran(1)
      t = truth
      k2coll_gettran = t
    end select
  #endif
  
  end function k2coll_gettran
  
  !>
  