%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                            
% Name: LP_Curre.m                                                           
% Author: Anders I. Eriksson                                                       
% Description:                                                               
%                                                                            
% Calculates the probe electron current                                      
%                                                                            
% Input:                                                                     
%   vp: probe potential [V]
%   n: electron density [cm-3]
%   T: electron temperature [eV]
%   dn: white noise dn/n perturbation, length equal to vp [%]
%
% Output:                                                                    
%   ie: Current [A]                                                                     
%                                                                            
%                                                                            
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ie = LP_Curre(vp,n,T,dn)

global IN CO

ie0 = IN.probe_area*CO.qe*n*(1+dn/100)*1e6*sqrt(T*CO.qe/(2*pi*CO.me));

nind = find(vp<=0); 
pind = find(vp>0);

% Initialize return:
ie = zeros(size(vp));

% Use Whipple eqns (3.4) - (3.6) for attractive case
%   (should always be valid):
rs = LP_Walker(vp(pind),n,T,IN.probe_radius);  % Sheath radius [m]
% Use M-S&L relation with Walker sheath radius:

ie(pind) = (rs/IN.probe_radius).^2 .* (1 - (rs.^2 - IN.probe_radius^2) .* exp(-IN.probe_radius^2 * vp(pind) ./(T * (rs.^2 - IN.probe_radius^2))) ./ rs.^2);

%ie(pind)=(1+vp(pind)/T);

% Use M-S&L relation for repulsive case (not valid in s/c wake):
ie(nind) = exp(vp(nind)/T);

ie = ie0 .* ie;
