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 | |
parent | 319d6e06f11dd4ff6c0d64a3f198464148f1a472 (diff) | |
download | libpqf-089adb31af9612188088274c248fc490f24cf41e.tar.gz |
Simple tool to plot prototype from test module
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rw-r--r-- | test/plottool.c | 59 |
2 files changed, 68 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 876be18..011d234 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,14 @@ add_executable(ut test/ut_dca_pr.c test/ut_dca_pr_long.c test/common.c) + +add_executable(plottool + test/plottool.c + test/ut_dca_pr.c + test/ut_dca_pr_long.c + test/common.c) + + target_include_directories( ut PRIVATE @@ -22,3 +30,4 @@ target_include_directories( . ) target_link_libraries(ut pqf m) +target_link_libraries(plottool pqf m) 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; +} |