function [ alpha, m, tau, taut ] = SP_Sub2(alpha, G, H, IUP, k, m, NYS, tau, taut)
%sub2 Summary of this function goes here
%   Check for loading-unloading

if m==0
    
    if (taut-alpha(1))^2-k(1)^2>=0
        [alpha, m, tau, taut] = SP_Sub34(alpha, G, H, IUP, k, m, NYS, tau, taut);
    else
        tau=taut;
    end
    
elseif m>=1
    
    Q=(tau-alpha(m))/((tau-alpha(m))^2)^.5;
    
    if Q*(taut-tau)>=0
        % loading
        m=m-1;
        [alpha, m, tau, taut] = SP_Sub34(alpha, G, H, IUP, k, m, NYS, tau, taut);
    else
        % unloading
        [alpha, m, tau, taut] = SP_Sub7(alpha, G, H, IUP, k, m, NYS, tau, taut);
    end
end

end

