%% MTEX - Analysis of EBSD Data
% Analysis of odf ice simulations

clear;
nt      = 1;     % Number of timesteps to compute
count=0;

%% Specify Crystal and Specimen Symmetry

%crystal symmetry
CS  = crystalSymmetry('6/mmm', [4.5181 4.5181 7.3560],'xIIa','zIIc', 'mineral', 'Ice Ih');

 %specimen symmetry
SS = specimenSymmetry('hexagonal');

start = 1;
time = 1;

for it=start:nt
itime=time*it;

% specify file name

fname = fullfile('C:/',sprintf('make_%01d.out', itime));
ebsd  = loadEBSD_generic(fname,'Columns',[1,2,3,4,5],'ColumnNames',{'Euler1','Euler2','Euler3','x','y'},'cs',CS);

%% IMPORTANT: for simulations with two phases (ice+water) remove the second phase:
%% (remove at the make.out the unodes with phase attribute 2)

plotx2east;
degree=1


%%CALC ODF AND MINDEX
odf=calcODF(ebsd.orientations);
MI = calcMIndex(odf)

%Plot Polar Figure
figure('position',[160 389 632 216]);
plotx2east;
plotPDF(odf,Miller({0,0,0,1},{1,1,-2,0},{1,0,-1,0},CS),'antipodal','HALFWIDTH',5*degree,'minmax');
setColorRange([0.2 10]);
saveFigure(sprintf('C:/POLE_%01d.png', itime));

close all;

end