5 echo "$0 -i <result> -j <file2> -o <result>"
9 function addToPartialResult {
10 IN1=$2 #merged file for previous jobs
12 RESULT=$6 #output merged file
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 # sum square_edep: get the 2 values, sum them and replace it in the file3
48 sqEdep1=$(echo ${file1} | cut -f5 -d' ')
49 sqEdep2=$(echo ${file2} | cut -f5 -d' ')
50 sqEdep3=$(python -c "print($sqEdep1+$sqEdep2)")
51 sqEdep3=${sqEdep3/#./0.}
52 file3=$(echo $file3 |awk -v r=${sqEdep3} '{$5=r}1')
54 # sum dose: get the 2 values, sum them and replace it in the file3
55 dose1=$(echo ${file1} | cut -f6 -d' ')
56 dose2=$(echo ${file2} | cut -f6 -d' ')
57 dose3=$(python -c "print($dose1+$dose2)")
59 file3=$(echo $file3 |awk -v r=${dose3} '{$6=r}1')
61 # sum square_dose: get the 2 values, sum them and replace it in the file3
62 sqDose1=$(echo ${file1} | cut -f8 -d' ')
63 sqDose2=$(echo ${file2} | cut -f8 -d' ')
64 sqDose3=$(python -c "print($sqDose1+$sqDose2)")
65 sqDose3=${sqDose3/#./0.}
66 file3=$(echo $file3 |awk -v r=${sqDose3} '{$8=r}1')
68 # sum n_hits: get the 2 values, sum them and replace it in the file3
69 hit1=$(echo ${file1} | cut -f9 -d' ')
70 hit2=$(echo ${file2} | cut -f9 -d' ')
71 hit3=$(python -c "print($hit1+$hit2)")
72 file3=$(echo $file3 |awk -v r=${hit3} '{$9=r}1')
74 # sum n_event_hits: get the 2 values, sum them and replace it in the file3
75 event1=$(echo ${file1} | cut -f10 -d' ')
76 event2=$(echo ${file2} | cut -f10 -d' ')
77 event3=$(python -c "print($event1+$event2)")
78 file3=$(echo $file3 |awk -v r=${event3} '{$10=r}1')
81 echo "${file3}" >> ${TMP}
83 mv -f ${TMP} ${RESULT}
86 function divideUncertaintyResult {
93 # check if all 2 text files have the same number of lines
94 nblines=`cat ${IN1} | wc -l`
95 nb3=`cat ${RESULT} | wc -l`
97 if [ $nblines -ne $nb3 ]; then
98 echo "Files does not have the same size"
102 #Copy the 1st line in output
103 line1=`sed -n "1p" < ${RESULT}`
104 echo "${line1}" >> ${TMP}
105 # for all lines (except the 1st), split according tab
106 # sum the some elements (dose, edep) ...
107 for i in $(seq 2 $nblines); do
109 file1=`sed -n "${i}p" < ${IN1}`
110 file3=`sed -n "${i}p" < ${RESULT}`
112 # Divide uncertainty and replace it in the file3
113 edep1=$(echo ${file1} | cut -f3 -d' ')
114 sqEdep1=$(echo ${file1} | cut -f5 -d' ')
115 stdEdep3=$(python <<EOP
117 temp=math.sqrt(($sqEdep1/$value-pow($edep1/$value, 2))/($value-1))/$edep1/$value
121 stdEdep3=${stdEdep3/#./0.}
122 file3=$(echo $file3 |awk -v r=${stdEdep3} '{$4=r}1')
124 # Divide uncertainty and replace it in the file3
125 dose1=$(echo ${file1} | cut -f6 -d' ')
126 sqDose1=$(echo ${file1} | cut -f8 -d' ')
127 stdDose3=$(python <<EOP
129 temp=math.sqrt(($sqDose1/$value-pow($dose1/$value, 2))/($value-1))/$dose1/$value
133 stdDose3=${stdDose3/#./0.}
134 file3=$(echo $file3 |awk -v r=${stdDose3} '{$7=r}1')
137 echo "${file3}" >> ${TMP}
139 mv -f ${TMP} ${RESULT}