Home > marsbar > @mardo > cd_images.m

cd_images

PURPOSE ^

method for changing path to image files in design

SYNOPSIS ^

function D = cd_images(D, newpath, byteswap)

DESCRIPTION ^

 method for changing path to image files in design
 FORMAT D = cd_images(D, newpath [, byteswap])

 Synopsis
 D = cd_images(D); % get new path from GUI
 D = cd_images(D, '/new/root/path'); 
 D = cd_images(D, '/new/root/path', 1); % force byteswap
 D = cd_images(D, '/new/root/path', 1); % prevent byteswap  
  
 D          - mardo design
 newpath    - path to replace common path of files in analysis [GUI]
 byteswap   - whether to indicate byte swapping in vol structs 
              [determined from images by default]
             
 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function D = cd_images(D, newpath, byteswap)
0002 % method for changing path to image files in design
0003 % FORMAT D = cd_images(D, newpath [, byteswap])
0004 %
0005 % Synopsis
0006 % D = cd_images(D); % get new path from GUI
0007 % D = cd_images(D, '/new/root/path');
0008 % D = cd_images(D, '/new/root/path', 1); % force byteswap
0009 % D = cd_images(D, '/new/root/path', 1); % prevent byteswap
0010 %
0011 % D          - mardo design
0012 % newpath    - path to replace common path of files in analysis [GUI]
0013 % byteswap   - whether to indicate byte swapping in vol structs
0014 %              [determined from images by default]
0015 %
0016 % $Id$
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 % get images
0026 if ~has_images(D)
0027   warning('Design does not contain images');
0028   return
0029 end
0030 VY = get_images(D);
0031 
0032 % now change directory
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; % common path
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); % common path removed
0041 tmp = ffnames == other_filesep; % filesep exchanged for this platform
0042 ffnames(tmp) = filesep;
0043 nfnames = cellstr(...
0044     strcat(repmat(newpath,n,1),filesep,ffnames));
0045 [VY(:).fname] = deal(nfnames{:});
0046 
0047 % do the files exist here then?
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 % do byteswap as necessary
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);

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