-
Notifications
You must be signed in to change notification settings - Fork 0
/
4d_check.c
102 lines (90 loc) · 2.45 KB
/
4d_check.c
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
/* 4D检验法去除异常数据 */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
// #define MIN_TIME 0.000001
// #define DEBUG 1
int main(int argc, char *argv[]) {
int flag = 0, count = 0, row = 0, base = 0, i = 0, j = 0;
FILE *data1;
long double time_base[100];
long double time_base_sum = 0;
int start, end;
long double time_sum = 0;
long double time_output_sum = 0;
int time_output_count = 0;
#ifdef DEBUG
printf("4D Test will opening file(%s).\r\n", argv[1]);
#endif // DEBUG
data1 = fopen(argv[1], "r");
if (!data1) {
printf("Error in opening file(%s).\r\n", argv[1]);
exit(1);
}
row = 0;
while (fscanf(data1, "%Lf\n", &time_base[row]) != EOF)
row++;
#ifdef DEBUG
printf("the file(%s) total has %d lines data.\r\n", argv[1], row);
#endif // DEBUG
start = 0;
end = row - start;
for (i = start; i < end; i++) {
time_sum += time_base[i];
}
#ifdef DEBUG
printf("the sum of the %d lines data is %.10LF.\r\n", row, time_sum);
#endif // DEBUG
for (i = start; i < end; i++) {
#ifdef DEBUG
printf("the %dth data is %.10LF.\r\n", i, time_base[i]);
#endif // DEBUG
/*
// 设置时间最小值,如果小于该值直接舍弃.
if (time_base[i] < MIN_TIME) {
continue;
}*/
time_base_sum = time_sum - time_base[i];
#ifdef DEBUG
printf("time_base_sum is %.10LF.\r\n", time_base_sum);
#endif // DEBUG
long double avg1 = time_base_sum / (row - 1);
#ifdef DEBUG
printf("avg1 is %.10LF.\r\n", avg1);
#endif // DEBUG
long double avg2 = 0.0;
for (j = start; j < end; j++) {
if (j != i) {
avg2 += (fabsl(time_base[j] - avg1));
}
}
#ifdef DEBUG
printf("avg2 is %.10LF.\r\n", avg2);
#endif // DEBUG
avg2 = (avg2 / (row - 1)) * 4;
if (0 == (time_base[i] - avg1) && 0 == avg2) {
time_output_sum += time_base[i];
time_output_count++;
continue;
}
if (fabsl(time_base[i] - avg1) < avg2) {
time_output_sum += time_base[i];
time_output_count++;
}
#ifdef DEBUG
printf("after calculate the %dth data(%.10LF),the count is %d .\r\n", i,
time_base[i], time_output_count);
#endif // DEBUG
}
// printf("%s\t", argv[1]);
if (time_output_count != 0) {
printf("%.10Lf\n", time_output_sum / time_output_count);
#ifdef DEBUG
printf("All the count is %d .\r\n", time_output_count);
#endif // DEBUG
} else {
printf("Error:input numbers are all incorrect!\n");
}
fclose(data1);
return (0);
}