#!/bin/tcsh -f

set stat = 0
set hem = lh

if ("$1" == "-clean") then
   \rm -f v2s.??.DEL.smoothed.niml.dset 
   \rm -f v2s.??.DEL.smoothed.niml.dset.1D.smrec
   goto END
endif 


if ( ! -f v2s.${hem}.DEL.niml.dset ) then
   echo ""
   echo "Missing input data. To create then run:"
   echo "   tcsh ./run_3dVol2Surf "
   echo "then rerun tcsh `basename $0`"
   goto BEND
endif

set talkopt = "-npb `afni -available_npb_quiet` -pif SSD_demo"
@Quiet_Talkers -pif SSD_demo
suma        -spec   ../SurfData/SUMA/std.DemoSubj_${hem}.spec          \
            -sv DemoSubj_SurfVol_Alnd_Exp+orig                 \
            -niml $talkopt -dev  &
set mm = `prompt_user -pause "When SUMA is up, hit Enter for data smoothing"`
if ( ! $mm)   goto END
#Load a nice view
DriveSuma $talkopt -com viewer_cont -load_view SSD_demo.niml.vvs 
DriveSuma $talkopt -com viewer_cont -key 'R' 

#Blur without allowing leakage from nodes with no data (0 value)
SurfSmooth  $talkopt -overwrite \
            -spec    ../SurfData/SUMA/std.DemoSubj_${hem}.spec         \
            -surf_A  std.${hem}.smoothwm.asc                           \
            -met HEAT_07                                        \
            -blurmaster TS.${hem}.DEL.niml.dset                             \
            -target_fwhm 8                            \
            -input v2s.${hem}.DEL.niml.dset                       \
            -cmask "-a v2s.${hem}.DEL.niml.dset[0] -expr bool(a)"  \
            -output v2s.${hem}.DEL.smoothed.niml.dset -talk_suma        

goto END

BEND:
   set stat = 1

END:
   exit $stat
