X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2Fscripts%2Fcreate_mhd_4D.sh;h=ae3f5fa4711e094613353e4c2f835e8e6f66eeb4;hb=8519d8459a3cf5a6941c2a332ca9eba3671091c9;hp=238e26aa9b4e68f649fc13af46003d098ced77c3;hpb=2e5622ae26b0806d6617024abe4297e05bed9ffb;p=clitk.git diff --git a/vv/scripts/create_mhd_4D.sh b/vv/scripts/create_mhd_4D.sh index 238e26a..ae3f5fa 100755 --- a/vv/scripts/create_mhd_4D.sh +++ b/vv/scripts/create_mhd_4D.sh @@ -1,32 +1,73 @@ #!/bin/sh -##################################################################### -# create_mhd_4D argument : repertoire nom_fichier_de_sortie # -##################################################################### +################################################# +# create_mhd_4D argument : repertoire # +################################################# if [ $# -lt 1 ] then - echo "Usage: create_mhd_4D.sh directory output_file_name(without path)" - exit 1 + echo "Usage: create_mhd_4D.sh DIRECTORY" + exit 1 fi -cd $1 -nbph=`find . -iname "*0.mhd" | wc -l` -if [ $nbph = 0 ] +nb_phase_file=`find $1 -iname "*[0-99].[0-9].mhd" | wc -l` +if [ $nb_phase_file = 0 ] then - echo "Error: no phase found" - exit 1 + echo "Error: no phase found" + exit 1 fi -orig=`ls -1 *0.mhd | head -n 1` - -cat $orig | sed "s/NDims = .*/NDims = 4/ - s/TransformMatrix = .*/TransformMatrix = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1/ - /Offset/ s/.*/& 0/ - /CenterOfRotation/ s/.*/& 0/ - s/AnatomicalOrientation = .*/AnatomicalOrientation = ????/ - /ElementSpacing/ s/.*/& 1/ - /DimSize/ s/.*/& $nbph/ - s/ElementDataFile = .*/ElementDataFile = LIST/" > $2 - -ls -1 *0.raw >> $2 -cd .. + +list_pattern="" +list_phase_file=`find $1 -iname "*[0-99].[0-9].mhd"` +for phase_file in $list_phase_file +do + phase_file_name=`basename $phase_file` + if [[ ! -z `echo "$phase_file_name" | grep ","` ]] + then + preffix=`echo $phase_file_name | sed "s/,_.*/,_/"` + else + preffix="NONE" + fi + if [[ -z `echo "$list_pattern" | grep "$preffix"` ]] + then + list_pattern="$list_pattern $preffix" + fi +done + + +for pattern in $list_pattern +do + + if [ "$pattern" = "NONE" ] + then + pattern="" + fi + + nbph0=`find $1 -iname "${pattern}[0-9].[0-9].mhd" | wc -l` + orig0=`find $1 -iname "${pattern}[0-9].[0-9].mhd" | sort | head -n 1` + listph0=`find $1 -iname "${pattern}[0-9].[0-9].raw" | sort` + + nbph1=`find $1 -iname "${pattern}[0-9][0-9].[0-9].mhd" | wc -l` + orig1=`find $1 -iname "${pattern}[0-9][0-9].[0-9].mhd" | sort | head -n 1` + listph1=`find $1 -iname "${pattern}[0-9][0-9].[0-9].raw" | sort` + + nbph=$(( nbph0+nbph1 )) + orig=`echo -e "$orig0\n$orig1" | head -n 1` + listph="$listph0 $listph1" + + cat $orig | sed "s/NDims = .*/NDims = 4/ + s/TransformMatrix = .*/TransformMatrix = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1/ + /Offset/ s/.*/& 0/ + /CenterOfRotation/ s/.*/& 0/ + s/AnatomicalOrientation = .*/AnatomicalOrientation = ????/ + /ElementSpacing/ s/.*/& 1/ + /DimSize/ s/.*/& $nbph/ + s/ElementDataFile = .*/ElementDataFile = LIST/" > "$1/${pattern}_4D.mhd" + + for ph in $listph + do + ph=`basename $ph` + echo "$ph" >> "$1/${pattern}_4D.mhd" + done + +done