-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergescan.m
144 lines (138 loc) · 4.57 KB
/
mergescan.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
function sresult = mergescan(varargin)
% MERGESCAN Merge and plot scans from the same spec file.
%
% Usage:
% M = MERGESCAN(FILENAME,SCANS,BACKGROUND)
% M = MERGESCAN(FILENAME,SCANS,BACKGROUND,DETECTOR)
% M = MERGESCAN(FILENAME,SCANS,BACKGROUND,PLOTSWITCH)
% M = MERGESCAN(FILENAME,SCANS,BACKGROUND,DETECTOR,PLOTSWITCH)
%
% Input Argument:
% FILENAME : Spec file name string.
% SCANS : List of scans to be merged, e.g., [17,18,19].
% BACKGROUND : List of background of corresponding backgournd, e.g.,
% [110,110,110]. Enter [0,0,0] for zero background.
% DETECTOR : Detecor string; default value is the last column
% PLOTSWITCH : {'on'} or {'off'}; default is {'off'}. When it is
% {'on'}, plot style can be specified in form of
% {'on',LineSpec}, where LineSpec is defined in
% matlab buildin function ERRORBAR. For more
% information on LineSpec, refer to ERRORBAR. The plot
% is set to logy scale automatically.
%
% Out Argument:
% M : three column matrix, the 3rd col of which is the absolute
% statistical error.
%
% Example:
% m = mergescan('ba5103ps',[17,18,19],[370,370,370])
% m = mergescan('ba5103ps',[17,18,19],[370,370,370],'pind3')
% m = mergescan('ba5103ps',[17,18,19],[370,370,370],{'on'})
% m = mergescan('ba5103ps',[17,18,19],[370,370,370],{'on','ro-'})
% m = mergescan('ba5103ps',[17,18,19],[370,370,370],'pind3',{'on','k^:'})
%
% Copyright 2006 Zhang Jiang
% $Revision: 1.0 $ $Date: 2006/01/24 $
if nargin < 3 | nargin > 5
error('Invalid input argument.');
return;
end
f = varargin{1};
scan = varargin{2};
bkg = varargin{3};
if ~ischar(f)
error('Invalid spec filename.');
return;
end
if ~isnumeric(scan) | min(size(scan)) ~= 1
error('Invalid scan numbers.');
return;
end
if ~isnumeric(bkg) | numel(scan)-numel(bkg) ~= 0
error('Invalid background or background dimension differs from scan dimension.');
return;
end
switch nargin
case 3
detector = '-1';
plotswitch = {'off'};
case 4
if ischar(varargin{4})
detector = varargin{4};
plotswitch = {'off'};
elseif iscell(varargin{4})
detector = '-1';
plotswitch = varargin{4};
else
error('Invalid input argument.')'
return;
end
case 5
detector = varargin{4};
plotswitch = varargin{5};
end
if length(plotswitch) == 1
if ~ischar(plotswitch{1}) | (~strcmpi(plotswitch{1},'off') & ~strcmpi(plotswitch{1},'on'))
error('Invalid plotswitch.');
return;
end
elseif length(plotswitch) == 2
if ~ischar(plotswitch{1}) | ~strcmpi(plotswitch{1},'on')...
| ~ischar(plotswitch{2})
error('Invalid plotswitch.');
return;
end
else
error('Two many arguments in plotswitch.');
return;
end
% merge settings
merge.mode = 1; % intersnity based
merge.interpMethod = 1; % interplation method
% --- load data
nOfScan = length(scan);
scanData = cell(1,nOfScan);
for iOfScan = 1:nOfScan
tempScan = rdspec(f,scan(iOfScan));
if strcmp('-1',detector);
headIndex = length(tempScan.head);
else
headIndex = 0;
for iOfHead = 1:length(tempScan.head)
if strcmpi(detector,tempScan.head{iOfHead})
headIndex = iOfHead;
end
end
if headIndex == 0
error('Invalid detector name.');
return;
end
end
xdata = tempScan.data(:,1);
ydata = tempScan.data(:,headIndex);
ydataRelErr = 1./sqrt(ydata);
ydata = ydata - bkg(iOfScan);
ydataErr = ydata.*ydataRelErr;
negIndex = find(ydata<=0);
xdata(negIndex) = [];
ydata(negIndex) = [];
ydataErr(negIndex) = [];
scanData{iOfScan} = [xdata,ydata,ydataErr];
clear tempScan headIndex iOfHead
end
% --- mergescans
sresult = mrgker(scanData,merge);
% --- plot
if strcmpi(plotswitch{1},'off')
return;
elseif strcmpi(plotswitch{1},'on') & length(plotswitch)==1
errorbar(sresult(:,1),sresult(:,2),sresult(:,3));
elseif strcmpi(plotswitch{1},'on') & length(plotswitch)==2
errorbar(sresult(:,1),sresult(:,2),sresult(:,3),plotswitch{2});
else
return;
end
figure(gcf);
set(gca,'yscale','log');
box on;
% -- EOF