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

Return .true. if the input array is sorted, either ascending or descending, or all equal. More...

Detailed Description

Return .true. if the input array is sorted, either ascending or descending, or all equal.

Parameters
[in]array: The input contiguous array of rank 1 of either
  1. type css_pdt or,
  2. type css_type 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,
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,
whose elements will be checked to have an all ascending, or all descending order with the possibility of elements being equal.
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.)
Returns
sorted : An output logical of default kind LK that is .true. if all elements of the input array are in ascending order, in descending order, or all equal. Otherwise, it is .false..


Possible calling interfaces

sorted = isSorted(array)
sorted = isSorted(array, isSorted)
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.
Warning
The output of this procedure is .true. when the input array has zero length.
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.
See also
isAscending
isDescending
setSorted
setSorted


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK ! all intrinsic types and kinds are supported.
4 use pm_arraySort, only: isSorted
5 use pm_io, only: display_type
6
7 implicit none
8
9 type(display_type) :: disp
10
11 disp = display_type(file = "main.out.F90")
12
13 call disp%skip()
14 call disp%show("isSorted('')")
15 call disp%show( isSorted('') )
16 call disp%skip()
17 call disp%show("isSorted('?Aa')")
18 call disp%show( isSorted('?Aa') )
19 call disp%skip()
20 call disp%show("isSorted('A!b')")
21 call disp%show( isSorted('A!b') )
22 call disp%skip()
23 call disp%show("isSorted('zxw')")
24 call disp%show( isSorted('zxw') )
25 call disp%skip()
26 call disp%show("isSorted('AAA')")
27 call disp%show( isSorted('AAA') )
28 call disp%skip()
29
30 call disp%skip()
31 call disp%show("isSorted([character(0) ::])")
32 call disp%show( isSorted([character(0) ::]) )
33 call disp%skip()
34 call disp%show("isSorted(['?', 'A', 'a'])")
35 call disp%show( isSorted(['?', 'A', 'a']) )
36 call disp%skip()
37 call disp%show("isSorted(['A', '!', 'b'])")
38 call disp%show( isSorted(['A', '!', 'b']) )
39 call disp%skip()
40 call disp%show("isSorted(['z', 'x', 'w'])")
41 call disp%show( isSorted(['z', 'x', 'w']) )
42 call disp%skip()
43 call disp%show("isSorted(['A', 'A', 'A'])")
44 call disp%show( isSorted(['A', 'A', 'A']) )
45 call disp%skip()
46
47 call disp%skip()
48 call disp%show("isSorted([integer ::])")
49 call disp%show( isSorted([integer ::]) )
50 call disp%skip()
51 call disp%show("isSorted([+1, +2, +3])")
52 call disp%show( isSorted([+1, +2, +3]) )
53 call disp%skip()
54 call disp%show("isSorted([-1, -2, -3])")
55 call disp%show( isSorted([-1, -2, -3]) )
56 call disp%skip()
57 call disp%show("isSorted([-1, +2, -3])")
58 call disp%show( isSorted([-1, +2, -3]) )
59 call disp%skip()
60 call disp%show("isSorted([-1, -1, -1])")
61 call disp%show( isSorted([-1, -1, -1]) )
62 call disp%skip()
63
64 call disp%skip()
65 call disp%show("isSorted([logical ::])")
66 call disp%show( isSorted([logical ::]) )
67 call disp%skip()
68 call disp%show("isSorted([.false., .false., .true.])")
69 call disp%show( isSorted([.false., .false., .true.]) )
70 call disp%skip()
71 call disp%show("isSorted([.true., .false., .false.])")
72 call disp%show( isSorted([.true., .false., .false.]) )
73 call disp%skip()
74 call disp%show("isSorted([.false., .true., .false.])")
75 call disp%show( isSorted([.false., .true., .false.]) )
76 call disp%skip()
77 call disp%show("isSorted([.true., .true., .true.])")
78 call disp%show( isSorted([.true., .true., .true.]) )
79 call disp%skip()
80
81 call disp%skip()
82 call disp%show("isSorted([complex ::])")
83 call disp%show( isSorted([complex ::]) )
84 call disp%skip()
85 call disp%show("isSorted([(+1., -1.), (+2., -2.), (+3., -3.)])")
86 call disp%show( isSorted([(+1., -1.), (+2., -2.), (+3., -3.)]) )
87 call disp%skip()
88 call disp%show("isSorted([(-1., +1.), (-2., +2.), (-3., +3.)])")
89 call disp%show( isSorted([(-1., +1.), (-2., +2.), (-3., +3.)]) )
90 call disp%skip()
91 call disp%show("isSorted([(-1., +1.), (+2., -2.), (-3., +3.)])")
92 call disp%show( isSorted([(-1., +1.), (+2., -2.), (-3., +3.)]) )
93 call disp%skip()
94 call disp%show("isSorted([(-1., +1.), (-1., +1.), (-1., +1.)])")
95 call disp%show( isSorted([(-1., +1.), (-1., +1.), (-1., +1.)]) )
96 call disp%skip()
97 call disp%show("isSorted([(-1., +1.), (-1., -2.), (-1., +3.)])")
98 call disp%show( isSorted([(-1., +1.), (-1., -2.), (-1., +3.)]) )
99 call disp%skip()
100
101 call disp%skip()
102 call disp%show("isSorted([real ::])")
103 call disp%show( isSorted([real ::]) )
104 call disp%skip()
105 call disp%show("isSorted([+1., +2., +3.])")
106 call disp%show( isSorted([+1., +2., +3.]) )
107 call disp%skip()
108 call disp%show("isSorted([-1., -2., -3.])")
109 call disp%show( isSorted([-1., -2., -3.]) )
110 call disp%skip()
111 call disp%show("isSorted([-1., +2., -3.])")
112 call disp%show( isSorted([-1., +2., -3.]) )
113 call disp%skip()
114 call disp%show("isSorted([-1., -1., -1.])")
115 call disp%show( isSorted([-1., -1., -1.]) )
116 call disp%skip()
117
118#if PDT_ENABLED
119 ! \bug
120 ! Intel ifort 2022.3 cannot handle aliases for pdt names (e.g., strc => css_pdt).
121 block
122 use pm_container, only: css_pdt
123 call disp%skip()
124 call disp%show("isSorted([css_pdt('is'), css_pdt( 'sorted'), css_pdt('string')])")
125 call disp%show( isSorted([css_pdt('is'), css_pdt( 'sorted'), css_pdt('string')]) )
126 call disp%skip()
127 call disp%show("isSorted([css_pdt('string'), css_pdt('is'), css_pdt('sorted')])")
128 call disp%show( isSorted([css_pdt('string'), css_pdt('is'), css_pdt('sorted')]) )
129 call disp%skip()
130 call disp%show("isSorted([css_pdt('same string'), css_pdt('same '), css_pdt('same')])")
131 call disp%show( isSorted([css_pdt('same string'), css_pdt('same '), css_pdt('same')]) )
132 call disp%skip()
133 end block
134#endif
135
136end program example
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
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
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
2isSorted('')
3T
4
5isSorted('?Aa')
6T
7
8isSorted('A!b')
9F
10
11isSorted('zxw')
12T
13
14isSorted('AAA')
15T
16
17
18isSorted([character(0) ::])
19T
20
21isSorted(['?', 'A', 'a'])
22T
23
24isSorted(['A', '!', 'b'])
25F
26
27isSorted(['z', 'x', 'w'])
28T
29
30isSorted(['A', 'A', 'A'])
31T
32
33
34isSorted([integer ::])
35T
36
37isSorted([+1, +2, +3])
38T
39
40isSorted([-1, -2, -3])
41T
42
43isSorted([-1, +2, -3])
44F
45
46isSorted([-1, -1, -1])
47T
48
49
50isSorted([logical ::])
51T
52
53isSorted([.false., .false., .true.])
54T
55
56isSorted([.true., .false., .false.])
57T
58
59isSorted([.false., .true., .false.])
60F
61
62isSorted([.true., .true., .true.])
63T
64
65
66isSorted([complex ::])
67T
68
69isSorted([(+1., -1.), (+2., -2.), (+3., -3.)])
70T
71
72isSorted([(-1., +1.), (-2., +2.), (-3., +3.)])
73T
74
75isSorted([(-1., +1.), (+2., -2.), (-3., +3.)])
76F
77
78isSorted([(-1., +1.), (-1., +1.), (-1., +1.)])
79T
80
81isSorted([(-1., +1.), (-1., -2.), (-1., +3.)])
82T
83
84
85isSorted([real ::])
86T
87
88isSorted([+1., +2., +3.])
89T
90
91isSorted([-1., -2., -3.])
92T
93
94isSorted([-1., +2., -3.])
95F
96
97isSorted([-1., -1., -1.])
98T
99
100
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, 3:54 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin

Definition at line 2251 of file pm_arraySort.F90.


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