function [vecType, vec, partitionIndex] = ...
    clarifyVectorInformation(vecType, vec, simplex, dec, zerotol, ...
    enforceValid)
% obtain simplex partition and obtain proper vector type
%
% No matter what "simplex" says, this function returns ALWAYS a simplex
%   partition index. However, if vec is {p, vec} then p is interpreted
%   as simplex partition (simplex=1) or unified partition (simplex=0),
%   directly.
%
% THIS FUNCTION IS NO USER FUNCTION.

% The elk-library: convex geometry applied to crystallization modeling.
%   Copyright (C) 2012 Alexander Reinhold
%
% This program is free software: you can redistribute it and/or modify it 
%   under the terms of the GNU General Public License as published by the 
%   Free Software Foundation, either version 3 of the License, or (at your 
%   option) any later version.
%
% This program is distributed in the hope that it will be useful, but 
%   WITHOUT ANY WARRANTY; without even the implied warranty of 
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
%   General Public License for more details.
%
% You should have received a copy of the GNU General Public License along 
%   with this program.  If not, see <http://www.gnu.org/licenses/>.

%% Skip incomplete dec
% no validity mapping, only one partition
if ~dec.isComplete
    if iscell(vec)
        if simplex
            partitionIndex = vec{1};
        else
            partitionIndex = dec.unifiedToSimplexVector(vec{1});
        end
        vec = vec{2};
    else
        % the default partition is nPS not 1
        partitionIndex = dec.unifiedToSimplexVector*ones(1, size(vec, 2));
    end
    return
end

%% Determine simplex partition
% if partition is provided
if iscell(vec)
    if simplex
        % simplex partition is given number
        partitionIndex = vec{1};
    else
        % unified is given, determine a matching simplex partition
        partitionIndex = dec.unifiedToSimplexVector(vec{1});
    end
    % the following is my vector
    vec = vec{2};
    
elseif strcmpi(vecType, 'hc')
    %% Check validity
    %! ToDo: added these lines of code, but not documented it:
    validVector = isValidDec(vec, dec, zerotol);
    partitionIndex = nan(size(validVector));
    if all(validVector)
        % nothing to do
    elseif enforceValid == 1
        % map vectors to valid vectors
        vec = mapToValidityCone(vec, dec, zerotol);
        validVector = true(size(validVector));
    elseif enforceValid == -1
        % set partitions to 0 for invalid partitions and use the proper
        %   partition otherwise.
        partitionIndex = double(validVector);
    else
        error('elk:decomposition:invalidPoints', ['Not all input vectors ' ...
            'are valid. You might want to use the enforceValid option.']);
    end
    %/
    if simplex
        partitionIndex(validVector) = computePartitionIndexDec(dec, ...
            vec(:, validVector), zerotol, 0);
    else
        partitionIndex(validVector) = computePartitionIndexDec(dec, ...
            vec(:, validVector), zerotol, 1);
        partitionIndex(validVector) = dec.unifiedToSimplexVector(...
            partitionIndex(validVector));
    end
    
    
else
    error('elk:decomposition:wrongInput', ...
        ['For a given vector of scalar multiples of structuring elements ' ...
         'the partition must be provided']);
end

% Result: independent of the simplex option, the vector paritionIndex 
%   represents the simplex partitions for the vectors in vec.

%% Ensure format of vec
% ensure hc being a column vector or matrix of hc-vectors
if size(vec, 1) ~= dec.nC
    if size(vec, 2) == dec.nC
        vec = vec';
    else
        error('elk:decomposition:wrongInput', ...
            ['the provided vector must be a row vector (or matrix of ' ...
             'vectors) with the dimension of: size(dec.se, 2)']);
    end
end