-
Notifications
You must be signed in to change notification settings - Fork 1
/
renameSLEICSerDirs
executable file
·41 lines (31 loc) · 1.14 KB
/
renameSLEICSerDirs
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
#!/bin/bash
if [ "$#" -eq 0 ]; then
TARGET=$( pwd )
else
TARGET="$1"
fi
[ ! -r "$TARGET" ] && echo "Target directory: $TARGET does not exist." && exit 1
cd $TARGET
#which dicom_hdr >/dev/null 2>&1
if command -v module >/dev/null && uname -a | grep -q aci.ics.psu.edu && ! command -v dicom_hdr >/dev/null; then
module load afni 2>&1 >/dev/null
fi
serList=$( find . -regex ".*ser[0-9]+.*" -type d | sort -n | xargs -n 1 basename )
#serList=$( ls -d ser[0-9]* )
for s in ${serList}; do
firstDicom=$( find "$s" -iname "1.3.12*" -type f -print -quit )
if [ -z "${firstDicom}" ]; then
echo "Unable to find any files of pattern 1.3.12* in dir: $s"
exit 1
fi
sername=$( dicom_hdr $firstDicom | grep -i "ACQ Protocol Name" | perl -pe "s:.*ACQ Protocol Name//(\w+).*$:\1:" )
sernumber=$( printf '%02d' ${s/ser/} )
#is this a single-band reference image?
sbref=
dicom_hdr $firstDicom | grep -q "REL Image Comments//Single-band reference" >/dev/null
if [ $? -eq 0 ]; then
sbref=_sbref
fi
mv "$s" "${sernumber}_${sername}${sbref}"
echo "$s" > "${sernumber}_${sername}${sbref}/.origdirname"
done