]> Creatis software - clitk.git/blob - scripts/create_mhd_4D-2.0.sh
new SetBackground filter
[clitk.git] / scripts / create_mhd_4D-2.0.sh
1 #!/bin/sh +x
2
3
4 write_mhd_4D()
5 {
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/
8                   /Offset/ s/.*/& 0/
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"
14   
15   for ph in $listph
16   do
17     phase=`basename $ph`
18     echo "$phase" >> "$1/$file_name_4D"
19   done
20 }
21
22 #################################################
23 # create_mhd_4D         argument : repertoire   #
24 #################################################
25 if [ $# -lt 1 ]
26 then
27   echo "Usage: create_mhd_4D.sh DIRECTORY"
28   exit 1
29 fi
30
31 dirname=`dirname $1`
32 pattern=`basename $1`
33
34 list_phase_file=`ls -1 $1*[0-9].mhd`
35 nb_phase_file=`ls -1 $1*[0-9].mhd | wc -l`
36 if [ $nb_phase_file = 0 ]
37 then
38   echo "Error: no phase found"
39   exit 1
40 fi
41
42 nbph=$nb_phase_file
43 orig=`echo $list_phase_file | cut -f 1 -d ' '`
44 listph=`echo $list_phase_file | sed 's:\.mhd:\.raw:g'`
45
46 file_name_4D=`echo "${pattern}4D.mhd"`
47
48 write_mhd_4D $dirname
49 echo "$dirname/$file_name_4D"