0001 function [o, errf] = do_set(o, item, flags, data, filename)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 if nargin < 2
0023 error('Need item');
0024 end
0025 if nargin < 3
0026 error('Need calling flags');
0027 end
0028 if nargin < 4
0029 data = NaN;
0030 end
0031 if nargin < 5
0032 filename = NaN;
0033 end
0034
0035
0036 errf = 0;
0037
0038
0039 if ischar(flags)
0040 if ~isempty(flags)
0041 flags = struct('action', flags);
0042 end
0043 end
0044 if ~isstruct(flags), flags = []; end
0045 if ~isfield(flags, 'action'), flags.action = 'set'; end
0046 action = flags.action;
0047
0048
0049 item_struct = get_item_struct(o, item);
0050
0051
0052 if strcmp(action, 'set_ui')
0053 [fn pn] = mars_uifile('get', ...
0054 item_struct.filter_spec, ...
0055 ['Select ' item_struct.title '...']);
0056 if isequal(fn,0) | isequal(pn,0), errf = 1;, return, end
0057 filename = fullfile(pn, fn);
0058 data = [];
0059 end
0060
0061
0062 passed_filename = filename;
0063
0064
0065
0066 if item_struct.char_is_filename & ischar(data)
0067 if ~pr_is_nix(filename)
0068 warning(sprintf(...
0069 'Passed filename %s overrides data filename %s\n',...
0070 filename, data));
0071 else
0072 filename = data;
0073 end
0074 data = [];
0075 end
0076
0077 if pr_is_nix(filename)
0078 item_struct.has_changed = 1;
0079 else
0080 item_struct.has_changed = 0;
0081 if isempty(data)
0082 data = load(filename, ['-' item_struct.file_type]);
0083 end
0084 end
0085 item_struct.data = data;
0086
0087
0088
0089
0090 is_update = strcmp(action, 'update');
0091 if pr_is_nan(filename)
0092 if ~is_update
0093 filename = '';
0094 end
0095 end
0096 item_struct.file_name = filename;
0097
0098
0099 if pr_isempty(item_struct), item_struct.has_changed = 0; end
0100
0101
0102
0103
0104 old_o = o;
0105 o = set_item_struct(o, item, item_struct);
0106
0107
0108 is_clear = strcmp(action, 'clear');
0109 if ~isempty(item_struct.set_action) & ...
0110 (ismember(action, {'get','set','set_ui'}) | ...
0111 (is_update & item_struct.set_action_if_update) | ...
0112 (is_clear & item_struct.set_action_if_clear))
0113 [tmp errf msg] = eval(item_struct.set_action);
0114 if errf
0115 o = old_o;
0116 warning(['Data not set: ' msg]);
0117 return
0118 end
0119
0120
0121
0122 if isa(tmp, 'marmoire')
0123 o = tmp;
0124 item_struct = get_item_struct(o, item);
0125 elseif isstruct(tmp) & isfield(tmp, 'set_action')
0126 item_struct = tmp;
0127 else
0128 item_struct.data = tmp;
0129 end
0130 end
0131
0132
0133 if strcmp(action, 'update')
0134 item_struct.has_changed = 1;
0135 end
0136
0137
0138 if ~item_struct.has_changed & item_struct.leave_as_file
0139 item_struct.data = [];
0140 end
0141
0142
0143 o = set_item_struct(o, item, item_struct);
0144
0145 return