diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2021-10-22 22:12:34 +0300 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2021-10-22 22:12:34 +0300 |
commit | 089adb31af9612188088274c248fc490f24cf41e (patch) | |
tree | 28da07636fbed662bd561b1ef3cfdfd9c5e0a145 /test | |
parent | 319d6e06f11dd4ff6c0d64a3f198464148f1a472 (diff) | |
download | libpqf-089adb31af9612188088274c248fc490f24cf41e.tar.gz |
Simple tool to plot prototype from test module
Diffstat (limited to 'test')
-rw-r--r-- | test/plottool.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/plottool.c b/test/plottool.c new file mode 100644 index 0000000..c52dfe3 --- /dev/null +++ b/test/plottool.c @@ -0,0 +1,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; +} |