-
Notifications
You must be signed in to change notification settings - Fork 1
/
findVols.sh
executable file
·101 lines (87 loc) · 1.79 KB
/
findVols.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
#!/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
#
# Modified to accept a file extension for finding files.
# 2012 Dec 18
#
# Explicitly put in exclusion of directoy name of ANALYZE
#
# Copyright Robert C. Welsh, Ann Arbor Michigan. 2005-2011
#
#
theDIRS=""
searchDir=$1
if [ -z "$1" ]
then
echo "Usage:"
echo
echo " findVols.sh [directory name] [volumeWILD] [subdir] [fileextension]"
echo ""
echo " e.g. findVols.sh 050128mh ravol"
echo
exit 0
fi
if [ ! -d $searchDir ]
then
exit
fi
# Bugger out if anatomy directory.
if [ $searchDir == "anatomy" ]
then
exit
fi
cd $searchDir
# Default to using just nii, the calling program has responsbility to set to img
if [ -z "${4}" ]
then
FILEXT=nii
else
FILEXT=$4
fi
# How many images are in this directory?
nIMGS=`ls $2*.${FILEXT}* 2> /dev/null | wc | awk '{print $1}'`
if (( $nIMGS > 0 ))
then
#
# Get the full path to the directory that contains
# our files of interest.
#
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
# Become recursive for the other directories present.
for newDIR in `ls -l 2> /dev/null | grep -e drw -e lrw | awk '{print $NF}'`
do
if [ -d "${newDIR}" ]
then
if [ "${newDIR}" != "ANALYZE" ]
then
foundDIR=`findVols.sh "$newDIR" "$2" "$3" "$FILEXT"`
if [ ! -z "${foundDIR}" ]
then
theDIRS=${theDIRS},${foundDIR}
fi
fi
fi
done
tmpDIRS=`echo $theDIRS | sed 's/,,/,/g'`
theDIRS=$tmpDIRS
echo $theDIRS
#
# All done.
#