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

Generate and return bin, the index of the element of the input ascending-ordered array, such that array(bin) <= value < array(bin+1) holds for the input value.
More...

Detailed Description

Generate and return bin, the index of the element of the input ascending-ordered array, such that array(bin) <= value < array(bin+1) holds for the input value.

The following conditions hold.

  • If value < array(1), then bin = 0_IK.
  • If array(size(array)) <= value, then bin = size(array, kind = IK).
  • The less-than < comparison operator can be also customized by a user-defined comparison supplied as the external function isLess input argument for arrays that are not ascending-ordered.
    In such a case, the output bin satisfies both .not.(value < array(bin)) and value < array(bin+1) where the < binary operator is defined by the isLess() user-supplied function.
Parameters
[in]array: The input contiguous array of shape (:) of either
  • type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary length type parameter, or
  • type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64), or
  • type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128), or
  • type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
or,
  • a scalar assumed-length character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
whose elements will have to be searched for the largest value smaller than the input value.
The input array must be sorted in ascending-order unless an appropriate isLess external comparison function is supplied according to which the array effectively behaves as if it is ascending-ordered.
If the array is of type complex, then only its real component will be compared unless the comparison is defined by the external user-specified input comparison function isLess.
[in]value: The input scalar of the same type and kind as the input array whose value is to be searched in array.
isLess: 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 two input arguments meet the user-defined comparison criterion.
Otherwise, it is .false.. If array is a scalar character, the two input arguments to isLess() will be scalar character values of the same length as the input value (which could be larger than 1).
The following illustrates the generic interface of isLess(),
function isLess(value, segment) result(isLess)
use pm_kind, only: LK
TYPE(KIND) , intent(in) :: value, segment
logical(LK) :: isLess
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) represents the type and kind of the input argument array, which can be one of the following,
integer(IK) , intent(in) :: value, segment
complex(CK) , intent(in) :: value, segment
real(RK) , intent(in) :: value, segment
character(len(value),SK), intent(in) :: value, segment
This external function is extremely useful where a user-defined comparison check other than < is desired, for example, when the array segments should match the input value only within a given threshold or, when the case-sensitivity in character comparisons do not matter, or when the input array can be considered as an ascending-ordered sequence under certain conditions, for example, when only the magnitudes of the array elements are considered or when the array elements are multiplied by -1 or inverted (that is, when the array is in descending-order). See below for example use cases.
(optional, the default comparison operator is <.)
Returns
bin : The output scalar integer of default kind IK representing the index of the element of array for which array(bin) <= value < array(bin+1) holds or if isLess() is specified, the following conditions hold,
isLess(value, array(bin+1)) .and. .not. isLess(value, array(bin)) ! evaluates to .true._LK


Possible calling interfaces

bin = getBin(array, value)
bin = getBin(array, value, isLess)
Generate and return bin, the index of the element of the input ascending-ordered array,...
This module contains procedures and generic interfaces for finding the specific array index whose ele...
Warning
The procedures under this generic interface are impure when the user-specified external procedure isLess is specified as input argument.
Note that in Fortran, trailing blanks are ignored in character comparison, that is, "Fortran" == "Fortran " yields .true..
The input array must be a non-empty sequence of values that is sorted according to the criterion specified by the external function isLess() or if it is missing, then the values are sorted in ascending order.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
Be mindful of scenario where there are duplicate values in the input array.
In such cases, the returned bin is not necessarily the index of the first or the last occurrence of such value.
See below for illustrative examples.
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.
See also
getLoc
setLoc
setReplaced
getReplaced
setInserted
setSplit


Example usage

1program example
2
3 use pm_kind, only: SK ! All kinds are supported.
4 use pm_kind, only: IK ! All kinds are supported.
5 use pm_kind, only: RK ! All kinds are supported.
6 use pm_io, only: display_type
7 use pm_arraySearch, only: getBin
8
9 implicit none
10
11 character(:, SK), allocatable :: string_SK, strval_SK
12 character(2, SK), allocatable :: Array_SK(:) ! Can be any processor-supported kind.
13 integer(IK) , allocatable :: Array_IK(:) ! Can be any processor-supported kind.
14 real(RK) , allocatable :: Array_RK(:) ! Can be any processor-supported kind.
15
16 character(2,SK) :: value_SK ! Can be any processor-supported kind.
17 integer(IK) :: value_IK ! Can be any processor-supported kind.
18 real(RK) :: value_RK ! Can be any processor-supported kind.
19
20 integer(IK) :: bin ! Must be of default kind IK
21
22 type(display_type) :: disp
23
24 disp = display_type(file = "main.out.F90")
25
26 call disp%skip()
27 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
28 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
29 call disp%show("! Find the index of the largest element in the ascending-ordered `array` that is smaller than or equal to `value` via Binary Search.")
30 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
31 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
32 call disp%skip()
33
34 string_SK = "abcdefghi"
35 Array_SK = ["aa", "bb", "dd", "ee", "ff", "gg", "hh", "ii", "jj"]
36 Array_RK = [0._RK, 1._RK, 2._RK, 4._RK, 5._RK, 6._RK]
37 Array_IK = [0_IK, 1_IK, 2_IK, 4_IK, 5_IK, 6_IK]
38
39 strval_SK = "c"
40 value_SK = "cc"
41 value_IK = 3_IK
42 value_RK = 3.5_RK
43
44 call disp%skip()
45 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
46 call disp%show("! Find the index of character scalar.")
47 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
48 call disp%skip()
49
50 call disp%skip()
51 call disp%show("string_SK")
52 call disp%show( string_SK, deliml = SK_"""" )
53 call disp%show("strval_SK")
54 call disp%show( strval_SK, deliml = SK_"""" )
55 call disp%show("bin = getBin(string_SK, strval_SK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.")
56 bin = getBin(string_SK, strval_SK)
57 call disp%show("bin")
58 call disp%show( bin )
59 call disp%skip()
60
61 strval_SK = "cz"
62 call disp%skip()
63 call disp%show("string_SK")
64 call disp%show( string_SK, deliml = SK_"""" )
65 call disp%show("strval_SK")
66 call disp%show( strval_SK, deliml = SK_"""" )
67 call disp%show("bin = getBin(string_SK, strval_SK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.")
68 bin = getBin(string_SK, strval_SK)
69 call disp%show("bin")
70 call disp%show( bin )
71 call disp%skip()
72
73 strval_SK = "ca"
74 call disp%skip()
75 call disp%show("string_SK")
76 call disp%show( string_SK, deliml = SK_"""" )
77 call disp%show("strval_SK")
78 call disp%show( strval_SK, deliml = SK_"""" )
79 call disp%show("bin = getBin(string_SK, strval_SK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.")
80 bin = getBin(string_SK, strval_SK)
81 call disp%show("bin")
82 call disp%show( bin )
83 call disp%skip()
84
85 call disp%skip()
86 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
87 call disp%show("! Find the index of character array.")
88 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
89 call disp%skip()
90
91 call disp%skip()
92 call disp%show("Array_SK")
93 call disp%show( Array_SK, deliml = SK_"""" )
94 call disp%show("value_SK")
95 call disp%show( value_SK, deliml = SK_"""" )
96 call disp%show("bin = getBin(Array_SK, value_SK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.")
97 bin = getBin(Array_SK, value_SK)
98 call disp%show("bin")
99 call disp%show( bin )
100 call disp%skip()
101
102 call disp%skip()
103 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
104 call disp%show("! Find the index of integer array.")
105 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
106 call disp%skip()
107
108 call disp%skip()
109 call disp%show("Array_IK")
110 call disp%show( Array_IK )
111 call disp%show("value_IK")
112 call disp%show( value_IK )
113 call disp%show("bin = getBin(Array_IK, value_IK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.")
114 bin = getBin(Array_IK, value_IK)
115 call disp%show("bin")
116 call disp%show( bin )
117 call disp%skip()
118
119 call disp%skip()
120 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
121 call disp%show("! Find the index of real array.")
122 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
123 call disp%skip()
124
125 call disp%skip()
126 call disp%show("Array_RK")
127 call disp%show( Array_RK )
128 call disp%show("value_RK")
129 call disp%show( value_RK )
130 call disp%show("bin = getBin(Array_RK, value_RK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.")
131 bin = getBin(Array_RK, value_RK)
132 call disp%show("bin")
133 call disp%show( bin )
134 call disp%skip()
135
136 call disp%skip()
137 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
138 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
139 call disp%show("! The index of a `value` that is out of range.")
140 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
141 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
142 call disp%skip()
143
144 value_IK = Array_IK(1) - 1_IK
145 call disp%skip()
146 call disp%show("Array_IK")
147 call disp%show( Array_IK )
148 call disp%show("value_IK")
149 call disp%show( value_IK )
150 call disp%show("bin = getBin(Array_IK, value_IK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.")
151 bin = getBin(Array_IK, value_IK)
152 call disp%show("bin")
153 call disp%show( bin )
154 call disp%skip()
155
156 value_IK = Array_IK(size(Array_IK)) + 1_IK
157 call disp%skip()
158 call disp%show("Array_IK")
159 call disp%show( Array_IK )
160 call disp%show("value_IK")
161 call disp%show( value_IK )
162 call disp%show("bin = getBin(Array_IK, value_IK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.")
163 bin = getBin(Array_IK, value_IK)
164 call disp%show("bin")
165 call disp%show( bin )
166 call disp%skip()
167
168 call disp%skip()
169 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
170 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
171 call disp%show("! Find the index of the smallest element in the descending-ordered `array` that is")
172 call disp%show("! larger than or equal to `value` via Binary Search with a custom comparison function.")
173 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
174 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
175 call disp%skip()
176
177 call disp%skip()
178 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
179 call disp%show("! Find the index of a `value` in a descending-ordered input `Array`.")
180 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
181 call disp%skip()
182
183 value_IK = 2_IK
184 Array_IK = Array_IK(size(Array_IK):1:-1)
185 call disp%skip()
186 call disp%show("Array_IK")
187 call disp%show( Array_IK )
188 call disp%show("value_IK")
189 call disp%show( value_IK )
190 call disp%show("bin = getBin(Array_IK, value_IK, isLess_IK) ! index of the smallest value in `array` that is larger than or equal to the input `value`.")
191 bin = getBin(Array_IK, value_IK, isLess_IK)
192 call disp%show("bin")
193 call disp%show( bin )
194 call disp%skip()
195
196 call disp%skip()
197 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
198 call disp%show("! Find the index of a `value` in an input `array` whose absolute value is ascending-ordered.")
199 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
200 call disp%skip()
201
202 Array_RK = [( Array_RK(bin)*(-1)**bin, bin = 1, size(Array_RK, kind = IK) )]
203 call disp%skip()
204 call disp%show("Array_RK")
205 call disp%show( Array_RK )
206 call disp%show("value_RK")
207 call disp%show( value_RK )
208 call disp%show("bin = getBin(Array_RK, value_RK, isLess_RK) ! index of the largest absolute value in `array` that is smaller than or equal to the input `value`.")
209 bin = getBin(Array_RK, value_RK, isLess_RK)
210 call disp%show("bin")
211 call disp%show( bin )
212 call disp%skip()
213
214 call disp%skip()
215 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
216 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
217 call disp%show("! Be mindful of duplicate values in the input `Array`.")
218 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
219 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
220 call disp%skip()
221
222 value_IK = 0_IK
223 Array_IK = int([0, 0, 3, 3, 3], kind = IK)
224 call disp%skip()
225 call disp%show("Array_IK")
226 call disp%show( Array_IK )
227 call disp%show("value_IK")
228 call disp%show( value_IK )
229 call disp%show("bin = getBin(Array_IK, value_IK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.")
230 bin = getBin(Array_IK, value_IK)
231 call disp%show("bin")
232 call disp%show( bin )
233 call disp%skip()
234
235 value_IK = 3_IK
236 Array_IK = int([0, 0, 3, 3, 3], kind = IK)
237 call disp%skip()
238 call disp%show("Array_IK")
239 call disp%show( Array_IK )
240 call disp%show("value_IK")
241 call disp%show( value_IK )
242 call disp%show("bin = getBin(Array_IK, value_IK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.")
243 bin = getBin(Array_IK, value_IK)
244 call disp%show("bin")
245 call disp%show( bin )
246 call disp%skip()
247
248contains
249
252 pure function isLess_IK(value, segment) result(less)
253 use pm_kind, only: LK
254 integer(IK) , intent(in) :: value, segment
255 logical(LK) :: less
256 less = value > segment
257 end function
258
261 pure function isLess_RK(value, segment) result(less)
262 use pm_kind, only: LK
263 real(RK) , intent(in) :: value, segment
264 logical(LK) :: less
265 less = value < abs(segment)
266 end function
267
268end 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 RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Definition: pm_kind.F90:543
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
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4! Find the index of the largest element in the ascending-ordered `array` that is smaller than or equal to `value` via Binary Search.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8
9!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10! Find the index of character scalar.
11!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12
13
14string_SK
15"abcdefghi"
16strval_SK
17"c"
18bin = getBin(string_SK, strval_SK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.
19bin
20+3
21
22
23string_SK
24"abcdefghi"
25strval_SK
26"cz"
27bin = getBin(string_SK, strval_SK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.
28bin
29+3
30
31
32string_SK
33"abcdefghi"
34strval_SK
35"ca"
36bin = getBin(string_SK, strval_SK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.
37bin
38+2
39
40
41!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42! Find the index of character array.
43!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44
45
46Array_SK
47"aa", "bb", "dd", "ee", "ff", "gg", "hh", "ii", "jj"
48value_SK
49"cc"
50bin = getBin(Array_SK, value_SK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.
51bin
52+2
53
54
55!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56! Find the index of integer array.
57!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58
59
60Array_IK
61+0, +1, +2, +4, +5, +6
62value_IK
63+3
64bin = getBin(Array_IK, value_IK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.
65bin
66+3
67
68
69!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70! Find the index of real array.
71!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72
73
74Array_RK
75+0.0000000000000000, +1.0000000000000000, +2.0000000000000000, +4.0000000000000000, +5.0000000000000000, +6.0000000000000000
76value_RK
77+3.5000000000000000
78bin = getBin(Array_RK, value_RK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.
79bin
80+3
81
82
83!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85! The index of a `value` that is out of range.
86!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88
89
90Array_IK
91+0, +1, +2, +4, +5, +6
92value_IK
93-1
94bin = getBin(Array_IK, value_IK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.
95bin
96+0
97
98
99Array_IK
100+0, +1, +2, +4, +5, +6
101value_IK
102+7
103bin = getBin(Array_IK, value_IK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.
104bin
105+6
106
107
108!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110! Find the index of the smallest element in the descending-ordered `array` that is
111! larger than or equal to `value` via Binary Search with a custom comparison function.
112!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114
115
116!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117! Find the index of a `value` in a descending-ordered input `Array`.
118!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119
120
121Array_IK
122+6, +5, +4, +2, +1, +0
123value_IK
124+2
125bin = getBin(Array_IK, value_IK, isLess_IK) ! index of the smallest value in `array` that is larger than or equal to the input `value`.
126bin
127+4
128
129
130!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131! Find the index of a `value` in an input `array` whose absolute value is ascending-ordered.
132!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133
134
135Array_RK
136-0.0000000000000000, +1.0000000000000000, -2.0000000000000000, +4.0000000000000000, -5.0000000000000000, +6.0000000000000000
137value_RK
138+3.5000000000000000
139bin = getBin(Array_RK, value_RK, isLess_RK) ! index of the largest absolute value in `array` that is smaller than or equal to the input `value`.
140bin
141+3
142
143
144!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146! Be mindful of duplicate values in the input `Array`.
147!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149
150
151Array_IK
152+0, +0, +3, +3, +3
153value_IK
154+0
155bin = getBin(Array_IK, value_IK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.
156bin
157+2
158
159
160Array_IK
161+0, +0, +3, +3, +3
162value_IK
163+3
164bin = getBin(Array_IK, value_IK) ! index of the largest value in `array` that is smaller than or equal to the input `value`.
165bin
166+5
167
168
Test:
test_pm_arraySearch


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, September 1, 2017, 12:00 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin

Definition at line 174 of file pm_arraySearch.F90.


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