mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-12-23 12:56:53 +01:00
Renamed backend -> back_end for consistency + Better type names, using types in functions.
This commit is contained in:
parent
0651ef66b6
commit
73a8ef1925
@ -83,8 +83,8 @@ module trexio
|
|||||||
implicit none
|
implicit none
|
||||||
|
|
||||||
integer, parameter :: trexio_exit_code = c_int32_t
|
integer, parameter :: trexio_exit_code = c_int32_t
|
||||||
integer, parameter :: trexio_backend = c_int32_t
|
integer, parameter :: trexio_back_end_t = c_int32_t
|
||||||
integer, parameter :: trexio_filetype = c_int64_t
|
integer, parameter :: trexio_t = c_int64_t
|
||||||
|
|
||||||
character(kind=c_char), parameter :: TREXIO_DELIM = c_new_line
|
character(kind=c_char), parameter :: TREXIO_DELIM = c_new_line
|
||||||
#+end_src
|
#+end_src
|
||||||
@ -560,15 +560,16 @@ 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.
|
The helper function ~trexio_has_back_end~ 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.
|
This is useful due to the fact that HDF5 back end can be disabled at configure step.
|
||||||
|
|
||||||
#+begin_src c :tangle prefix_front.h
|
#+begin_src c :tangle prefix_front.h
|
||||||
bool trexio_has_backend(back_end_t back_end);
|
bool trexio_has_backend(back_end_t back_end);
|
||||||
|
bool trexio_has_back_end(back_end_t back_end);
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
#+begin_src c :tangle prefix_front.c
|
#+begin_src c :tangle prefix_front.c
|
||||||
bool trexio_has_backend(back_end_t back_end) {
|
bool trexio_has_back_end(back_end_t back_end) {
|
||||||
switch (back_end) {
|
switch (back_end) {
|
||||||
case TREXIO_TEXT:
|
case TREXIO_TEXT:
|
||||||
return true;
|
return true;
|
||||||
@ -581,20 +582,32 @@ bool trexio_has_backend(back_end_t back_end) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool trexio_has_backend(back_end_t back_end) {
|
||||||
|
return trexio_has_back_end(back_end);
|
||||||
|
}
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
*** Fortran
|
*** Fortran
|
||||||
|
|
||||||
#+begin_src f90 :tangle prefix_fortran.f90
|
#+begin_src f90 :tangle prefix_fortran.f90
|
||||||
integer(trexio_backend), parameter :: TREXIO_HDF5 = 0
|
integer(trexio_back_end_t), parameter :: TREXIO_HDF5 = 0
|
||||||
integer(trexio_backend), parameter :: TREXIO_TEXT = 1
|
integer(trexio_back_end_t), parameter :: TREXIO_TEXT = 1
|
||||||
! integer(trexio_backend), parameter :: TREXIO_JSON = 2
|
! integer(trexio_back_end_t), parameter :: TREXIO_JSON = 2
|
||||||
integer(trexio_backend), parameter :: TREXIO_INVALID_BACK_END = 2
|
integer(trexio_back_end_t), 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.
|
The function below is a Fortran interface for the aforementioned C-compatible ~trexio_has_back_end~ function.
|
||||||
|
|
||||||
#+begin_src f90 :tangle prefix_fortran.f90
|
#+begin_src f90 :tangle prefix_fortran.f90
|
||||||
|
interface
|
||||||
|
logical(c_bool) function trexio_has_back_end (back_end) bind(C)
|
||||||
|
use, intrinsic :: iso_c_binding
|
||||||
|
import
|
||||||
|
integer(c_int32_t), intent(in), value :: back_end
|
||||||
|
end function trexio_has_back_end
|
||||||
|
end interface
|
||||||
|
|
||||||
interface
|
interface
|
||||||
logical(c_bool) function trexio_has_backend (back_end) bind(C)
|
logical(c_bool) function trexio_has_backend (back_end) bind(C)
|
||||||
use, intrinsic :: iso_c_binding
|
use, intrinsic :: iso_c_binding
|
||||||
@ -604,6 +617,9 @@ interface
|
|||||||
end interface
|
end interface
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
Originally, the function was named ~trexio_has_backend~. For
|
||||||
|
consistency, in version 2.2 it was renamed ~trexio_has_back_end~.
|
||||||
|
|
||||||
*** Python
|
*** Python
|
||||||
|
|
||||||
#+begin_src python :tangle prefix_python.py
|
#+begin_src python :tangle prefix_python.py
|
||||||
@ -968,12 +984,12 @@ trexio_open(const char* file_name, const char mode,
|
|||||||
|
|
||||||
#+begin_src f90 :tangle prefix_fortran.f90
|
#+begin_src f90 :tangle prefix_fortran.f90
|
||||||
interface
|
interface
|
||||||
integer(c_int64_t) function trexio_open_c (filename, mode, backend, rc_open) bind(C, name="trexio_open")
|
integer(c_int64_t) function trexio_open_c (filename, mode, back_end, rc_open) bind(C, name="trexio_open")
|
||||||
use, intrinsic :: iso_c_binding
|
use, intrinsic :: iso_c_binding
|
||||||
import
|
import
|
||||||
character(kind=c_char), dimension(*) :: filename
|
character(kind=c_char), dimension(*) :: filename
|
||||||
character(kind=c_char), intent(in), value :: mode
|
character(kind=c_char), intent(in), value :: mode
|
||||||
integer(trexio_backend), intent(in), value :: backend
|
integer(trexio_back_end_t), intent(in), value :: back_end
|
||||||
integer(trexio_exit_code), intent(out) :: rc_open
|
integer(trexio_exit_code), intent(out) :: rc_open
|
||||||
end function trexio_open_c
|
end function trexio_open_c
|
||||||
end interface
|
end interface
|
||||||
@ -3736,7 +3752,7 @@ interface
|
|||||||
bind(C, name="trexio_write_$group_str$")
|
bind(C, name="trexio_write_$group_str$")
|
||||||
use, intrinsic :: iso_c_binding
|
use, intrinsic :: iso_c_binding
|
||||||
import
|
import
|
||||||
integer(c_int64_t), intent(in), value :: trex_file
|
integer(trexio_t), intent(in), value :: trex_file
|
||||||
character(kind=c_char), intent(in) :: str(*)
|
character(kind=c_char), intent(in) :: str(*)
|
||||||
integer(c_int32_t), intent(in), value :: max_str_len
|
integer(c_int32_t), intent(in), value :: max_str_len
|
||||||
end function trexio_write_$group_str$_c
|
end function trexio_write_$group_str$_c
|
||||||
@ -3749,7 +3765,7 @@ interface
|
|||||||
bind(C, name="trexio_read_$group_str$")
|
bind(C, name="trexio_read_$group_str$")
|
||||||
use, intrinsic :: iso_c_binding
|
use, intrinsic :: iso_c_binding
|
||||||
import
|
import
|
||||||
integer(c_int64_t), intent(in), value :: trex_file
|
integer(trexio_t), intent(in), value :: trex_file
|
||||||
character(kind=c_char), intent(out) :: str(*)
|
character(kind=c_char), intent(out) :: str(*)
|
||||||
integer(c_int32_t), intent(in), value :: max_str_len
|
integer(c_int32_t), intent(in), value :: max_str_len
|
||||||
end function trexio_read_$group_str$_c
|
end function trexio_read_$group_str$_c
|
||||||
@ -3761,7 +3777,7 @@ interface
|
|||||||
integer(trexio_exit_code) function trexio_has_$group_str$ (trex_file) bind(C)
|
integer(trexio_exit_code) function trexio_has_$group_str$ (trex_file) bind(C)
|
||||||
use, intrinsic :: iso_c_binding
|
use, intrinsic :: iso_c_binding
|
||||||
import
|
import
|
||||||
integer(c_int64_t), intent(in), value :: trex_file
|
integer(trexio_t), intent(in), value :: trex_file
|
||||||
end function trexio_has_$group_str$
|
end function trexio_has_$group_str$
|
||||||
end interface
|
end interface
|
||||||
#+end_src
|
#+end_src
|
||||||
@ -3769,7 +3785,7 @@ end interface
|
|||||||
#+begin_src f90 :tangle helper_read_attr_str_front_fortran.fh_90
|
#+begin_src f90 :tangle helper_read_attr_str_front_fortran.fh_90
|
||||||
integer(trexio_exit_code) function trexio_read_$group_str$ (trex_file, str, max_str_len)
|
integer(trexio_exit_code) function trexio_read_$group_str$ (trex_file, str, max_str_len)
|
||||||
implicit none
|
implicit none
|
||||||
integer(c_int64_t), intent(in), value :: trex_file
|
integer(trexio_t), intent(in), value :: trex_file
|
||||||
integer(c_int32_t), intent(in), value :: max_str_len
|
integer(c_int32_t), intent(in), value :: max_str_len
|
||||||
character, intent(out) :: str(*)
|
character, intent(out) :: str(*)
|
||||||
|
|
||||||
@ -3782,7 +3798,7 @@ end interface
|
|||||||
integer(trexio_exit_code) function trexio_write_$group_str$ (trex_file, str, max_str_len)
|
integer(trexio_exit_code) function trexio_write_$group_str$ (trex_file, str, max_str_len)
|
||||||
use, intrinsic :: iso_c_binding, only : c_null_char
|
use, intrinsic :: iso_c_binding, only : c_null_char
|
||||||
implicit none
|
implicit none
|
||||||
integer(c_int64_t), intent(in), value :: trex_file
|
integer(trexio_t), intent(in), value :: trex_file
|
||||||
integer(c_int32_t), intent(in), value :: max_str_len
|
integer(c_int32_t), intent(in), value :: max_str_len
|
||||||
character(len=*), intent(in) :: str
|
character(len=*), intent(in) :: str
|
||||||
|
|
||||||
@ -3887,18 +3903,18 @@ def has_$group_str$(trexio_file) -> bool:
|
|||||||
|
|
||||||
#+begin_src f90 :tangle helper_fortran.f90
|
#+begin_src f90 :tangle helper_fortran.f90
|
||||||
contains
|
contains
|
||||||
integer(c_int64_t) function trexio_open (filename, mode, backend, rc_open)
|
integer(trexio_t) function trexio_open (filename, mode, back_end, rc_open)
|
||||||
use, intrinsic :: iso_c_binding, only : c_null_char
|
use, intrinsic :: iso_c_binding, only : c_null_char
|
||||||
implicit none
|
implicit none
|
||||||
character(len=*), intent(in) :: filename
|
character(len=*), intent(in) :: filename
|
||||||
character, intent(in), value :: mode
|
character, intent(in), value :: mode
|
||||||
integer(trexio_backend), intent(in), value :: backend
|
integer(trexio_back_end_t), intent(in), value :: back_end
|
||||||
integer(trexio_exit_code), intent(out) :: rc_open
|
integer(trexio_exit_code), intent(out) :: rc_open
|
||||||
character(len=len_trim(filename)+1) :: filename_c
|
character(len=len_trim(filename)+1) :: filename_c
|
||||||
integer(trexio_exit_code) :: rc
|
integer(trexio_exit_code) :: rc
|
||||||
|
|
||||||
filename_c = trim(filename) // c_null_char
|
filename_c = trim(filename) // c_null_char
|
||||||
trexio_open = trexio_open_c(filename_c, mode, backend, rc_open)
|
trexio_open = trexio_open_c(filename_c, mode, back_end, rc_open)
|
||||||
if (trexio_open == 0_8 .or. rc_open /= TREXIO_SUCCESS) then
|
if (trexio_open == 0_8 .or. rc_open /= TREXIO_SUCCESS) then
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
Loading…
Reference in New Issue
Block a user