5 echo "$0 -i <file1> -j <file2> -o <result>"
18 test -f ${IN1} && test -f ${IN2} || usage
21 echo "merging dose by regions file"
22 # check if all 3 text files have the same number of lines
23 nblines=`cat ${IN1} | wc -l`
24 nb2=`cat ${IN2} | wc -l`
25 nb3=`cat ${RESULT} | wc -l`
27 if [ $nblines -ne $nb2 ] || [ $nblines -ne $nb3 ]; then
28 echo "Files does not have the same size"
32 #Copy the 1st line in output
33 line1=`sed -n "1p" < ${RESULT}`
34 echo "${line1}" >> ${TMP}
36 # for all lines (except the 1st), split according tab
37 # sum the some elements (dose, edep) ...
38 for i in $(seq 2 $nblines); do
40 line1=`sed -n "${i}p" < ${IN1}`
41 line2=`sed -n "${i}p" < ${IN2}`
42 line3=`sed -n "${i}p" < ${RESULT}`
44 # sum edep: get the 2 values, sum them and replace it in the line3
45 # The /#./0. is important to add 0 for decimal value between 0 and 1
46 edep1=$(echo ${line1} | cut -f3 -d' ')
47 edep2=$(echo ${line2} | cut -f3 -d' ')
48 edep3=$(echo "scale=30;$edep1+$edep2" | bc)
50 line3=$(echo $line3 |awk -v r=${edep3} '{$3=r}1')
52 # sqrt sum square std_edep: get the 2 values, sum the square, take the sqrt and replace it in the line3
53 edep1=$(echo ${line1} | cut -f4 -d' ')
54 edep2=$(echo ${line2} | cut -f4 -d' ')
55 edep3=$(echo "scale=30;sqrt($edep1*$edep1+$edep2*$edep2)" | bc)
57 line3=$(echo $line3 |awk -v r=${edep3} '{$4=r}1')
59 # sum square_edep: get the 2 values, sum them and replace it in the line3
60 edep1=$(echo ${line1} | cut -f5 -d' ')
61 edep2=$(echo ${line2} | cut -f5 -d' ')
62 edep3=$(echo "scale=30;$edep1+$edep2" | bc)
64 line3=$(echo $line3 |awk -v r=${edep3} '{$5=r}1')
66 # sum dose: get the 2 values, sum them and replace it in the line3
67 edep1=$(echo ${line1} | cut -f6 -d' ')
68 edep2=$(echo ${line2} | cut -f6 -d' ')
69 edep3=$(echo "scale=30;$edep1+$edep2" | bc)
71 line3=$(echo $line3 |awk -v r=${edep3} '{$6=r}1')
73 # sqrt sum square std_dose: get the 2 values, sum the square, take the sqrt and replace it in the line3
74 edep1=$(echo ${line1} | cut -f7 -d' ')
75 edep2=$(echo ${line2} | cut -f7 -d' ')
76 edep3=$(echo "scale=30;sqrt($edep1*$edep1+$edep2*$edep2)" | bc)
78 line3=$(echo $line3 |awk -v r=${edep3} '{$7=r}1')
80 # sum square_dose: get the 2 values, sum them and replace it in the line3
81 edep1=$(echo ${line1} | cut -f8 -d' ')
82 edep2=$(echo ${line2} | cut -f8 -d' ')
83 edep3=$(echo "scale=30;$edep1+$edep2" | bc)
85 line3=$(echo $line3 |awk -v r=${edep3} '{$8=r}1')
87 # sum n_hits: get the 2 values, sum them and replace it in the line3
88 edep1=$(echo ${line1} | cut -f9 -d' ')
89 edep2=$(echo ${line2} | cut -f9 -d' ')
90 edep3=$(echo "scale=30;$edep1+$edep2" | bc)
91 line3=$(echo $line3 |awk -v r=${edep3} '{$9=r}1')
93 # sum n_event_hits: get the 2 values, sum them and replace it in the line3
94 edep1=$(echo ${line1} | cut -f10 -d' ')
95 edep2=$(echo ${line2} | cut -f10 -d' ')
96 edep3=$(echo "scale=30;$edep1+$edep2" | bc)
97 line3=$(echo $line3 |awk -v r=${edep3} '{$10=r}1')
100 echo "${line3}" >> ${TMP}
102 mv -f ${TMP} ${RESULT}