-
Notifications
You must be signed in to change notification settings - Fork 5
/
cat_get_defaults.m
87 lines (82 loc) · 2.79 KB
/
cat_get_defaults.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
function varargout = cat_get_defaults(defstr, varargin)
% Get/set the defaults values associated with an identifier
% FORMAT defval = cat_get_defaults(defstr)
% Return the defaults value associated with identifier "defstr".
% Currently, this is a '.' subscript reference into the global
% "defaults" variable defined in spm_defaults.m.
%
% FORMAT cat_get_defaults(defstr, defval)
% Sets the cat value associated with identifier "defstr". The new
% cat value applies immediately to:
% * new modules in batch jobs
% * modules in batch jobs that have not been saved yet
% This value will not be saved for future sessions of SPM. To make
% persistent changes, edit cat_defaults.m.
%
% FORMAT cat_get_defaults(defstr, 'rmfield')
% Removes last field of defstr eg. defstr = 'opts.sopt.myfield' will remove
% 'myfield'.
%
% FORMAT cat_get_defaults(defstr, 'rmentry')
% Removes last field of defstr eg. defstr = 'opts.sopt.myfield' will remove
% 'sopt' with all all subfield.
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% based on Volkmar Glauches version of
% spm_get_defaults
% ______________________________________________________________________
%
% Christian Gaser, Robert Dahnke
% Structural Brain Mapping Group (https://neuro-jena.github.io)
% Departments of Neurology and Psychiatry
% Jena University Hospital
% ______________________________________________________________________
% $Id$
global cat;
if isempty(cat)
cat_defaults;
end
if nargin == 0
varargout{1} = cat;
return
end
% construct subscript reference struct from dot delimited tag string
tags = textscan(defstr,'%s', 'delimiter','.');
subs = struct('type','.','subs',tags{1}');
if nargin == 1
% default output
try
varargout{1} = subsref(cat, subs);
catch
varargout{1} = [];
end
return;
elseif nargin == 2
if iscell( varargin{1} )
% add an new entry
cat = subsasgn(cat, subs, varargin{1});
else
switch varargin{1}
case 'rmfield'
% remove the last field of the given defstr
mainfield = tags{1}{1};
for ti=2:numel(tags{1})-1
mainfield = [mainfield '.' tags{1}{ti}]; %#ok<AGROW>
end
subfield = tags{1}{end};
%fprintf('Remove field "%s" in "cat.%s"!\n',subfield,mainfield);
eval(sprintf('cat.%s = rmfield(cat.%s,subfield);',mainfield,mainfield));
case 'rmentry'
% removes the complete entry of the given defstr
%fprintf('Remove entry "%s" "cat"!\n',tags{1}{1});
cat = rmfield(cat,defstr);
otherwise
% add an new entry
cat = subsasgn(cat, subs, varargin{1});
end
end
end
if nargout == 1
% output in case changes in cat
varargout{1} = cat;
end