-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm_correlation.f90
131 lines (107 loc) · 2.82 KB
/
m_correlation.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
!----------------------------------------------------------------------
! MELQUIADES: Metropolis Monte Carlo Program
!----------------------------------------------------------------------
!bop
!
! !Module: m_correlation
!
! !Description: This module contains a routine for correlation calculation!\\
!\\
! !Interface:
!
module m_correlation
!
! !Uses
use m_kind
use m_simtype
use m_unit
!
! !Public member functions:
!
private
public :: r_corr
!
! ! Revision history:
! 11Nov 2015 Asdrubal Lozada
!
!eop
!------------------------------------------------------------------------
contains
!
!bop
!
! !Iroutine: r_corr
!
! !Description: Correlation eneregy calculation.
!\\
!\\
! !Interface:
subroutine r_corr( y, var, iter, stats )
implicit none
! Dummy arguments
type(simulation), intent(inout) :: y
integer, intent(in) :: var ! Total number of variables to be used
integer, intent(in) :: stats ! Define variable to correlation
real(rkind), allocatable, dimension(:) :: acc
real(rkind), allocatable, dimension(:) :: corr
integer, allocatable, dimension(:) :: istore
integer :: id, i, j, ntotal, error, tau
real(rkind) aver, dev
real(rkind) :: threshold, corr0, tole
integer, intent(in) :: iter
aver = 0.0_rkind
dev = 0.0_rkind
ntotal = 0
threshold = 0.001_rkind
tole = 0.005_rkind
tau = int(iter/5.0_rkind) ! Value sugest by V.S. Pugachev "I.Teória Probabilidades"
allocate(acc(0:iter),istore(0:iter),stat=error)
if( error /= 0) then
write(*,*) "Allocation Error in m_correlation"
stop
end if
allocate(corr(0:iter),stat=error)
if( error /= 0) then
write(*,*) "Allocation Error in m_correlation"
stop
end if
rewind(intemp)
do i = 0, iter-1
read(intemp,*,end=100) acc(i), istore(i)
corr(i) = 0.0_rkind
ntotal = ntotal + 1
end do
100 continue
do i = 0, iter-1
aver = aver + acc(i)
dev = dev + acc(i) * acc(i)
end do
aver = aver/real(ntotal,rkind)
dev = (dev/real(ntotal,rkind)) - aver * aver
!----------------------------------------------------
open(incorr, file='correlation',status='unknown', form='formatted')
rewind(incorr)
write(incorr,'(a)')
write(incorr,*) dev
close(incorr)
!----------------------------------------------------
!!* if( dev > 0.0_rkind ) dev = dsqrt(dev)
if(dev <= threshold) then
do i = 0, tau
do j = 1, iter-tau
corr(i) = corr(i) + (acc(j) - aver) *(acc(j+i)-aver)
if( abs(corr(i)) <= tole ) then
! write(*,*) istore(j+i)
end if
end do
end do
corr0 = corr(0)
do i =0, tau
corr(i) = corr(i)/corr0
write(39,*) i, corr(i)
end do
end if
deallocate(acc,corr,istore)
close(intemp)
end subroutine r_corr
end module m_correlation