-
Notifications
You must be signed in to change notification settings - Fork 0
/
weights
executable file
·134 lines (110 loc) · 2.86 KB
/
weights
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# Copyright (C) 2013 Thomas Carette
###############################################################
TRUE=0
FALSE=1
NO_ARGS=1
E_OPTERROR=65
VERBOSE=/dev/null
print_help()
{
echo -ne "
weight:\n
Print the squared summed weight of all Csf of case.c and case.l file
Usage: weight {-hm:v} case\n
Options: -h : Print this help\n
-v : Be verbose
Arguments:\n
case : The name of the .l and .c file.\n
"
exit 0
}
while getopts "h:v" Option
do
case $Option in
h ) print_help;;
v ) VERBOSE=/dev/stdout;;
* ) echo "Unimplemented option chosen.";; # DEFAULT
esac
done
shift $(($OPTIND - 1))
if [ "$1" = "" ]
then
echo "Please specify the name of the .l and .c file."
exit 1
fi
Input_c="$1.c"
Input_l="$1.l"
if [ ! -e $Input_c ]
then
echo "Missing file '$Input_c'." > /dev/stderr
exit 1
fi
if [ ! -e $Input_l ]
then
echo "Missing file '$Input_l'." > /dev/stderr
exit 1
fi
rm .result &> /dev/null
if [ "$2" != "" ]
then
gawk '{ if ( FNR %2 ==1 ) { print $0 } }' $2.c | grep ')' | uniq > .ref.weight
else
gawk '{ if ( FNR %2 ==1 ) { print $0 } }' $1.c | grep ')' | uniq > .ref.weight
fi
if $( grep -q "0\." .ref.weight )
then
rm bid
touch bid
for li in $( seq 1 $( wc .ref.weight | gawk '{print $1}' ) )
do
tmp=$( head -${li} .ref.weight | tail -1 )
lgth=$( echo "8*$( echo $tmp | grep -o ")" | wc | gawk '{print $1}' ) " | bc -l )
echo "${tmp:0:${lgth}}" >> bid
done
cat bid | uniq > .ref.weight
fi
for linenr in $( seq 1 $(( $( cat .ref.weight | wc -l ) )) )
do
line="$( head -$linenr .ref.weight | tail -1 )"
echo "-----------------------------------------------------" >> $VERBOSE
echo "${line}" >> $VERBOSE
name=$line
csfnrall=$( grep -n "$line" $Input_c | cut -d ':' -f1 )
Mrweight=0
for csfnrdouble in $csfnrall
do
csfnr=$(( ($csfnrdouble-1)/2 ))
entry=$(( $csfnr % 7 ))
if [ $entry = 0 ]
then
entry=7
fi
line=$(( ($csfnr-$entry)/7 ))
weightline="$( head -$(( 7+$line )) $Input_l | tail -1 )"
weight=$( echo "$weightline" | \
cut -c$(( $entry*11-10 ))-$(( $entry*11 )) )
echo "Csf $csfnr, line $line, entry $entry, mixing $weight" >> $VERBOSE
Mrweight=$( echo "$Mrweight+($weight*$weight)" | bc -l )
done
echo "-----------------------------------------------------" >> $VERBOSE
echo "Weight total: $( echo "sqrt( $Mrweight ) " | bc -l ) " >> $VERBOSE
printf "%13.11f %70s\n" \
"$( echo "sqrt( $Mrweight ) " | bc -l )" "$name" >> .result
echo "" >> $VERBOSE
done
Weighttottemp=0
inc=0
sort -r .result > .result1
for i in $( cat .result1 | gawk '{ print $1 }' )
do
let inc++
Weighttottemp=$( echo "${Weighttottemp}+${i}^2" | bc -l )
Weighttot=$( echo "sqrt(${Weighttottemp})" | bc -l )
Weighttot=${Weighttot:0:13}
echo "${Weighttot} $( head -${inc} .result1 | tail -1 )"
done
rm .result
rm .result1
rm .ref.weight
exit 0