Home > marsbar > mars_arm_call.m

mars_arm_call

PURPOSE ^

services callbacks from marmoire object set functions

SYNOPSIS ^

function [o,errf,msg] = mars_arm_call(action, o, item, old_o)

DESCRIPTION ^

 services callbacks from marmoire object set functions
 FORMAT [o,errf,msg] = mars_arm_call(action, o, item)
 See documentation for marmoire object for more detail

 action     - action string
 o          - candidate object for checking etc
 item       - name of item that has just been set
 old_o      - object before set

 Returns
 o          - possibly modified object
 errf       - flag, set if error in processing
 msg        - message to examplain error

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [o,errf,msg] = mars_arm_call(action, o, item, old_o)
0002 % services callbacks from marmoire object set functions
0003 % FORMAT [o,errf,msg] = mars_arm_call(action, o, item)
0004 % See documentation for marmoire object for more detail
0005 %
0006 % action     - action string
0007 % o          - candidate object for checking etc
0008 % item       - name of item that has just been set
0009 % old_o      - object before set
0010 %
0011 % Returns
0012 % o          - possibly modified object
0013 % errf       - flag, set if error in processing
0014 % msg        - message to examplain error
0015 %
0016 % $Id$
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   % callback for setting design
0038 
0039   % Check for save of current design
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   % Make design into object, do conversions
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   % Unload roi data if design has been set, and data exists
0055   % and data is not the same size as design
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   % callback for setting data
0069 
0070   % Check for save of current data
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   % Make data into object, do conversions
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   % Check data matches default design; clear if not
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   % Clear default region if data has changed
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   % callback for setting results
0106 
0107   % Need to set default data from results, and load contrast file
0108   % if not present (this is so for old MarsBaR results)
0109 
0110   data = item_struct.data;
0111   if isempty(data), return, end
0112   
0113   % Check for save of current design
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   % Make design into object, do conversions
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   % Deal with case of old MarsBaR designs
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     % Default refreshing
0136     refreshf = mars_get_option('statistics', 'refresh_contrasts');
0137     % If the filename does not correspond to marsbar estimation, refresh the
0138     % contrasts for safety (the user could have selected an SPM xCon fle).
0139     refreshf = refreshf | ~strcmp(fn, 'mars_xCon.mat')
0140     data = set_contrasts(data, tmp, refreshf);
0141   end
0142 
0143   % Put data into object
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 % Make design into object, do conversions
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 % Make data structure into object, do conversions
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

Generated on Thu 17-Mar-2016 01:14:46 by m2html © 2005