5 echo "$0 -i <result> -j <file2> -o <result>"
9 function addToPartialResult {
14 test -f ${IN1} && test -f ${IN2} || usage
18 # check if all 3 text files have the same number of lines
19 nblines=`cat ${IN1} | wc -l`
20 nb2=`cat ${IN2} | wc -l`
21 nb3=`cat ${RESULT} | wc -l`
23 if [ $nblines -ne $nb2 ] || [ $nblines -ne $nb3 ]; then
24 echo "Files does not have the same size"
28 #Copy the 1st line in output
29 line1=`sed -n "1p" < ${RESULT}`
30 echo "${line1}" >> ${TMP}
31 # for all lines (except the 1st), split according tab
32 # sum the some elements (dose, edep) ...
33 for i in $(seq 2 $nblines); do
35 file1=`sed -n "${i}p" < ${IN1}`
36 file2=`sed -n "${i}p" < ${IN2}`
37 file3=`sed -n "${i}p" < ${RESULT}`
39 # sum edep: get the 2 values, sum them and replace it in the file3
40 # The /#./0. is important to add 0 for decimal value between 0 and 1
41 edep1=$(echo ${file1} | cut -f3 -d' ')
42 edep2=$(echo ${file2} | cut -f3 -d' ')
43 edep3=$(python -c "print($edep1+$edep2)")
45 file3=$(echo $file3 |awk -v r=${edep3} '{$3=r}1')
47 # sqrt sum square std_edep*edep: get the 2 values, sum the square, take the sqrt and replace it in the file3
48 stdEdep1=$(echo ${file1} | cut -f4 -d' ')
49 stdEdep2=$(echo ${file2} | cut -f4 -d' ')
50 stdEdep3=$(python <<EOP
52 temp=$edep2*$stdEdep2;
53 print(math.sqrt($stdEdep1*$stdEdep1+temp*temp))
56 stdEdep3=${stdEdep3/#./0.}
57 file3=$(echo $file3 |awk -v r=${stdEdep3} '{$4=r}1')
59 # sum square_edep: get the 2 values, sum them and replace it in the file3
60 sqEdep1=$(echo ${file1} | cut -f5 -d' ')
61 sqEdep2=$(echo ${file2} | cut -f5 -d' ')
62 sqEdep3=$(python -c "print($sqEdep1+$sqEdep2)")
63 sqEdep3=${sqEdep3/#./0.}
64 file3=$(echo $file3 |awk -v r=${sqEdep3} '{$5=r}1')
66 # sum dose: get the 2 values, sum them and replace it in the file3
67 dose1=$(echo ${file1} | cut -f6 -d' ')
68 dose2=$(echo ${file2} | cut -f6 -d' ')
69 dose3=$(python -c "print($dose1+$dose2)")
71 file3=$(echo $file3 |awk -v r=${dose3} '{$6=r}1')
73 # sqrt sum square std_dose*dose: get the 2 values, sum the square, take the sqrt and replace it in the file3
74 stdDose1=$(echo ${file1} | cut -f7 -d' ')
75 stdDose2=$(echo ${file2} | cut -f7 -d' ')
76 stdDose3=$(python <<EOP
78 temp=$dose2*$stdDose2;
79 print(math.sqrt($stdDose1*$stdDose1+temp*temp))
82 stdDose3=${stdDose3/#./0.}
83 file3=$(echo $file3 |awk -v r=${stdDose3} '{$7=r}1')
85 # sum square_dose: get the 2 values, sum them and replace it in the file3
86 sqDose1=$(echo ${file1} | cut -f8 -d' ')
87 sqDose2=$(echo ${file2} | cut -f8 -d' ')
88 sqDose3=$(python -c "print($sqDose1+$sqDose2)")
89 sqDose3=${sqDose3/#./0.}
90 file3=$(echo $file3 |awk -v r=${sqDose3} '{$8=r}1')
92 # sum n_hits: get the 2 values, sum them and replace it in the file3
93 hit1=$(echo ${file1} | cut -f9 -d' ')
94 hit2=$(echo ${file2} | cut -f9 -d' ')
95 hit3=$(python -c "print($hit1+$hit2)")
96 file3=$(echo $file3 |awk -v r=${hit3} '{$9=r}1')
98 # sum n_event_hits: get the 2 values, sum them and replace it in the file3
99 event1=$(echo ${file1} | cut -f10 -d' ')
100 event2=$(echo ${file2} | cut -f10 -d' ')
101 event3=$(python -c "print($event1+$event2)")
102 file3=$(echo $file3 |awk -v r=${event3} '{$10=r}1')
105 echo "${file3}" >> ${TMP}
107 mv -f ${TMP} ${RESULT}
110 function addWithoutPartialResult {
114 test -f ${IN1} || usage
118 nblines=`cat ${IN1} | wc -l`
120 #Copy the 1st line in output
121 line1=`sed -n "1p" < ${IN1}`
122 echo "${line1}" >> ${TMP}
123 # for all lines (except the 1st), split according tab
124 # sum the some elements (dose, edep) ...
125 for i in $(seq 2 $nblines); do
127 file1=`sed -n "${i}p" < ${IN1}`
130 id1=$(echo ${file1} | cut -f1 -d' ')
135 vol1=$(echo ${file1} | cut -f2 -d' ')
137 file3=$(echo "$file3 $vol1")
140 edep1=$(echo ${file1} | cut -f3 -d' ')
142 file3=$(echo "$file3 $edep1")
144 # sqrt sum square std_edep*edep
145 stdEdep1=$(echo ${file1} | cut -f4 -d' ')
146 stdEdep3=$(python <<EOP
148 temp=$edep1*$stdEdep1;
149 print(math.sqrt(temp*temp))
152 stdEdep3=${stdEdep3/#./0.}
153 file3=$(echo "$file3 $stdEdep3")
156 sqEdep1=$(echo ${file1} | cut -f5 -d' ')
157 sqEdep1=${sqEdep1/#./0.}
158 file3=$(echo "$file3 $sqEdep1")
161 dose1=$(echo ${file1} | cut -f6 -d' ')
163 file3=$(echo "$file3 $dose1")
165 # sqrt sum square std_dose*dose
166 stdDose1=$(echo ${file1} | cut -f7 -d' ')
167 stdDose3=$(python <<EOP
169 temp=$dose1*$stdDose1;
170 print(math.sqrt(temp*temp))
173 stdDose3=${stdDose3/#./0.}
174 file3=$(echo "$file3 $stdDose3")
177 sqDose1=$(echo ${file1} | cut -f8 -d' ')
178 sqDose1=${sqDose1/#./0.}
179 file3=$(echo "$file3 $sqDose1")
182 hit1=$(echo ${file1} | cut -f9 -d' ')
184 file3=$(echo "$file3 $hit1")
187 event1=$(echo ${file1} | cut -f10 -d' ')
188 event1=${event1/#./0.}
189 file3=$(echo "$file3 $event1")
192 echo "${file3}" >> ${TMP}
194 mv -f ${TMP} ${RESULT}
198 function divideUncertaintyResult {
205 # check if all 3 text files have the same number of lines
206 nblines=`cat ${IN1} | wc -l`
207 nb3=`cat ${RESULT} | wc -l`
209 if [ $nblines -ne $nb3 ]; then
210 echo "Files does not have the same size"
214 #Copy the 1st line in output
215 line1=`sed -n "1p" < ${RESULT}`
216 echo "${line1}" >> ${TMP}
217 # for all lines (except the 1st), split according tab
218 # sum the some elements (dose, edep) ...
219 for i in $(seq 2 $nblines); do
221 file1=`sed -n "${i}p" < ${IN1}`
222 file3=`sed -n "${i}p" < ${RESULT}`
224 # Divide uncertainty and replace it in the file3
225 edep1=$(echo ${file1} | cut -f3 -d' ')
226 stdEdep1=$(echo ${file1} | cut -f4 -d' ')
227 stdEdep3=$(python <<EOP
228 temp=$stdEdep1/$value
236 stdEdep3=${stdEdep3/#./0.}
237 file3=$(echo $file3 |awk -v r=${stdEdep3} '{$4=r}1')
239 # Divide uncertainty and replace it in the file3
240 dose1=$(echo ${file1} | cut -f6 -d' ')
241 stdDose1=$(echo ${file1} | cut -f7 -d' ')
242 stdDose3=$(python <<EOP
243 temp=$stdDose1/$value
251 stdDose3=${stdDose3/#./0.}
252 file3=$(echo $file3 |awk -v r=${stdDose3} '{$7=r}1')
255 echo "${file3}" >> ${TMP}
257 mv -f ${TMP} ${RESULT}