%
% Reading a large number of *.ctf files
%
% with plot and orientation convections for Montpellier SEMs
% A) X to east Z out of the plane
% B) convert Spatial to Euler Reference Frame
%
% David Mainprice 23/11/2014
%
%%
%**************************************************************************
% open file containing file list
%**************************************************************************
fid=0;
while fid < 1 
   filenames=input('Open file with list of files names *.txt : ', 's');
   [fid,message] = fopen(filenames, 'r');
   if fid == -1
     disp(message)
   end
end
% plot convention for all files
setMTEXpref('xAxisDirection','east');
setMTEXpref('zAxisDirection','outOfPlane');
% file counter
n=0;
%**************************************************************************
% read *.ctf files
%**************************************************************************
while 1
    % Read line from file, removing newline characters
    file_name = fgetl(fid);
    % detect when there is no character array
    if ~ischar(file_name), break, end
    n=n+1;
    fprintf(' ')
    fprintf(' File No. %d %s ',n, file_name)
    fprintf(' ')
% import ctf file
ebsd = loadEBSD_ctf(file_name,'convertSpatial2EulerReferenceFrame')
% CS for minerals
Forsterite_CS = ebsd('Forsterite').CS
BYTOWNITE_CS = ebsd('BYTOWNITE').CS
Diopside_CS = ebsd('Diopside').CS
% plag only
% plag+ol
% plag+ol+cpx
%
% application
%********************************************************
% end of file loop
%********************************************************
end
%********************************************************
% close files containing Euler file list and output
%********************************************************
fclose(fid);
%fclose(fid2); 