Root/usrp/p.c

Source at commit 424ddce9756cb5ead3e86ec27e767b4e25596ed6 created 8 years 10 months ago.
By Werner Almesberger, ants/: Passive board for antenna testing.
1#include <stdlib.h>
2#include <stdio.h>
3#include <math.h>
4#include <sys/types.h>
5
6
7#define PERC 0.9
8#define SKIP 1000000
9
10
11static int comp(const void *_a, const void *_b)
12{
13    float a = *(const float *) _a;
14    float b = *(const float *) _b;
15
16    return a < b ? -1 : a > b;
17}
18
19
20int main(int argc, char **argv)
21{
22    float max = 0;
23    float c[2], a;
24    float *rec = NULL;
25    int e = 0, n = 0, skip = SKIP;
26
27    while (1) {
28        size_t s;
29
30        s = fread(c, sizeof(c), 1, stdin);
31        if (!s) {
32            if (!ferror(stdin))
33                break;
34            if (s < 0) {
35                perror("read");
36                return 1;
37            }
38        }
39        if (skip) {
40            skip--;
41            continue;
42        }
43        a = hypotf(c[0], c[1]);
44        if (a > max)
45            max = a;
46        if (e <= n) {
47            e = e ? e*2 : 10000;
48            rec = realloc(rec, e*sizeof(float));
49            if (!rec) {
50                perror("realloc");
51                exit(1);
52            }
53        }
54        rec[n] = a;
55        n++;
56    }
57    qsort(rec, n, sizeof(float), comp);
58    printf("%f %f\n", max, rec[(int) (PERC*n)]);
59#if 0
60int i;
61
62    for (i = 0; i < n; i += 1000)
63        printf("%f %f\n", (double) i/n, rec[i]);
64#endif
65    return 0;
66}
67

Archive Download this file



interactive