From d3cab00691791666f3edb0e24a931263312a6222 Mon Sep 17 00:00:00 2001 From: Pierre Gueth Date: Fri, 24 Jun 2011 11:10:45 +0200 Subject: [PATCH] refactor --- cluster_tools/gate_power_merge.sh | 82 ++++++++++++++++--------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/cluster_tools/gate_power_merge.sh b/cluster_tools/gate_power_merge.sh index c1c4755..404409b 100755 --- a/cluster_tools/gate_power_merge.sh +++ b/cluster_tools/gate_power_merge.sh @@ -150,86 +150,90 @@ 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 -- 2.47.1