-
Notifications
You must be signed in to change notification settings - Fork 5
/
export2ang.m
91 lines (81 loc) · 3.3 KB
/
export2ang.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function export2ang(ebsd, old_ang, varargin)
% EXPORT2ANG Create a new TSL .ang file from an @EBSD object by copying the
% original .ang file header and exporting the object's data to the file.
%
% Input
% ebsd - @EBSD object
% old_ang - string of original .ang file to copy header from
%
% Options
% fout - string of file name (without extension) of output .ang file
% rotation - {'convertEuler2SpatialReferenceFrame',
% 'convertSpatial2EulerReferenceFrame'}. If orientation data was rotated when
% imported, by using either of the above options, the data is rotated back
% before exported if any of the options above are passed.
%
% Created by Håkon W. Ånes (hakon.w.anes@ntnu.no), 2019-02-26
if check_option(varargin, 'fout')
fout = get_option(varargin, 'fout');
else
[path, fin, ext] = fileparts(old_ang);
fout = fullfile(path, [fin '_e2a' ext]);
end
% Create output file
fido = fopen(fout, 'w'); % File id (fid) of output file (o) = fido
% Get header from old .ang file and write to new .ang file
old_ang_content = fileread(old_ang);
key = '#';
cstr = strsplit(old_ang_content, '\n');
match = strncmp(cstr, key, length(key));
cstr = cstr(match);
fprintf(fido, '%s\n', cstr{:});
% Rotate data if necessary
if check_option(varargin,'convertSpatial2EulerReferenceFrame')
ebsd = rotate(ebsd, rotation.byAxisAngle(xvector + yvector,...
-180*degree),'keepEuler');
elseif check_option(varargin,'convertEuler2SpatialReferenceFrame')
ebsd = rotate(ebsd, rotation.byAxisAngle(xvector + yvector,...
-180*degree), 'keepXY');
end
% Check if data set contains not indexed pixels and those values are set to NaN
if ~isempty(ebsd(ebsd.phase == -1)) && isnan(ebsd(ebsd.phase == -1).ci(1))
notIndexed = ebsd(ebsd.phase == -1);
notIndexed.rotations = orientation('Euler',12.56637,12.56637,12.56637);
notIndexed.ci = -1;
notIndexed.iq = 0;
notIndexed.fit = 180;
notIndexed.sem_signal = 0;
notIndexed.unknown1 = 0;
notIndexed.unknown2 = 0;
notIndexed.unknown3 = 0;
notIndexed.unknown4 = 0;
ebsd(ebsd.phase == -1) = notIndexed;
end
% Check if data is gridified and unravel the square matrix if it is
new_shape = [size(ebsd, 1)*size(ebsd, 2), 1];
if size(ebsd, 2) > 1
ebsd.rotations = reshape(ebsd.rotations, new_shape);
ebsd.x = reshape(ebsd.x, new_shape);
ebsd.y = reshape(ebsd.y, new_shape);
ebsd.iq = reshape(ebsd.iq, new_shape);
ebsd.ci = reshape(ebsd.ci, new_shape);
ebsd.fit = reshape(ebsd.fit, new_shape);
ebsd.sem_signal = reshape(ebsd.sem_signal, new_shape);
ebsd.unknown1 = reshape(ebsd.unknown1, new_shape);
ebsd.unknown2 = reshape(ebsd.unknown2, new_shape);
ebsd.unknown3 = reshape(ebsd.unknown3, new_shape);
ebsd.unknown4 = reshape(ebsd.unknown4, new_shape);
end
% Create matrix with relevant values (cannot get phase data to reshape if
% gridified?)
m = [ebsd.rotations.phi1'; ebsd.rotations.Phi';...
ebsd.rotations.phi2';ebsd.x'; ebsd.y'; ebsd.iq'; ebsd.ci';...
reshape(ebsd.phase, new_shape)';ebsd.sem_signal';ebsd.fit';...
ebsd.unknown1'; ebsd.unknown2';ebsd.unknown3'; ebsd.unknown4'];
% Write matrix to file
tsl_format = [' %8.5f %8.5f %8.5f %10.5f %10.5f %10.3f %6.3f'...
' %2i %2i %7.3f %7.5f %7.5f %7.5f %7.5f\n'];
fprintf(fido, tsl_format, m);
% Close output file
fclose(fido);
end