-
Notifications
You must be signed in to change notification settings - Fork 1
/
dcm2niiXL
executable file
·73 lines (70 loc) · 1.97 KB
/
dcm2niiXL
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
#! /bin/bash
# Run multiple instances of dcm2niix in parallel
#Example
# ./dcm2niiXL -f %p_%s -i y -z y -o ~/tst/out ~/dcm_qa/In/
#SETTINGS
# set numCores to 0 for autodetect, otherwise number of threads desired
numCores=0
# set number of depth of subdirectories to search
searchDepth=10
#CHECK INPUT
if [ $# -lt 1 ]; then
echo "Please call this script with input arguments"
echo " $0 -f %p_%s -i y -z y -o "~/tst/out" "~/dcm_qa/In/""
exit 1
fi
#get last input argument https://stackoverflow.com/questions/1853946/getting-the-last-argument-passed-to-a-shell-script
for lastArg; do true; done
if [ "$lastArg" == "" ];then
echo "Error: no input folder provided"
exit 1
fi
#CHECK NUMBER OF THREADS
if [ $numCores -lt 1 ] ; then
numCores=$(getconf _NPROCESSORS_ONLN)
if [ $numCores -lt 1 ] ; then
echo "unable to detect cores"
exit 1
fi
fi
echo "dcm2niix running $numCores threads"
#FIND EXECUTABLE
scriptdir=$(dirname $0)
if [ "$scriptdir" = "." ]; then
scriptdir=$(pwd)
fi
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) exe=$scriptdir/dcm2niixLinux;;
Darwin*) exe=$scriptdir/dcm2niixMacOS;;
esac
if [ ! -e $exe ]
then
echo "Error: Unable to find $exe"
exit 1
fi
#REMOVE LAST ARGUMENT
set -- "${@:1:$(($#-1))}"
#PROCESS FOLDERS
# n.b. limit number of active jobs
# https://stackoverflow.com/questions/1537956/bash-limit-the-number-of-concurrent-jobs?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
# https://stackoverflow.com/questions/1131484/wait-for-bash-background-jobs-in-script-to-be-finished?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
n=1
for d in $(find $lastArg -maxdepth $searchDepth -type d)
do
echo $exe -d 0 "$@" "$d"
$exe -d 0 "$@" "$d" &
nPID=`jobs -pr | wc -l`
while [ $nPID -ge $numCores ]; do
sleep 0.4
nPID=`jobs -pr | wc -l`
done
n=`expr $n + 1`
done
%pause until everything is done
nPID=`jobs -pr | wc -l`
while [ $nPID -ge 1 ]; do
sleep 0.4
nPID=`jobs -pr | wc -l`
done
exit 0