10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-11-08 07:03:57 +01:00
quantum_package/src/Bitmask/bitmasks_routines.irp.f

185 lines
5.1 KiB
Fortran
Raw Normal View History

2014-04-03 01:50:22 +02:00
subroutine bitstring_to_list( string, list, n_elements, Nint)
use bitmasks
implicit none
BEGIN_DOC
! Gives the inidices(+1) of the bits set to 1 in the bit string
END_DOC
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: string(Nint)
integer, intent(out) :: list(Nint*bit_kind_size)
integer, intent(out) :: n_elements
integer :: i, ishift
integer(bit_kind) :: l
n_elements = 0
ishift = 2
do i=1,Nint
l = string(i)
do while (l /= 0_bit_kind)
n_elements = n_elements+1
list(n_elements) = ishift+popcnt(l-1_bit_kind) - popcnt(l)
l = iand(l,l-1_bit_kind)
enddo
ishift = ishift + bit_kind_size
enddo
end
subroutine list_to_bitstring( string, list, n_elements, Nint)
use bitmasks
implicit none
2015-03-02 10:36:22 +01:00
BEGIN_DOC
! Returns the physical string "string(N_int,2)" from the array of
! occupations "list(N_int*bit_kind_size,2)
END_DOC
2014-04-03 01:50:22 +02:00
integer, intent(in) :: Nint
integer(bit_kind), intent(out) :: string(Nint)
integer, intent(in) :: list(Nint*bit_kind_size)
integer, intent(in) :: n_elements
integer :: i, j
integer :: ipos, iint
2015-03-02 10:32:04 +01:00
!
2014-04-03 01:50:22 +02:00
! <== ipos ==>
! |
! v
!string :|------------------------|-------------------------|------------------------|
! <==== bit_kind_size ====> <==== bit_kind_size ====> <==== bit_kind_size ====>
! { iint } { iint } { iint }
2015-03-02 10:32:04 +01:00
!
2014-04-03 01:50:22 +02:00
string = 0_bit_kind
do i=1,n_elements
iint = ishft(list(i)-1,-bit_kind_shift) + 1
ipos = list(i)-ishft((iint-1),bit_kind_shift)-1
string(iint) = ibset( string(iint), ipos )
enddo
end
2014-04-17 15:10:26 +02:00
subroutine bitstring_to_str( output, string, Nint )
use bitmasks
2014-04-03 01:50:22 +02:00
implicit none
2014-04-17 15:10:26 +02:00
BEGIN_DOC
! Transform a bit string to a string for printing
END_DOC
character*(*), intent(out) :: output
2014-04-03 01:50:22 +02:00
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: string(Nint)
integer :: i, j, ibuf
integer(bit_kind) :: itemp
ibuf = 1
2014-04-17 15:10:26 +02:00
output = ''
output(ibuf:ibuf) = '|'
2014-04-03 01:50:22 +02:00
ibuf = ibuf+1
do i=1,Nint
itemp = 1_bit_kind
do j=1,bit_kind_size
if (iand(itemp,string(i)) == itemp) then
2014-04-17 15:10:26 +02:00
output(ibuf:ibuf) = '+'
2014-04-03 01:50:22 +02:00
else
2014-04-17 15:10:26 +02:00
output(ibuf:ibuf) = '-'
2014-04-03 01:50:22 +02:00
endif
ibuf = ibuf+1
itemp = ishft(itemp,1)
enddo
enddo
2014-04-17 15:10:26 +02:00
output(ibuf:ibuf) = '|'
2014-04-03 01:50:22 +02:00
end
2014-04-17 15:10:26 +02:00
subroutine bitstring_to_hexa( output, string, Nint )
use bitmasks
implicit none
BEGIN_DOC
! Transform a bit string to a string in hexadecimal format for printing
END_DOC
character*(*), intent(out) :: output
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: string(Nint)
integer :: i, j, ibuf
integer(bit_kind) :: itemp
character*(32) :: f
write(f,*) '(Z',bit_kind_size/4,'.',bit_kind_size/4,')'
ibuf = 1
2014-04-17 15:10:26 +02:00
output = ''
do i=Nint,1,-1
write(output(ibuf:ibuf+bit_kind_size/4),f) string(i)
ibuf = ibuf+bit_kind_size/4
2014-04-17 15:10:26 +02:00
enddo
end
2014-05-13 13:57:58 +02:00
subroutine debug_det(string,Nint)
use bitmasks
2014-05-13 13:57:58 +02:00
implicit none
2015-03-02 10:36:22 +01:00
BEGIN_DOC
! Subroutine to print the content of a determinant in '+-' notation and
! hexadecimal representation.
END_DOC
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: string(Nint,2)
character*(2048) :: output(2)
2014-05-13 13:57:58 +02:00
call bitstring_to_hexa( output(1), string(1,1), Nint )
call bitstring_to_hexa( output(2), string(1,2), Nint )
print *, trim(output(1)) , '|', trim(output(2))
2015-03-02 10:36:22 +01:00
call print_det(string,Nint)
2014-05-13 13:57:58 +02:00
end
2014-11-12 14:26:57 +01:00
subroutine print_det(string,Nint)
use bitmasks
implicit none
2015-03-02 10:36:22 +01:00
BEGIN_DOC
! Subroutine to print the content of a determinant using the '+-' notation
END_DOC
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: string(Nint,2)
character*(2048) :: output(2)
2014-11-12 14:26:57 +01:00
call bitstring_to_str( output(1), string(1,1), Nint )
call bitstring_to_str( output(2), string(1,2), Nint )
print *, trim(output(1))
print *, trim(output(2))
end
subroutine debug_spindet(string,Nint)
use bitmasks
implicit none
BEGIN_DOC
! Subroutine to print the content of a determinant in '+-' notation and
! hexadecimal representation.
END_DOC
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: string(Nint,2)
character*(2048) :: output(1)
call bitstring_to_hexa( output(1), string(1,1), Nint )
print *, trim(output(1))
call print_spindet(string,Nint)
end
subroutine print_spindet(string,Nint)
use bitmasks
implicit none
BEGIN_DOC
! Subroutine to print the content of a determinant using the '+-' notation
END_DOC
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: string(Nint,2)
character*(2048) :: output(1)
call bitstring_to_str( output(1), string(1,1), Nint )
print *, trim(output(1))
end