-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspget.m
92 lines (82 loc) · 2.56 KB
/
spget.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
function o = spget(options,name,default,flag)
% SPGET Get sparse interpolation OPTIONS parameters
% VAL = SPGET(OPTIONS,'NAME') extracts the value of the named property
% from the sparse grid options structure OPTIONS, returning an
% empty matrix if the property value is not specified in
% OPTIONS. It is sufficient to type only the leading characters
% that uniquely identify the property. Case is ignored for
% property names. [] is a valid OPTIONS argument.
%
% VAL = SPGET(OPTIONS,'NAME',DEFAULT) extracts the named property as
% above, but returns VAL = DEFAULT if the named property is not
% specified in OPTIONS. For example
%
% val = spget(opts,'RelTol',1e-2);
%
% returns val = 1e-2 if the RelTol property is not specified in opts.
%
% See also SPSET, SPINTERP, SPVALS.
% undocumented usage for fast access with no error checking
if (nargin == 4) && isequal(flag,'fast')
o = getknownfield(options,name,default);
return
end
if nargin < 2
error('Not enough input arguments.');
end
if nargin < 3
default = [];
end
if ~isempty(options) && ~isa(options,'struct')
error('First argument must be an options structure created with SPSET.');
end
if isempty(options)
o = default;
return;
end
Names = {'GridType', 'RelTol', 'AbsTol', 'Vectorized', 'MinDepth', ...
'MaxDepth', 'VariablePositions', 'NumberOfOutputs', ...
'PrevResults', 'FunctionArgType', 'KeepFunctionValues', ...
'KeepGrid' 'DimensionAdaptive', 'MinPoints', ...
'MaxPoints', 'DimadaptDegree', 'DegreeStrategy', ...
'SparseIndices', 'DropTol', 'EnableDCT'};
m = length(Names);
names = cell(m,1);
for k = 1:m
names{k} = lower(Names{k});
end
lowName = lower(name);
matched = strmatch(lowName,names);
if isempty(matched) % if no matches
msg = sprintf(['Unrecognized property name ''%s''. ' ...
'See SPSET for possibilities.'], name);
error(msg);
elseif length(matched) > 1
msg = sprintf('Ambiguous property name ''%s'' ', name);
msg = [msg '(' Names{matched}];
for k = j(2:length(matched))'
msg = [msg ', ' Names{matched}];
end
msg = sprintf('%s).', msg);
error(msg);
end
if any(strcmp(fieldnames(options),Names{matched}))
o = options.(Names{matched});
if isempty(o)
o = default;
end
else
o = default;
end
% -------------------------------------------------------------------
function v = getknownfield(s, f, d)
% GETKNOWNFIELD Get field f from struct s, or else yield default
% d.
if isfield(s,f) % s could be empty.
v = subsref(s, struct('type','.','subs',f));
if isempty(v)
v = d;
end
else
v = d;
end