function printMillerSummary(cdef, P)
% print information on Miller indices
%
% This includes a verification of completenes and conflicts.
%
% 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/>.

disp(' ');
if isfield(cdef, 'millerDefined')
    %% obtain Miller information
    % defined miller indices
    millerDefinedMatrix = cdef.millerDefined;
    millerDefinedStringList = convertMillerToString(...
        millerDefinedMatrix, '{');
    if ~iscell(millerDefinedStringList)
        millerDefinedStringList = {millerDefinedStringList};
    end
    % grouped information
    millerGroupList = {};
    millerCompleteMatrix = zeros(0, 3);
    for i = 1:size(cdef.millerDefined, 1)
        thisGroup =  executeExternBorchertFunction('form2face', ...
            cdef.millerDefined(i, :), P(2, cdef.sym.defined));
        millerGroupList{i} = sortrows(thisGroup);
        millerCompleteMatrix = [millerCompleteMatrix; thisGroup];
    end
    millerCompleteMatrix = sortrows(millerCompleteMatrix);
    
    %% Output facet information
    disp('You selected the following face groups and resulting faces: ');
    for iGroup = 1:length(millerGroupList)
        outstring = ['   ' millerDefinedStringList{iGroup} ': '];
        thisFacetStringList = convertMillerToString(...
            millerGroupList{iGroup}, '(');
        if ~iscell(thisFacetStringList)
            thisFacetStringList = {thisFacetStringList};
        end
        for iStr = 1:length(thisFacetStringList)
            outstring = [outstring thisFacetStringList{iStr} ', '];
        end
        outstring(end-1:end) = [];
        disp(outstring);
    end
    
    %% output interfering groups (not unique)
    interfering = [];
    for i = 1:size(millerDefinedMatrix, 1)
        for j = (i+1):size(millerDefinedMatrix, 1)
            filter = (millerGroupList{i}(:,1) == millerDefinedMatrix(j,1)) & ...
                (millerGroupList{i}(:,2) == millerDefinedMatrix(j,2)) & ...
                (millerGroupList{i}(:,3) == millerDefinedMatrix(j,3));
            if sum(filter) > 0
                interfering(end+1, :) = [i, j];
            end
        end
    end
    if isempty(interfering)
        disp('No interfering crystal forms detected.')
    else
        for i = 1:size(interfering, 1)
            disp(['CRYSTAL FORM ' millerDefinedStringList{interfering(i,1)}...
                ' DOES INTERFERE WITH '...
                millerDefinedStringList{interfering(i,2)} '.']);
        end
    end
    %% output, if shape is complete
    % Therefore, we construct a polytope and investigate if it is flat.
    hrep = struct('A', millerCompleteMatrix, 'h', ...
        ones(size(millerCompleteMatrix, 1), 1));
    vrep = convertHrepToVrep(hrep, elkZerotol, 1e5);
    if any(abs(vrep.V(:)) > 1e4)
        disp('DEFINITION OF CRYSTAL FORMS NOT YET COMPLETED.');
    else
        disp('Enough faces defined for a closed shape.');
    end
else
    disp('Please define crystal forms.');
end