-
Notifications
You must be signed in to change notification settings - Fork 0
/
hdsoption.m
156 lines (147 loc) · 6.09 KB
/
hdsoption.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
function out = hdsoption(varargin)
%HDSOPTION(...) Set options for HDS database behavior.
% HDSOPTION('optionStr', Value, ...) sets the option
% definined in 'optionStr' to 'value'. For all available
% options, see below.
%
% HDSOPTION('default') sets all options back to their
% default values.
%
% Options:
%
% 'metaMode' : Meta data retrieval mode.
% 'dataMode' : Data retrieval mode.
% 'decimation' : Vector with decimation values.
% 'loadLimit' : Threshold limiting the size of loaded data.
% 'maxNCFileSize' : Sets the maximum data file size in bytes.
%
%
% -- metaMode --
%
% MetaMode 0 (default)
%
% When an object is loaded from disk by indexing a property in a parent object, the HDS
% Toolbox will load all objects in the associated MAT-file and disregard any objects that are
% not requested by the user.
%
% This option usually results in faster retrieval when all or most objects in a property of an
% HDS-object are loaded simultaneously. If you want to get specific objects from disk, this
% might be a little slower and you can choose to switch to 'metaMode 2'.
%
% MetaMode 1
%
% When an object is loaded from disk, the specific variable containing the object is loaded
% from disk. This is usually slower than 'metaMode 1' but can be faster in case you load
% single objects from a MAT-file with large number of variables. (This is also different
% depending on Windows/Mac)
%
% -- dataMode --
%
% DataMode 1 (default):
%
% In this mode, each time a dataproperty is accessed, the
% retrieved data is stored in the object and consecutive
% requests for the data are retrieved from memory. This
% works well as long as the retrieved data
%
% DataMode 2:
%
% In this mode, each time the dataproperty is accessed,
% the data is loaded from disk and not stored in the
% object. Data can automatically be decimated by setting
% the 'decimation' option with the HDSOPTIONS method. In
% this mode, data is read-only. This mode is mostly
% usefull if the data property contains massive amounts
% of data and you are interested in the complete data set
% or a decimated version.
%
% -- loadLimit --
%
% This option is only used when 'dataMode' == 1. When a subset of
% data is requested from a 'data'-property, the HDS- toolbox will
% load the complete dataset into the object if the total number of
% points in the dataset does not exceed the 'loadLimit'.
%
% If the dataset contains more points, only the requested subset is
% loaded into memory. Subsequent data requests will check what subset
% is in memory and retrieve additional points if necessary.
%
% -- decimation -- (Not implemented yet)
%
% This option is only used when 'dataMode' == 2. The decimation
% option is either a single value or a vector of decimation values.
% When data is requested from a 'data'-property and the decimation
% factor is set to ~= 1, decimated data is returned by the HDS-
% toolbox. If the option is a single value, the largest dimension
% will be decimated. If the option is a vector, it can set decimation
% in multiple dimensions.
%
% No smoothing or filtering is applied for the decimation such that:
% x(1:2500) with the decimation option set to 25 returns the same
% data as x(1:25:2500) without decimation.
%
% Copyright (c) 2012, J.B.Wagenaar
% This source file is subject to version 3 of the GPL license,
% that is bundled with this package in the file LICENSE, and is
% available online at http://www.gnu.org/licenses/gpl.txt
%
% This source file can be linked to GPL-incompatible facilities,
% produced or made available by MathWorks, Inc.
persistent options
try
if isempty(options)
options = struct('decimation',1, 'metaMode',0, 'dataMode',1, 'maxNCFileSize',1e9,'loadLimit',1e5);
mlock
end
if nargin
if strcmp(varargin{1},'default')
assert(length(varargin) ==1, ...
'HDS:HDSOPTION','HDSOPTION Setting HDSOPTION to ''default'' values requires only one input.');
options = struct('decimation',1, 'metaMode',0, 'dataMode',1, 'maxNCFileSize',1e9,'loadLimit',1e5);
end
else
out = options;
return
end
ix = 1;
while ix < nargin
if nargin >= (ix + 1)
switch varargin{ix}
case 'decimation'
assert(isnumeric(varargin{ix+1}) && isvector(varargin{ix+1}), ...
'HDSOPTION: Incorrect value for ''decmation'' option.');
options.decimation = varargin{ix+1};
ix = ix+2;
case 'metaMode'
assert(varargin{ix+1} ==0 || varargin{ix+1}==1, ...
'HDSOPTION: Incorrect value for ''metaMode'' option.');
options.metaMode = varargin{ix+1};
ix = ix+2;
case 'dataMode'
assert(varargin{ix+1} ==1 || varargin{ix+1}==2, ...
'HDSOPTION: Incorrect value for ''dataMode'' option.');
options.dataMode = varargin{ix+1};
ix = ix+2;
case 'maxNCFileSize'
assert(isnumeric(varargin{ix+1}) && length(varargin{ix+1})==1, ...
'HDSOPTION: Incorrect value for ''maxNCFileSize'' option.');
options.maxNCFileSize = varargin{ix+1};
ix = ix+2;
case 'loadLimit'
assert(isnumeric(varargin{ix+1}) && length(varargin{ix+1})==1, ...
'HDSOPTION: Incorrect value for ''loadLimit'' option.');
options.loadLimit = varargin{ix+1};
ix = ix+2;
case 'default'
error('HDS:HDSOPTION',['HDSOPTION Setting HDSOPTION to ''default'' '...
'values requires only one input.']);
otherwise
error('HDS:HDSOPTION','HDSOPTION: Incorrect option.');
end
end
end
out = options;
catch ME
throwAsCaller(ME)
end
end