#!/bin/tcsh

setenv FREESURFER_HOME /Applications/freesurfer/
source $FREESURFER_HOME/SetUpFreeSurfer.csh
#Must set SUBJECTS_DIR to where data is or else uses what was set up when installing freesurfer
#setenv SUBJECTS_DIR /Volumes/DANIEL/tutorial_data/diffusion_recons/
@ linenum = 1

#cd /Volumes/DANIEL/
#mkdir tutorial_data
#cd /Volumes/DANIEL/tutorial_data
#mkdir diffusion_recons
#cd /Volumes/DANIEL/
#make directory for all subjects FA data before loop


foreach subj (`ls -d /Volumes/DANIEL/AES1* | sed 's/\// /g' | awk '{print $3}'`)

foreach cond (Ex Rest)

echo "subj = " ${subj} ", cond = " ${cond}

#cp /Volumes/DANIEL/${subj}/${subj}.${cond}/dti_FDT_FA.nii.gz /Volumes/DANIEL/ROI_Analysis/${subj}.${cond}.dti_FDT_FA.nii.gz


mkdir /Volumes/DANIEL/tutorial_data/diffusion_recons/${subj}.${cond}
cd /Volumes/DANIEL/tutorial_data/diffusion_recons/${subj}.${cond}
cp /Applications/freesurfer/subjects/Freesurfer_output/${subj}.${cond}.fsoutput/mri/orig.mgz /Volumes/DANIEL/tutorial_data/diffusion_recons/${subj}.${cond}/orig.mgz

cp /Volumes/DANIEL/${subj}/${subj}.${cond}/DTI/*.dcm /Volumes/DANIEL/tutorial_data/diffusion_recons/${subj}.${cond}/

cd /Volumes/DANIEL/tutorial_data/diffusion_recons/${subj}.${cond}/
mri_convert image000001.dcm /Volumes/DANIEL/tutorial_data/diffusion_recons/${subj}.${cond}/dwi.nii.gz
dt_recon --sd /Volumes/DANIEL/tutorial_data/diffusion_recons/ --debug --i /Volumes/DANIEL/tutorial_data/diffusion_recons/${subj}.${cond}/image000001.dcm --s ${subj}.${cond} --o /Volumes/DANIEL/tutorial_data/dtrecon/${subj}.${cond}.
#--b bvalue.txt bvec.txt
end

end
