Home > marsbar > mars_options.m

mars_options

PURPOSE ^

options utility routines

SYNOPSIS ^

function [mars, msgstr] = mars_options(optstr, mars, cfg_fname)

DESCRIPTION ^

 options utility routines
 FORMAT [mars msgstr] = mars_options(optstr, mars, cfg_fname)

 Input [default]
 optstr            - option string: one of
                     'put','load','save','edit','defaults',
                     'basedefaults','fill' [load]  
 mars              - marsbar options structure [MARS.OPTIONS]
 cfg_fname         - filename for configuration file [GUI]
 
 Output
 mars              - possible modified MARS.OPTIONS structure
 msgstr            - any relevant messages

 Matthew Brett 20/10/00,2/6/01

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [mars, msgstr] = mars_options(optstr, mars, cfg_fname)
0002 % options utility routines
0003 % FORMAT [mars msgstr] = mars_options(optstr, mars, cfg_fname)
0004 %
0005 % Input [default]
0006 % optstr            - option string: one of
0007 %                     'put','load','save','edit','defaults',
0008 %                     'basedefaults','fill' [load]
0009 % mars              - marsbar options structure [MARS.OPTIONS]
0010 % cfg_fname         - filename for configuration file [GUI]
0011 %
0012 % Output
0013 % mars              - possible modified MARS.OPTIONS structure
0014 % msgstr            - any relevant messages
0015 %
0016 % Matthew Brett 20/10/00,2/6/01
0017 %
0018 % $Id$
0019   
0020 if nargin < 1
0021   optstr = 'load';
0022 end
0023 if nargin < 2
0024   mars = mars_struct('getifthere', spm('getglobal','MARS'), 'OPTIONS');
0025 end
0026 if nargin < 3
0027   cfg_fname = '';
0028 end
0029 
0030 msgstr = '';
0031 
0032 % editable fields, and descriptions of fields, in mars options structure
0033 optfields = {'spacebase','structural','statistics', 'events'}; 
0034 optlabs =  {'Base space for ROIs','Default structural','Statistics', ...
0035         'Working with events'};
0036 
0037 switch lower(optstr)
0038   
0039  % --------------------------------------------------
0040  case 'put'
0041   maroi('classdata', 'spacebase', mars_space(mars.spacebase.fname));
0042   maroi('classdata', 'def_hold', mars.roidefs.spm_hold);
0043  
0044  % --------------------------------------------------
0045  case 'load'
0046   if isempty(cfg_fname)
0047     [fn, fn2] = marsbar('cfgfile');
0048     if isempty(fn), fn=fn2;end
0049     [p f e] = fileparts(fn);
0050     cfg_fname = spm_get([0 1],[f e], 'Configuration file to load',p);
0051   end
0052   if ~isempty(cfg_fname)
0053     tmp = load(cfg_fname);
0054     if ~isempty(tmp)
0055       if isfield(tmp, 'mars')
0056     mars = mars_struct('fillafromb', tmp.mars, mars);
0057       end
0058     end
0059   end
0060  
0061   % --------------------------------------------------
0062  case 'save'
0063   if nargin < 3
0064     [fn, fn2] = marsbar('cfgfile');
0065     if isempty(fn), fn=fn2;end
0066     [f p] = mars_uifile('put', fn, 'Configuration file to save');
0067     if isequal(f,0) || isequal(p,0), return, end
0068     cfg_fname = fullfile(p, f);
0069   end
0070   if ~isempty(cfg_fname)
0071     try
0072       save(cfg_fname, 'mars');
0073       fprintf('Saved options to %s\n', cfg_fname);
0074     catch
0075       warning(sprintf('%s: error saving config to file %s', ...
0076               lasterr, cfg_fname))
0077     end
0078   end
0079   
0080   % --------------------------------------------------
0081  case 'basedefaults'
0082   % hardcoded defaults
0083   msgstr = 'base defaults';
0084 
0085   % default structural image for display
0086   mars.structural.fname = fullfile(spm('Dir'), 'canonical', ...
0087     ['avg152T1' mars_veropts('template_ext')]);
0088 
0089   % default image specifying base space for ROIs
0090   mars.spacebase.fname = mars.structural.fname;
0091   
0092   % ROI defaults
0093   mars.roidefs.spm_hold = 1;
0094   
0095   % default summary function for ROI data
0096   mars.statistics.sumfunc = 'mean';
0097   
0098   % flag to indicate voxel data should be used to calculate filter
0099   mars.statistics.voxfilter = 0;
0100 
0101   % option to say if images should be flipped when converting
0102   % to and from spm99 designs
0103   mars.statistics.flip_option = mars_veropts('flip_option');
0104 
0105   % Whether to refresh contrast structure when loading designs
0106   mars.statistics.refresh_contrasts = 1;
0107   
0108   % Difference function to calculate % signal change
0109   mars.events.diff_func = 'abs max';
0110   
0111 % --------------------------------------------------
0112  case 'edit'
0113   
0114   % Edit defaults.  See 'basedefaults' option for other defaults
0115   defarea = cfg_fname;  % third arg is defaults area, if specified
0116   if isempty(defarea)
0117     % get defaults area
0118     [Finter,Fgraph,CmdLine] = spm('FnUIsetup','MarsBar Defaults');
0119 
0120     defarea = char(...
0121       spm_input('Defaults area', '+1', 'm',{optlabs{:} 'Quit'},...
0122         {optfields{:} 'quit'},length(optfields)+1));
0123   end
0124   
0125   oldmars = mars;
0126   switch defarea
0127    case 'quit'
0128     return
0129    
0130     % display stuff - default structural scan
0131    case 'structural'
0132     mars.structural.fname = spm_get(1, mars_veropts('get_img_ext'),...
0133                     'Default structural image', ...
0134                     fileparts(mars.structural.fname));
0135 
0136     % default ROI base space
0137    case 'roidefs'
0138     mars.roidefs.spm_hold = ...
0139     spm_input('ROI interpolation method?','+1','m',...
0140           ['Nearest neighbour' ...
0141           '|Trilinear Interpolation'...
0142           '|Sinc Interpolation'],...
0143                  [0 1 -9],2);
0144     
0145    % default ROI base space
0146    case 'spacebase'
0147     mars.spacebase.fname = spm_get(1, mars_veropts('get_img_ext'),...
0148                    'Default ROI image space', ...
0149                    fileparts(mars.spacebase.fname));
0150     
0151    % statistics
0152    case 'statistics'
0153     mars.statistics = getdefs(...
0154     mars.statistics,...
0155     oldmars.statistics,...
0156     'sumfunc',...
0157     'Data summary function',...
0158     {'mean','wtmean','median','ask'},...
0159     'Mean|Weighted mean|Median|Always ask');
0160        
0161     tmp = [1 0]; tmpi = find(tmp == mars.statistics.flip_option);
0162     mars.statistics.flip_option = spm_input('Flip design images SPM99-2',...
0163                      '+1','b','Yes|No',tmp, tmpi);
0164 
0165     tmp = [1 0]; tmpi = find(tmp == mars.statistics.refresh_contrasts);
0166     mars.statistics.refresh_contrasts = spm_input(...
0167         'Load updates F contrasts?', '+1','b','Yes|No',tmp, tmpi);
0168 
0169    case 'events'
0170     mars.events = getdefs(...
0171     mars.events,...
0172     oldmars.events,...
0173     'diff_func',...
0174     'Event height function',...
0175     {'abs max','abs max-min','max','max-min','window'},...
0176     'Abs max|Abs max-min|Max|Max-min|Mean over time window');
0177     
0178    otherwise 
0179     error('Unknown defaults area')
0180   end
0181 
0182   % Offer a rollback
0183   if spm_input('Accept these settings', '+1', 'b','Yes|No',[0 1],1)
0184     mars = oldmars;
0185   end
0186   
0187   % --------------------------------------------------
0188  case 'defaults'                             %-get marsbar defaults
0189   pwdefs = [];
0190   msgstr = 'base defaults';
0191   cfgfile = marsbar('cfgfile');
0192   if ~isempty(cfgfile);
0193     tmp = load(cfgfile);
0194     if isfield(tmp, 'mars')
0195       pwdefs = tmp.mars;
0196       msgstr = cfgfile;
0197     else
0198       warning(...
0199       ['File ' cfgfile ' does not contain valid config settings'],...
0200       'Did not load marsbar config file');
0201     end
0202   end
0203   mars = mars_struct('fillafromb',pwdefs, mars_options('basedefaults'));
0204   
0205    % --------------------------------------------------
0206  case 'fill'                             %-fill from template
0207   mars = mars_struct('fillafromb',mars,cfg_fname);
0208   
0209  otherwise
0210   error('Don''t recognize options action string')
0211 end
0212 return
0213 
0214 
0215 function s = getdefs(s, defval, fieldn, prompt, vals, labels)
0216 % sets field in structure given values, labels, etc
0217     
0218 if isstruct(defval)
0219   defval = getfield(defval, fieldn);  
0220 end
0221 
0222 if ischar(defval)
0223   defind = find(strcmp(defval,vals));
0224 else
0225   defind = find(defval == vals);
0226 end
0227 
0228 v = spm_input(prompt, '+1', 'm', labels, vals, defind);
0229 if iscell(v) && ischar(defval)
0230   v = char(v);
0231 end
0232   
0233 s = setfield(s,fieldn,v);
0234 
0235 return

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019