-
Notifications
You must be signed in to change notification settings - Fork 0
/
addfsns.m
137 lines (129 loc) · 5.15 KB
/
addfsns.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
function [A,header,summed] = addfsns(filebeg,fsns,fileend,fieldinheader,valueoffield)
% function [A,header,summed] = addfsns(filebeg,fsns,fileend,fieldinheader,valueoffield)
%
% IN:
%
% Adds fsns together if in the header data the sample names,
% detector distances, and energies are the same
% The data of the first FSN is taken as the comparison for others.
% If some data does not have the same energy and distance as the first FSN,
% it is simply ignored.
%
% Example of use: [A,header,summed] = addfsns('ORG',[245 249],'.DAT');
%
% Examples of more sophisticated use:
% [A,header,summed] = addfsns(filebeg,fsns,fileend,1);
% where 1 indicates that the program is allowed
% to add up data with different file names
%
% [A,header,summed] = addfsns(filebeg,fsns,fileend,'PosSample',21.6);
% By giving the sample position the Sample name
% is ignored and all measurents where sample stage was at position 21.6
% are added.
%
% OUT:
% A = matrix where all the matrices with correct headers were summed
% header = the FSNs of summed files
% summed = FSNs of summed files
% Prints also on the screen the details of the added files.
%
% Note: It is suggested that this macro is used only for sensitivity
% data and that sample measurements are united after integration
% because of possible beam position movements.
%
% Created 10.8.2007 Ulla Vainio
% In case of bugs, contact: ulla.vainio@desy.de or ulla.vainio@gmail.com
%
% Reading in files.
[Aorig,headerorig] = read2dB1data(filebeg,fsns,fileend);
if(length(fsns)==1) % Checking that we are actually adding something.
A = Aorig; header = headerorig; % Nothing needs to be done..
summed = fsns;
% disp('No adding necessary. Only one FSN was given.')
return;
end;
titles = getfield(headerorig(1),'Title');
sizeA = size(Aorig);
for(k = 1:sizeA(3)) % Getting the header fields that we need or
% that need to changed if we add up the data
if(k > 1)
titles = strvcat(titles,getfield(headerorig(k),'Title'));
end;
energies(k) = getfield(headerorig(k),'Energy');
distances(k) = getfield(headerorig(k),'Dist');
rot1(k) = getfield(headerorig(k),'Rot1');
rot2(k) = getfield(headerorig(k),'Rot2');
possample(k) = getfield(headerorig(k),'PosSample');
posref(k) = getfield(headerorig(k),'PosRef');
end;
A = zeros(sizeA(1,1)); % Initialising A.
ll = 1; % Initialising.
counter = 1;
for(k = 1:sizeA(3))
% Adding the data if energy and distance are the same. (only if 4 input parameters are given)
if(energies(k)==energies(1) && distances(k)==distances(1) && nargin == 4)
A = A + Aorig(:,:,k); % Adding the data.
ll(counter) = k;
header(counter) = headerorig(k);
if(counter == 1)
getsamplenames(filebeg,headerorig(k).FSN,'.DAT');
else
getsamplenames(filebeg,headerorig(k).FSN,'.DAT',1);
end;
counter = counter + 1;
% Adding the data if sample name, energy, distance are the same (normal case):
elseif(nargin == 3 && energies(k)==energies(1) && distances(k)==distances(1) && strcmp(headerorig(k).Title,headerorig(1).Title))
if(rot1(k)~=rot1(1) || rot2(k)~=rot2(1)) % For safety it is checked.
disp(sprintf('Warning! Rotation of sample in FSN %d (%s) is different from FSN %d (%s).',headerorig(k).FSN,title(k),fsns(1),title(1)))
disp(sprintf('Do you still want to add the data? (y/n) '))
scanf(temp);
if(temp(1)~='y')
return;
end;
end;
if(posref(k)~=posref(1)) % For safety the position of reference sample is checked.
disp(sprintf('Warning! Position of reference sample in FSN %d (%s) is different from FSN %d (%s).\n',headerorig(k).FSN,title(k),fsns(1),title(1)))
disp(sprintf('Do you still want to add the data? (y/n) '))
scanf(temp);
if(temp(1)~='y')
return;
end;
end;
A = A + Aorig(:,:,k);
ll(counter) = k;
header(counter) = headerorig(k);
if(counter == 1)
getsamplenames(filebeg,headerorig(k).FSN,'.DAT');
else
getsamplenames(filebeg,headerorig(k).FSN,'.DAT',1);
end;
counter = counter + 1;
% Adding with user specified criteria and energy and distance.
elseif(nargin==5 && energies(k)==energies(1) && distances(k)==distances(1))
if(sprintf('%d',getfield(headerorig(k),fieldinheader))==sprintf('%d',valueoffield))
A = A + Aorig(:,:,k);
ll(counter) = k;
header(counter) = headerorig(k);
if(counter == 1)
getsamplenames(filebeg,headerorig(k).FSN,'.DAT');
else
getsamplenames(filebeg,headerorig(k).FSN,'.DAT',1);
end;
counter = counter + 1;
end;
end;
end;
% Dealing with special cases:
% Nothing to add was found. (input 3 or 4 parameters)
if(length(ll)==1 && nargin<5)
header = headerorig;
A=Aorig(:,:,1);
end;
summed = fsns(ll);
% Nothing was found, user specified header field.
if(length(ll)==1 && nargin==5)
disp(sprintf('No data found with %s as the specified value.',fieldinheader))
A = 0;
header = 0;
summed = 0;
end;