-
Notifications
You must be signed in to change notification settings - Fork 0
/
avg_jk
executable file
·99 lines (95 loc) · 1.42 KB
/
avg_jk
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
#! /usr/bin/awk -f
function isnum(x){return(x==x+0)}
BEGIN{
if (ARGC>2)
{
print "#WARING: Average over multiple files!!";
}
if (name=="")
{
if (ARGV[1]=="")
{
print "#FILE: STDIN";
}
else
{
print "#FILE:",ARGV[1];
}
}
else
{
print "#FILE:",name,"(set by user)";
}
if (col=="")
{
col=1;
print "#Setting column to",col,"(use option \"-v col=X\" to change)";
}
else
{
print "#Using column",col,"(set by user)";
}
if (N_B=="")
{
N_B=16;
print "#Setting Number of blocks to",N_B,"(use option \"-v N_B=X\" to change)";
}
else
{
print "#Using ",N_B," blocks ";
}
c=0;
warn=0;
}
/^[@#]/{
next;
}
{
if (NF>=col && isnum($col))
{
x[c]=$col;
c++;
}
else
{
if (warn == 0)
{
print "# Not enough data in line",NR;
warn++;
}
}
}
END{
L_B=int(c/N_B);
sum=0;
sum2=0;
for (b=0;b<N_B;b++){
for (i=0;i<L_B;i++){
nr=int(b*L_B+i)
sum+=x[nr];
sum2+=x[nr]*x[nr];
for (b2=0;b2<N_B;b2++){
if (b2!=b){
sum_b[b2]+=x[nr];
}
}
}
}
sum=sum/(L_B*N_B);
sum2=sum2/(L_B*N_B);
se_n=(sum2-sum*sum)/(L_B*N_B);
se_n=sqrt(se_n);
se_b=0;
for (b=0;b<N_B;b++){
sum_b[b]=sum_b[b]/(L_B*(N_B-1));
#print b,sum,sum_b[b],se;
se_b+=(sum_b[b]-sum)*(sum_b[b]-sum);
}
# print se;
se_b=se_b*(N_B-1)/N_B;
# print se;
se_b=sqrt(se_b);
print "#Output format: avg se naiv_se values_jk values";
print sum,se_b,se_n,L_B*N_B,c;
}
#fs md5sum 83e6f5f92e44f4ea03a76a8cd04f1b06