6 cat $orig | sed "s/NDims = .*/NDims = 4/
7 s/TransformMatrix = .*/TransformMatrix = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1/
9 /CenterOfRotation/ s/.*/& 0/
10 s/AnatomicalOrientation = .*/AnatomicalOrientation = ????/
11 /ElementSpacing/ s/.*/& 1/
12 /DimSize/ s/.*/& $nbph/
13 s/ElementDataFile = .*/ElementDataFile = LIST/" > "$1/$file_name_4D"
15 for ph in ${listph[@]}
18 echo "$ph" >> "$1/$file_name_4D"
23 #################################################
24 # create_mhd_4D argument : repertoire #
25 #################################################
28 echo "Usage: create_mhd_4D.sh DIRECTORY"
32 nb_phase_file=`find $1 -maxdepth 1 -iname "*[0-9]*.mhd" | wc -l`
33 if [ $nb_phase_file = 0 ]
35 echo "No phase found in $1"
41 list_phase_file=`find $1 -maxdepth 1 -iname "*[0-9]*.mhd"`
42 for phase_file in $list_phase_file
44 if grep -q "NDims = 4" $phase_file 2> /dev/null
46 #echo $phase_file is 4D
50 phase_file_name=`basename $phase_file .mhd`
51 # if [[ ! -z `echo "$phase_file_name" | grep "__[0-9]"` ]]
53 # prefix=`echo $phase_file_name | sed "s/__[0-9].*/__/"`
55 # if [[ ! -z `echo "$phase_file_name" | grep "[0-9]-.*\]"` ]]
57 # if [[ ! -z `echo "$phase_file_name" | grep "[0-9][0-9]-.*\]"` ]]
59 # prefix=`echo $phase_file_name | sed "s/[0-9][0-9]-.*//"`
61 # prefix=`echo $phase_file_name | sed "s/[0-9]-.*//"`
68 # preffix: grep sequence of characters followed by sequence of numbers and remove sequence of numbers
69 # prefix=`echo $phase_file_name | grep -o "\(^[[:alpha:][:punct:]]*\)\([[:digit:]\.\_\-]\+\)" | sed 's/\(^[[:alpha:][:punct:]]*\)\([[:digit:]\.\_\-]\+\)/\1/'`
70 prefix=`echo $phase_file_name | grep -o "\(^[[:alpha:][:punct:]]*\)\([[:digit:]]\+\)\([\.\_\-]*\)"`
71 prefix=`echo $prefix | sed 's/^\-\+//' | sed 's/\(^[[:alpha:][:punct:]]*\)\([[:digit:]]\+\)\([\.\_\-]*\)/\1/'`
77 # register new preffix if not yet done
78 if [[ -z `echo "$list_prefix" | grep -w -- "$prefix"` ]]
80 list_prefix="$list_prefix $prefix"
85 for prefix in $list_prefix
87 if [ "$prefix" = "NONE" ]
93 list_phase_file_prefix=`find $1 -maxdepth 1 -iname "${prefix}[0-9]*.mhd"`
94 for phase_file_prefix in $list_phase_file_prefix
96 if grep -q "NDims = 4" $phase_file_prefix 2> /dev/null
98 #echo $phase_file_prefix is 4D
101 phase_file_prefix_name=`basename $phase_file_prefix .mhd`
102 # if [[ ! -z `echo "$phase_file_prefix_name" | grep "__[0-9]"` ]]
106 # if [[ ! -z `echo "$phase_file_prefix_name" | grep "[0-9]-.*\]"` ]]
108 # suffix=`echo $phase_file_prefix_name | sed "s/.*[0-9]-//;s/_\.mhd//;s/\.mhd//"`
115 # suffix: grep sequence of numbers followed by sequence of characters and remove sequence of numbers
116 # suffix=`echo $phase_file_prefix_name | grep -o "\([[:digit:]\.\_\-]\+\)\([[:alpha:][:punct:]]*$\)" | sed 's/\([[:digit:]\.\_\-]\+\)\([[:alpha:][:punct:]]*$\)/\2/'`
117 suffix=`echo $phase_file_prefix_name | grep -o "\([\.\_\-]*\)\([[:digit:]]\+\)\([[:alpha:][:punct:]]*$\)"`
118 if ! echo $suffix | grep -qo "^\-\+"; then
119 suffix=`echo $suffix | sed 's/\([\.\_\-]*\)\([[:digit:]]\+\)\([[:alpha:][:punct:]]*$\)/\3/'`
121 suffix=`echo $suffix | sed 's/[\.\_\-]\+$//'`
127 # register new suffix if not yet done
128 if [[ -z `echo "$list_suffix" | grep -w -- "$suffix"` ]]
130 list_suffix="$list_suffix $suffix"
135 for suffix in $list_suffix
137 if [ "$suffix" = "NONE" ]
141 orig=`find $1 -maxdepth 1 -iname "${prefix}[0-9]*${suffix}*.mhd" | grep "${prefix}[[:digit:][:punct:]]\+${suffix}[\.\_\-]*.mhd" | sort | head -n 1`
142 listph=( `find $1 -maxdepth 1 -iname "${prefix}[0-9]*${suffix}*.*raw" | grep "${prefix}[[:digit:][:punct:]]\+${suffix}[\.\_\-]*.z*raw" | sort` )
145 # only create 4D file if potential number of phases is > 1
146 if [ $nbph -gt 1 ]; then
147 file_name_4D="${prefix}4D${suffix}.mhd"