-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctrper.f90
116 lines (114 loc) · 4.57 KB
/
ctrper.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
!>
!! \brief This module contains data and routines for permuting arrays randomly, but leaving elements close to their initial locations
!!
!! \b Author: Michel Olagnon
!!
!! \b Date: May 2000
!!
!! \b Version:
!!
Module m_ctrper
Use m_mrgrnk
Private
Integer, Parameter :: kdp = selected_real_kind(15)
public :: ctrper
!private :: kdp
private :: R_ctrper, I_ctrper, D_ctrper
interface ctrper
module procedure d_ctrper, r_ctrper, i_ctrper
end interface ctrper
contains
Subroutine D_ctrper (XDONT, PCLS)
! Permute array XVALT randomly, but leaving elements close
! to their initial locations (nearbyness is controled by PCLS).
! _________________________________________________________________
! The routine takes the 1...size(XVALT) index array as real
! values, takes a combination of these values and of random
! values as a perturbation of the index array, and sorts the
! initial set according to the ranks of these perturbated indices.
! The relative proportion of initial order and random order
! is 1-PCLS / PCLS, thus when PCLS = 0, there is no change in
! the order whereas the new order is fully random when PCLS = 1.
! Michel Olagnon - May 2000.
! _________________________________________________________________
! __________________________________________________________
Real (kind=kdp), Dimension (:), Intent (InOut) :: XDONT
Real, Intent (In) :: PCLS
! __________________________________________________________
!
Real, Dimension (Size(XDONT)) :: XINDT
Integer, Dimension (Size(XDONT)) :: JWRKT
Real :: PWRK
Integer :: I
!
Call Random_number (XINDT(:))
PWRK = Min (Max (0.0, PCLS), 1.0)
XINDT = Real(Size(XDONT)) * XINDT
XINDT = PWRK*XINDT + (1.0-PWRK)*(/ (Real(I), I=1,size(XDONT)) /)
Call MRGRNK (XINDT, JWRKT)
XDONT = XDONT (JWRKT)
!
End Subroutine D_ctrper
Subroutine R_ctrper (XDONT, PCLS)
! Permute array XVALT randomly, but leaving elements close
! to their initial locations (nearbyness is controled by PCLS).
! _________________________________________________________________
! The routine takes the 1...size(XVALT) index array as real
! values, takes a combination of these values and of random
! values as a perturbation of the index array, and sorts the
! initial set according to the ranks of these perturbated indices.
! The relative proportion of initial order and random order
! is 1-PCLS / PCLS, thus when PCLS = 0, there is no change in
! the order whereas the new order is fully random when PCLS = 1.
! Michel Olagnon - May 2000.
! _________________________________________________________________
! _________________________________________________________
Real, Dimension (:), Intent (InOut) :: XDONT
Real, Intent (In) :: PCLS
! __________________________________________________________
!
Real, Dimension (Size(XDONT)) :: XINDT
Integer, Dimension (Size(XDONT)) :: JWRKT
Real :: PWRK
Integer :: I
!
Call Random_number (XINDT(:))
PWRK = Min (Max (0.0, PCLS), 1.0)
XINDT = Real(Size(XDONT)) * XINDT
XINDT = PWRK*XINDT + (1.0-PWRK)*(/ (Real(I), I=1,size(XDONT)) /)
Call MRGRNK (XINDT, JWRKT)
XDONT = XDONT (JWRKT)
!
End Subroutine R_ctrper
Subroutine I_ctrper (XDONT, PCLS)
! Permute array XVALT randomly, but leaving elements close
! to their initial locations (nearbyness is controled by PCLS).
! _________________________________________________________________
! The routine takes the 1...size(XVALT) index array as real
! values, takes a combination of these values and of random
! values as a perturbation of the index array, and sorts the
! initial set according to the ranks of these perturbated indices.
! The relative proportion of initial order and random order
! is 1-PCLS / PCLS, thus when PCLS = 0, there is no change in
! the order whereas the new order is fully random when PCLS = 1.
! Michel Olagnon - May 2000.
! _________________________________________________________________
! __________________________________________________________
Integer, Dimension (:), Intent (InOut) :: XDONT
Real, Intent (In) :: PCLS
! __________________________________________________________
!
Real, Dimension (Size(XDONT)) :: XINDT
Integer, Dimension (Size(XDONT)) :: JWRKT
Real :: PWRK
Integer :: I
!
Call Random_number (XINDT(:))
PWRK = Min (Max (0.0, PCLS), 1.0)
XINDT = Real(Size(XDONT)) * XINDT
XINDT = PWRK*XINDT + (1.0-PWRK)*(/ (Real(I), I=1,size(XDONT)) /)
Call MRGRNK (XINDT, JWRKT)
XDONT = XDONT (JWRKT)
!
End Subroutine I_ctrper
end module m_ctrper