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

Hello,

Below is part of the script I obtained using afni_proc.py. 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,
Duong

============================ 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
20170309.pt001_rtfMRI_1Trn3Tst_GD_030917.pt001_rtfMRI_1Trn3Tst_GD_030917/funcHeadBrik/epi.r1+orig’[6…179]’
3dTcat -prefix $output_dir/pb00.$subj.r02.tcat
20170309.pt001_rtfMRI_1Trn3Tst_GD_030917.pt001_rtfMRI_1Trn3Tst_GD_030917/funcHeadBrik/epi.r2+orig’[6…179]’

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
endif

end

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
pb00.$subj.r$run.tcat+orig
end

You can use 3dTsplit4D to do exactly this.