]> Creatis software - clitk.git/blobdiff - cluster_tools/gate_power_merge.sh
Debug RTStruct conversion with empty struc
[clitk.git] / cluster_tools / gate_power_merge.sh
index fa2904a5a33855557dff6e68c221858a3152173c..43d90d02c496d6dba5c3f696a88b195c4b535f0c 100755 (executable)
@@ -51,9 +51,9 @@ END { print xsize * ysize * zsize * byte_per_pixel; }' "${input_interfile}")
 
 function write_mhd_header {
     local input_interfile="${1:?"provide input interfile"}"
-    local output_mhd="$(dirname "${input_interfile}")/$(basename "${input_interfile}" ".hdr").hdr.mhd"
+    local output_mhd="$(dirname "${input_interfile}")/$(basename "${input_interfile}" ".hdr").mhd"
 
-    check_interfile "${input_interfile}" || warning "${input_interfile} isn't an interfile image (or unknown format)"
+    check_interfile "${input_interfile}" || error "${input_interfile} isn't an interfile image"
 
     local header_start='ObjectType = Image
 NDims = 3
@@ -165,7 +165,7 @@ function merge_stat {
     echo "  ${indent}merged ${count} files"
 }
 
-doseMerger="mergeDosePerEnegryFile.sh"
+doseMerger="mergeDosePerEnergyFile.sh"
 test -x "./mergeDosePerEnergyFile.sh" && doseMerger="./mergeDosePerEnergyFile.sh"
 
 function merge_dose {
@@ -196,6 +196,40 @@ function merge_dose {
     echo "  ${indent}merged ${count} files"
 }
 
+doseMerger="mergeDoseByRegions.sh"
+test -x "./mergeDoseByRegions.sh" && doseMerger="./mergeDoseByRegions.sh"
+
+function merge_doseByRegions {
+    local merged="$1"
+    shift
+    echo "  ${indent}entering dose merger"
+    echo "  ${indent}merger is ${doseMerger}"
+    echo "  ${indent}creating ${merged}"
+    local count=0
+    start_bar $#
+    source ${doseMerger}
+    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}"
+            copyFirstPartialResult -i "${merged}" -o "${merged}" 2> /dev/null > /dev/null || warning "error while calling ${doseMerger}"
+            continue
+        fi
+
+        update_bar ${count} "adding ${partial}"
+        addToPartialResult -i "${merged}" -j "${partial}" -o "${merged}" 2> /dev/null > /dev/null || warning "error while calling ${doseMerger}"
+    done
+    divideUncertaintyResult -i "${merged}" -o "${merged}" 2> /dev/null > /dev/null || warning "error while calling ${doseMerger}"
+    end_bar
+    echo "  ${indent}merged ${count} files"
+}
+
 txtImageMerger="clitkMergeAsciiDoseActor"
 test -f "./clitkMergeAsciiDoseActor" && txtImageMerger="./clitkMergeAsciiDoseActor"
 
@@ -329,13 +363,13 @@ function merge_dispatcher {
     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%.*}.hdr.mhd"; done)"
-        local mhd_mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}" ".hdr").hdr.mhd"
+        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
@@ -347,7 +381,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
@@ -409,6 +443,15 @@ function merge_dispatcher {
         fi
     fi
 
+    if test "${firstpartialoutputextension}" == "txt" && grep -qs 'vol(mm3)' "${firstpartialoutputfile}"
+    then
+        echo "${indent}this is a DoseByRegions file"
+        local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")"
+        merge_doseByRegions "${mergedfile}" ${partialoutputfiles} || error "error while merging"
+        return
+    fi
+
+
     if test "${firstpartialoutputextension}" == "txt"
     then
         echo "${indent}this is a non specific txt output"
@@ -450,7 +493,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
@@ -472,7 +515,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}"
@@ -491,7 +541,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
@@ -520,18 +570,39 @@ 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}" "${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}" "${force}"
 done
 
+echo "compute job statistics"
+python computeEnlapsedTime.py ${rundir} gate
+mv "statJobs.txt" "${outputdir}/statJobs.txt"
+
+
 if [ -f "${rundir}/params.txt" ]
 then
     echo "copying params file"