#!/bin/tcsh -f

set subj = 620

MAP_TO_SURF:
foreach hemi (lh rh)
   
   #Average over gray matter
   if ( ! -f ${hemi}.s${subj}_rest_r1.clean.niml.dset ) then
      3dVol2Surf  -spec SUMA/s${subj}_${hemi}.spec   \
                  -sv s${subj}_SurfVol_Alnd_Exp+orig     \
                  -surf_A ${hemi}.smoothwm               \
                  -surf_B ${hemi}.pial                   \
                  -f_steps    10                         \
                  -f_index    nodes                      \
                  -map_func   ave                        \
                  -grid_parent s${subj}_rest_r1.clean+orig \
                  -out_niml ${hemi}.s${subj}_rest_r1.clean.niml.dset  \
                  -oob_value 0
   endif
   
   #Average only within 2mm from wm surface
   if ( ! -f ${hemi}.s${subj}_rest_r1.clean.wm.niml.dset ) then
      3dVol2Surf  -spec SUMA/s${subj}_${hemi}.spec   \
                  -sv s${subj}_SurfVol_Alnd_Exp+orig     \
                  -surf_A ${hemi}.smoothwm               \
                  -surf_B ${hemi}.pial                   \
                  -f_steps    4                         \
                  -f_index    nodes                      \
                  -map_func   ave                        \
                  -f_p1_mm 0.0                           \
                  -f_pn_fr -0.5                          \
                  -grid_parent s${subj}_rest_r1.clean+orig \
                  -out_niml ${hemi}.s${subj}_rest_r1.clean.wm.niml.dset  \
                  -oob_value 0
   endif  
end

#BLUR data
foreach hemi (lh rh)
   foreach sm (2 4 6 8) 
      if ( ! -f ${hemi}.s${subj}_rest_r1.clean.wm.sm${sm}.niml.dset ) then   
         SurfSmooth  -spec SUMA/s${subj}_${hemi}.spec   \
                     -surf_A ${hemi}.smoothwm   \
                     -met HEAT_07      \
                     -blurmaster ${hemi}.s${subj}_rest_r1.clean.wm.niml.dset  \
                     -target_fwhm $sm  \
                     -input ${hemi}.s${subj}_rest_r1.clean.wm.niml.dset  \
                     -output ${hemi}.s${subj}_rest_r1.clean.wm.sm${sm}.niml.dset       endif     
   end
end

