2021-02-12 12:04:21 +01:00
|
|
|
module Utils
|
|
|
|
implicit none
|
|
|
|
contains
|
2021-02-22 09:50:42 +01:00
|
|
|
subroutine Read_dataset(filename, &
|
|
|
|
cycle_id, &
|
|
|
|
dim, &
|
|
|
|
n_updates, &
|
|
|
|
S, &
|
|
|
|
S_inv, &
|
|
|
|
Updates_index, &
|
|
|
|
Updates)
|
2021-02-12 19:31:31 +01:00
|
|
|
use, intrinsic :: iso_c_binding, only : c_int, c_double
|
|
|
|
implicit none
|
2021-02-12 12:04:21 +01:00
|
|
|
|
2021-02-12 19:31:31 +01:00
|
|
|
character (len = *), intent(in) :: filename
|
|
|
|
integer, intent(inout) :: cycle_id, dim, n_updates
|
|
|
|
integer(c_int), allocatable, intent(inout) :: Updates_index(:)
|
|
|
|
real(c_double), allocatable, intent(inout) :: S(:,:), S_inv(:,:)
|
|
|
|
real(c_double), allocatable, intent(inout) :: Updates(:,:)
|
|
|
|
integer :: i, j
|
|
|
|
character (len = 32) :: ignore
|
|
|
|
|
2021-02-22 09:50:42 +01:00
|
|
|
!! Start reading dataset from file
|
2021-02-12 19:31:31 +01:00
|
|
|
open(unit = 1000, file = filename)
|
2021-02-12 12:04:21 +01:00
|
|
|
read(1000,*)
|
|
|
|
read(1000,*) ignore, cycle_id
|
|
|
|
read(1000,*) ignore, dim
|
|
|
|
read(1000,*) ignore,n_updates
|
2021-02-22 09:50:42 +01:00
|
|
|
|
|
|
|
!! Initialise the arrays
|
|
|
|
allocate(Updates_index(n_updates), &
|
|
|
|
S(dim,dim), &
|
|
|
|
S_inv(dim,dim), &
|
|
|
|
Updates(dim,n_updates))
|
2021-02-12 12:04:21 +01:00
|
|
|
|
|
|
|
!! Read S and S_inv
|
|
|
|
read(1000,*)
|
|
|
|
do i=1,dim
|
|
|
|
do j=1,dim
|
2021-02-22 09:50:42 +01:00
|
|
|
!! For some reason S_inv needs to be read transposed &
|
|
|
|
! for S*S_inv to give the identity matrix
|
|
|
|
read(1000,*) ignore, ignore, S(i,j), S_inv(j,i)
|
2021-02-12 12:04:21 +01:00
|
|
|
end do
|
|
|
|
end do
|
|
|
|
|
2021-02-22 09:50:42 +01:00
|
|
|
!! Read Updates and Updates_index
|
2021-02-12 12:04:21 +01:00
|
|
|
do j=1,n_updates
|
|
|
|
read(1000,*) ignore, Updates_index(j)
|
|
|
|
do i=1,dim
|
|
|
|
read(1000,*) ignore, Updates(i,j)
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
!! End of reading the dataset from file
|
2021-02-22 09:50:42 +01:00
|
|
|
close(1000)
|
2021-02-12 12:04:21 +01:00
|
|
|
end subroutine Read_dataset
|
2021-02-12 19:31:31 +01:00
|
|
|
end module Utils
|