aboutsummaryrefslogtreecommitdiffstats
path: root/test/plottool.c
blob: c52dfe3adbc9045f2dcf61cd47254dccbe3f7a31 (plain) (blame)
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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "ut_dca_pr.h"
#include "ut_dca_pr_long.h"

#define FILL_IF_MATCH(SZ, H, NAME, MODULE) \
    do { \
        if (strcmp(#MODULE, NAME) == 0) { \
            SZ = MODULE.get_proto_sz(); \
	    H = MODULE.get_proto(); \
	} \
    } while (0) \

int main(int argc, char** argv) {

    if (argc != 2) {
        fprintf(stderr, "expected one argument\n");
	return 1;
    }

    const char * const name = argv[1];
    FILE* pipe;
    size_t sz = 0;
    const float* h;

    pipe = popen("gnuplot -persistent", "w");

    if (!pipe) {
        fprintf(stderr, "unable launch gnuplot\n");
        return 1;
    }

    FILL_IF_MATCH(sz, h, name, ut_dca_pr);
    FILL_IF_MATCH(sz, h, name, ut_dca_pr_long);

    if (!sz) {
        fprintf(stderr, "no data to plot\n");
        pclose(pipe);
	return 1;
    }

    fprintf(pipe, "set title \"%s\" noenhanced \n", name);
    fprintf(pipe, "set term x11 \n");
    fprintf(pipe, "set style line 1linecolor rgb '#0060ad' linetype 1 linewidth 2 pointtype 7 pointsize 0.1 \n");
    fprintf(pipe, "plot '-' with linespoints linestyle 1 \n");
    int i;

    for (size_t i = 0; i < sz; i++) {
        fprintf(pipe, "%zu %lf\n", i, h[i]);
    }

    fprintf(pipe, "e");

    pclose(pipe);

    return 0;
}