Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interface return type and remove unused dummy argument #145

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/templates_front/templator_front.org
Original file line number Diff line number Diff line change
Expand Up @@ -4521,7 +4521,7 @@ end interface
if (rc /= TREXIO_SUCCESS) then
trexio_write_$group_dset$ = rc
else
call trexio_strarray2str(dset, $group_dset_dim$, max_str_len, str_compiled)
call trexio_strarray2str(dset, $group_dset_dim$, str_compiled)
trexio_write_$group_dset$ = trexio_write_$group_dset$_low(trex_file, str_compiled, max_str_len)
endif

Expand Down Expand Up @@ -6332,9 +6332,9 @@ trexio_mark_safety (trexio_t* const file, const int32_t safety_flag)

#+begin_src f90 :tangle prefix_fortran.f90
interface
integer function trexio_info () bind(C)
integer(c_int32_t) function trexio_info_c () bind(C, name="trexio_info")
use, intrinsic :: iso_c_binding
end function trexio_info
end function trexio_info_c
end interface
#+end_src

Expand Down Expand Up @@ -6647,13 +6647,20 @@ def evaluate_nao_radial_all(nucleus_index, nucleus_coords, grid_start,

* Fortran helper/wrapper functions

#+begin_src f90 :tangle helper_fortran.f90
contains
integer function trexio_info ()
implicit none
trexio_info = trexio_info_c()
end function trexio_info
#+end_src

The function below adapts the original C-based ~trexio_open~ for Fortran.
This is needed due to the fact that strings in C are terminated by ~NULL~ character ~\0~
unlike strings in Fortran.
Note, that Fortran interface calls the main ~TREXIO~ API, which is written in C.

#+begin_src f90 :tangle helper_fortran.f90
contains
integer(trexio_t) function trexio_open (filename, mode, back_end, rc_open)
use, intrinsic :: iso_c_binding, only : c_null_char
implicit none
Expand Down Expand Up @@ -6790,12 +6797,11 @@ contains
C API. This is needed due to the fact that strings in C are terminated by ~NULL~ character ~\0~.

#+begin_src f90 :tangle helper_fortran.f90
subroutine trexio_strarray2str(str_array, max_num_str, max_len_str, str_res)
subroutine trexio_strarray2str(str_array, max_num_str, str_res)
use, intrinsic :: iso_c_binding, only : c_null_char
implicit none

integer(c_int64_t), intent(in), value :: max_num_str ! number of elements in strign array
integer, intent(in), value :: max_len_str ! maximum length of a string in an array
integer(c_int64_t), intent(in), value :: max_num_str ! number of elements in string array
character(len=*), intent(in) :: str_array(*)
character(len=:), allocatable, intent(out) :: str_res
integer(c_int64_t) :: i
Expand Down
Loading