29 CHARACTER(len=20) FUNCTION str(k)
30 INTEGER,
INTENT(IN) :: k
36 CHARACTER(len=40) FUNCTION rstr(x,fm)
37 REAL(KIND=8),
INTENT(IN) :: x
38 CHARACTER(len=20),
INTENT(IN) :: fm
39 WRITE (
rstr, trim(adjustl(fm))) x
45 USE iso_fortran_env
, only: int64
48 INTEGER,
ALLOCATABLE :: seed_loc(:)
49 INTEGER :: i, n, un, istat, dt(8), pid
52 CALL random_seed(
size = n)
55 OPEN(newunit=un, file=
"/dev/urandom", access=
"stream", &
56 form=
"unformatted", action=
"read", status=
"old", iostat=istat)
66 CALL date_and_time(values=dt)
67 t = (dt(1) - 1970) * 365_int64 * 24 * 60 * 60 * 1000 &
68 + dt(2) * 31_int64 * 24 * 60 * 60 * 1000 &
69 + dt(3) * 24_int64 * 60 * 60 * 1000 &
70 + dt(5) * 60 * 60 * 1000 &
71 + dt(6) * 60 * 1000 + dt(7) * 1000 &
75 t = ieor(t, int(pid, kind(t)))
80 CALL random_seed(put=seed_loc)
90 s = mod(s, 4294967296_int64)
92 s = mod(s * 279470273_int64, 4294967291_int64)
93 lcg = int(mod(s, int(huge(0), int64)), kind(0))
100 REAL(KIND=8),
DIMENSION(:,:),
INTENT(INOUT) :: A
111 REAL(KIND=8),
DIMENSION(:,:) :: A
112 REAL(KIND=8) :: mat_trace
117 mat_trace=mat_trace+a(i,i)
123 REAL(KIND=8),
DIMENSION(:,:) :: A,B
124 REAL(KIND=8) :: mat_contract
130 mat_contract=mat_contract+a(i,j)*b(i,j)
137 REAL(KIND=8),
DIMENSION(:,:) :: a
138 REAL(KIND=8),
DIMENSION(:) :: p
147 sum=sum-a(i,k)*a(j,k)
150 IF (sum.le.0.) stop
'choldc failed' 160 SUBROUTINE printmat(A) ! to be moved to util
161 REAL(KIND=8),
DIMENSION(:,:),
INTENT(IN) :: A
169 SUBROUTINE cprintmat(A) ! to be moved to util
170 COMPLEX(KIND=16),
DIMENSION(:,:),
INTENT(IN) :: A
178 FUNCTION invmat(A) RESULT(Ainv)
179 REAL(KIND=8),
DIMENSION(:,:),
INTENT(IN) :: A
180 REAL(KIND=8),
DIMENSION(SIZE(A,1),SIZE(A,2)) :: Ainv
182 REAL(KIND=8),
DIMENSION(SIZE(A,1)) :: work
183 INTEGER,
DIMENSION(SIZE(A,1)) :: ipiv
192 CALL dgetrf(n, n, ainv, n, ipiv, info)
195 stop
'Matrix is numerically singular!' 200 CALL dgetri(n, ainv, n, ipiv, work, n, info)
203 stop
'Matrix inversion failed!' 208 REAL(KIND=8),
DIMENSION(:,:),
INTENT(IN) :: A
209 REAL(KIND=8),
DIMENSION(:,:),
INTENT(OUT) :: T
220 REAL(KIND=8),
DIMENSION(:,:),
INTENT(IN) :: A
221 REAL(KIND=8),
DIMENSION(:),
INTENT(OUT) :: d
229 SUBROUTINE cdiag(A,d)
230 COMPLEX(KIND=16),
DIMENSION(:,:),
INTENT(IN) :: A
231 COMPLEX(KIND=16),
DIMENSION(:),
INTENT(OUT) :: d
241 INTEGER :: i,j,floordiv
242 floordiv=int(floor(
real(i)/
real(j)))
246 SUBROUTINE reduce(A,Ared,n,ind,rind)
247 REAL(KIND=8),
DIMENSION(:,:),
INTENT(IN) :: A
248 REAL(KIND=8),
DIMENSION(:,:),
INTENT(OUT) :: Ared
249 INTEGER,
INTENT(OUT) :: n
250 INTEGER,
DIMENSION(:),
INTENT(OUT) :: ind,rind
251 LOGICAL,
DIMENSION(SIZE(A,1)) :: sel
259 IF (any(a(i,:)/=0))
THEN 269 IF (sel(i).and.sel(j)) ared(rind(i),rind(j))=a(i,j)
274 SUBROUTINE ireduce(A,Ared,n,ind,rind)
275 REAL(KIND=8),
DIMENSION(:,:),
INTENT(OUT) :: A
276 REAL(KIND=8),
DIMENSION(:,:),
INTENT(IN) :: Ared
277 INTEGER,
INTENT(IN) :: n
278 INTEGER,
DIMENSION(:),
INTENT(IN) :: ind,rind
283 a(ind(i),ind(j))=ared(i,j)
289 REAL(KIND=8),
DIMENSION(:),
INTENT(IN) :: u,v
290 REAL(KIND=8),
DIMENSION(:,:),
INTENT(OUT) :: A
subroutine, public choldc(a, p)
subroutine, public init_random_seed()
Random generator initialization routine.
integer function, public floordiv(i, j)
subroutine, public cdiag(A, d)
character(len=40) function, public rstr(x, fm)
Convert a real to string with a given format.
subroutine, public printmat(A)
subroutine, public diag(A, d)
subroutine, public ireduce(A, Ared, n, ind, rind)
real(kind=8) function, public mat_trace(A)
character(len=20) function, public str(k)
Convert an integer to string.
subroutine, public vector_outer(u, v, A)
real(kind=8) function, public mat_contract(A, B)
subroutine, public reduce(A, Ared, n, ind, rind)
subroutine, public triu(A, T)
subroutine, public init_one(A)
Initialize a square matrix A as a unit matrix.
real(kind=8) function, dimension(size(a, 1), size(a, 2)), public invmat(A)
subroutine, public cprintmat(A)