]> Creatis software - clitk.git/blobdiff - cluster_tools/gate_power_merge.sh
replace remote rsync with local
[clitk.git] / cluster_tools / gate_power_merge.sh
index c35d67d6b4238389d1e2ff7af17c483f6077730b..fa2904a5a33855557dff6e68c221858a3152173c 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").mhd"
+    local output_mhd="$(dirname "${input_interfile}")/$(basename "${input_interfile}" ".hdr").hdr.mhd"
 
-    check_interfile "${input_interfile}" || error "${input_interfile} isn't an interfile image"
+    check_interfile "${input_interfile}" || warning "${input_interfile} isn't an interfile image (or unknown format)"
 
     local header_start='ObjectType = Image
 NDims = 3
@@ -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
@@ -319,7 +319,10 @@ function merge_dispatcher {
     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)"
@@ -331,8 +334,8 @@ function merge_dispatcher {
         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"
+        local mhd_partialoutputfiles="$(for partialoutputfile in $partialoutputfiles; do echo "${partialoutputfile%.*}.hdr.mhd"; done)"
+        local mhd_mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}" ".hdr").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
@@ -436,7 +439,10 @@ function merge_dispatcher_uncertainty {
     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)"
@@ -493,10 +499,13 @@ function merge_dispatcher_uncertainty {
 }
 
 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 -o -type l -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"
@@ -511,17 +520,16 @@ echo "output dir is ${outputdir}"
 
 test -d "${outputdir}" && rm -r "${outputdir}"
 mkdir "${outputdir}"
-ls ${rundir}/
 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 -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" ]
@@ -530,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)"