%% Import Script for PoleFigure Data
%
% This script was automatically created by the import wizard. You should
% run the whoole script or parts of it in order to import your data. There
% is no problem in making any changes to this script.

close all
%% Specify Crystal and Specimen Symmetries

% crystal symmetry
CS = crystalSymmetry('m-3m', [3.5451 3.5451 3.5451], 'mineral', 'Ni', 'color', 'light blue');

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

% plotting convention
setMTEXpref('xAxisDirection','north');
setMTEXpref('zAxisDirection','outOfPlane');

%% Specify File Names

% path to files
pname = 'data_XTG\';

% sample name
sname = 'No_2';
%sname = 'No_1';
%sname = 'No_9';
%sname = 'No10';

% which files to be imported
fname = {...
  [pname sname '_111.pan'],...
  [pname sname '_200.pan'],...
  [pname sname '_220.pan'],...
  };

%% Specify Miller Indice

h = { ...
  Miller(1,1,1,CS),...
  Miller(2,0,0,CS),...
  Miller(2,2,0,CS),...
  };

%% Import the Data

% create a Pole Figure variable containing the data
pf = loadPoleFigure(fname,h,CS,SS,'interface','generic',...
  'ColumnNames', { 'Azimuth Angle' 'Polar Angle' 'Intensity'});

figure(1)
plot(pf,'projection','stereo','antipodal')
annotate([xvector,yvector,zvector],'label',{'Xs','Ys','Zs'});
colorbar

%rotate raw data
if (sname == 'No_2')
    rot = rotation('Euler',0*degree,90*degree,90*degree)
elseif (sname == 'No_1')
    rot = rotation('axis',zvector,'angle',-45*degree) 
elseif (sname == 'No_9') 
    rot = rotation('Euler',180*degree,90*degree,0*degree) 
elseif (sname == 'No10')
    rot = rotation('axis',zvector,'angle',0*degree) 
end;    
pf_rot = rotate(pf,rot);

% remove outliers
pf_rot(pf_rot.isOutlier) = [];

figure(2)
plot(pf_rot,'projection','stereo','antipodal')
annotate([xvector,-yvector,zvector],'label',{'P','T','B'});
colorbar

%% odf calculation
odf = calcODF(pf_rot)

%% pole figure plots
figure(3)
plotPDF(odf,pf.h,'projection','stereo','antipodal')
CLim(gcm,'equal');
annotate([xvector,-yvector,zvector],'label',{'P','T','B'});
colorbar
