-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parser.awk
150 lines (135 loc) · 3.73 KB
/
Parser.awk
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#
# usage:
# awk -f thp.awk log.txt
# awk -f thp.awk log.txt | awk 'NF >= 2' > thp00
BEGIN {
debug = 0
fifo_err = 0
event = 0
# Print header
# !!! Comment this line to reduce head line !!!
printf "Event\tIanode\tTmos\tUp\tfifo_err\n"
}
# ----------------------------------------------------
# ----------------------------------------------------
{
if(/File/)
{
sub(/is open!/," ")
sub(/File/,"")
#printf $0 "\n"
}
# ------------------------------------------------
# Read high voltage line
if(/Ianode/)
{
gsub(/=/, " ")
if(debug)
printf "\n>>>>"$0 "\n"
# Find number of the word "Ianode" in the line
for(i = 1; i <= NF; i++)
{
if($i == "Ianode")
icur = i + 1
if($i == "Up")
iup = i + 1
if($i == "T")
it = i + 1
}
Tmos = $it
Ianode = $icur
Up = $iup
if(debug)
printf "\n!!!!Up=>"Up"<-----Ia=>"Ianode"<-----Tmos=>"Tmos"<----\n"
}
# ------------------------------------------------
# Read and calculate Up= Unegative + Upositive
if( (/Measure current:/) \
|| (/read_vip_ADC:/) \
|| (/Measure_high: current:/) \
|| (/Mosaic: measure_high:/) \
)
{
if(debug)
printf "\n==>"$0 "<==\n"
if(/current:/)
{
if(/current =/)
gsub(/current =/, " ")
# Find number of the word "current:" in the line
for(i = 1; i <= NF; i++)
if($i == "current:")
iup = i + 1
ch0 = $iup
ch1 = $(iup + 1)
ch2 = $(iup + 2)
ch3 = $(iup + 3)
}
else if((/read_vip_ADC:/) || (/easure_high:/))
{
gsub(/\[/, " ")
gsub(/\]/, " ")
for(i = 1; i <= NF; i++)
if($i == "CH0")
iup = i + 1
ch0 = $iup
ch1 = $(iup + 2)
ch2 = $(iup + 4)
ch3 = $(iup + 6)
}
if(debug)
printf "CH:"ch0" "ch1" "ch2" "ch3"\n"
Upositive = ch1 / 2000.
Unegative = 0.01514 * ch0 - 36.6
Up = -1 * (Unegative - Upositive)
I = 0.005012 * (ch2-ch1)
Tmos = (ch3/2.0 - 500.0) * 0.1
if(debug)
printf "VA: I"Ianode" Tmos"Tmos" Up"Up" \n"
}
# ------------------------------------------------
# Read fifo_err
if(/Fifo_err/)
{
fifo_err += 1
}
# ------------------------------------------------
# Print info for previous event. Read new Event number.
#
if(/<K/)
{
# print info for previous event
if(event != 0)
{
Up = -1 * (Unegative - Upositive)
str_out = sprintf("%d\t%5.3f\t%6.2f\t%5.2f\t%2d", \
event, Ianode, Tmos, Up, fifo_err)
print(str_out)
#printf event" "Ianode" "Tmos" "Up" "fifo_err"\n"
}
# init fifo_err counter
fifo_err = 0
# read new event number
for(i=1; i<=NF; i++)
{
if( index($i,"<K"))
{
sub(/<K/," ")
sub(/>/," ")
# if "<K" is not in the firts word
if(i != 1)
{
iev=i+1
event = $iev
}
# if "<K" is in the first word
else
event = $1
}
}
}
}
# ----------------------------------------------------
# ----------------------------------------------------
END {
}