-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_saver.m
58 lines (50 loc) · 1.87 KB
/
data_saver.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
classdef data_saver
%Helper class to save or load resolution pulse data
properties
ds
% if use_velocity_scale is true, the time
% signal should be rebinned according to the velocity resolution
use_velocity_scale = false;
end
methods
function obj = data_saver(vel_distr,tsample,vsample,fsample,...
V_pulseI,t_chop,t_det,f_det_vs_t,L_det,L_samp,tau_char,V_char)
if nargin>0
obj.ds = struct('tsample',tsample,'vsample',vsample,'fsample',fsample,...
'V_pulseI',V_pulseI,'t_chop',t_chop,...
't_det',t_det,'f_det_vs_t',f_det_vs_t,...
'L_det',L_det,'L_samp',L_samp,...
'tau_char',tau_char,'V_char',V_char,...
'vel_distr_fun',vel_distr);
if ~isa(obj.ds.vel_distr_fun,'function_handle')
obj.ds.vel_distr_fun= @vel_distribution0;
end
else
obj.ds = struct();
end
end
function save_data(obj)
ds_ = obj.ds;
fn = obj.pulse_name();
save(fn,'-struct','ds_');
end
function obj = load_data(obj,filename)
ds_ = load(filename);
obj.ds = ds_;
end
function name = pulse_name(obj)
% function to generate pulse dependent file name to cache appropriate data
%
velocity = obj.ds.V_pulseI;
fh = obj.ds.vel_distr_fun;
addinfo = fh('Name');
name = sprintf('Pulse_V%d_%s_input_data',floor(velocity*100),addinfo);
end
function varargout = get_data(obj)
fn = fieldnames(obj.ds);
for i=1:nargout
varargout{i} = obj.ds.(fn{i});
end
end
end
end