X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=cluster_tools%2Fgate_power_merge.sh;h=cc4203a6e000e5871d929cbd730196e577774760;hb=bf524e64011b3d10ce2ee7b86236e4c53efb8e5f;hp=ab9ac976a06c3a392cb34ac35702cdb5600953a6;hpb=2b65b28b2a3f522d2f2dba7f6831220bedc423c7;p=clitk.git diff --git a/cluster_tools/gate_power_merge.sh b/cluster_tools/gate_power_merge.sh index ab9ac97..cc4203a 100755 --- a/cluster_tools/gate_power_merge.sh +++ b/cluster_tools/gate_power_merge.sh @@ -272,6 +272,7 @@ test -x "./clitkImageArithm" && mhdImageMerger="./clitkImageArithm" function merge_mhd_image { local merged="$1" local merged_bin="${merged%.*}.raw" + local last_character=${merged#${merged%?}} shift echo " ${indent}entering mhd image merger" echo " ${indent}merger is ${mhdImageMerger}" @@ -289,14 +290,20 @@ function merge_mhd_image { then update_bar ${count} "copying first partial result ${partial}" cp "${partial}" "${merged}" - cp "${partial_bin}" "${merged_bin%.*}.${partial_bin##*.}" + if test "$last_character" = "d" + then + cp "${partial_bin}" "${merged_bin%.*}.${partial_bin##*.}" + fi continue fi update_bar ${count} "adding ${partial}" ${mhdImageMerger} -t 0 -i "${partial}" -j "${merged}" -o "${merged}" 2> /dev/null > /dev/null || warning "error while calling ${mhdImageMerger}" - mv "${merged_bin}" "${merged_bin%.*}.${partial_bin##*.}" - sed -i "s/$(basename "${merged_bin}")/$(basename "${merged_bin%.*}.${partial_bin##*.}")/" "${merged}" + if test "$last_character" = "d" && test "${merged_bin}" != "${merged_bin%.*}.${partial_bin##*.}" + then + mv "${merged_bin}" "${merged_bin%.*}.${partial_bin##*.}" + sed -i "s/$(basename "${merged_bin}")/$(basename "${merged_bin%.*}.${partial_bin##*.}")/" "${merged}" + fi done end_bar echo " ${indent}merged ${count} files" @@ -307,7 +314,7 @@ function merge_dispatcher { local outputfile="${1:?"provide output filename"}" echo "merging ${outputfile}" - local partialoutputfiles="$(find "${rundir}" -mindepth 2 -type f -name "${outputfile}")" + local partialoutputfiles="$(find -L "${rundir}" -mindepth 2 -type f -name "${outputfile}")" local nboutputfiles="$(echo "${partialoutputfiles}" | wc -l)" if test ${nboutputdirs} -ne ${nboutputfiles} then @@ -343,7 +350,7 @@ function merge_dispatcher { return fi - if test "${firstpartialoutputextension}" == "mhd" + if test "${firstpartialoutputextension}" == "mhd" || test "${firstpartialoutputextension}" == "mha" then echo "${indent}this is a mhd image" local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" @@ -424,7 +431,7 @@ function merge_dispatcher_uncertainty { local indent=" ** " local outputfile="${1:?"provide output filename"}" - local partialoutputfiles="$(find "${rundir}" -mindepth 2 -type f -name "${outputfile}")" + local partialoutputfiles="$(find -L "${rundir}" -mindepth 2 -type f -name "${outputfile}")" local nboutputfiles="$(echo "${partialoutputfiles}" | wc -l)" if test ${nboutputdirs} -ne ${nboutputfiles} then @@ -437,7 +444,7 @@ function merge_dispatcher_uncertainty { if [[ "${firstpartialoutputfile}" == *Uncertainty* ]] then - if test "${firstpartialoutputextension}" == "mhd" + if test "${firstpartialoutputextension}" == "mhd" || test "${firstpartialoutputextension}" == "mha" then echo "${indent}Uncertainty file found: ${firstpartialoutputfile}" ## search for sum @@ -459,7 +466,7 @@ function merge_dispatcher_uncertainty { echo "${indent}${squared_merged_file} found" ## search for NumberOfEvent totalEvents=0; - for outputfile in $(find "${rundir}" -regextype 'posix-extended' -type f -regex "${rundir}/output.*\.(hdr|mhd|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) + for outputfile in $(find -L "${rundir}" -regextype 'posix-extended' -type f -regex "${rundir}/output.*\.(hdr|mhd|mha|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) do #echo $outputfile if grep -q 'NumberOfEvent' "${outputdir}/${outputfile}" @@ -478,6 +485,8 @@ function merge_dispatcher_uncertainty { warning "${totalEvents} not positive. A at least one stat file (SimulationStatisticActor) must be provided. Error, no uncertainty computed" return; fi + else + error "merge_dispatcher_uncertainty does not handle ${firstpartialoutputfile} files" fi fi @@ -487,7 +496,7 @@ echo "!!!! this is $0 v0.3k !!!!" rundir="${1?"provide run dir"}" rundir="$(echo "${rundir}" | sed 's|/*$||')" -nboutputdirs="$(find "${rundir}" -mindepth 1 -type d -name 'output*' | wc -l)" +nboutputdirs="$(find "${rundir}" -mindepth 1 -type d -name 'output*' -o -type l -name 'output*' | wc -l)" test ${nboutputdirs} -gt 0 || error "no output dir found" echo "found ${nboutputdirs} partial output dirs" @@ -502,15 +511,14 @@ echo "output dir is ${outputdir}" test -d "${outputdir}" && rm -r "${outputdir}" mkdir "${outputdir}" - -for outputfile in $(find "${rundir}" -regextype 'posix-extended' -type f -regex "${rundir}/output.*\.(hdr|mhd|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) +for outputfile in $(find -L "${rundir}" -regextype 'posix-extended' -type f -regex "${rundir}/output.*\.(hdr|mhd|mha|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) do merge_dispatcher "${outputfile}" done echo "" echo "Merging done. Special case for statistical uncertainty" -for outputfile in $(find "${outputdir}" -regextype 'posix-extended' -type f -regex "${outputdir}/output.*\.(hdr|mhd|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) +for outputfile in $(find -L "${outputdir}" -regextype 'posix-extended' -type f -regex "${outputdir}/.*\.(hdr|mhd|mha|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) do merge_dispatcher_uncertainty "${outputfile}" done @@ -521,4 +529,10 @@ then cp "${rundir}/params.txt" "${outputdir}/params.txt" fi +if [ -d "${rundir}/mac" ] +then + echo "copying mac folder" + cp -r "${rundir}/mac" "${outputdir}/mac" +fi + echo "these was ${warning_count} warning(s)"