#!/bin/tcsh

# set output grid
set master = ~/abin/MNI152_2009_template_SSW.nii.gz
goto RESTART

@SSwarper -base ~/abin/MNI152_2009_template_SSW.nii.gz -input ~/abin/TT_N27+tlrc. -init_skullstr_off -subid TTN27 -odir TTN27_to_MNI152_2009c

RESTART:
mkdir MNI2009c_Desai_MPM
cd MNI2009c_Desai_MPM/

# there are two kinds of Desai atlases (dd and dk), 
# derived from the two kinds of FreeSurfer annotations
foreach atlas ( dd dk )
   # warp the atlases from Talairach TT_N27 space to MNI
   #  using warp computed above
   3dNwarpApply -nwarp \
 '../TTN27_to_MNI152_2009c/anatQQ.TTN27_WARP.nii ../TTN27_to_MNI152_2009c/anatQQ.TTN27.aff12.1D' \
     -prefix temp_MNI2009c_desai_${atlas}_MPM.nii.gz -interp NN -short \
     -source ~/abin/TT_desai_${atlas}_mpm+tlrc. -master $master -overwrite
   # modally smooth the warped atlas to get rid of irregular edges
   3dLocalstat -prefix MNI2009c_desai_${atlas}_MPM.nii.gz \
     -stat mode -nbhd 'SPHERE(1.8)' -datum byte -overwrite \
     temp_MNI2009c_desai_${atlas}_MPM.nii.gz
   # mark these as MNI space and 
   3drefit -cmap INT_CMAP -space MNI MNI2009c_desai_${atlas}_MPM.nii.gz
   3drefit -copytables ~/abin/TT_desai_${atlas}_mpm+tlrc. MNI2009c_desai_${atlas}_MPM.nii.gz
end

