0001 function tf = save_spm(D, fname);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if nargin < 2
0015 if is_spm_estimated(D)
0016 fname = 'SPM.mat';
0017 elseif has_images(D)
0018 fname = 'SPMcfg.mat';
0019 elseif is_fmri(D)
0020 fname = 'SPM_fMRIDesMtx.mat';
0021 else
0022 error('Cannot work out design type for default filename');
0023 end
0024 end
0025
0026
0027 D = convert_vols(D, native_vol_ver(D));
0028
0029 SPM = des_struct(D);
0030 if ~mars_utils('isabspath', fname)
0031 Swd = mars_struct('getifthere', SPM, 'swd');
0032 if isempty(Swd)
0033 error('No path passed, and none in design');
0034 end
0035 fname = fullfile(Swd, fname);
0036 else
0037 SPM.swd = fileparts(fname);
0038 end
0039
0040 try
0041 if verbose(D)
0042 fprintf('Saving design to file %s\n', fname);
0043 end
0044 savestruct(SPM, fname);
0045 tf = 1;
0046 catch
0047 warning(lasterr);
0048 tf = 0;
0049 end