]> Creatis software - clitk.git/commitdiff
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
authorDavid Sarrut <david.sarrut@creatis.insa-lyon.fr>
Fri, 28 Jun 2013 08:28:31 +0000 (10:28 +0200)
committerDavid Sarrut <david.sarrut@creatis.insa-lyon.fr>
Fri, 28 Jun 2013 08:28:31 +0000 (10:28 +0200)
cluster_tools/gate_job_cluster.job [new file with mode: 0644]
cluster_tools/gate_power_merge.sh [new file with mode: 0755]
cluster_tools/gate_run_submit_cluster.sh [new file with mode: 0755]
cluster_tools/mergeStatFile.sh [new file with mode: 0755]

diff --git a/cluster_tools/gate_job_cluster.job b/cluster_tools/gate_job_cluster.job
new file mode 100644 (file)
index 0000000..6b893b1
--- /dev/null
@@ -0,0 +1,102 @@
+#!/bin/bash
+#
+# MACRODIR
+# MACROFILE
+# RELEASEDIR
+# OUTPUTDIR
+# INDEX
+# INDEXMAX
+# PARAM
+#
+#PBS -r n
+#PBS -l walltime=100:00:00
+#PBS -j oe
+
+#env
+#pwd
+#exit 1
+
+
+function error {
+echo "ERROR: $1"
+exit 1
+}
+
+function warning {
+echo "WARNING: $1"
+}
+
+test -f ${HOME}/.bashrc && echo "Sourcing bashrc" && source ${HOME}/.bashrc
+set -u
+
+echo "Checking"
+uname -a
+echo "MACRODIR=${MACRODIR:?"unknown MACRODIR"}"
+echo "MACROFILE=${MACROFILE:?"unknown MACROFILE"}"
+echo "RELEASEDIR=${RELEASEDIR:?"unknown RELEASEDIR"}"
+echo "OUTPUTDIR=${OUTPUTDIR:?"unknown OUTPUTDIR"}"
+echo "PBS_JOBID=${PBS_JOBID}"
+echo "INDEX=${INDEX}"
+echo "INDEXMAX=${INDEX}"
+echo "PARAM=${PARAM}"
+
+if test "$RELEASEDIR" = "NONE"
+then
+       echo Using $(which Gate)
+       ldd $(which Gate)
+else
+       test -d "${RELEASEDIR}" || error "can't find release"
+       md5sum ${RELEASEDIR}/Gate
+       test -f ${RELEASEDIR}/libGate.so && md5sum ${RELEASEDIR}/libGate.so
+
+       echo "Finding libraries"
+       ROOTLIBS="${RELEASEDIR}/libCore.so:${RELEASEDIR}/libCint.so:${RELEASEDIR}/libRIO.so:${RELEASEDIR}/libNet.so:${RELEASEDIR}/libHist.so:${RELEASEDIR}/libGraf.so:${RELEASEDIR}/libGraf3d.so:${RELEASEDIR}/libGpad.so:${RELEASEDIR}/libTree.so:${RELEASEDIR}/libRint.so:${RELEASEDIR}/libPostscript.so:${RELEASEDIR}/libMatrix.so:${RELEASEDIR}/libPhysics.so:${RELEASEDIR}/libMathCore.so:${RELEASEDIR}/libThread.so:"
+       echo "ROOTLIBS=${ROOTLIBS}"
+       G4LIBS="$(for library in $(find "${RELEASEDIR}" -maxdepth 1 -name 'libG4*.so'); do echo -n "${library}:"; done)"
+       echo "G4LIBS=${G4LIBS}"
+       CLHEPLIBS="$(for library in $(find "${RELEASEDIR}" -maxdepth 1 -name 'libCLHEP*.so'); do echo -n "${library}:"; done)"
+       echo "CLHEPLIBS=${CLHEPLIBS}"
+       GATELIBS=""
+       test -f ${RELEASEDIR}/libGate.so && GATELIBS="${RELEASEDIR}/libGate.so:"
+       echo "GATELIBS=${GATELIBS}"
+fi
+test -d "${MACRODIR}" && test -d "${MACRODIR}/mac" || error "invalid macro"
+
+
+echo "Copying inputs"
+LOCALMACRODIR=$(mktemp -d)
+trap "rm -rf ${LOCALMACRODIR} ; exit 1" 1 2 3 15
+cd ${LOCALMACRODIR}
+cp -r -L "${MACRODIR}"/{data,mac} .
+mkdir output
+
+# Enforce one thread
+ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1
+
+echo "Lauching macro"
+date
+if test "$RELEASEDIR" = "NONE"
+then
+       Gate ${PARAM} ${MACROFILE} || error "gate failed"
+else
+       LD_PRELOAD="${ROOTLIBS}${G4LIBS}${CLHEPLIBS}${GATELIBS}" \
+       G4LEVELGAMMADATA="${RELEASEDIR}/PhotonEvaporation2.1" \
+       G4RADIOACTIVEDATA="${RELEASEDIR}/RadioactiveDecay3.3" \
+       G4LEDATA="${RELEASEDIR}/G4EMLOW6.19" \
+       G4NEUTRONHPDATA="${RELEASEDIR}/G4NDL3.14" \
+       G4ABLADATA="${RELEASEDIR}/G4ABLA3.0" \
+       G4REALSURFACEDATA="${RELEASEDIR}/RealSurface1.0" \
+       G4NEUTRONXSDATA="${RELEASEDIR}/G4NEUTRONXS1.0" \
+       G4PIIDATA="${RELEASEDIR}/G4PII1.2" \
+       /usr/bin/time --format="real %es\nuser %Us\nsys %Ss\nmaxmem %Mk" \
+       ${RELEASEDIR}/Gate ${PARAM} ${MACROFILE} \
+       || error "gate failed"
+fi
+
+echo "Copying data back"
+mv output "${OUTPUTDIR}/output.${PBS_JOBID%%.*}"
+
+echo "Cleanup"
+rm -r ${LOCALMACRODIR}
+
+echo "Success!!!"
diff --git a/cluster_tools/gate_power_merge.sh b/cluster_tools/gate_power_merge.sh
new file mode 100755 (executable)
index 0000000..55fc1f0
--- /dev/null
@@ -0,0 +1,412 @@
+#!/usr/bin/env bash
+
+set -u 
+
+function error {
+echo "ERROR: $1"
+exit 1
+}
+
+warning_count=0
+function warning {
+let "warning_count++"
+echo "MERGE_WARNING: $1"
+}
+
+function start_bar {
+count_max="${1:?"provide count max"}"
+}
+
+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%% %-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'
+}
+
+function check_interfile {
+local input_interfile="${1:?"provide input interfile"}"
+
+grep -qs '!INTERFILE :=' "${input_interfile}" || return 1
+
+local header_byte_size=$(awk -F' ' '
+BEGIN { zsize = 0; }
+/matrix size/ && $3 == "[1]" { xsize = $5; }
+/matrix size/ && $3 == "[2]" { ysize = $5; }
+/number of projections/ { zsize += $5; }
+/number of bytes per pixel/ { byte_per_pixel = $7; }
+END { print xsize * ysize * zsize * byte_per_pixel; }' "${input_interfile}")
+
+local raw_interfile="$(dirname "${input_interfile}")/$(awk -F' := ' '/name of data file/ { print $2; }' "${input_interfile}")"
+
+test -f "${raw_interfile}" || return 1
+test $(stat -c%s "${raw_interfile}") -eq ${header_byte_size} || return 1
+}
+
+function write_mhd_header {
+local input_interfile="${1:?"provide input interfile"}"
+local output_mhd="$(dirname "${input_interfile}")/$(basename "${input_interfile}" ".hdr").mhd"
+
+check_interfile "${input_interfile}" || error "${input_interfile} isn't an interfile image"
+
+local header_start='ObjectType = Image
+NDims = 3
+AcquisitionDate = none
+BinaryData = True
+BinaryDataByteOrderMSB = False
+CompressedData = False
+TransformMatrix = 1 0 0 0 1 0 0 0 1
+Offset = 0 0 0
+CenterOfRotation = 0 0 0
+DistanceUnits = mm
+AnatomicalOrientation = RIP'
+
+echo "${header_start}" > "${output_mhd}"
+
+awk -F' ' '
+/scaling factor/ && $4 == "[1]" { xspacing = $6; }
+/scaling factor/ && $4 == "[2]" { yspacing = $6; }
+END { print "ElementSpacing = " xspacing " " yspacing " 1"; }' "${input_interfile}" >> "${output_mhd}"
+
+awk -F' ' '
+BEGIN { zsize = 0; }
+/matrix size/ && $3 == "[1]" { xsize = $5; }
+/matrix size/ && $3 == "[2]" { ysize = $5; }
+/number of projections/ { zsize += $5; }
+END { print "DimSize = " xsize " " ysize " " zsize; }' "${input_interfile}" >> "${output_mhd}"
+
+awk -F' := ' '
+/number format/ { format = $2; }
+/number of bytes per pixel/ { byte_per_pixel = $2 }
+END {
+if (format == "unsigned integer" && byte_per_pixel == 8) { print "ElementType = MET_ULONG"; exit };
+if (format == "unsigned integer" && byte_per_pixel == 4) { print "ElementType = MET_UINT"; exit };
+if (format == "unsigned integer" && byte_per_pixel == 2) { print "ElementType = MET_USHORT"; exit };
+if (format == "unsigned integer" && byte_per_pixel == 1) { print "ElementType = MET_UCHAR"; exit };
+if (format == "integer" && byte_per_pixel == 8) { print "ElementType = MET_LONG"; exit };
+if (format == "integer" && byte_per_pixel == 4) { print "ElementType = MET_INT"; exit };
+if (format == "integer" && byte_per_pixel == 2) { print "ElementType = MET_SHORT"; exit };
+if (format == "integer" && byte_per_pixel == 1) { print "ElementType = MET_CHAR"; exit };
+if (format == "float" && byte_per_pixel == 8) { print "ElementType = MET_FLOAT"; exit };
+if (format == "float" && byte_per_pixel == 4) { print "ElementType = MET_DOUBLE"; exit };
+print "ElementType = MET_INT";
+}' "${input_interfile}" >> "${output_mhd}"
+
+awk -F' := ' '
+/name of data file/ { print "ElementDataFile = " $2; }' "${input_interfile}" >> "${output_mhd}"
+}
+
+rootMerger="clitkMergeRootFiles"
+test -x "./clitkMergeRootFiles" && rootMerger="./clitkMergeRootFiles"
+
+function merge_root {
+local merged="$1"
+shift
+echo "  ${indent}entering root merger"
+echo "  ${indent}merger is ${rootMerger}"
+echo "  ${indent}creating ${merged}"
+#echo "######## $#"
+#echo "######## $*"
+
+if test $# -eq 1
+then
+    echo "  ${indent}just one partial file => just copy it"
+    cp "$1" "${merged}"
+    return
+fi
+
+local count=0
+local arguments=" -o ${merged}"
+while test $# -gt 0
+do
+    local partial="$1"
+    shift
+    let count++
+    local arguments=" -i ${partial} ${arguments}"
+done
+${rootMerger} ${arguments} > /dev/null || error "error while calling ${rootMerger}"
+echo "  ${indent}merged ${count} files"
+}
+
+statMerger="mergeStatFile.py"
+test -x "./mergeStatFile.sh" && statMerger="./mergeStatFile.sh"
+
+function merge_stat {
+local merged="$1"
+shift
+echo "  ${indent}entering stat merger"
+echo "  ${indent}merger is ${statMerger}"
+echo "  ${indent}creating ${merged}"
+local count=0
+start_bar $#
+while test $# -gt 0
+do
+    local partial="$1"
+    shift
+    let count++
+
+    if test ! -f "${merged}"
+    then
+        update_bar ${count} "copying first partial result ${partial}"
+        cp "${partial}" "${merged}"
+        continue
+    fi
+
+    update_bar ${count} "adding ${partial}"
+    ${statMerger} -i "${merged}" -j "${partial}" -o "${merged}" 2> /dev/null > /dev/null || warning "error while calling ${statMerger}"
+done
+end_bar
+echo "  ${indent}merged ${count} files"
+}
+
+txtImageMerger="clitkMergeAsciiDoseActor"
+test -f "./clitkMergeAsciiDoseActor" && txtImageMerger="./clitkMergeAsciiDoseActor"
+
+function merge_txt_image {
+local merged="$1"
+shift
+echo "  ${indent}entering text image merger"
+echo "  ${indent}merger is ${txtImageMerger}"
+echo "  ${indent}creating ${merged}"
+local count=0
+start_bar $#
+while test $# -gt 0
+do
+    local partial="$1"
+    shift
+    let count++
+
+    if test ! -f "${merged}"
+    then
+        update_bar ${count} "copying first partial result ${partial}"
+        cp "${partial}" "${merged}"
+        continue
+    fi
+
+    update_bar ${count} "adding ${partial}"
+    local header="$(cat "${merged}" | head -n 6)"
+    local tmp="$(mktemp)"
+    ${txtImageMerger} -i "${partial}" -j "${merged}" -o "${tmp}" 2> /dev/null > /dev/null || warning "error while calling ${txtImageMerger}"
+    echo "${header}" > "${merged}"
+    grep -v '## Merge' "${tmp}" >> "${merged}"
+    rm "${tmp}"
+done
+end_bar
+echo "  ${indent}merged ${count} files"
+}
+
+hdrImageMerger="clitkImageArithm"
+test -x "./clitkImageArithm" && hdrImageMerger="./clitkImageArithm"
+
+function merge_hdr_image {
+local merged="$1"
+local merged_bin="${merged%.*}.img"
+shift
+echo "  ${indent}entering hdr image merger"
+echo "  ${indent}merger is ${hdrImageMerger}"
+echo "  ${indent}creating ${merged}"
+local count=0
+start_bar $#
+while test $# -gt 0
+do
+    local partial="$1"
+    local partial_bin="${partial%.*}.img"
+    shift
+    let count++
+
+    if test ! -f "${merged}"
+    then
+        update_bar ${count} "copying first partial result ${partial}"
+        cp "${partial}" "${merged}"
+        cp "${partial_bin}" "${merged_bin}"
+        continue
+    fi
+
+    update_bar ${count} "adding ${partial}"
+    ${hdrImageMerger} -t 0 -i "${partial}" -j "${merged}" -o "${merged}" 2> /dev/null > /dev/null || warning "error while calling ${hdrImageMerger}"
+done
+end_bar
+echo "  ${indent}merged ${count} files"
+}
+
+mhdImageMerger="clitkImageArithm"
+test -x "./clitkImageArithm" && mhdImageMerger="./clitkImageArithm"
+
+function merge_mhd_image {
+local merged="$1"
+local merged_bin="${merged%.*}.raw"
+shift
+echo "  ${indent}entering mhd image merger"
+echo "  ${indent}merger is ${mhdImageMerger}"
+echo "  ${indent}creating ${merged}"
+local count=0
+start_bar $#
+while test $# -gt 0
+do
+    local partial="$1"
+    local partial_bin="$(dirname "${partial}")/$(awk -F' = ' '/ElementDataFile/ { print $2; }' "${partial}")"
+    shift
+    let count++
+
+    if test ! -f "${merged}"
+    then
+        update_bar ${count} "copying first partial result ${partial}"
+        cp "${partial}" "${merged}"
+        cp "${partial_bin}" "${merged_bin%.*}.${partial_bin##*.}"
+        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}"
+done
+end_bar
+echo "  ${indent}merged ${count} files"
+}
+
+function merge_dispatcher {
+    local indent="  ** "
+    local outputfile="${1:?"provide output filename"}"
+    echo "merging ${outputfile}"
+
+    local partialoutputfiles="$(find "${rundir}" -mindepth 2 -type f -name "${outputfile}")"
+    local nboutputfiles="$(echo "${partialoutputfiles}" | wc -l)"
+    if test ${nboutputdirs} -ne ${nboutputfiles}
+    then
+        warning "missing files"
+        return
+    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}"
+    then
+        echo "${indent}this is a 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)"
+        local mhd_mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}" ".hdr").mhd"
+        merge_mhd_image "${mhd_mergedfile}" ${mhd_partialoutputfiles} || error "error while merging"
+        echo "${indent}cleaning mhd headers"
+        for mhd_partialoutputfile in $mhd_partialoutputfiles; do rm "${mhd_partialoutputfile}"; done
+        rm "${mhd_mergedfile}"
+        echo "${indent}copy interfile header"
+        cp "${firstpartialoutputfile}" "${outputdir}"
+        return
+    fi
+
+    if test "${firstpartialoutputextension}" == "hdr"
+    then
+        echo "${indent}this is a analyse image"
+        local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")"
+        merge_hdr_image "${mergedfile}" ${partialoutputfiles} || error "error while merging"
+        return
+    fi
+
+    if test "${firstpartialoutputextension}" == "mhd"
+    then
+        echo "${indent}this is a mhd image"
+        local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")"
+        merge_mhd_image "${mergedfile}" ${partialoutputfiles} || error "error while merging"
+        return
+    fi
+
+    if test "${firstpartialoutputextension}" == "root"
+    then
+        echo "${indent}this is a root file"
+        local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")"
+        merge_root "${mergedfile}" ${partialoutputfiles} || error "error while merging"
+        return
+    fi
+
+    if test "${firstpartialoutputextension}" == "txt" && grep -qs 'NumberOfEvent' "${firstpartialoutputfile}"
+    then
+        echo "${indent}this is a stat file"
+        local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")"
+        merge_stat "${mergedfile}" ${partialoutputfiles} || error "error while merging"
+        return
+    fi
+
+    if test "${firstpartialoutputextension}" == "txt" && grep -qs 'Resol' "${firstpartialoutputfile}"
+    then
+        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"
+            local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")"
+            merge_txt_image "${mergedfile}" ${partialoutputfiles} || error "error while merging"
+            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"
+            local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")"
+            merge_txt_image "${mergedfile}" ${partialoutputfiles} || error "error while merging"
+            return
+        fi
+    fi
+
+    if test "${firstpartialoutputextension}" == "txt"
+    then
+        echo "${indent}this is a non specific txt output"
+        local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")"
+        local nbdifferent="$(md5sum ${partialoutputfiles} | awk '{ print $1; }' | sort | uniq | wc -l)"
+        echo "  ${indent}${nbdifferent} different files"
+        if test ${nbdifferent} -gt 1
+        then
+            echo "  ${indent}catting to ${mergedfile}"
+            cat ${partialoutputfiles} > "${mergedfile}" || error "error while merging"
+            return
+        else
+            echo "  ${indent}moving to ${mergedfile}"
+            cp "${firstpartialoutputfile}" "${mergedfile}" || error "error while merging"
+            return
+        fi
+    fi
+
+    error "unknown file type"
+}
+
+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)"
+
+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 "${rundir}/output.*\.(hdr|mhd|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)"
diff --git a/cluster_tools/gate_run_submit_cluster.sh b/cluster_tools/gate_run_submit_cluster.sh
new file mode 100755 (executable)
index 0000000..f47ed6d
--- /dev/null
@@ -0,0 +1,72 @@
+#!/usr/bin/env bash 
+
+set -u
+SCRIPTNAME="$(basename "${0}")"
+
+function error {
+echo "ERROR: $1"
+usage
+exit 1
+}
+
+DEFAULTRELEASESUFFIX="NONE"
+DEFAULTNUMBEROFJOBS="10"
+
+function usage {
+echo "${SCRIPTNAME} mac/main.mac njobs releasesuffix paramtogate"
+echo "default njobs = ${DEFAULTNUMBEROFJOBS}"
+echo "default releasesuffix = ${DEFAULTRELEASESUFFIX} (NONE means use Gate in PATH)"
+}
+
+test $# -eq 0 && usage && exit 0
+
+SCRIPTDIR="${HOME}/git/gate-tests/bin"
+RELEASESUFFIX=${3:-"${DEFAULTRELEASESUFFIX}"}
+RELEASEDIR="${HOME}/releases/grid_release${RELEASESUFFIX}"
+JOBFILE="$(dirname $0)/gate_job_cluster.job"
+
+echo "Checking stuff"
+test -f ${JOBFILE} || error "can't find job file ${JOBFILE}"
+if test "${RELEASESUFFIX}" = "${DEFAULTRELEASESUFFIX}"
+then
+       RELEASEDIR="NONE"
+       which Gate 2>&1 >/dev/null || error "there is no Gate in the PATH"
+else
+       test -d ${RELEASEDIR} || error "invalid release dir ${RELEASEDIR}"
+fi
+MACRODIR=$(pwd)
+test -d ${MACRODIR}/mac && test -d ${MACRODIR}/data || error "invalid path"
+MACROFILE=${1:?"provide relative macro path"}
+test -f ${MACRODIR}/${MACROFILE} || error "invalid macro"
+OUTPUTDIR=$(mktemp --tmpdir=${MACRODIR} -d run.XXXX || error "can't create temp dir")
+test -d ${OUTPUTDIR} || error "can't locate output dir"
+RUNID=${OUTPUTDIR##*.}
+NJOBS=${2:-"${DEFAULTNUMBEROFJOBS}"}
+NJOBSMAX=${NJOBS}
+PARAM="${4:-""}"
+
+echo "Lets roll!!"
+echo "runid is ${RUNID}"
+echo "qsub is $(which qsub)"
+test -z "${PARAM}" && echo "no param" || echo "param is ${PARAM}"
+if test "$RELEASESUFFIX" = "$DEFAULTRELEASESUFFIX"
+then
+       echo "using $(which Gate)"
+else
+       echo "using release $(basename ${RELEASEDIR})"
+fi
+echo "submitting ${NJOBS} jobs"
+
+PARAMFILE="${OUTPUTDIR}/params.txt"
+echo "njobs = ${NJOBS}" >> "${PARAMFILE}"
+echo "macro = ${MACROFILE}" >> "${PARAMFILE}"
+test -z "${PARAM}" || echo "param = ${PARAM}" >> "${PARAMFILE}"
+
+while test $NJOBS -gt 0; do
+       qsub -N "gatejob.${RUNID}" -o "${OUTPUTDIR}" \
+       -v "PARAM=\"${PARAM}\",INDEX=${NJOBS},INDEXMAX=${NJOBSMAX},SCRIPTDIR=${SCRIPTDIR},OUTPUTDIR=${OUTPUTDIR},RELEASEDIR=${RELEASEDIR},MACROFILE=${MACROFILE},MACRODIR=${MACRODIR}" \
+       "${JOBFILE}" || error "submission error"
+       let NJOBS--
+done
+
+echo "runid is ${RUNID}"
diff --git a/cluster_tools/mergeStatFile.sh b/cluster_tools/mergeStatFile.sh
new file mode 100755 (executable)
index 0000000..12c7c05
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/bash
+set -u
+
+function usage {
+       echo "$0 -i <file1> -j <file2> -o <result>"
+       exit 1
+}
+
+if [ $# != 6 ]
+then
+       usage
+fi
+
+IN1=$2
+IN2=$4
+RESULT=$6
+
+
+test -f ${IN1} && test -f ${IN2} || usage
+
+TMP="$(mktemp)"
+echo "merging stat file"
+for PARAM in `awk '$1 == "#" {print $2}' ${IN1}`
+do
+        echo "merging ${PARAM}"
+       V1=`awk -v P=${PARAM} '$2 == P {print $4}' ${IN1} `
+       V2=`awk -v P=${PARAM} '$2 == P {print $4}' ${IN2} `
+       R=`echo "${V1} + ${V2}" | bc`
+        test -z "${R}" && continue
+        echo "# ${PARAM} = ${R}" >> ${TMP}
+done
+mv -f ${TMP} ${RESULT}