X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=cluster_tools%2Fgate_power_merge.sh;h=a0c3e183318d0fbdd17c338dc6e2ecdaa315c303;hb=996c472dd4315215c25890d6b8a9b565413352f7;hp=cc4203a6e000e5871d929cbd730196e577774760;hpb=bf524e64011b3d10ce2ee7b86236e4c53efb8e5f;p=clitk.git diff --git a/cluster_tools/gate_power_merge.sh b/cluster_tools/gate_power_merge.sh index cc4203a..a0c3e18 100755 --- a/cluster_tools/gate_power_merge.sh +++ b/cluster_tools/gate_power_merge.sh @@ -319,16 +319,19 @@ function merge_dispatcher { if test ${nboutputdirs} -ne ${nboutputfiles} then warning "missing files" - return + if ! test "${2}" == "--force" + then + return + fi fi local firstpartialoutputfile="$(echo "${partialoutputfiles}" | head -n 1)" local firstpartialoutputextension="${firstpartialoutputfile##*.}" echo "${indent}testing file type on ${firstpartialoutputfile}" - if test "${firstpartialoutputextension}" == "hdr" && grep -qs 'INTERFILE' "${firstpartialoutputfile}" + if test "${firstpartialoutputextension}" == "hdr" && test grep -qs 'INTERFILE' "${firstpartialoutputfile}" then - echo "${indent}this is a interfile image" + echo "${indent}this is an interfile image" echo "${indent}creating mhd headers" for partialoutputfile in $partialoutputfiles; do write_mhd_header "${partialoutputfile}"; done local mhd_partialoutputfiles="$(for partialoutputfile in $partialoutputfiles; do echo "${partialoutputfile%.*}.mhd"; done)" @@ -344,7 +347,7 @@ function merge_dispatcher { if test "${firstpartialoutputextension}" == "hdr" then - echo "${indent}this is a analyse image" + echo "${indent}this is an analyse image" local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" merge_hdr_image "${mergedfile}" ${partialoutputfiles} || error "error while merging" return @@ -436,7 +439,10 @@ function merge_dispatcher_uncertainty { if test ${nboutputdirs} -ne ${nboutputfiles} then warning "missing files" - return + if ! test "${2}" == "--force" + then + return + fi fi local firstpartialoutputfile="$(echo "${partialoutputfiles}" | head -n 1)" @@ -444,7 +450,7 @@ function merge_dispatcher_uncertainty { if [[ "${firstpartialoutputfile}" == *Uncertainty* ]] then - if test "${firstpartialoutputextension}" == "mhd" || test "${firstpartialoutputextension}" == "mha" + if test "${firstpartialoutputextension}" == "mhd" || test "${firstpartialoutputextension}" == "mha" then echo "${indent}Uncertainty file found: ${firstpartialoutputfile}" ## search for sum @@ -466,7 +472,14 @@ function merge_dispatcher_uncertainty { echo "${indent}${squared_merged_file} found" ## search for NumberOfEvent totalEvents=0; - 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) + unamestr=`uname` + if [[ "$unamestr" == 'Darwin' ]]; then + files=$(find -L "${rundir}" -type f -regex ".*output.*[hdr|mhd|mha|root|txt]" | awk -F '/' '{ print $NF; }' | sort | uniq) + else + files=$(find -L "${rundir}" -regextype 'posix-extended' -type f -regex "${rundir}/output.*\.(hdr|mhd|mha|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) + fi + echo $files + for outputfile in ${files} do #echo $outputfile if grep -q 'NumberOfEvent' "${outputdir}/${outputfile}" @@ -485,7 +498,7 @@ 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 + else error "merge_dispatcher_uncertainty does not handle ${firstpartialoutputfile} files" fi fi @@ -493,8 +506,11 @@ function merge_dispatcher_uncertainty { } echo "!!!! this is $0 v0.3k !!!!" +echo "Usage: gate_power_merge.sh run.dir [--force]" +echo " where --force allows to merge files even if the file is missing in some output directories" rundir="${1?"provide run dir"}" +force=${2:-""} rundir="$(echo "${rundir}" | sed 's|/*$||')" nboutputdirs="$(find "${rundir}" -mindepth 1 -type d -name 'output*' -o -type l -name 'output*' | wc -l)" @@ -511,16 +527,32 @@ echo "output dir is ${outputdir}" test -d "${outputdir}" && rm -r "${outputdir}" mkdir "${outputdir}" -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) + +unamestr=`uname` +if [[ "$unamestr" == 'Darwin' ]]; then + files=$(find -L "${rundir}" -type f -regex ".*output.*[hdr|mhd|mha|root|txt]" | awk -F '/' '{ print $NF; }' | sort | uniq) +else + files=$(find -L "${rundir}" -regextype 'posix-extended' -type f -regex "${rundir}/output.*\.(hdr|mhd|mha|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) +fi +echo files $files +for outputfile in ${files} do - merge_dispatcher "${outputfile}" + merge_dispatcher "${outputfile}" "${force}" done echo "" echo "Merging done. Special case for statistical uncertainty" -for outputfile in $(find -L "${outputdir}" -regextype 'posix-extended' -type f -regex "${outputdir}/.*\.(hdr|mhd|mha|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) + +unamestr=`uname` +if [[ "$unamestr" == 'Darwin' ]]; then + files=$(find -L "${outputdir}" -type f -regex ".*[hdr|mhd|mha|root|txt]" | awk -F '/' '{ print $NF; }' | sort | uniq) +else + files=$(find -L "${outputdir}" -regextype 'posix-extended' -type f -regex "${outputdir}/.*\.(hdr|mhd|mha|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) +fi +echo files = $files +for outputfile in ${files} do - merge_dispatcher_uncertainty "${outputfile}" + merge_dispatcher_uncertainty "${outputfile}" "${force}" done if [ -f "${rundir}/params.txt" ]