X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=cluster_tools%2Fgate_power_merge.sh;h=9710866e1e06e793de1a0fcb35daf858eb95e66a;hb=1f9f2c7ad25fb505ca3b7a1c316a69df1ddb6324;hp=53da5a907503e9de75f8411121f7d703561adc48;hpb=9e2cce65d56648c28451ab0dcfe1786862ce958d;p=clitk.git diff --git a/cluster_tools/gate_power_merge.sh b/cluster_tools/gate_power_merge.sh index 53da5a9..9710866 100755 --- a/cluster_tools/gate_power_merge.sh +++ b/cluster_tools/gate_power_merge.sh @@ -7,7 +7,9 @@ echo "ERROR: $1" exit 1 } +warning_count=0 function warning { +let "warning_count++" echo "WARNING: $1" } @@ -19,12 +21,13 @@ function update_bar { local count="${1:?"provide count"}" local message="${2:?"provide message"}" local percent=$(echo "100*${count}/${count_max}" | bc) -printf "[%03d/%03d] %3d%% %-80s\r" ${count} ${count_max} ${percent} "${message}" +#printf "[%03d/%03d] %3d%% %-80.80s\r" ${count} ${count_max} ${percent} "${message}" +printf "[%03d/%03d] %3d%% %-80.80s\n" ${count} ${count_max} ${percent} "${message}" } function end_bar { unset count_max -echo -ne '\n' +#echo -ne '\n' } rootMerger="clitkMergeRootFiles" @@ -45,12 +48,13 @@ do let count++ local arguments=" -i ${partial} ${arguments}" done -${rootMerger} ${arguments} || warning "error while calling ${rootMerger}" +${rootMerger} ${arguments} > /dev/null || { warning "error while calling ${rootMerger}" && return; } echo " ${indent}merged ${count} files" } statMerger="mergeStatFile.py" test -x "./mergeStatFile.sh" && statMerger="./mergeStatFile.sh" +test -x "./mergeStatFile.py" && statMerger="./mergeStatFile.py" function merge_stat { local merged="$1" @@ -74,7 +78,7 @@ do fi update_bar ${count} "adding ${partial}" - ${statMerger} -i "${merged}" -j "${partial}" -o "${merged}" || warning "error while calling ${statMerger}" + ${statMerger} -i "${merged}" -j "${partial}" -o "${merged}" 2> /dev/null > /dev/null || { warning "error while calling ${statMerger}" && return; } done end_bar echo " ${indent}merged ${count} files" @@ -107,7 +111,7 @@ do update_bar ${count} "adding ${partial}" local header="$(cat "${merged}" | head -n 6)" local tmp="$(mktemp)" - ${txtImageMerger} -i "${partial}" -j "${merged}" -o "${tmp}" || warning "error while calling ${txtImageMerger}" + ${txtImageMerger} -i "${partial}" -j "${merged}" -o "${tmp}" 2> /dev/null > /dev/null || { warning "error while calling ${txtImageMerger}" && return; } echo "${header}" > "${merged}" grep -v '## Merge' "${tmp}" >> "${merged}" rm "${tmp}" @@ -144,92 +148,103 @@ do fi update_bar ${count} "adding ${partial}" - ${hdrImageMerger} -t 0 -i "${partial}" -j "${merged}" -o "${merged}" || warning "error while calling ${hdrImageMerger}" + ${hdrImageMerger} -t 0 -i "${partial}" -j "${merged}" -o "${merged}" 2> /dev/null > /dev/null || { warning "error while calling ${hdrImageMerger}" && return; } done end_bar echo " ${indent}merged ${count} files" } -rundir="${1?"provide run dir"}" -nboutputdirs="$(find "${rundir}" -mindepth 1 -type d -name 'output*' | wc -l)" - -test ${nboutputdirs} -gt 0 || error "no output dir found" -echo "found ${nboutputdirs} partial output dirs" - -outputdir="results" -if [ "${rundir}" != "." -a "${rundir##*.}" != "${rundir}" ] -then - outputdir="results.${rundir##*.}" -fi -outputdir="$(basename "${outputdir}")" -echo "output dir is ${outputdir}" -test -d "${outputdir}" && rm -r "${outputdir}" -mkdir "${outputdir}" - -for outputfile in $(find "${rundir}" -regextype 'posix-extended' -type f -regex '.*\.(hdr|root|txt)' | awk -F '/' '{ print $NF }' | sort | uniq) -do - indent=" ** " +function merge_dispatcher { + local indent=" ** " + local outputfile="${1:?"provide output filename"}" echo "merging ${outputfile}" - partialoutputfiles="$(find "${rundir}" -type f -name "${outputfile}")" - nboutputfiles="$(echo "${partialoutputfiles}" | wc -l)" + local partialoutputfiles="$(find "${rundir}" -type f -name "${outputfile}")" + local nboutputfiles="$(echo "${partialoutputfiles}" | wc -l)" if test ${nboutputdirs} -ne ${nboutputfiles} then warning "missing files" - continue + return fi - firstpartialoutputfile="$(echo "${partialoutputfiles}" | head -n 1)" - firstpartialoutputextension="${firstpartialoutputfile##*.}" + local firstpartialoutputfile="$(echo "${partialoutputfiles}" | head -n 1)" + local firstpartialoutputextension="${firstpartialoutputfile##*.}" echo "${indent}testing file type on ${firstpartialoutputfile}" if test "${firstpartialoutputextension}" == "hdr" then echo "${indent}this is a analyse image" - mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" + local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" merge_hdr_image "${mergedfile}" ${partialoutputfiles} || error "error while merging" - continue + return fi if test "${firstpartialoutputextension}" == "root" then echo "${indent}this is a root file" - mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" + local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" merge_root "${mergedfile}" ${partialoutputfiles} || error "error while merging" - continue + return fi if test "${firstpartialoutputextension}" == "txt" && grep 'NumberOfEvent' "${firstpartialoutputfile}" > /dev/null then echo "${indent}this is a stat file" - mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" + local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" merge_stat "${mergedfile}" ${partialoutputfiles} || error "error while merging" - continue + return fi if test "${firstpartialoutputextension}" == "txt" && grep 'Resol' "${firstpartialoutputfile}" > /dev/null then - resol="$(sed -nr '/Resol/s/^.*=\s+\((.+)\)\s*$/\1/p' "${firstpartialoutputfile}")" - resolx="$(echo "${resol}" | cut -d',' -f1)" - resoly="$(echo "${resol}" | cut -d',' -f2)" - resolz="$(echo "${resol}" | cut -d',' -f3)" + local resol="$(sed -nr '/Resol/s/^.*=\s+\((.+)\)\s*$/\1/p' "${firstpartialoutputfile}")" + local resolx="$(echo "${resol}" | cut -d',' -f1)" + local resoly="$(echo "${resol}" | cut -d',' -f2)" + local resolz="$(echo "${resol}" | cut -d',' -f3)" if test "${resol}" == "1,1,1" then echo "${indent}this is a txt integral value" - mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" + local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" merge_txt_image "${mergedfile}" ${partialoutputfiles} || error "error while merging" - continue + return fi if test \( "${resolx}" == "1" -a "${resoly}" == "1" \) -o \( "${resoly}" == "1" -a "${resolz}" == "1" \) -o \( "${resolz}" == "1" -a "${resolx}" == "1" \) then echo "${indent}this is a txt profile" - mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" + local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" merge_txt_image "${mergedfile}" ${partialoutputfiles} || error "error while merging" - continue + return fi fi - warning "unknown file type" +} + +rundir="${1?"provide run dir"}" +nboutputdirs="$(find "${rundir}" -mindepth 1 -type d -name 'output*' | wc -l)" + +test ${nboutputdirs} -gt 0 || error "no output dir found" +echo "found ${nboutputdirs} partial output dirs" + +outputdir="results" +if [ "${rundir}" != "." -a "${rundir##*.}" != "${rundir}" ] +then + outputdir="results.${rundir##*.}" +fi +outputdir="$(basename "${outputdir}")" +echo "output dir is ${outputdir}" +test -d "${outputdir}" && rm -r "${outputdir}" +mkdir "${outputdir}" + +for outputfile in $(find "${rundir}" -regextype 'posix-extended' -type f -regex '.*\.(hdr|root|txt)' | awk -F '/' '{ print $NF }' | sort | uniq) +do + merge_dispatcher "${outputfile}" done +if [ -f "${rundir}/params.txt" ] +then + echo "copying params file" + cp "${rundir}/params.txt" "${outputdir}/params.txt" +fi + +echo "these was ${warning_count} warning(s)"