convert 3D+time back to 3D nii's


Below is part of the script I obtained using Since I wanted to check something in SPM after the despiking block, I need to convert the 3D+time dataset ‘pb01.$subj.r$run.despike’ back to individual 3D datasets, one for each TR, in the *.nii format.
What command would I use to do that?

Thanks a lot,

============================ auto block: tcat ============================

apply 3dTcat to copy input dsets to results dir, while

removing the first 6 TRs

3dTcat -prefix $output_dir/pb00.$subj.r01.tcat
3dTcat -prefix $output_dir/pb00.$subj.r02.tcat

and make note of repetitions (TRs) per run

set tr_counts = ( 174 174 )


enter the results directory (can begin processing data)

cd $output_dir

========================== auto block: outcount ==========================

data check: compute outlier fraction for each volume

touch out.pre_ss_warn.txt
foreach run ( $runs )
3dToutcount -automask -fraction -polort 3 -legendre
pb00.$subj.r$run.tcat+orig > outcount.r$run.1D

# censor outlier TRs per run, ignoring the first 0 TRs
# - censor when more than 0.1 of automask voxels are outliers
# - step() defines which TRs to remove via censoring
1deval -a outcount.r$run.1D -expr "1-step(a-0.1)" > rm.out.cen.r$run.1D

# outliers at TR 0 might suggest pre-steady state TRs
if ( `1deval -a outcount.r$run.1D"{0}" -expr "step(a-0.4)"` ) then
    echo "** TR #0 outliers: possible pre-steady state TRs in run $run" \
        >> out.pre_ss_warn.txt


catenate outlier counts into a single time series

cat outcount.r*.1D > outcount_rall.1D

catenate outlier censor files into a single time series

cat rm.out.cen.r*.1D > outcount_${subj}_censor.1D

================================ despike =================================

apply 3dDespike to each run

foreach run ( $runs )
3dDespike -NEW -nomask -prefix pb01.$subj.r$run.despike

You can use 3dTsplit4D to do exactly this.