SCALE-RM
scale_sort.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
10 #include "scalelib.h"
11 module scale_sort
12  !-----------------------------------------------------------------------------
13  !
14  !++ used modules
15  !
16  use scale_precision
17  use scale_io
18  !-----------------------------------------------------------------------------
19  implicit none
20  private
21  !-----------------------------------------------------------------------------
22  !
23  !++ Public procedure
24  !
25  public :: sort_exec
26 
27  interface sort_exec
28  module procedure sort_exec_without_idx
29  module procedure sort_exec_with_idxs
30  module procedure sort_exec_with_idx
31  end interface sort_exec
32 
33  !-----------------------------------------------------------------------------
34  !
35  !++ Public parameters & variables
36  !
37  !-----------------------------------------------------------------------------
38  !
39  !++ Private procedure
40  !
41  !-----------------------------------------------------------------------------
42  !
43  !++ Private parameters & variables
44  !
45  !-----------------------------------------------------------------------------
46 contains
47  !-----------------------------------------------------------------------------
49 !OCL SERIAL
50  subroutine sort_exec_with_idxs( &
51  npoints, &
52  val, &
53  idx_i, idx_j )
54  implicit none
55 
56  integer, intent(in) :: npoints ! number of interpolation points
57  real(RP), intent(inout) :: val (npoints) ! value to sort
58  integer, intent(inout) :: idx_i(npoints) ! i-index
59  integer, intent(inout) :: idx_j(npoints) ! j-index
60 
61  integer :: itmp
62  integer :: jtmp
63  real(RP) :: vtmp
64 
65  integer :: n1, n2
66  !---------------------------------------------------------------------------
67 
68  do n1 = 1, npoints-1
69  do n2 = n1+1, npoints
70  if ( val(n1) > val(n2) ) then
71  itmp = idx_i(n1)
72  jtmp = idx_j(n1)
73  vtmp = val(n1)
74 
75  idx_i(n1) = idx_i(n2)
76  idx_j(n1) = idx_j(n2)
77  val(n1) = val(n2)
78 
79  idx_i(n2) = itmp
80  idx_j(n2) = jtmp
81  val(n2) = vtmp
82  endif
83  enddo
84  enddo
85 
86  return
87  end subroutine sort_exec_with_idxs
88 
89 !OCL SERIAL
90  subroutine sort_exec_with_idx( &
91  npoints, &
92  val, index )
93  implicit none
94 
95  integer, intent(in) :: npoints ! number of interpolation points
96  real(RP), intent(inout) :: val (npoints) ! value to sort
97  integer, intent(inout) :: index(npoints) ! index
98 
99  integer :: itmp
100  real(RP) :: vtmp
101 
102  integer :: n1, n2
103  !---------------------------------------------------------------------------
104 
105  do n1 = 1, npoints-1
106  do n2 = n1+1, npoints
107  if ( val(n1) > val(n2) ) then
108  itmp = index(n1)
109  vtmp = val(n1)
110 
111  index(n1) = index(n2)
112  val(n1) = val(n2)
113 
114  index(n2) = itmp
115  val(n2) = vtmp
116  endif
117  enddo
118  enddo
119 
120  return
121  end subroutine sort_exec_with_idx
122 
123 !OCL SERIAL
124  subroutine sort_exec_without_idx( &
125  npoints, &
126  val )
127  implicit none
128 
129  integer, intent(in) :: npoints ! number of interpolation points
130  real(RP), intent(inout) :: val (npoints) ! value to sort
131 
132  real(RP) :: vtmp
133 
134  integer :: n1, n2
135  !---------------------------------------------------------------------------
136 
137  do n1 = 1, npoints-1
138  do n2 = n1+1, npoints
139  if ( val(n1) > val(n2) ) then
140  vtmp = val(n1)
141 
142  val(n1) = val(n2)
143 
144  val(n2) = vtmp
145  endif
146  enddo
147  enddo
148 
149  return
150  end subroutine sort_exec_without_idx
151 
152 end module scale_sort
module PRECISION
module STDIO
Definition: scale_io.F90:10
module SORT
Definition: scale_sort.F90:11