1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-11-03 20:54:07 +01:00

Shift indices of MOs to be 0-based in C and 1-based in Fortran

This commit is contained in:
q-posev 2022-05-23 16:00:21 +02:00
parent 760d85612a
commit 1034f3818e

View File

@ -5293,7 +5293,7 @@ trexio_exit_code trexio_to_orbital_list(const int32_t N_int,
pos = trailz(tmp); pos = trailz(tmp);
if (pos < 0) return TREXIO_FAILURE; if (pos < 0) return TREXIO_FAILURE;
list[k] = ( (int32_t) pos) + shift; list[k] = ( (int32_t) pos) + shift - 1;
tmp ^= ( ((bitfield_t) 1) << pos); tmp ^= ( ((bitfield_t) 1) << pos);
k++; k++;
} }
@ -5413,27 +5413,30 @@ end interface
#+begin_src f90 :tangle prefix_fortran.f90 #+begin_src f90 :tangle prefix_fortran.f90
interface interface
integer(trexio_exit_code) function trexio_to_orbital_list(N_int, d1, list, occupied_num) bind(C) integer(trexio_exit_code) function trexio_to_orbital_list_c(N_int, d1, list, occupied_num) bind(C, name="trexio_to_orbital_list")
use, intrinsic :: iso_c_binding use, intrinsic :: iso_c_binding
import import
integer(c_int32_t), intent(in), value :: N_int integer(c_int32_t), intent(in), value :: N_int
integer(c_int64_t), intent(in) :: d1(*) integer(c_int64_t), intent(in) :: d1(*)
integer(c_int32_t), intent(out) :: list(*) integer(c_int32_t), intent(inout) :: list(*)
integer(c_int32_t), intent(inout) :: occupied_num integer(c_int32_t), intent(inout) :: occupied_num
end function trexio_to_orbital_list end function trexio_to_orbital_list_c
end interface end interface
#+end_src
#+begin_src f90 :tangle prefix_fortran.f90
interface interface
integer(trexio_exit_code) function trexio_to_orbital_list_up_dn(N_int, d1, list_up, list_dn, occ_num_up, occ_num_dn) bind(C) integer(trexio_exit_code) function trexio_to_orbital_list_up_dn_c(N_int, d1, list_up, list_dn, occ_num_up, occ_num_dn) &
bind(C, name="trexio_to_orbital_list_up_dn")
use, intrinsic :: iso_c_binding use, intrinsic :: iso_c_binding
import import
integer(c_int32_t), intent(in), value :: N_int integer(c_int32_t), intent(in), value :: N_int
integer(c_int64_t), intent(in) :: d1(*) integer(c_int64_t), intent(in) :: d1(*)
integer(c_int32_t), intent(out) :: list_up(*) integer(c_int32_t), intent(inout) :: list_up(*)
integer(c_int32_t), intent(out) :: list_dn(*) integer(c_int32_t), intent(inout) :: list_dn(*)
integer(c_int32_t), intent(inout) :: occ_num_up integer(c_int32_t), intent(inout) :: occ_num_up
integer(c_int32_t), intent(inout) :: occ_num_dn integer(c_int32_t), intent(inout) :: occ_num_dn
end function trexio_to_orbital_list_up_dn end function trexio_to_orbital_list_up_dn_c
end interface end interface
#+end_src #+end_src
@ -5554,7 +5557,58 @@ contains
filename_c = trim(filename) // c_null_char filename_c = trim(filename) // c_null_char
trexio_inquire = trexio_inquire_c(filename_c) trexio_inquire = trexio_inquire_c(filename_c)
end function trexio_inquire end function trexio_inquire
#+end_src
The subrotine below wrap the ~to_orbital_list~ functions to shift the MO indices
by 1 since in Fortran arrays are 1-based and C/Python they are 0-based.
#+begin_src f90 :tangle helper_fortran.f90
integer(trexio_exit_code) function trexio_to_orbital_list(N_int, d1, list, occupied_num)
use, intrinsic :: iso_c_binding
implicit none
integer(c_int32_t), intent(in), value :: N_int
integer(c_int64_t), intent(in) :: d1(*)
integer(c_int32_t), intent(out) :: list(*)
integer(c_int32_t), intent(out) :: occupied_num
integer :: i
trexio_to_orbital_list = trexio_to_orbital_list_c(N_int, d1, list, occupied_num)
if (trexio_to_orbital_list /= TREXIO_SUCCESS) then
return
endif
do i = 1,occupied_num
list(i) = list(i) + 1
enddo
end function trexio_to_orbital_list
integer(trexio_exit_code) function trexio_to_orbital_list_up_dn(N_int, d1, list_up, list_dn, occ_num_up, occ_num_dn)
use, intrinsic :: iso_c_binding
implicit none
integer(c_int32_t), intent(in), value :: N_int
integer(c_int64_t), intent(in) :: d1(*)
integer(c_int32_t), intent(out) :: list_up(*)
integer(c_int32_t), intent(out) :: list_dn(*)
integer(c_int32_t), intent(out) :: occ_num_up
integer(c_int32_t), intent(out) :: occ_num_dn
integer :: i
trexio_to_orbital_list_up_dn = trexio_to_orbital_list_up_dn_c(N_int, d1, list_up, list_dn, occ_num_up, occ_num_dn)
if (trexio_to_orbital_list_up_dn /= TREXIO_SUCCESS) then
return
endif
do i = 1,occ_num_up
list_up(i) = list_up(i) + 1
enddo
do i = 1,occ_num_dn
list_dn(i) = list_dn(i) + 1
enddo
end function trexio_to_orbital_list_up_dn
#+end_src #+end_src
The subroutine below transforms an array of Fortran strings into one big string using ~TREXIO_DELIM~ symbol The subroutine below transforms an array of Fortran strings into one big string using ~TREXIO_DELIM~ symbol