for groupnum=1
    par;
for sb =1:length(PAR.subjects) % for each subject 
    clear P;
    P=spm_select('ExtFPList', char(PAR.condirs{sb,c}),  ['^' PAR.fmriprefix{c} '\w*\.nii$'], 1);
    v=spm_vol(P);
    nslices=v.dim(3);
    PAR.num_slices=nslices;
    PAR.slicetime = PAR.TRs(1)/PAR.num_slices; 
    if mod(PAR.num_slices,2)
        PAR.sliceorder=[2:2:PAR.num_slices 1:2:PAR.num_slices];
    else
        PAR.sliceorder=[1:2:PAR.num_slices 2:2:PAR.num_slices];
    end
    PAR.slice_gap = PAR.slicetime;  % since the last slice is acquired in the end, the time between last slices and next volume is MYV.slicetime 

    fprintf('Slice time correction for sub:%d, %d left!\n',sb, length(PAR.subjects)-sb);
    for ses=1:PAR.nsess(sb)
        % get files in this directory 
        for c=1:PAR.ncond  
           
            P=spm_select('ExtFPList', char(PAR.condirs{sb,c}),  ['^' PAR.fmriprefix{c} '\w*\.nii$'], 1:1000);
            
            if isempty(P)
                P=spm_select('FPList', char(PAR.condirs{sb,c}),  ['^' PAR.fmriprefix{c} '\w*\.img$']);
                if isempty(P)
                    disp('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n NO epi file\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
                    continue;
                end
            end;
                      
            if isempty(P), continue; end;
            spm_slice_timing(P,PAR.sliceorder,PAR.ref_slice,[PAR.slicetime PAR.slice_gap]);
        end
    end
end
end