-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathload2d.m
More file actions
264 lines (214 loc) · 7.21 KB
/
load2d.m
File metadata and controls
264 lines (214 loc) · 7.21 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
function s = load2d(basename, pop_time, varargin)
% rbLoad2d
% rb, 20110527: wrote function
%
% If there is no varargin given, it will use the naming scheme from before
% summer 2009. If the varargin is 'new', it will use the scheme used
% between summer 2009 and May 2011. If there is a number given, it will use
% the scheme used after May 2011.
%
% input:
% - basename: the name given in the 2d-mess program
% - pop_time: the population time (T2)
% - time_stamp: the time the measurement started (see note above)
% these three variables are needed to construct the folder and filename
% - scans (opt): default is [0]: import the averaged scan. [n] (where n >
% 0) will import a single specific scan. [n, m, ...] will import multiple
% scans. If noise_flag = true, it will weigh the scans depending on the
% noise
% - noise: will set the noise flag. Default is false. If set to true and
% only 1 scan is imported, it will just import the noise. If multiple scans
% are imported it will weigh the scans based on the noise.
% - meta: will read the metadata.
s = construct2d;
if nargin == 0
return
end
% determine type (old, new, newer)
% nothing given: old (before 2009)
% 'new': summer 2009 - may 2011
% 1234: used as timestamp (where 1234 is the time)
type_flag = 0;
if ~isempty(varargin)
%disp('has varargin')
if isequal(class(varargin{1}), 'char')
%disp('is char')
if strcmpi(varargin{1},'new')
%disp('is string new')
type_flag = 1;
end
varargin = varargin(2:end);
elseif isequal(class(varargin{1}), 'double')
%disp('is double')
type_flag = 2;
time_stamp = varargin{1};
varargin = varargin(2:end);
end
end
if type_flag == 2
% which scans are imported [0]: averaged, [n]: one scan, [n:m] or [n, m, ..]: more scans
scans = [0];
% take noise weighted average
noise_flag = false;
% import metadata
meta_flag = true;
% read arguments
while length(varargin)>=2
arg = varargin{1};
val = varargin{2};
switch lower(arg)
case 'scans'
scans = val;
case 'noise'
noise_flag = val;
case 'meta'
meta_flag = val;
otherwise
error(['load2d: unknown option ',arg])
end
varargin = varargin(3:end);
end
% fill construct with info
s.basename = basename;
s.t2 = pop_time;
s.time_stamp = time_stamp;
% construct the base for the name
folder = [basename, '_', num2str(s.time_stamp), '_T', num2str(s.t2), '/'];
filebase = [basename, '_', num2str(s.time_stamp), '_T', num2str(s.t2)];
% import only a single file
if length(scans) == 1
% import the averaged data
if scans(1) == 0
file_R = [filebase, '.dat'];
file_NR = [filebase, '_NR.dat'];
if noise_flag == true
file_R_noise = [filebase, '_R_noise.dat'];
file_NR_noise = [filebase, '_NR_noise.dat'];
end
% import a single scan
else
file_R = [filebase, '_R_', num2str(scans(1)), '.dat'];
file_NR = [filebase, '_NR_', num2str(scans(1)), '.dat'];
if noise_flag == true
file_R_noise = [filebase, '_R_', num2str(scans(1)), '_noise.dat'];
file_NR_noise = [filebase, '_NR_', num2str(scans(1)), '_noise_.dat'];
end
end
% import R1
temp = load([folder, file_R]);
s.R1 = temp(2:end,2:end);
% extract more info
s.freq = temp(1,2:end);
s.freq_units = 'cm-1';
s.time = temp(2:end,1);
s.time_units = 'fs';
% import R2
temp = load([folder, file_NR]);
s.R2 = temp(2:end,2:end);
if noise_flag == true
% import R1 noise
temp = load([folder, file_R_noise]);
s.R1_noise = temp(2:end,2:end);
% import R2 noise
temp = load([folder, file_NR_noise]);
s.R2_noise = temp(2:end,2:end);
end
% import multiple individual scans
else
for i = scans
% construct folder and filename
file_R = [filebase, '_R_', num2str(i), '.dat'];
file_NR = [filebase, '_NR_', num2str(i), '.dat'];
if noise_flag == true
file_R_noise = [filebase, '_R_', num2str(i), '_noise.dat'];
file_NR_noise = [filebase, '_NR_', num2str(i), '_noise_.dat'];
end
temp = load([folder, file_R]);
if noise_flag == false
% if we shouldn't import noise, set it to ones
temp_noise = ones(size(temp(:,:)));
else
% otherwise import noise
temp_noise = load([folder, file_R_noise]);
% and save it
% first check if it exists
if size(s.R1_noise) == size(temp_noise(2:end,2:end))
% if so, add it
s.R1_noise = s.R1_noise + temp_noise(2:end,2:end);
else
% if it doesn't exist, make it
s.R1_noise = temp_noise(2:end,2:end);
end
end
disp(mean(mean(temp_noise(2:end,2:end))))
% multiply the measurement with the noise (or the ones)
if size(s.R1) == size(temp(2:end,2:end))
s.R1 = s.R1 + temp(2:end,2:end) ./ mean(mean(temp_noise(2:end,2:end)));
else
s.R1 = temp(2:end,2:end) ./ mean(mean(temp_noise(2:end,2:end)));
end
if isempty(s.freq)
% extract more info
s.freq = temp(1,2:end);
s.freq_units = 'cm-1';
s.time = temp(2:end,1);
s.time_units = 'fs';
end
% import R2
temp = load([folder, file_NR]);
if noise_flag == false
% if we shouldn't import noise, set it to ones
temp_noise = ones(size(temp(:,:)));
else
% otherwise import noise
temp_noise = load([folder, file_NR_noise]);
% and save it
% first check if it exists
if size(s.R2_noise) == size(temp_noise(2:end,2:end))
% if so, add it
s.R2_noise = s.R2_noise + temp_noise(2:end,2:end);
else
% if it doesn't exist, make it
s.R2_noise = temp_noise(2:end,2:end);
end
end
% multiply the measurement with the noise (or the ones)
if size(s.R2) == size(temp(2:end,2:end))
s.R2 = s.R2 + temp(2:end,2:end) ./ mean(mean(temp_noise(2:end,2:end)));
else
s.R2 = temp(2:end,2:end) ./ mean(mean(temp_noise(2:end,2:end)));
end
end
s.R1 = s.R1/length(scans);
s.R2 = s.R2/length(scans);
if noise_flag == true
s.R1_noise = s.R1_noise/length(scans);
s.R2_noise = s.R2_noise/length(scans);
end
% end of importing multiple scans
end
%disp(s)
if meta_flag
file_meta = [folder, filebase, '_meta.txt'];
s = rbLoadMetadata(s, file_meta);
end
%disp(s)
elseif type_flag == 0 || type_flag == 1
if type_flag == 1
temp = load([basename,'_T',num2str(pop_time),'.dat']);
else
temp = load([basename,'_R_T',num2str(pop_time),'.dat']);
end
s.freq = temp(1,2:end);
s.freq_units = 'cm-1';
s.time = temp(2:end,1);
s.time_units = 'fs';
s.R1 = temp(2:end,2:end);
if type_flag == 1
temp = load([basename,'_T',num2str(pop_time),'_NR.dat']);
else
temp = load([basename,'_NR_T',num2str(pop_time),'.dat']);
end
s.R2 = temp(2:end,2:end);
s.t2 = pop_time;
end