%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                        
% Name: LP_IProbe.m                                                      
% Author: Anders I. Eriksson       
% Modified: Kristoffer Hultgren
%
% Description:                                                           
% 
% Calculates the probe currents
%
%                                                                        
% Input:                                                                 
%   vp    : probe potential [V]
%   P.ne  : electron density [cm-3]
%   P.Te  : electron temperature [eV]
%   P.v   : ram speed [km/s]
%   P.nsp : number of ion species 
%   P.ni  : ion densities in percent (vector of length nsp) [%]
%   P.mi  : ion masses (vector of length nsp) [proton masses]
%   P.Zi  : ion charges (vector of length nsp) [proton charges]
%   P.Ti  : ion temperatures (vector of length nsp) [eV]
%                                                                        
%                                                                        
% Output:                                                                
%                                                                        
%   ip    : Current [A]                                                                  
%   ii    : Ion current for debugging
%   iph   : Photo current for debugging                                                                                                                                     
%                                                                        
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function curr = LP_IProbe(vp,P)

global CO;

ie = LP_Curre(vp,P.ne,P.Te,0);
ii = zeros(size(ie));

if vp > 0    
    for j = 1:P.nsp
        ii = ii + LP_Curri(vp,P.ni(j),P.Ti(j),P.Zi(j),P.mi(j),P.v(j),P.dn*randn(size(vp)));
    end
end

if vp <= 0
    debye = LP_Debye(P.ni,P.Ti);
    if debye < 0.025*0.1
        for j = 1:P.nsp
            ii = ii + P.ni(j).*CO.qe.*P.v(j).*(1+(debye./0.025).^(2/3).*sqrt(CO.qe.*abs(vp)./(P.Ti(j)))).^2;
        end
    else
        for j = 1:P.nsp
            ii = ii + LP_Curri(vp,P.ni(j),P.Ti(j),P.Zi(j),P.mi(j),P.v(j),P.dn*randn(size(vp)));
        end
    end
end

iph = LP_Currf(vp,P.jf0,P.Tf);

ip = ie + ii + iph;

curr = [ip ii iph];
