From cbbc5b0fddd41780944974b285d98bea5c3f04e7 Mon Sep 17 00:00:00 2001 From: Gauthier Bouilhol Date: Tue, 27 Sep 2011 18:15:11 +0200 Subject: [PATCH] search prefix and suffix --- scripts/create_mhd_4D.sh | 111 ++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 55 deletions(-) diff --git a/scripts/create_mhd_4D.sh b/scripts/create_mhd_4D.sh index bc51da4..5b60244 100755 --- a/scripts/create_mhd_4D.sh +++ b/scripts/create_mhd_4D.sh @@ -35,80 +35,81 @@ then exit 1 fi -########## CT ######### -list_pattern="" +list_prefix="" list_phase_file=`find $1 -maxdepth 1 -iname "*[0-9]*.mhd"` for phase_file in $list_phase_file do phase_file_name=`basename $phase_file` - if [[ ! -z `echo "$phase_file_name" | grep ","` ]] + if [[ ! -z `echo "$phase_file_name" | grep "__[0-9]"` ]] then - prefix=`echo $phase_file_name | sed "s/,_.*/,_/"` + prefix=`echo $phase_file_name | sed "s/__[0-9].*/__/"` else - prefix="NONE" + if [[ ! -z `echo "$phase_file_name" | grep "[0-9]-.*\]"` ]] + then + if [[ ! -z `echo "$phase_file_name" | grep "[0-9][0-9]-.*\]"` ]] + then + prefix=`echo $phase_file_name | sed "s/[0-9][0-9]-.*//"` + else + prefix=`echo $phase_file_name | sed "s/[0-9]-.*//"` + fi + else + prefix="NONE" + fi fi - if [[ -z `echo "$list_pattern" | grep "$prefix"` ]] - then - list_pattern="$list_pattern $prefix" - fi -done - -for pattern in $list_pattern -do - - if [ "$pattern" = "NONE" ] + if [[ -z `echo "$list_prefix" | grep "$prefix"` ]] then - pattern="" + list_prefix="$list_prefix $prefix" fi - - nbph=`find $1 -maxdepth 1 -iname "${pattern}*[0-9]*.mhd" | wc -l` - orig=`find $1 -maxdepth 1 -iname "${pattern}*[0-9]*.mhd" | sort | head -n 1` - listph=`find $1 -maxdepth 1 -iname "${pattern}*[0-9]*.raw" | sort` - - file_name_4D="${pattern}_4D.mhd" - echo $file_name_4D - - write_mhd_4D $1 - done -############ PET ########### - -list_pattern="" -list_phase_file=`find $1 -maxdepth 1 -iname "*[0-9]*\]*.mhd"` -for phase_file in $list_phase_file +for prefix in $list_prefix do - phase_file_name=`basename $phase_file` - if [[ ! -z `echo "$phase_file_name" | grep "[0-9]-.*\]"` ]] - then - prefix=`echo $phase_file_name | sed "s/.*[0-9]-/-/;s/\]_.*//"` - else - prefix="NONE" - fi - if [[ -z `echo "$list_pattern" | grep -- "$prefix"` ]] + if [ "$prefix" = "NONE" ] then - list_pattern="$list_pattern $prefix" + prefix="" fi -done - -for pattern in $list_pattern -do - - if [ "$pattern" = "NONE" ] - then - pattern="" - fi + list_suffix="" + list_phase_file_prefix=`find $1 -maxdepth 1 -iname "${prefix}[0-9]*.mhd"` + for phase_file_prefix in $list_phase_file_prefix + do + phase_file_prefix_name=`basename $phase_file_prefix` + if [[ ! -z `echo "$phase_file_prefix_name" | grep "__[0-9]"` ]] + then + suffix="NONE" + else + if [[ ! -z `echo "$phase_file_prefix_name" | grep "[0-9]-.*\]"` ]] + then + suffix=`echo $phase_file_prefix_name | sed "s/.*[0-9]-//;s/_\.mhd//;s/\.mhd//"` + else + suffix="NONE" + fi + fi + + if [[ -z `echo "$list_suffix" | grep "$suffix"` ]] + then + list_suffix="$list_suffix $suffix" + fi + done - nbph=`find $1 -maxdepth 1 -iname "*[0-9]${pattern}\]*.mhd" | wc -l` - orig=`find $1 -maxdepth 1 -iname "*[0-9]${pattern}\]*.mhd" | sort | head -n 1` - listph=`find $1 -maxdepth 1 -iname "*[0-9]${pattern}\]*.raw" | sort` - - file_name_4D=`basename "$orig" | sed "s/[0-9]${pattern}\]/${pattern}\]/;s/_.mhd/_4D.mhd/"` + for suffix in $list_suffix + do + if [ "$suffix" = "NONE" ] + then + suffix="" + fi + nbph=`find $1 -maxdepth 1 -iname "*${prefix}*[0-9]*${suffix}*.mhd" | wc -l` + orig=`find $1 -maxdepth 1 -iname "*${prefix}*[0-9]*${suffix}*.mhd" | sort | head -n 1` + listph=`find $1 -maxdepth 1 -iname "*${prefix}*[0-9]*${suffix}*.raw" | sort` + + file_name_4D="${prefix}4D${suffix}.mhd" + + write_mhd_4D $1 - write_mhd_4D $1 + done done + -- 2.47.1