-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXRDBruker.m
159 lines (139 loc) · 5.79 KB
/
XRDBruker.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
classdef XRDBruker
%XRDBruker allows analysis of 'uxd' data output from XRD Bruker Instrument.
% Data Updated: 02/12/20 Date Created: 1/13/20
% Bibek Karki
% Input Argument: A = XRDBruker(filename)
% Output properties :filename, data, names
% Methods: plotAll(), plotTest(n), c_over_a_NM(n,cutoff), offaxis()
properties
filename % Name of the uxd file
data % Cells of different from XRD tests
names % seperate chi and two theta dataset
end
methods
function obj = XRDBruker(fname)
%XRDBruker Construct an instance of this class
% check if filname is inserted in correct format
if ischar(fname) == 0
error('Please input file name in character form and try again.');
end
% store the name of the file
obj.filename = fname;
% Open the file & read first line
fid = fopen(fname);
% instance of output cell
Data = {};
% loop to read until the end of line
while ~feof(fid)
% read each line
read_line = fgetl(fid);
% Does the line contain 'Data for range'
if contains(read_line, 'Data for range ')
a = strfind(read_line,'Data for range ');
b = length('Data for range ');
n = str2double(read_line(a+b:end));
Data{n} = [];
clear a b
end
% convert each lines to numbers. Returns empty if character or string in the line
if contains(read_line,'; KHI')
Names(n) = "chi vs intensity";
elseif contains (read_line,'; 2THETA')
Names(n) = "2theta vs intensity";
end
numbers = str2num(read_line);
% If numbers variable is not empty gather data.
if ~isempty(numbers)
Data{n} = [Data{n}; [numbers(1), numbers(2)]];
end
end
obj.data = Data;
obj.names = Names;
end
function plotAll(obj)
%overlaid plots of 2theta vs intensity & chi vs intensity for all data
ind = obj.names == "chi vs intensity";
if ~isempty(ind)
figure, hold on
Data = obj.data(ind);
for i = 1 : length(Data)
X = Data{i};
plot(X(:,1),X(:,2),'LineWidth',1)
end
xlabel('\chi'), ylabel('counts'), title(obj.filename(1:end-4))
set(gca,'FontSize',20,'FontName','Helvetica')
set(gcf,'color','w')
grid on, box on, axis tight
hold off
end
figure, hold on
Data = obj.data(~ind);
for i = 1 : length(Data)
X = Data{i};
plot(X(:,1),X(:,2),'LineWidth',1)
end
xlabel('2\theta'), ylabel('counts'), title(obj.filename(1:end-4))
set(gca,'FontSize',20,'FontName','Helvetica')
set(gcf,'color','w')
grid on, box on, axis tight
hold off
end
function plotTest(obj, n)
%%Plots the output of test n
X = obj.data{n};
plot(X(:,1),X(:,2),'LineWidth',1)
if obj.names(n) == "chi vs intensity"
xlabel('\chi')
else
xlabel('2\theta')
end
ylabel('counts'), title(strcat(obj.filename(1:end-4),' test-',num2str(n)))
set(gca,'FontSize',20,'FontName','Helvetica')
set(gcf,'color','w')
grid on, box on
end
function outputArg = c_over_a_NM(obj,cutoff)
% calculates the c over a ratio based on 2theta peaks of Non-modulated Ni-Mn-Ga
% select only twotheta vs intensity dataset
ind = obj.names == "chi vs intensity";
Data = obj.data(~ind);
for i = 1 : length(Data)
test = Data{i}; % obtain matrix of a test
twotheta = test(:,1); % two theta
counts = test(:,2); % intensity
% indices of data below cutoff twotheta
j = twotheta <= cutoff;
% a = index of maximum instensity for twotheta <= cutoff
[~,a] = max(counts(j));
% b+c = index of maximum intensity for twotheta > cutoff
b = length(counts(j));
[~,c] = max(counts(~j));
% c/a = sine of bigger angle over sine of smaller angle
ca(i) = sind(twotheta(b+c)/2)/sind(twotheta(a)/2);
end
% plot output
outputArg = ca;
end
function output = offaxis(obj)
% Calculates the offsets of plane normal from z-axis
% select only chi vs intensity dataset
ind = obj.names == "chi vs intensity";
if isempty(ind)
error ('The function does not containt chi vs intensity data')
else
Data = obj.data(ind);
end
for i = 1:length(Data)
X = Data{i};
chi = X(:,1); counts = X(:,2);
% indices of data below cutoff twotheta
j = chi <= -90;
[~,a] = max(counts(j));
b = length(counts(j));
[~,c] = max(counts(~j));
axistilt(i) = abs(chi(a)-chi(b+c))/4;
end
output = axistilt;
end
end
end