-
Notifications
You must be signed in to change notification settings - Fork 3
/
dcm_batch.bash
executable file
·155 lines (118 loc) · 3.53 KB
/
dcm_batch.bash
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# "include" the set of common script functions
source common.bash
declare -i Gi_verbose=0
declare -i Gb_useOverrideOut=0
declare -i Gb_forceStage=1
declare -i Gb_scanAll=0
DICOMDIR="/chb/users/dicom/files"
MRISLIST=""
G_SYNOPSIS="
NAME
dcm_MRIDget.bash
SYNOPSIS
dcm_MRIDget.bash [-v <verbosity>] \\
[-d <dicomDir>] \\
[-a] \\
[<DICOMDIR1> <DICOMDIR2> ... <DICOMDIRn>]
DESCRIPTION
'dcm_MRIDgetXML.bash' targets a given <dicomDir>, and for each
subdirectory, checks for the MRID.
ARGUMENTS
-v <level> (optional)
Verbosity level.
-d <dicomDir> (optional)
The 'root' directory containing dicom subdirs.
Defaults to $DICOMDIR.
-a (optional)
Scan all directories in <dicomDir>. By default, the script will
only flag the first directory containing the MRID. For multiple
scans of the same MRID, the *entire* directory needs to be scanned.
<DICOMDIR1> <DICOMDIR2> ... <DICOMDIRn>
A list of target DICOM dirs. If specified, dcm_MRIDget will only search
for these DICOM dirs, otherwise all MRIDs in <dicomDir> will be shown.
PRECONDITIONS
o Assumes that the <dicomDir> is a 'root' directory containing
subdirectories, each of which contains dicoms for a particular
MRID.
o FreeSurfer env.
POSTCONDITIONS
o For each subdir in <dicomDir>, the MRID associated with each
subdir is displayed. If a MRID is specified on the command line
the script will only output the particular subdirectory containing
the passed MRID.
HISTORY
12 March 2010
o Initial design and coding.
"
###\\\
# Globals are in capital letters. Immutable globals are prefixed by 'G'.
###///
# Actions
A_noDCMFILE="checking for <DCMFILE>"
A_noDICOMDIR="checking on <dicomDir>"
A_noSubjectsDirVar="checking environment"
# Error messages
EM_noDCMFILE="could not read <DCMFILE>."
EM_noDICOMDIR="could not find <dicomDir>."
EM_noSubjectsDirVar="it seems that the SUBJECTS_DIR environment var is not set."
# Error codes
EC_noDCMFILE=1
EC_noDICOMDIR=2
EC_noSubjectsDir=10
# Defaults
D_whatever=
###\\\
# Function definitions
###///
###\\\
# Process command options
###///
while getopts d:v:a option ; do
case "$option"
in
d) DICOMDIR=$OPTARG ;;
a) let Gb_scanAll=1 ;;
v) let Gi_verbose=$OPTARG ;;
\?) synopsis_show
exit 0;;
esac
done
verbosity_check
topDir=$(pwd)
printf "%40s" "Checking for SUBJECTS_DIR env variable"
b_subjectsDir=$(set | grep SUBJECTS_DIR | wc -l)
if (( !b_subjectsDir )) ; then
fatal noSubjectsDirVar
fi
ret_check $?
printf "%40s" "Checking for <dicomDir>"
dirExist_check $DICOMDIR || fatal noDICOMDIR
cd $DICOMDIR ; DICOMDIR=$(pwd) ; cd $topDir
shift $(($OPTIND - 1))
DCMLIST=$*
b_DCMLIST=$(echo $DCMLIST | wc -w)
cd $DICOMDIR
let hitCount=0
let b_hit=0
exec 1>&6 6>&-
if (( !b_DCMLIST )) ; then
echo "<?xml version=\"1.0\"?>"
fi
for DIR in * ; do
dirExist_check $DIR >/dev/null
if (( !$? )) ; then
cd "$DIR" >/dev/null 2>/dev/null;
DCMMKINDX=""
if [ -f toc.txt ] ; then
dcm_mkIndx.bash -a > toc.txt
fi
cd $DICOMDIR;
fi
done
verbosity_check
if (( b_hit )) ; then
shut_down 0
else
shut_down 1
fi