% Toolbox for batch processing ASL perfusion based fMRI data.
% All rights reserved.
% Ze Wang @ TRC, CFN, Upenn 2004

    par;
% get the subdirectories in the main directory
for sb =1:length(PAR.subjects) % for each subject 
    fprintf('smoothing subject %u  %s.........',sb,PAR.subjects{sb})
    %go get the sessions
        %now get all images to smooth!
        %prepare directory
        %P=[];
        for c=1:PAR.ncond
            rbim_dir = fullfile(PAR.root,PAR.subjects{sb}, PAR.rbimdir);
            
            P=spm_select('FPList', rbim_dir, sprintf('^w%s_BEN.*.nii',PAR.subjects{sb}));
            
            fprintf('      %u images \n',size(P,1))
            %put files in spm volumes:
            %P = spm_get('Files', dir_func,...
		    %    ['w' PAR.conprefs{c} '*img']);
            %take image per image smooth
            for im=1:size(P,1)
               %this is actual image
               Pim=P(im,:);
               [pth,nam,ext] = fileparts(P(im,:));
                t = find(ext==',');
                n = [1 1];
               if ~isempty(t),
                   % to speed up, output each volume into an separate image
                   % file
                    Qim   = fullfile(pth,['s' nam '_' num2str(im,'%.3d') '.nii,' num2str(1)]);
               else
                    Qim=fullfile(pth,['s' spm_str_manip(Pim,'dt')]);
               end
               %now call spm_smooth with kernel defined at PAR
               spm_smooth(Pim,Qim,PAR.FWHMben);
            end
                        
           
        end % end for c
    
end  % end for sb

