-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfindVols2.sh
executable file
·118 lines (102 loc) · 2.09 KB
/
findVols2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
#
# A little script to discard the first 2/3 volumes
# of any run. It will run recursively
# looking for files that end in 0001-0002/3
#
# Modified to look for NIFTI images (.nii or .nii.gz)
# 2011 April 18
#
# Copyright Robert C. Welsh, Ann Arbor Michigan. 2005-2011
#
theDIRS=""
searchDir=$1
if [ -z "$1" ]
then
echo "Usage:"
echo
echo " findVols2.sh directory_name [volumeWILD [subdir]"
echo ""
echo " e.g. findVols2.sh 050128mh ravol"
echo
exit 0
fi
if [ -z "$2" ]
then
echo "Usage:"
echo
echo " findVols2.sh directory_name volumeWILD [subdir]"
echo ""
echo " e.g. findVols2.sh 050128mh raprun"
echo
exit 0
fi
if [ ! -d $searchDir ]
then
exit
fi
# Bugger out if anatomy directory.
if [ $searchDir == "anatomy" ]
then
exit
fi
cd $searchDir
if [ ! -z $4 ]
then
PWD=`pwd `
echo "1: ${PWD}, 1:$1, 2:$2, 3:$3, 4:$4" >> ${HOME}/debug_findVols2.log
fi
# How many images (.nii only) are in this directory?
nIMGS=`ls $2*.nii 2> /dev/null | wc | awk '{print $1}'`
if (( $nIMGS > 0 ))
then
thisDIR=`pwd`
if [ -z "$3" ]
then
theDIRS=${theDIRS},${thisDIR}
else
yesno=`echo $thisDIR | grep $3`
if [ ! -z "$yesno" ]
then
theDIRS=${theDIRS},${thisDIR}
fi
fi
fi
if [ ! -z $4 ]
then
PWD=`pwd `
echo "2: ${PWD}, 1:$1, 2:$2, 3:$3, 4:$4" >> ${HOME}/debug_findVols2.log
fi
# Become recursive for the other directories present.
for newDIR in `ls -1 2> /dev/null`
do
if [ ! -z $4 ]
then
PWD=`pwd `
echo "3: ${PWD}, 1:$1, 2:$2, 3:$3, 4:$4" >> ${HOME}/debug_findVols2.log
fi
if [ -d "${newDIR}" ]
then
if [ ! -z $4 ]
then
PWD=`pwd `
echo "4: ${PWD}, 1:$1, 2:$2, 3:$3, 4:$4, newDIR:${newDIR}" >> ${HOME}/debug_findVols2.log
fi
foundDIR=`findVols2.sh $newDIR $2 $3 $4 | tail -1`
if [ ! -z "${foundDIR}" ]
then
theDIRS=${theDIRS},${foundDIR}
fi
if [ ! -z $4 ]
then
PWD=`pwd `
echo "5: ${PWD}, 1:$1, 2:$2, 3:$3, 4:$4" >> ${HOME}/debug_findVols2.log
fi
fi
done
tmpDIRS=`echo $theDIRS | sed 's/,,/,/g'`
theDIRS=$tmpDIRS
echo $theDIRS
#
# All done.
#