ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_arraySort::getSorted Interface Reference

Generate and return the sorted elements of the input scalar string or contiguous vector in ascending order, or the sorted indices of the input scalar string or contiguous array of rank 1 in ascending order or in the user-specified order. More...

Detailed Description

Generate and return the sorted elements of the input scalar string or contiguous vector in ascending order, or the sorted indices of the input scalar string or contiguous array of rank 1 in ascending order or in the user-specified order.

This generic interface either sorts the contents of an array or its indices in ascending order or via the user-specified custom input procedure isSorted().

The resulting output array or its sorting will be in ascending order (or in the requested order as specified by isSorted().

Note
This generic interface is merely a convenient functional wrapper for the lower-level subroutine interface setSorted.
Parameters
[in]array: The contiguous array of rank 1 of either
  1. type css_pdt (string container) or,
  2. type css_type (string container of default kind) or,
  3. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary length type parameter or,
  4. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) or,
  5. type logical of kind any supported by the processor (e.g., LK) or,
  6. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128) or,
  7. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
or,
  1. a scalar of type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary length type parameter.
isSorted: The external user-specified function that takes two input scalar arguments of the same type and kind as the input array.
It returns a scalar logical of default kind LK that is .true. if the first input scalar argument is sorted with respect to the second input argument according to the user-defined condition within isSorted, otherwise, it is .false..
If array is a scalar string (i.e., an assumed-length scalar character), then both input arguments to isSorted() are scalar characters of length 1 of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU).
The following illustrates the generic interface of isSorted(),
function isSorted(lhs, rhs) result(sorted)
use pm_kind, only: LK
TYPE(KIND) , intent(in) :: lhs, rhs
logical(LK) :: sorted
end function
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
where TYPE(KIND) is the same as the type and kind of the input argument array, which can be one of the following.
character(*, SK), intent(in) :: lhs, rhs
character(1, SK), intent(in) :: lhs, rhs
type(css_type) , intent(in) :: lhs, rhs
type(css_pdt) , intent(in) :: lhs, rhs
integer(IK) , intent(in) :: lhs, rhs
logical(LK) , intent(in) :: lhs, rhs
complex(CK) , intent(in) :: lhs, rhs
real(RK) , intent(in) :: lhs, rhs
This module contains the derived types for generating allocatable containers of scalar,...
This is the css_pdt parameterized type for generating instances of container of scalar of string obje...
This is the css_type type for generating instances of container of scalar of string objects.
where the specified kind type parameters (SK, IK, LK, CK, RK) can refer to any of the supported kinds by the processor.
This user-defined equivalence check is extremely useful where a user-defined sorting criterion other than simple ascending order is needed, for example, when the case-sensitivity of an input string or array of strings is irrelevant or when sorting of the absolute values matters excluding the signs of the numbers, or when descending order is desired.
In such cases, user can define a custom sorting condition within the user-defined external function isSorted to achieve the goal.
(optional, the default sorting condition is ascending order, that is a < b.)
method: The input scalar constant that can be any of the following:
  1. The constant isort or equivalently, an object of type isort_type, implying that the sorted indices of the input array must be returned (instead of the sorted elements of array).
  2. The constant qsorti or equivalently, an object of type qsorti_type, implying that the iterative version of the QuickSort sorting algorithm should be used.
    This method sorts the input array by a mixture of Quicksort and Selection sorting methods.
    When the size the array to be sorted reaches 30 or less, the algorithm switches from Quicksort to Selection sorting.
    This algorithm is typically of order \( N \log_2 N\), and the worst-case order of \(N^2\).
    The worst case performance occurs for completely sorted input arrays.
  3. The constant qsortr or equivalently, an object of type qsortr_type, implying that the recursive version of the QuickSort sorting algorithm should be used.
  4. The constant qsortrdp or equivalently, an object of type qsortrdp_type, implying that the recursive version of the Dual-Pivot QuickSort sorting algorithm should be used.
    The Dual-Pivot Quicksort algorithm can be slightly faster than the default Quicksort algorithms above.
    However, performance benchmarks indicate that the efficiency gain is marginal and insignificant.
    This algorithm is typically of order \( N \log_2 N\), and the worst-case order of \(N^2\). The worst case performance occurs for completely sorted input arrays.
  5. The constant bubble or equivalently, an object of type bubble_type, implying that the Bubble sorting algorithm should be used.
    This algorithm is of order \(N^2\).
  6. The constant heapi or equivalently, an object of type heapi_type, implying that the iterative version of the Heap sorting algorithm should be used.
    This algorithm is typically of order \( N \log_2 N\).
  7. The constant heapr or equivalently, an object of type heapr_type, implying that the recursive version of the Heap sorting algorithm should be used.
    This algorithm is typically of order \( N \log_2 N\).
  8. The constant insertionl or equivalently, an object of type insertionl_type, implying that the linear-search version of the insertion sorting algorithm should be used.
    The complexity of this algorithm is typically of order \(N^2\).
  9. The constant insertionb or equivalently, an object of type insertionb_type, implying that the binary-search version of the insertion sorting algorithm should be used.
    The complexity of this algorithm is typically of order \(N^2\).
  10. The constant merger or equivalently, an object of type merger_type, implying that the recursive version of the Merge sorting algorithm should be used.
    This algorithm is typically of order \( N \log_2 N\).
  11. The constant selection or equivalently, an object of type selection_type, implying that the Selection sorting algorithm should be used.
    This algorithm is of order \(N^2\).
  12. The constant shell or equivalently, an object of type shell_type, implying that the Shell sorting algorithm should be used.
    This algorithm is of order \(N\log(N)\).
The presence of this argument is merely for compile-time resolution of the procedures of this generic interface.
(optional. default = qsorti. It can be present only if the input argument sorting is missing.)
Returns
sorting : The output object whose type and kind depends on the specified input method:
  1. If method is set to isort or an object of type set to isort_type, then the output sorting is of type integer of default kind IK of rank 1 of the same size as the number of elements in the input array containing the sorted indices of the elements of the input array.<br> **Readsorting(i)as the index of the element ofarraythat contains theith smallest (or ranked) value in thearray`.**
    This kind of sorting of indices is also widely known as ordinal ranking.
    In ordinal ranking, all items receive distinct ordinal numbers, including items that compare equal.
    The assignment of distinct ordinal numbers to items that compare equal can be done at random, or arbitrarily.
    But it is generally preferable to use a system that is arbitrary but consistent, as this gives stable results if the ranking is done multiple times.
    In computer data processing, ordinal ranking is also referred to as row numbering.
  2. If method is missing or set to any other value than the above, then the output sorting is of the same type, kind, rank, and shape as the input array, containing the sorted elements of the input array.


Possible calling interfaces

! Sorting the indices of an array.
sorting(1:len(array)) = getSorted(array, isort, isSorted = isSorted) ! scalar characer `array`.
sorting(1:size(array)) = getSorted(array(:), isort, isSorted = isSorted) ! all other intrinsic data types.
! Sorting the contents of an array.
sorting(1:len(array)) = getSorted(array, method = method, isSorted = isSorted) ! scalar characer `array`.
sorting(1:size(array)) = getSorted(array(:), method = method, isSorted = isSorted) ! all other intrinsic data types.
Generate and return the sorted elements of the input scalar string or contiguous vector in ascending ...
Return .true. if the input array is sorted, either ascending or descending, or all equal.
This module contains procedures and generic interfaces for various sorting tasks.
type(isort_type), parameter isort
Warning
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds. The procedures under this generic interface are always impure when the input argument isSorted() is present.
Developer Remark:
The use of the Fortran intrinsic minloc in the sorting routines appears to lead a slightly better performance than the manual search.
Note
To rank the input array in descending order using the output sorting indices, simply call the output sorting indices from the end to the beginning or, rewrite the array with array = array(sorting(ubound(array, dim = 1) : lbound(array, dim = 1) : -1) ).
To sort the input array in descending order, simply call the output array elements from the end to the beginning or, rewrite the array with array = array(ubound(array, dim = 1) : lbound(array, dim = 1) : -1).
Alternatively, supply an external comparison function isSorted() with the appropriate comparison.
A rooter array can be sorted along with a leader array with the help of getSorted.
See also
getLoc
setLoc
getBin
getSorted
setSorted
getRankDense
setRankDense
getRankOrdinal
setRankOrdinal
getRankModified
setRankModified
getRankStandard
setRankStandard
getRankFractional
setRankFractional
getSelected
setSelected


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK
4 use pm_arraySort, only: isort
5 use pm_arraySort, only: getSorted
6 use pm_distUnif, only: getUnifRand
9 use pm_io, only: display_type
10
11 implicit none
12
13 integer(IK), allocatable :: index(:)
14
15 type(display_type) :: disp
16 disp = display_type(file = "main.out.F90")
17
18 call disp%skip()
19 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
20 call disp%show("!Sort a string of characters of arbitrary kind in arbitrary orders.")
21 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
22 call disp%skip()
23
24 block
25 character(:), allocatable :: array
26 call disp%skip()
27 call disp%show("!Sort array in ascending order with case-sensitivity.")
28 call disp%show("array = 'ParaMonte'")
29 array = 'ParaMonte'
30 call disp%show("index = getSorted(array, isort)")
31 index = getSorted(array, isort)
32 call disp%show("index")
33 call disp%show( index )
34 call disp%show("getRemapped(array, index)")
35 call disp%show( getRemapped(array, index) , deliml = SK_"""" )
36 call disp%show("array = getSorted(array)")
37 array = getSorted(array)
38 call disp%show("array")
39 call disp%show( array , deliml = SK_"""" )
40 call disp%skip()
41
42 call disp%skip()
43 call disp%show("!Sort array in ascending order without case-sensitivity via a custom-designed input comparison function.")
44 array = "ParaMonte"
45 call disp%skip()
46 call disp%show("array")
47 call disp%show( array , deliml = SK_"""" )
48 call disp%show("index = getSorted(array, isSortedChar, isort)")
49 index = getSorted(array, isSortedChar, isort)
50 call disp%show("index")
51 call disp%show( index )
52 call disp%show("getRemapped(array, index)")
53 call disp%show( getRemapped(array, index) , deliml = SK_"""" )
54 call disp%show("array = getSorted(array, isSortedChar)")
55 array = getSorted(array, isSortedChar)
56 call disp%show("array")
57 call disp%show( array , deliml = SK_"""" )
58 call disp%skip()
59 end block
60
61 call disp%skip()
62 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
63 call disp%show("!Sort array of strings of the same length of arbitrary kind in ascending order.")
64 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
65 call disp%skip()
66
67 block
68 character(10), allocatable :: array(:)
69 array = [ "ParaMonte " &
70 , "V.2 " &
71 , "is " &
72 , "a " &
73 , "Parallel " &
74 , "Monte " &
75 , "Carlo " &
76 , "and " &
77 , "Machine " &
78 , "Learning " &
79 , "Library. " &
80 ]
81 call disp%skip()
82 call disp%show("array")
83 call disp%show( array , deliml = SK_"""" )
84 call disp%show("index = getSorted(array, isort)")
85 index = getSorted(array, isort)
86 call disp%show("index")
87 call disp%show( index )
88 call disp%show("array(index)")
89 call disp%show( array(index) , deliml = SK_"""" )
90 call disp%show("array = getSorted(array)")
91 array = getSorted(array)
92 call disp%show("array")
93 call disp%show( array , deliml = SK_"""" )
94 call disp%skip()
95 end block
96
97 call disp%skip()
98 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
99 call disp%show("!Sort array of integer values of arbitrary kind in arbitrary orders.")
100 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
101 call disp%skip()
102
103 block
104 integer, allocatable :: array(:)
105 call disp%skip()
106 call disp%show("!Sort integer values in ascending order.")
107 call disp%show("array = getUnifRand(-9, 9, s1 = getUnifRand(5_IK, 10_IK))")
108 array = getUnifRand(-9, 9, s1 = getUnifRand(5_IK, 10_IK))
109 call disp%show("array")
110 call disp%show( array )
111 call disp%show("index = getSorted(array, isort)")
112 index = getSorted(array, isort)
113 call disp%show("index")
114 call disp%show( index )
115 call disp%show("array(index)")
116 call disp%show( array(index) )
117 call disp%show("array = getSorted(array)")
118 array = getSorted(array)
119 call disp%show("array")
120 call disp%show( array )
121 call disp%skip()
122
123 call disp%skip()
124 call disp%show("!Sort integer values in descending order via a custom-designed input comparison function.")
125 call disp%skip()
126 call disp%show("array")
127 call disp%show( array )
128 call disp%show("index = getSorted(array, isSortedInteger, isort)")
129 index = getSorted(array, isSortedInteger, isort)
130 call disp%show("index")
131 call disp%show( index )
132 call disp%show("array(index)")
133 call disp%show( array(index) )
134 call disp%show("array = getSorted(array, isSortedInteger)")
135 array = getSorted(array, isSortedInteger)
136 call disp%show("array")
137 call disp%show( array )
138 call disp%skip()
139 end block
140
141 call disp%skip()
142 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
143 call disp%show("!Sort array of logical values of arbitrary kind in arbitrary orders.")
144 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
145 call disp%skip()
146
147 block
148 logical, allocatable :: array(:)
149 call disp%skip()
150 call disp%show("!Sort logical values in ascending order.")
151 call disp%show("array = getUnifRand(.false., .true., s1 = getUnifRand(5_IK, 10_IK))")
152 array = getUnifRand(.false., .true., s1 = getUnifRand(5_IK, 10_IK))
153 call disp%show("array")
154 call disp%show( array )
155 call disp%show("index = getSorted(array, isort)")
156 index = getSorted(array, isort)
157 call disp%show("index")
158 call disp%show( index )
159 call disp%show("array(index)")
160 call disp%show( array(index) )
161 call disp%show("array = getSorted(array)")
162 array = getSorted(array)
163 call disp%show("array")
164 call disp%show( array )
165 call disp%skip()
166
167 call disp%skip()
168 call disp%show("!Sort logical values in descending order via a custom-designed input comparison function.")
169 call disp%skip()
170 call disp%show("array")
171 call disp%show( array )
172 call disp%show("index = getSorted(array, isSortedLogical, isort)")
173 index = getSorted(array, isSortedLogical, isort)
174 call disp%show("index")
175 call disp%show( index )
176 call disp%show("array(index)")
177 call disp%show( array(index) )
178 call disp%show("array = getSorted(array, isSortedLogical)")
179 array = getSorted(array, isSortedLogical)
180 call disp%show("array")
181 call disp%show( array )
182 call disp%skip()
183 end block
184
185 call disp%skip()
186 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
187 call disp%show("!Sort array of complex values of arbitrary kind in arbitrary orders.")
188 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
189 call disp%skip()
190
191 block
192 complex, allocatable :: array(:)
193 call disp%skip()
194 call disp%show("!Sort complex values in ascending order.")
195 call disp%show("array = getUnifRand((-9., -9), (9., 9.), s1 = getUnifRand(3_IK, 5_IK))")
196 array = getUnifRand((-9., -9), (9., 9.), s1 = getUnifRand(3_IK, 5_IK))
197 call disp%show("array")
198 call disp%show( array )
199 call disp%show("index = getSorted(array, isort)")
200 index = getSorted(array, isort)
201 call disp%show("index")
202 call disp%show( index )
203 call disp%show("array(index)")
204 call disp%show( array(index) )
205 call disp%show("array = getSorted(array)")
206 array = getSorted(array)
207 call disp%show("array")
208 call disp%show( array )
209 call disp%skip()
210
211 call disp%skip()
212 call disp%show("!Sort complex values in ascending order of their modulus via a custom-designed input comparison function.")
213 call disp%skip()
214 call disp%show("array")
215 call disp%show( array )
216 call disp%show("index = getSorted(array, isSortedComplex, isort)")
217 index = getSorted(array, isSortedComplex, isort)
218 call disp%show("index")
219 call disp%show( index )
220 call disp%show("array(index)")
221 call disp%show( array(index) )
222 call disp%show("array = getSorted(array, isSortedComplex, isort)")
223 array = getSorted(array, isSortedComplex, isort)
224 call disp%show("array")
225 call disp%show( array )
226 call disp%skip()
227 end block
228
229 call disp%skip()
230 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
231 call disp%show("!Sort array of real values of arbitrary kind in arbitrary orders.")
232 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
233 call disp%skip()
234
235 block
236 real, allocatable :: array(:)
237 call disp%skip()
238 call disp%show("!Sort real values in ascending order.")
239 call disp%show("array = getUnifRand(-9., 9., s1 = getUnifRand(4_IK, 8_IK))")
240 array = getUnifRand(-9., 9., s1 = getUnifRand(4_IK, 8_IK))
241 call disp%show("array")
242 call disp%show( array )
243 call disp%show("index = getSorted(array, isort)")
244 index = getSorted(array, isort)
245 call disp%show("index")
246 call disp%show( index )
247 call disp%show("array(index)")
248 call disp%show( array(index) )
249 call disp%show("array = getSorted(array)")
250 array = getSorted(array)
251 call disp%show("array")
252 call disp%show( array )
253 call disp%skip()
254
255 call disp%skip()
256 call disp%show("!Sort real values in ascending order of their modulus via a custom-designed input comparison function.")
257 call disp%skip()
258 call disp%show("array")
259 call disp%show( array )
260 call disp%show("index = getSorted(array, isSortedReal, isort)")
261 index = getSorted(array, isSortedReal, isort)
262 call disp%show("index")
263 call disp%show( index )
264 call disp%show("array(index)")
265 call disp%show( array(index) )
266 call disp%show("array = getSorted(array, isSortedReal, isort)")
267 array = getSorted(array, isSortedReal, isort)
268 call disp%show("array")
269 call disp%show( array )
270 call disp%skip()
271 end block
272
273#if PDT_ENABLED
274 call disp%skip()
275 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
276 call disp%show("!Sort array of string containers in ascending order.")
277 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
278 call disp%skip()
279
280 block
281 use pm_container, only: css_pdt ! \bug Intel ifort 2021.6 cannot handle PDT aliases such as `strc`.
282 type(css_pdt), allocatable :: array(:)
283 array = [ css_pdt("ParaMonte") &
284 , css_pdt("V.2") &
285 , css_pdt("is") &
286 , css_pdt("a") &
287 , css_pdt("Parallel") &
288 , css_pdt("Monte") &
289 , css_pdt("Carlo") &
290 , css_pdt("and") &
291 , css_pdt("Machine") &
292 , css_pdt("Learning") &
293 , css_pdt("Library.") &
294 ]
295 call disp%skip()
296 call disp%show("array")
297 call disp%show( array , deliml = SK_"""" )
298 call disp%show("index = getSorted(array, isort)")
299 index = getSorted(array, isort)
300 call disp%show("index")
301 call disp%show( index )
302 call disp%show("getRemapped(array, index)")
303 call disp%show( getRemapped(array, index) , deliml = SK_"""" )
304 call disp%show("array = getSorted(array)")
305 array = getSorted(array)
306 call disp%show("array")
307 call disp%show( array , deliml = SK_"""" )
308 call disp%skip()
309 end block
310#endif
311
312contains
313
314 function isSortedInteger(a,b) result(sorted)
315 use pm_kind, only: LK
316 integer , intent(in) :: a, b
317 logical(LK) :: sorted
318 sorted = a > b
319 end function
320
321 function isSortedLogical(a,b) result(sorted)
322 use pm_logicalCompare, only: operator(>)
323 use pm_kind, only: LK
324 logical , intent(in) :: a, b
325 logical(LK) :: sorted
326 sorted = a > b
327 end function
328
329 function isSortedComplex(a,b) result(sorted)
330 use pm_kind, only: LK
331 complex , intent(in) :: a, b
332 logical(LK) :: sorted
333 sorted = abs(a) < abs(b)
334 end function
335
336 function isSortedReal(a,b) result(sorted)
337 use pm_kind, only: LK
338 real , intent(in) :: a, b
339 logical(LK) :: sorted
340 sorted = abs(a) < abs(b)
341 end function
342
343 function isSortedChar(a,b) result(sorted)
344 use pm_strASCII, only: getStrLower
345 use pm_kind, only: LK
346 character(1) , intent(in) :: a, b
347 logical(LK) :: sorted
348 sorted = getStrLower(a) < getStrLower(b)
349 end function
350
351end program example
Generate a copy of the input array whose elements are reordered according to the input index array su...
Allocate or resize (shrink or expand) an input allocatable scalar string or array of rank 1....
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
Generate and return the input string where the uppercase English alphabets are all converted to lower...
This module contains procedures and generic interfaces for remapping arrays of various types.
This module contains procedures and generic interfaces for resizing allocatable arrays of various typ...
This module contains classes and procedures for computing various statistical quantities related to t...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
This module contains procedures and generic interfaces for performing a variety of logical comparison...
This module contains the uncommon and hardly representable ASCII characters as well as procedures for...
Definition: pm_strASCII.F90:61
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3!Sort a string of characters of arbitrary kind in arbitrary orders.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
7!Sort array in ascending order with case-sensitivity.
8array = 'ParaMonte'
9index = getSorted(array, isort)
10index
11+5, +1, +2, +4, +9, +7, +6, +3, +8
12getRemapped(array, index)
13"MPaaenort"
14array = getSorted(array)
15array
16"MPaaenort"
17
18
19!Sort array in ascending order without case-sensitivity via a custom-designed input comparison function.
20
21array
22"ParaMonte"
23index = getSorted(array, isSortedChar, isort)
24index
25+2, +4, +9, +5, +7, +6, +1, +3, +8
26getRemapped(array, index)
27"aaeMnoPrt"
28array = getSorted(array, isSortedChar)
29array
30"aaeMnoPrt"
31
32
33!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34!Sort array of strings of the same length of arbitrary kind in ascending order.
35!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36
37
38array
39"ParaMonte ", "V.2 ", "is ", "a ", "Parallel ", "Monte ", "Carlo ", "and ", "Machine ", "Learning ", "Library. "
40index = getSorted(array, isort)
41index
42+7, +10, +11, +9, +6, +1, +5, +2, +4, +8, +3
43array(index)
44"Carlo ", "Learning ", "Library. ", "Machine ", "Monte ", "ParaMonte ", "Parallel ", "V.2 ", "a ", "and ", "is "
45array = getSorted(array)
46array
47"Carlo ", "Learning ", "Library. ", "Machine ", "Monte ", "ParaMonte ", "Parallel ", "V.2 ", "a ", "and ", "is "
48
49
50!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51!Sort array of integer values of arbitrary kind in arbitrary orders.
52!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
54
55!Sort integer values in ascending order.
56array = getUnifRand(-9, 9, s1 = getUnifRand(5_IK, 10_IK))
57array
58-6, -8, +8, -8, -9, +1, +6, -6, -1, +4
59index = getSorted(array, isort)
60index
61+5, +2, +4, +1, +8, +9, +6, +10, +7, +3
62array(index)
63-9, -8, -8, -6, -6, -1, +1, +4, +6, +8
64array = getSorted(array)
65array
66-9, -8, -8, -6, -6, -1, +1, +4, +6, +8
67
68
69!Sort integer values in descending order via a custom-designed input comparison function.
70
71array
72-9, -8, -8, -6, -6, -1, +1, +4, +6, +8
73index = getSorted(array, isSortedInteger, isort)
74index
75+10, +9, +8, +7, +6, +4, +5, +2, +3, +1
76array(index)
77+8, +6, +4, +1, -1, -6, -6, -8, -8, -9
78array = getSorted(array, isSortedInteger)
79array
80+8, +6, +4, +1, -1, -6, -6, -8, -8, -9
81
82
83!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84!Sort array of logical values of arbitrary kind in arbitrary orders.
85!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86
87
88!Sort logical values in ascending order.
89array = getUnifRand(.false., .true., s1 = getUnifRand(5_IK, 10_IK))
90array
91T, T, T, T, T, F, T
92index = getSorted(array, isort)
93index
94+6, +1, +2, +3, +4, +5, +7
95array(index)
96F, T, T, T, T, T, T
97array = getSorted(array)
98array
99F, T, T, T, T, T, T
100
101
102!Sort logical values in descending order via a custom-designed input comparison function.
103
104array
105F, T, T, T, T, T, T
106index = getSorted(array, isSortedLogical, isort)
107index
108+2, +3, +4, +5, +6, +7, +1
109array(index)
110T, T, T, T, T, T, F
111array = getSorted(array, isSortedLogical)
112array
113T, T, T, T, T, T, F
114
115
116!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117!Sort array of complex values of arbitrary kind in arbitrary orders.
118!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119
120
121!Sort complex values in ascending order.
122array = getUnifRand((-9., -9), (9., 9.), s1 = getUnifRand(3_IK, 5_IK))
123array
124(-3.37121487, -0.592739105), (-5.46298885, -4.43353081), (+2.58042049, +0.854396820), (-1.23782992, -5.50205708)
125index = getSorted(array, isort)
126index
127+2, +1, +4, +3
128array(index)
129(-5.46298885, -4.43353081), (-3.37121487, -0.592739105), (-1.23782992, -5.50205708), (+2.58042049, +0.854396820)
130array = getSorted(array)
131array
132(-5.46298885, -4.43353081), (-3.37121487, -0.592739105), (-1.23782992, -5.50205708), (+2.58042049, +0.854396820)
133
134
135!Sort complex values in ascending order of their modulus via a custom-designed input comparison function.
136
137array
138(-5.46298885, -4.43353081), (-3.37121487, -0.592739105), (-1.23782992, -5.50205708), (+2.58042049, +0.854396820)
139index = getSorted(array, isSortedComplex, isort)
140index
141+4, +2, +3, +1
142array(index)
143(+2.58042049, +0.854396820), (-3.37121487, -0.592739105), (-1.23782992, -5.50205708), (-5.46298885, -4.43353081)
144array = getSorted(array, isSortedComplex, isort)
145array
146(+4.00000000, +0.00000000), (+2.00000000, +0.00000000), (+3.00000000, +0.00000000), (+1.00000000, +0.00000000)
147
148
149!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150!Sort array of real values of arbitrary kind in arbitrary orders.
151!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152
153
154!Sort real values in ascending order.
155array = getUnifRand(-9., 9., s1 = getUnifRand(4_IK, 8_IK))
156array
157-4.74495411, +4.34337425, -8.15056229, +1.58437991, +1.99221802, +6.19358540, -2.59473133, -6.83213043
158index = getSorted(array, isort)
159index
160+3, +8, +1, +7, +4, +5, +2, +6
161array(index)
162-8.15056229, -6.83213043, -4.74495411, -2.59473133, +1.58437991, +1.99221802, +4.34337425, +6.19358540
163array = getSorted(array)
164array
165-8.15056229, -6.83213043, -4.74495411, -2.59473133, +1.58437991, +1.99221802, +4.34337425, +6.19358540
166
167
168!Sort real values in ascending order of their modulus via a custom-designed input comparison function.
169
170array
171-8.15056229, -6.83213043, -4.74495411, -2.59473133, +1.58437991, +1.99221802, +4.34337425, +6.19358540
172index = getSorted(array, isSortedReal, isort)
173index
174+5, +6, +4, +7, +3, +8, +2, +1
175array(index)
176+1.58437991, +1.99221802, -2.59473133, +4.34337425, -4.74495411, +6.19358540, -6.83213043, -8.15056229
177array = getSorted(array, isSortedReal, isort)
178array
179+5.00000000, +6.00000000, +4.00000000, +7.00000000, +3.00000000, +8.00000000, +2.00000000, +1.00000000
180
181
Test:
test_pm_arraySort


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, April 21, 2017, 1:54 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin

Definition at line 3349 of file pm_arraySort.F90.


The documentation for this interface was generated from the following file: