0001 function [o,errf,msg] = mars_arm_call(action, o, item, old_o)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 if nargin < 1
0019 error('Need action');
0020 end
0021 if nargin < 2
0022 error('Need object');
0023 end
0024 if nargin < 3
0025 error('Need item name');
0026 end
0027 if nargin < 4
0028 error('Need old object');
0029 end
0030
0031 errf = 0; msg = '';
0032
0033 item_struct = get_item_struct(o, item);
0034
0035 switch lower(action)
0036 case 'set_design'
0037
0038
0039
0040 [btn o] = save_item_data_ui(old_o, 'def_design', ...
0041 struct('ync', 1, ...
0042 'prompt_prefix','previous '));
0043 if btn == -1
0044 errf = 1;
0045 msg = 'Cancelled save of previous design';
0046 return
0047 end
0048
0049
0050 [item_struct.data errf msg] = sf_check_design(item_struct.data);
0051 if errf, o = []; return, end
0052 o = set_item_struct(o, item, item_struct);
0053
0054
0055
0056 if ~isempty_item_data(o, 'roi_data')
0057 [Y o] = get_item_data(o, 'roi_data');
0058 if n_time_points(Y) ~= n_time_points(item_struct.data)
0059 fprintf('Design and data have different numbers of rows\n');
0060 [btn o] = save_item_data_ui(o, 'roi_data', struct('ync', 1));
0061 if btn == -1, errf = 1; msg = 'ROI save cancelled'; return, end
0062 o = clear_item_data(o, 'roi_data');
0063 fprintf('Reset of design, cleared ROI data...\n');
0064 end
0065 end
0066
0067 case 'set_data'
0068
0069
0070
0071 [btn o] = save_item_data_ui(old_o, 'roi_data', ...
0072 struct('ync', 1, ...
0073 'prompt_prefix','previous '));
0074 if btn == -1
0075 errf = 1; o = [];
0076 msg = 'Cancelled save of current data';
0077 return
0078 end
0079
0080
0081 [item_struct.data errf msg] = sf_check_data(item_struct.data);
0082 if errf, o = []; return, end
0083 o = set_item_struct(o, item, item_struct);
0084
0085
0086 if ~isempty_item_data(o, 'def_design')
0087 [D o] = get_item_data(o, 'def_design');
0088 if n_time_points(D) ~= n_time_points(item_struct.data)
0089 fprintf('Design and data have different numbers of rows\n');
0090 [btn o] = save_item_data_ui(o, 'def_design', struct('ync', 1));
0091 if btn == -1, errf = 1; msg = 'Design save cancelled'; return, end
0092 o = clear_item_data(o, 'def_design');
0093 fprintf('Reset of ROI data, cleared default design...\n');
0094 end
0095 end
0096
0097
0098 global MARS;
0099 if mars_struct('isthere', MARS, 'WORKSPACE', 'default_region')
0100 MARS.WORKSPACE.default_region = [];
0101 fprintf('Reset of data, cleared default region...\n');
0102 end
0103
0104 case 'set_results'
0105
0106
0107
0108
0109
0110 data = item_struct.data;
0111 if isempty(data), return, end
0112
0113
0114 [btn o] = save_item_data_ui(old_o, 'est_design', ...
0115 struct('ync', 1, ...
0116 'prompt_prefix','previous '));
0117 if btn == -1
0118 errf = 1;
0119 msg = 'Cancelled save of current design';
0120 return
0121 end
0122
0123
0124 [data errf msg] = sf_check_design(data);
0125 if errf, return, end
0126 if ~is_mars_estimated(data)
0127 error('Design has not been estimated')
0128 end
0129
0130
0131 if ~has_contrasts(data);
0132 fname = spm_get(1, '*x?on.mat', 'Select contrast file');
0133 [pth, fn, ext] = fileparts(fname);
0134 tmp = load(fname);
0135
0136 refreshf = mars_get_option('statistics', 'refresh_contrasts');
0137
0138
0139 refreshf = refreshf | ~strcmp(fn, 'mars_xCon.mat')
0140 data = set_contrasts(data, tmp, refreshf);
0141 end
0142
0143
0144 item_struct.data = data;
0145 o = set_item_struct(o, item, item_struct);
0146
0147 otherwise
0148 error(['Peverse request for ' action]);
0149 end
0150
0151 function [d,errf,msg] = sf_check_design(d)
0152
0153 errf = 0; msg = {};
0154 d = mardo(d);
0155 if ~is_valid(d)
0156 errf = 1;
0157 msg = 'This does not appear to be a valid design';
0158 end
0159 return
0160
0161 function [d,errf,msg] = sf_check_data(d)
0162
0163 errf = 0; msg = {};
0164 d = marsy(d);
0165 if ~is_valid(d)
0166 errf = 1;
0167 msg = 'This does not appear to be a valid data structure';
0168 end
0169 return