#!/bin/bash

#Charlotte Rae 2012

#Put me in your /home/bin/, and remember to make me executable with chmod a+rwx eddy_correct_data.

#1) Move bvals, bvecs and niftis to the proper subject folders and rename them something sensible.  
#2) Then, eddy_correct for eddy currents and subject motion.

subjs="110159 110309"
#Put your subject folders in here

#Write your main directory here
cd /imaging/cr01/folder/

echo "Moving bval files"
for zzVARbval in ${subjs} ; do
mv ${zzVARbval}/Series*/*.bval ${zzVARbval}/${zzVARbval}.bval
done

echo "Moving bvec files"
for zzVARbvec in ${subjs} ; do
mv ${zzVARbvec}/Series*/*.bvec ${zzVARbvec}/${zzVARbvec}.bvec
done

echo "Moving nifti files"
for zzVARnif in ${subjs} ; do
mv ${zzVARnif}/Series*/*.nii.gz ${zzVARnif}/${zzVARnif}.nii.gz
done

#2011:
#The eddy_correct command cannot be found unless you explicitly define the path:
#setenv FSLDIR /imaging/local/linux/bin/fsl-4.1.2
#source ${FSLDIR}/etc/fslconf/fsl.csh
#set path = (${FSLDIR}/bin $path)
#You will need to do this in each new terminal that you run eddy_correct in.  After you have done this, although you will be able to run eddy_corect, you will not be able to access scripts from your home bin (cr01/bin).  You will need to
#set path = (${FSLDIR}/bin/loadshare/bin $path)
#for FSL to find scripts in your home bin again.

#2012:
#Seems to be working ok now

for zzVARec in ${subjs} ; do
echo "${zzVARec} eddy correcting"
eddy_correct ${zzVARec}/${zzVARec}.nii.gz ${zzVARec}/${zzVARec}"ec".nii.gz 0
done


echo "End"

#eddy_correct usage
#eddy_correct PD_27/PD27.nii.gz PD_27/PD27.nii.gz 0
#eddy_correct <input> <output> <number of b0 image>
#(numbers of images start at 0, so if the first image is a b0, put 0, not 1)
