1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-01-03 10:06:01 +01:00

add trexio_has_backend function to the C and Fortran APIs

This commit is contained in:
q-posev 2021-11-02 11:05:27 +01:00
parent cce0f49785
commit 954ee4216c

View File

@ -25,6 +25,7 @@
#ifndef TREXIO_H #ifndef TREXIO_H
#define TREXIO_H #define TREXIO_H
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
typedef int32_t trexio_exit_code; typedef int32_t trexio_exit_code;
@ -539,7 +540,30 @@ typedef int32_t back_end_t;
#define TREXIO_DELIM "\n" #define TREXIO_DELIM "\n"
#+end_src #+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 *** Fortran
#+begin_src f90 :tangle prefix_fortran.f90 #+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 integer(trexio_backend), parameter :: TREXIO_INVALID_BACK_END = 2
#+end_src #+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 *** Python
#+begin_src python :tangle prefix_python.py #+begin_src python :tangle prefix_python.py