function [mean, cov] = ensureMeanAndCov(nDim, mean, cov)
% ensure proper mean and covariance
%
% THIS IS NO USER FUNCTION

% The elk-library: convex geometry applied to crystallization modeling.
%   Copyright (C) 2013 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/>.

%% mean
mean = mean(:);
if ~isempty(nDim) && numel(mean) ~= nDim
    error('elk:distribution:wrongInput', ...
        'Mean vector has improper dimension');
else
    nDim = numel(mean);
end

%% cov
if (size(cov, 1) == nDim) && (size(cov, 2) == nDim)
    % everything OK
elseif numel(cov) == 1
    cov = cov*eye(nDim);
elseif numel(cov) == nDim
    % this case assumes that the std is provided
    cov = diag(cov);
else
    error('elk:distribution:wrongInput', ['Covariance matrix does not ' ...
        'match the dimension of the continuous distribution']);
end