function check_bounds(resultfile)
% Checks whether upper or lower bounds are active in the solution
% input: resultfile name, which contains the structure 'Result'
% Last modification: 06.02.2008 (by Marko Ackermann)


load(resultfile,'Result');

n_nod = Result.Prob.user.n_nod;
n_f = Result.Prob.user.n_f;
n_m = Result.Prob.user.n_m;


xState = Result.xState; % vector of states for variables
                        % 0 - free
                        % 1 - on lower bound
                        % 2 - on upper bound
                        % 3 - fixed
            
if all(xState == 0)
    display('There is no active upper or lower bounds.')
else % there are active bounds on optimization variables
    for k = 1:n_nod-1 % for each node
        qState(:,k) = xState((k-1)*(2*n_f+3*n_m)+1:(k-1)*(2*n_f+3*n_m)+n_f);
        qpState(:,k) = xState((k-1)*(2*n_f+3*n_m)+n_f+1:(k-1)*(2*n_f+3*n_m)+2*n_f);
        lceState(:,k) = xState((k-1)*(2*n_f+3*n_m)+2*n_f+1:(k-1)*(2*n_f+3*n_m)+2*n_f+n_m);
        aState(:,k) = xState((k-1)*(2*n_f+3*n_m)+2*n_f+n_m:(k-1)*(2*n_f+3*n_m)+2*n_f+2*n_m);
        uState(:,k) = xState((k-1)*(2*n_f+3*n_m)+2*n_f+2*n_m:k*(2*n_f+3*n_m));
    end
    if isempty(Result.Prob.user.v_walk) % speed optimized
        vState = xState(end-1); % state of speed
    end
    TState = xState(end); % state of half or whole gait cycle duration
    
    display('  ')
    display('GENERALIZED COORDINATES')
    if any(any(qState)) % if there is any nonzero element in gen coords states
        display('WARNING: There are active upper or lower bounds on the following gen coords')
        for i = 1:n_f
            if any(qState(i,:)==1) % lower bound active
                display([int2str(i) ': lower bound'])
            end
            if any(qState(i,:)==2) % upper bound active
                display([int2str(i) ': upper bound'])
            end
            if any(qState(i,:)==3) % upper and lower bounds active, fixed variable
                display([int2str(i) ': lower and upper bounds, fixed variable'])
            end
        end
    else
        display('There is no active upper or lower bounds on the gen coords')
    end
    
    display('  ')
    display('GENERALIZED VELOCITIES')
    if any(any(qpState)) % if there is any nonzero element in gen vels states
        display('WARNING: There are active upper or lower bounds on the following gen vels')
        for i = 1:n_f
            if any(qpState(i,:)==1) % lower bound active
                display([int2str(i) ': lower bound'])
            end
            if any(qpState(i,:)==2) % upper bound active
                display([int2str(i) ': upper bound'])
            end
            if any(qpState(i,:)==3) % upper and lower bounds active, fixed variable
                display([int2str(i) ': lower and upper bounds, fixed variable'])
            end
        end
    else
        display('There is no active upper or lower bounds on the gen vels')
    end
    
    display('  ')
    display('CE LENGTHS')   
    if any(any(lceState)) % if there is any nonzero element in CE lengths states
        display('WARNING: There are active upper or lower bounds on the following CE lengths')
        for i = 1:n_m
            if any(lceState(i,:)==1) % lower bound active
                display([int2str(i) ': lower bound'])
            end
            if any(lceState(i,:)==2) % upper bound active
                display([int2str(i) ': upper bound'])
            end
            if any(lceState(i,:)==3) % upper and lower bounds active, fixed variable
                display([int2str(i) ': lower and upper bounds, fixed variable'])
            end
        end
    else
        display('There is no active upper or lower bounds on the CE lengths')
    end

    display('  ')
    display('ACTIVATIONS')   
    if any(any(aState)) % if there is any nonzero element in activation states
        display('WARNING: There are active upper or lower bounds on the following activations')
        for i = 1:n_m
            if any(aState(i,:)==1) % lower bound active
                display([int2str(i) ': lower bound'])
            end
            if any(aState(i,:)==2) % upper bound active
                display([int2str(i) ': upper bound'])
            end
            if any(aState(i,:)==3) % upper and lower bounds active, fixed variable
                display([int2str(i) ': lower and upper bounds, fixed variable'])
            end
        end
    else
        display('There is no active upper or lower bounds on the activations')
    end
    
    display('  ')
    display('NEURAL EXCITATIONS')   
    if any(any(uState)) % if there is any nonzero element in activation states
        display('There are active upper and/or lower bounds on the neural excitations')
    else
        display('There is no active upper or lower bounds on the neural excitations')
    end

    if isempty(Result.Prob.user.v_walk)      
    display('  ')
    display('SPEED') 
        if vState == 1
            display('WARNING: Lower bound for gait speed is active.')
        elseif vState == 2
            display('WARNING: Upper bound for gait speed is active.')
        elseif vState == 3
            display('WARNING: Lower and upper bounds for gait speed active.')
        else % vState == 0
            display('There is no active lower or upper bounds on gait speed.')
        end
    end
    
    display('  ')
    display('CYCLE DURATION') 
    if TState == 1
        display('WARNING: Lower bound for gait cycle duration is active.')
    elseif TState == 2
        display('WARNING: Upper bound for gait cycle duration is active.')
    elseif TState == 3
        display('WARNING: Gait cycle duration is fixed.')
    else
        display('There is no active lower or upper bounds on duration of gait cycle.')
    end
    
end