function current_sharing_temperature_nbti(c_pt,B,St,Jop,Bc0,Jc0,Tc,Tc0,Bc) result(current_sharing_temperature) bind(C)
type(c_ptr), value :: c_pt
real(dp), value :: B,St,Jop,Bc0,Jc0,Tc,Tc0,Bc
real(dp) :: current_sharing_temperature
real(dp) :: T,tt,ttlow,ttup,error,tolerance,Jc
logical :: converged
type(nbti_cfg_t), pointer :: nbti_ptr
call c_f_pointer(c_pt,nbti_ptr)
tolerance=1.0e-5_dp
if(B>=nbti_ptr%Bc20) then
current_sharing_temperature=0.0_dp
return
endif
if(Jop>=Jc0) then
current_sharing_temperature=0.0_dp
return
endif
if(Jop<=0.0_dp) then
current_sharing_temperature = nbti_ptr%Tc0_p
return
endif
ttup =1.0_dp
ttlow=0.0_dp
converged=.false.
do while(.not.converged)
tt=0.5_dp*(ttlow+ttup)
T = tt * nbti_ptr%Tc0_p
Jc = critical_current_density_nbti(c_pt,T,B,St,Tc0,Bc)
if(Jc>Jop) then
ttlow = tt
elseif(Jc<=Jop) then
ttup = tt
elseif(abs(Jc-Jop)<=1.0e-12_dp) then
ttup = tt
ttlow = tt
endif
error = abs(ttup-ttlow)
converged = error<=tolerance
enddo
current_sharing_temperature = tt*nbti_ptr%Tc0_p
end function current_sharing_temperature_nbti