convertMillerToString

PURPOSE ^

convertMiller2str converts a miller vector (mil) to a string with

SYNOPSIS ^

function stringList = convertMillerToString(millerMatrix, brackets, useComma)

DESCRIPTION ^

 convertMiller2str converts a miller vector (mil) to a string with
 appropriate brackets {'(', '{', '['}, if provided.

 THIS IS NO USER FUNCTION

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function stringList = convertMillerToString(millerMatrix, brackets, useComma)
0002 % convertMiller2str converts a miller vector (mil) to a string with
0003 % appropriate brackets {'(', '{', '['}, if provided.
0004 %
0005 % THIS IS NO USER FUNCTION
0006 
0007 % The elk-library: convex geometry applied to crystallization modeling.
0008 %   Copyright (C) 2013 Alexander Reinhold
0009 %
0010 % This program is free software: you can redistribute it and/or modify it
0011 %   under the terms of the GNU General Public License as published by the
0012 %   Free Software Foundation, either version 3 of the License, or (at your
0013 %   option) any later version.
0014 %
0015 % This program is distributed in the hope that it will be useful, but
0016 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0017 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0018 %   General Public License for more details.
0019 %
0020 % You should have received a copy of the GNU General Public License along
0021 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0022 
0023 %% input handling
0024 if ~exist('brackets', 'var')
0025     brackets = '{';
0026 elseif ~isstr(brackets) || length(brackets) ~= 1
0027     error('elk:crystal:wrongInput', ['The provided brackets parameter must ' ...
0028         'be a string of length 1']);
0029 elseif  ~strcmp(brackets, '(') && ~strcmp(brackets, '{') && ~strcmp(brackets, '[')
0030     if strcmp(brackets, ')')
0031         brackets = '(';
0032     elseif strcmp(brackets, '}')
0033         brackets = '{';
0034     elseif strcmp(brackets, ']')
0035         brackets = '[';
0036     else
0037         error('elk:crystal:wrongInput', ['The provided brackets parameter ' ...
0038             'must be ''('', ''{'' or ''[''']);
0039     end
0040 end
0041 if ~exist('useComma', 'var') || isempty(useComma)
0042     useComma = 1;
0043 end
0044 if useComma
0045     commaString = ', ';
0046 else
0047     commaString = '';
0048 end
0049 
0050 % correct size of input matrix
0051 if size(millerMatrix, 1) == 3
0052     millerMatrix = millerMatrix';
0053 end
0054 
0055 
0056 %% prepare opening/closing bracket
0057 switch brackets
0058     case '('
0059         b_open = '(';
0060         b_close = ')';
0061     case '{'
0062         b_open = '{';
0063         b_close = '}';
0064     case '['
0065         b_open = '[';
0066         b_close = ']';
0067 end
0068 
0069 %% conversion
0070 for i = 1:size(millerMatrix, 1)
0071     stringList{i} = [b_open num2str(millerMatrix(i,1)) commaString ...
0072                      num2str(millerMatrix(i,2)) commaString ...
0073                      num2str(millerMatrix(i,3)) b_close];
0074 end
0075 
0076 % return a simple string
0077 if length(stringList) == 1
0078     stringList = stringList{1};
0079 end

Generated on Sat 18-Jul-2015 16:45:31 by m2html © 2005