
par;
fprintf('\r%-40s\n','batch image normlizing ') 
close all;
global defaults;
spm_defaults;
defs = defaults.normalise;
PAR.SPM_path=spm('Dir');

clear matlabbatch subs;

matlabbatch{1}.spm.spatial.normalise.write.woptions.bb = [-90 -126 -72;  90    90  108]; %[-78 -112 -70; 78 76 85];
matlabbatch{1}.spm.spatial.normalise.write.woptions.vox = [2 2 2];
matlabbatch{1}.spm.spatial.normalise.write.woptions.interp = 4;
for sb =1:PAR.nsubs % for each subject 
 
    str   = sprintf('sub #%3d/%3d: %-5s',sb,PAR.nsubs,PAR.subjects{sb} );
        fprintf('\r%-40s  %30s',str,' ')
        fprintf('%s%30s',repmat(sprintf('\b'),1,30),'...normaling')  %-#
    deffile=spm_select('FPList', PAR.structdir{sb}, ['^y_' PAR.structprefs '.*\.nii$' ] );
    clear imgs
    for c=1:PAR.ncond    
          rbim_dir = fullfile(PAR.root,PAR.subjects{sb}, PAR.rbimdir);
          P=strvcat(P, spm_select('FPList', rbim_dir, sprintf('^%s_BEN_.*.nii',PAR.subjects{sb})));
    end
    for i=1:size(P,1)
        imgs{i,1}=deblank(P(i,:));
    end
    interp=4;
    opath='';
    res2mm=1;
    matlabbatch{1}.spm.spatial.normalise.write.subj.def{1} = deffile;
    matlabbatch{1}.spm.spatial.normalise.write.subj.resample = imgs;
    cfg_util('run', matlabbatch);
   fprintf('%s%30s',repmat(sprintf('\b'),1,30),'...done')  %-#
end