%% Calculates loss, retrieval and removal from phloem and apoplast

loss_zone = [Loc_1 Loc_2];

%Leakage specific parameters
KmSWEETex  = 70;     %mol/m3
KmSWEET    = 10;     %mol/m3
KmSUC      = 1;      %mol/m3
v_maxSWEET    = 0.148 * vp;
v_maxSWEETim  = 0.148 * vp;
v_maxSUC      = 0.117 * vp; 

%% Different leakage modes
%No leakage
if loss_mode == 1; 
    lat_SWEET(loss_zone) = 0* cp(loss_zone)  ;        
    lat_SUC(loss_zone)   = 0* cpa(loss_zone) ;   
%SWEET
elseif loss_mode == 2; 
    lat_SWEET(loss_zone) = v_maxSWEET .*  (cp(loss_zone) ./ (cp(loss_zone) + KmSWEET));   
    lat_SUC(loss_zone)   = 0 * vpa(loss_zone).* v_maxSUC   .*  (cpa(loss_zone) ./ (cpa(loss_zone)+ KmSUC)); 
%Bidirectional SWEET - SUC
elseif loss_mode == 3;
    lat_SWEETex(loss_zone) = v_maxSWEETim(loss_zone)   .* (cp(loss_zone) ./ (cp(loss_zone)  + KmSWEET))  ;
    lat_SWEETim(loss_zone) = v_maxSWEETim(loss_zone) .* (cpa(loss_zone)./ (cpa(loss_zone)+ KmSWEETex)) ;   
    lat_SWEET(loss_zone)   = lat_SWEETex(loss_zone) - lat_SWEETim(loss_zone);
    lat_SUC(loss_zone)     = v_maxSUC(loss_zone)     .* (cpa(loss_zone)./ (cpa(loss_zone) + KmSUC))  ;  
end

%Lateral sucrose flux in a vector
JS_lat = zeros(length(JWp_in),1);
if loss_mode ~= 1
JS_lat(loss_zone)    = -lat_SWEET(loss_zone) + lat_SUC(loss_zone);
end

%Apoplastic respiration
Resp_apo = ( Rmax .*(cpa)./(cpa+KmRes));