]> Creatis software - clitk.git/blobdiff - cluster_tools/gate_power_merge.sh
Debug Rigid Registration tool cancel
[clitk.git] / cluster_tools / gate_power_merge.sh
index f82a11931d69cbd3df28c289a620ccd461bdf4bc..aaf063b18d4f8cc85be856ef0f19df1087c1570d 100755 (executable)
@@ -290,7 +290,7 @@ function merge_mhd_image {
         then
             update_bar ${count} "copying first partial result ${partial}"
             cp "${partial}" "${merged}"
-            if test "$last_character" = "d" 
+            if test "$last_character" = "d"
             then
                 cp "${partial_bin}" "${merged_bin%.*}.${partial_bin##*.}"
             fi
@@ -299,7 +299,7 @@ function merge_mhd_image {
 
         update_bar ${count} "adding ${partial}"
         ${mhdImageMerger} -t 0 -i "${partial}" -j "${merged}" -o "${merged}" 2> /dev/null > /dev/null || warning "error while calling ${mhdImageMerger}"
-        if test "$last_character" = "d" 
+        if test "$last_character" = "d" && test "${merged_bin}" != "${merged_bin%.*}.${partial_bin##*.}"
         then
             mv "${merged_bin}" "${merged_bin%.*}.${partial_bin##*.}"
             sed -i "s/$(basename "${merged_bin}")/$(basename "${merged_bin%.*}.${partial_bin##*.}")/" "${merged}"
@@ -314,12 +314,15 @@ function merge_dispatcher {
     local outputfile="${1:?"provide output filename"}"
     echo "merging ${outputfile}"
 
-    local partialoutputfiles="$(find "${rundir}" -mindepth 2 -type f -name "${outputfile}")"
+    local partialoutputfiles="$(find -L "${rundir}" -mindepth 2 -type f -name "${outputfile}")"
     local nboutputfiles="$(echo "${partialoutputfiles}" | wc -l)"
     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)"
@@ -431,12 +434,15 @@ function merge_dispatcher_uncertainty {
     local indent="  ** "
     local outputfile="${1:?"provide output filename"}"
 
-    local partialoutputfiles="$(find "${rundir}" -mindepth 2 -type f -name "${outputfile}")"
+    local partialoutputfiles="$(find -L "${rundir}" -mindepth 2 -type f -name "${outputfile}")"
     local nboutputfiles="$(echo "${partialoutputfiles}" | wc -l)"
     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"
+       if test "${firstpartialoutputextension}" == "mhd" || test "${firstpartialoutputextension}" == "mha"
         then
             echo "${indent}Uncertainty file found: ${firstpartialoutputfile}"
             ## search for sum
@@ -466,7 +472,7 @@ function merge_dispatcher_uncertainty {
             echo "${indent}${squared_merged_file} found"
             ## search for NumberOfEvent
             totalEvents=0;
-            for outputfile in $(find "${rundir}" -regextype 'posix-extended' -type f -regex "${rundir}/output.*\.(hdr|mhd|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq)
+            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)
             do
                 #echo $outputfile
                 if grep -q 'NumberOfEvent' "${outputdir}/${outputfile}"
@@ -485,16 +491,21 @@ 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
+            error "merge_dispatcher_uncertainty does not handle ${firstpartialoutputfile} files"
         fi
     fi
 
 }
 
 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*' | wc -l)"
+nboutputdirs="$(find "${rundir}" -mindepth 1 -type d -name 'output*' -o -type l -name 'output*' | wc -l)"
 
 test ${nboutputdirs} -gt 0 || error "no output dir found"
 echo "found ${nboutputdirs} partial output dirs"
@@ -509,17 +520,16 @@ 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|mha|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq)
+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)
 do
-    merge_dispatcher "${outputfile}"
+    merge_dispatcher "${outputfile}" "${force}"
 done
 
 echo ""
 echo "Merging done. Special case for statistical uncertainty"
-for outputfile in $(find "${outputdir}" -regextype 'posix-extended' -type f -regex "${outputdir}/.*\.(hdr|mhd|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq)
+for outputfile in $(find -L "${outputdir}" -regextype 'posix-extended' -type f -regex "${outputdir}/.*\.(hdr|mhd|mha|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq)
 do
-    merge_dispatcher_uncertainty "${outputfile}"
+    merge_dispatcher_uncertainty "${outputfile}" "${force}"
 done
 
 if [ -f "${rundir}/params.txt" ]
@@ -528,4 +538,10 @@ then
     cp "${rundir}/params.txt" "${outputdir}/params.txt"
 fi
 
+if [ -d "${rundir}/mac" ]
+then
+    echo "copying mac folder"
+    cp -r "${rundir}/mac" "${outputdir}/mac"
+fi
+
 echo "these was ${warning_count} warning(s)"