0001 function D = cd_images(D, newpath, byteswap)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 if nargin < 2
0019 newpath = spm_get(-1, '', 'New directory root for files');
0020 end
0021 if nargin < 3
0022 byteswap=[];
0023 end
0024
0025
0026 if ~has_images(D)
0027 warning('Design does not contain images');
0028 return
0029 end
0030 VY = get_images(D);
0031
0032
0033 newpath = spm_get('cpath', newpath);
0034 if filesep == '\', other_filesep='/';else other_filesep='\';end
0035 n = length(VY);
0036 strout = strvcat(VY(:).fname);
0037 msk = diff(strout+0)~=0;
0038 d1 = min(find(sum(msk,1)));
0039 d1 = max([find(strout(1,1:d1) == other_filesep | strout(1,1:d1) == filesep) 0]);
0040 ffnames = strout(:,d1+1:end);
0041 tmp = ffnames == other_filesep;
0042 ffnames(tmp) = filesep;
0043 nfnames = cellstr(...
0044 strcat(repmat(newpath,n,1),filesep,ffnames));
0045 [VY(:).fname] = deal(nfnames{:});
0046
0047
0048 if ~exist(nfnames{1}, 'file')
0049 error(['Cannot find first file here: ' nfnames{1}]);
0050 end
0051 if isempty(byteswap)
0052 byteswap = mars_vol_utils('is_swapped_wrong', VY(1));
0053 end
0054
0055
0056 if byteswap
0057 VY = mars_vol_utils('byte_swap', VY);
0058 if verbose(D)
0059 disp('Images vols byteswapped');
0060 end
0061 end
0062
0063 D = set_images(D, VY);