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"
18 echo "$ph" >> "$1/$file_name_4D"
22 #################################################
23 # create_mhd_4D argument : repertoire #
24 #################################################
27 echo "Usage: create_mhd_4D.sh DIRECTORY"
31 nb_phase_file=`find $1 -maxdepth 1 -iname "*[0-9]*.mhd" -o -iname "*[0-9]*\]*.mhd" | wc -l`
32 if [ $nb_phase_file = 0 ]
34 echo "Error: no phase found"
38 ########## CT #########
41 list_phase_file=`find $1 -maxdepth 1 -iname "*[0-9]*.mhd"`
42 for phase_file in $list_phase_file
44 phase_file_name=`basename $phase_file`
45 if [[ ! -z `echo "$phase_file_name" | grep ","` ]]
47 prefix=`echo $phase_file_name | sed "s/,_.*/,_/"`
51 if [[ -z `echo "$list_pattern" | grep "$prefix"` ]]
53 list_pattern="$list_pattern $prefix"
58 for pattern in $list_pattern
61 if [ "$pattern" = "NONE" ]
66 nbph=`find $1 -maxdepth 1 -iname "${pattern}*[0-9]*.mhd" | wc -l`
67 orig=`find $1 -maxdepth 1 -iname "${pattern}*[0-9]*.mhd" | sort | head -n 1`
68 listph=`find $1 -maxdepth 1 -iname "${pattern}*[0-9]*.raw" | sort`
70 file_name_4D="${pattern}_4D.mhd"
78 ############ PET ###########
81 list_phase_file=`find $1 -maxdepth 1 -iname "*[0-9]*\]*.mhd"`
82 for phase_file in $list_phase_file
84 phase_file_name=`basename $phase_file`
85 if [[ ! -z `echo "$phase_file_name" | grep "[0-9]-.*\]"` ]]
87 prefix=`echo $phase_file_name | sed "s/.*[0-9]-/-/;s/\]_.*//"`
91 if [[ -z `echo "$list_pattern" | grep -- "$prefix"` ]]
93 list_pattern="$list_pattern $prefix"
98 for pattern in $list_pattern
101 if [ "$pattern" = "NONE" ]
106 nbph=`find $1 -maxdepth 1 -iname "*[0-9]${pattern}\]*.mhd" | wc -l`
107 orig=`find $1 -maxdepth 1 -iname "*[0-9]${pattern}\]*.mhd" | sort | head -n 1`
108 listph=`find $1 -maxdepth 1 -iname "*[0-9]${pattern}\]*.raw" | sort`
110 file_name_4D=`basename "$orig" | sed "s/[0-9]${pattern}\]/${pattern}\]/;s/_.mhd/_4D.mhd/"`