function str = convertMillerToString(mil, bracketType)
% converts a Miller vector to a string
%
% Syntax: str = convertMiller2String(mil)
%   or    str = convertMiller2String(mil, bracketType)
%
% A Miller index vector 'mil' (e.g. [1 1 0]) is converted to a string with
%   the bracket type defined in 'bracketType' (e.g. '{') to obtain a string,
%   like '{1,1,0}'. Possible bracket types are: '(', '{' and '['.
%
% see also: viewCrystal, obtainCrystal

% 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/>.

if ~exist('brackets', 'var')
    bracketType = '(';
elseif ~ischar(bracketType) ||length(bracketType) ~= 1
    error(Crystals:inputError, 'The provided brackets parameter must be a string of length 1');
elseif  ~strcmp(bracketType, '(') && ~strcmp(bracketType, '{') && ~strcmp(bracketType, '[')
    if strcmp(bracketType, ')')
        bracketType = '(';
    elseif strcmp(bracketType, '}')
        bracketType = '{';
    elseif strcmp(bracketType, ']')
        bracketType = '[';
    else
        error(Crystals:inputError, 'The provided brackets parameter must be ''('', ''{'' or ''[''');
    end
end

switch bracketType
    case '('
        b_open = '(';
        b_close = ')';
    case '{'
        b_open = '{';
        b_close = '}';
    case '['
        b_open = '[';
        b_close = ']';
end
        

if size(mil, 1) == 3
    mil = mil';
end

for i = 1:size(mil, 1)
    str{i} = [b_open num2str(mil(i,1)) ',' ...
                     num2str(mil(i,2)) ',' ...
                     num2str(mil(i,3)) b_close];
end

if length(str) == 1
    str = str{1};
end
         
                 
    