From 954ee4216c0fd6afeafb0ea47d6e3ed1738fcfa7 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 2 Nov 2021 11:05:27 +0100 Subject: [PATCH] add trexio_has_backend function to the C and Fortran APIs --- src/templates_front/templator_front.org | 37 ++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 95dd73b..5f9f3f3 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -25,6 +25,7 @@ #ifndef TREXIO_H #define TREXIO_H +#include #include typedef int32_t trexio_exit_code; @@ -539,7 +540,30 @@ typedef int32_t back_end_t; #define TREXIO_DELIM "\n" #+end_src - + + The helper function ~trexio_has_backend~ returns ~true~ if TREXIO compilation includes a back end provided as an argument; ~false~ otherwise. + This is useful due to the fact that HDF5 back end can be disabled at configure step. + + #+begin_src c :tangle prefix_front.h +bool trexio_has_backend(back_end_t back_end); + #+end_src + + #+begin_src c :tangle prefix_front.c +bool trexio_has_backend(back_end_t back_end) { + switch (back_end) { + case TREXIO_TEXT: + return true; + case TREXIO_HDF5: +#ifdef HAVE_HDF5 + return true; +#else + return false; +#endif + } + return false; +} + #+end_src + *** Fortran #+begin_src f90 :tangle prefix_fortran.f90 @@ -549,6 +573,17 @@ typedef int32_t back_end_t; integer(trexio_backend), parameter :: TREXIO_INVALID_BACK_END = 2 #+end_src + The function below is a Fortran interface for the aforementioned C-compatible ~trexio_has_backend~ function. + + #+begin_src f90 :tangle prefix_fortran.f90 +interface + logical function trexio_has_backend (back_end) bind(C) + use, intrinsic :: iso_c_binding + integer(4), intent(in), value :: back_end + end function trexio_has_backend +end interface + #+end_src + *** Python #+begin_src python :tangle prefix_python.py