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

Generate and return an allocatable array containing the remaining parts of the input array as a sequence after removing the input pattern at the requested occurrences. More...

Detailed Description

Generate and return an allocatable array containing the remaining parts of the input array as a sequence after removing the input pattern at the requested occurrences.

If an input vector of instance is specified, containing the indices of the specific instances of pattern that must be removed, then only those instances will be removed from the array.

Parameters
[in]array: The input contiguous array of rank 1 of either
  • type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU), or
  • type logical of kind any supported by the processor (e.g., LK), 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),
within which the requested instances of pattern is to be removed.
[in]pattern: The input contiguous array of rank 1 or scalar of the same type and kind as the input array containing the pattern that must be removed from the input array.
iseq: The external user-specified function that takes two input explicit-shape arguments of the same type and kind as the input array and possibly, also the length of the arguments as the third argument.
It returns a scalar logical of default kind LK that is .true. if all elements of the two input arguments are equivalent (e.g., equal) according to the user-defined criterion, otherwise, it is .false..
If pattern is an array of rank 1, then the last argument to iseq is the length of the input pattern, preceded by a segment of array and pattern as the first and second arguments whose lengths are given by the third argument lenPattern.
The following illustrates the generic interface of iseq where pattern is array-valued,
function iseq(Segment, pattern, lenPattern) result(equivalent)
use pm_kind, only: IK, LK
integer(IK) , intent(in) :: lenPattern
TYPE(KIND) , intent(in) :: Segment(lenPattern), pattern(lenPattern)
logical(LK) :: equivalent
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
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
where TYPE(KIND) represents the type and kind of the input argument array, which can be one of the following,
use pm_kind, only: SK, IK, LK, CK, RK
character(*, SK), intent(in) :: Segment(lenPattern), pattern(lenPattern)
integer(IK) , intent(in) :: Segment(lenPattern), pattern(lenPattern)
logical(LK) , intent(in) :: Segment(lenPattern), pattern(lenPattern)
complex(CK) , intent(in) :: Segment(lenPattern), pattern(lenPattern)
real(RK) , intent(in) :: Segment(lenPattern), pattern(lenPattern)
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 CK
The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I...
Definition: pm_kind.F90:542
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
where the kinds SK, IK, LK, CK, RK, can refer to any kind type parameter that is supported by the processor.
The following illustrates the generic interface of iseq where pattern is scalar-valued (including Fortran scalar strings),
function iseq(segment, pattern) result(equivalent)
use pm_kind, only: LK
TYPE(KIND) , intent(in) :: segment, pattern
logical(LK) :: equivalent
end function
where TYPE(KIND) represents the type and kind of the input argument array, which can be one of the following,
use pm_kind, only: SK, IK, LK, CK, RK
character(*, SK), intent(in) :: segment, pattern
integer(IK) , intent(in) :: segment, pattern
logical(LK) , intent(in) :: segment, pattern
complex(CK) , intent(in) :: segment, pattern
real(RK) , intent(in) :: segment, pattern
where the kinds SK, IK, LK, CK, RK, can refer to any kind type parameter that is supported by the processor.
This user-defined equivalence check is extremely useful where a user-defined equivalence test other than exact equality or identity is needed, for example, when the array segments should match the input pattern only within a given threshold or, when the case-sensitivity in character comparisons do not matter.
In such cases, user can define a custom equivalence criterion within the user-defined external function iseq to achieve the goal.
(optional, the default equivalence operator is .eqv. if the input array is logical, otherwise ==)
[in]instance: The input contiguous array of rank 1 of type integer of default kind IK, containing the instances of the input pattern in the input array that should be removed.
Any element of instance that points to an out-of-scope instance of pattern in the input array will be ignored.
Any element of instance that is negatively valued will be counted from end of the input array.
For example, instance = [2,-1] requests removing the second instance of pattern in array from the beginning and removing the first instance of pattern starting from the end of array.
(optional, the default value corresponds to removing all instances of pattern in array)
[in]sorted: The input logical of default kind LK indicating whether the elements of the specified input instance are all in ascending-order.
This includes the negative elements of instance after they are translated to the corresponding positive instances from the beginning of the input array. Setting sorted = .true. will lead to faster runtime of the procedure.
However, the onus will be strictly on the user to ensure all elements of instance are in ascending-order.
This is generally not an easy guarantee to make if there are negative elements in instance.
Therefore, set sorted = .true. only if you can guarantee the validity of the condition.
(optional, default = .false.. It can be present as input argument only if the input argument instance is present.)
[in]unique: The input logical of default kind LK indicating whether the elements of the specified input instance are all unique.
This includes the negative elements of instance after they are translated to the corresponding positive instances from the beginning of the input array.
Setting unique = .true. will lead to faster runtime of the procedure.
However, the onus will be strictly on the user to ensure all elements of instance are unique.
This is generally not an easy guarantee to make if there are negative elements in instance.
Therefore, set unique = .true. only if you can guarantee the validity of the condition.
(optional, default = .false.. It can be present as input argument only if the input argument instance is present.)
Returns
ArrayRemoved : The output allocatable of the same type, kind, and rank as the input array argument containing the remaining parts of the array in sequence after removing the requested (or all) instances of pattern.


Possible calling interfaces

ArrayRemoved = getRemoved(array, pattern)
ArrayRemoved = getRemoved(array, pattern, iseq)
ArrayRemoved = getRemoved(array, pattern, instance, sorted = sorted, unique = unique)
ArrayRemoved = getRemoved(array, pattern, iseq, instance, sorted = sorted, unique = unique)
Generate and return an allocatable array containing the remaining parts of the input array as a seque...
This module contains procedures and generic interfaces for removing a pattern from arrays of various ...
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 impure when the user-specified external procedure iseq is specified as input argument.
Note that in Fortran, trailing blanks are ignored in character comparison, that is, "Fortran" == "Fortran " yields .true..
Remarks
The functions under this generic interface could be slightly slower than the setRemoved subroutine implementations due to the extra copy action required upon return from the function.
See pm_arrayRemove for the relevant benchmarks.
See also
setRemoved
setReplaced
getReplaced
setInserted
setSplit


Example usage

1program example
2
3 use pm_kind, only: LK
4 use pm_kind, only: SK ! All kinds are supported.
5 use pm_kind, only: IK ! All kinds are supported.
6 use pm_kind, only: CK ! All kinds are supported.
7 use pm_kind, only: RK ! All kinds are supported.
8 use pm_io, only: display_type
10
11 implicit none
12
13 integer(IK) , allocatable :: instance(:) ! Must be of default kind IK
14
15 character(:, SK), allocatable :: string_SK , stringNew_SK , stringPattern_SK
16 character(9, SK), allocatable :: Array_SK(:) , ArrayNew_SK(:), ArrayPattern_SK(:) ! Can be any processor-supported kind.
17 integer(IK) , allocatable :: Array_IK(:) , ArrayNew_IK(:), ArrayPattern_IK(:) ! Can be any processor-supported kind.
18 complex(CK) , allocatable :: Array_CK(:) , ArrayNew_CK(:), ArrayPattern_CK(:) ! Can be any processor-supported kind.
19 real(RK) , allocatable :: Array_RK(:) , ArrayNew_RK(:), ArrayPattern_RK(:) ! Can be any processor-supported kind.
20 logical(LK) , allocatable :: Array_LK(:) , ArrayNew_LK(:), ArrayPattern_LK(:)
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("! Remove all instances of pattern in array.")
30 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
31 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
32 call disp%skip()
33
34 string_SK = "ParaMonte is a Machine Learning Library "
35 Array_SK = ["ParaMonte", "XXXXXXXXX", "is ", "XXXXXXXXX", "a ", "XXXXXXXXX", "Monte ", "XXXXXXXXX", "Carlo ", "XXXXXXXXX", "Library. ", "XXXXXXXXX"]
36 Array_IK = [1_IK, 0_IK, 2_IK, 0_IK, 3_IK, 0_IK, 4_IK]
37 Array_RK = [1._RK, 0._RK, 2._RK, 0._RK, 3._RK, 0._RK, 4._RK]
38 Array_CK = [(1._CK, -1._CK), (0._CK, -0._CK), (2._CK, -2._CK), (0._CK, -0._CK), (3._CK, -3._CK), (0._CK, -0._CK), (4._CK, -4._CK)]
39 Array_LK = [.false._LK, .true._LK, .false._LK, .true._LK, .false._LK, .true._LK, .false._LK]
40
41 stringPattern_SK = " "
42 ArrayPattern_SK = ["XXXXXXXXX"]
43 ArrayPattern_IK = [0_IK]
44 ArrayPattern_RK = [0._RK]
45 ArrayPattern_CK = [(0._CK, -0._CK)]
46 ArrayPattern_LK = [.true._LK]
47
48 call disp%skip()
49 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
50 call disp%show("! Remove character scalar.")
51 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
52 call disp%skip()
53
54 call disp%show("string_SK")
55 call disp%show( string_SK, deliml = SK_"""" )
56 call disp%show("stringPattern_SK")
57 call disp%show( stringPattern_SK, deliml = SK_"""" )
58 call disp%show("stringNew_SK = getRemoved(string_SK, stringPattern_SK)")
59 stringNew_SK = getRemoved(string_SK, stringPattern_SK)
60 call disp%show("stringNew_SK")
61 call disp%show( stringNew_SK, deliml = SK_"""" )
62
63 call disp%skip()
64 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%")
65 call disp%show("! Remove character array.")
66 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%")
67 call disp%skip()
68
69 call disp%show("Array_SK")
70 call disp%show( Array_SK, deliml = SK_"""" )
71 call disp%show("ArrayPattern_SK")
72 call disp%show( ArrayPattern_SK, deliml = SK_"""" )
73 call disp%show("ArrayNew_SK = getRemoved(Array_SK, ArrayPattern_SK)")
74 ArrayNew_SK = getRemoved(Array_SK, ArrayPattern_SK)
75 call disp%show("ArrayNew_SK")
76 call disp%show( ArrayNew_SK, deliml = SK_"""" )
77
78 call disp%skip()
79 call disp%show("!%%%%%%%%%%%%%%%%%%%%%")
80 call disp%show("! Remove logical array.")
81 call disp%show("!%%%%%%%%%%%%%%%%%%%%%")
82 call disp%skip()
83
84 call disp%show("Array_LK")
85 call disp%show( Array_LK )
86 call disp%show("ArrayPattern_LK")
87 call disp%show( ArrayPattern_LK )
88 call disp%show("ArrayNew_LK = getRemoved(Array_LK, ArrayPattern_LK)")
89 ArrayNew_LK = getRemoved(Array_LK, ArrayPattern_LK)
90 call disp%show("ArrayNew_LK")
91 call disp%show( ArrayNew_LK )
92
93 call disp%skip()
94 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%")
95 call disp%show("! Remove integer array.")
96 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%")
97 call disp%skip()
98
99 call disp%show("Array_IK")
100 call disp%show( Array_IK )
101 call disp%show("ArrayPattern_IK")
102 call disp%show( ArrayPattern_IK )
103 call disp%show("ArrayNew_IK = getRemoved(Array_IK, ArrayPattern_IK)")
104 ArrayNew_IK = getRemoved(Array_IK, ArrayPattern_IK)
105 call disp%show("ArrayNew_IK")
106 call disp%show( ArrayNew_IK )
107
108 call disp%skip()
109 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%")
110 call disp%show("! Remove complex array.")
111 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%")
112 call disp%skip()
113
114 call disp%show("Array_CK")
115 call disp%show( Array_CK )
116 call disp%show("ArrayPattern_CK")
117 call disp%show( ArrayPattern_CK )
118 call disp%show("ArrayNew_CK = getRemoved(Array_CK, ArrayPattern_CK)")
119 ArrayNew_CK = getRemoved(Array_CK, ArrayPattern_CK)
120 call disp%show("ArrayNew_CK")
121 call disp%show( ArrayNew_CK )
122
123 call disp%skip()
124 call disp%show("!%%%%%%%%%%%%%%%%%%%")
125 call disp%show("! Remove real array.")
126 call disp%show("!%%%%%%%%%%%%%%%%%%%")
127 call disp%skip()
128
129 call disp%show("Array_RK")
130 call disp%show( Array_RK )
131 call disp%show("ArrayPattern_RK")
132 call disp%show( ArrayPattern_RK )
133 call disp%show("ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK)")
134 ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK)
135 call disp%show("ArrayNew_RK")
136 call disp%show( ArrayNew_RK )
137
138
139
140 call disp%skip()
141 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
142 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
143 call disp%show("! Remove only particular instances of pattern in array.")
144 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
145 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
146 call disp%skip()
147
148 string_SK = "A_A_A_A_A_A_A_A_A"
149 Array_SK = ["A", "_", "A", "_", "A", "_", "A", "_", "A", "_", "A", "_", "A", "_", "A", "_", "A"]
150 Array_IK = [0_IK, 1_IK, 0_IK, 2_IK, 3_IK, 0_IK, 4_IK, 5_IK, 0_IK, 0_IK]
151 Array_RK = [0._RK, 1._RK, 0._RK, 2._RK, 3._RK, 0._RK, 4._RK, 5._RK, 0._RK, 0._RK]
152 Array_CK = [(0._CK, -0._CK), (1._CK, -1._CK), (0._CK, -0._CK), (2._CK, -2._CK), (3._CK, -3._CK), (0._CK, -0._CK), (4._CK, -4._CK), (5._CK, -5._CK), (0._CK, -0._CK), (0._CK, -0._CK)]
153 Array_LK = [.false._LK, .true._LK, .false._LK, .true._LK, .true._LK, .false._LK, .true._LK, .true._LK, .false._LK, .false._LK]
154
155 stringPattern_SK = "_"
156 ArrayPattern_SK = ["_"]
157 ArrayPattern_IK = [0_IK]
158 ArrayPattern_RK = [0._RK]
159 ArrayPattern_CK = [(0._CK, -0._CK)]
160 ArrayPattern_LK = [.false._LK]
161
162 instance = [-3, 2, -4] ! remove at the second occurrence from the beginning and the third occurrence from the end. Duplicate indices are ignored.
163
164 call disp%skip()
165 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
166 call disp%show("! Remove character scalar.")
167 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
168 call disp%skip()
169
170 call disp%show("string_SK")
171 call disp%show( string_SK, deliml = SK_"""" )
172 call disp%show("stringPattern_SK")
173 call disp%show( stringPattern_SK, deliml = SK_"""" )
174 call disp%show("instance")
175 call disp%show( instance )
176 call disp%show("stringNew_SK = getRemoved(string_SK, stringPattern_SK, instance = instance)")
177 stringNew_SK = getRemoved(string_SK, stringPattern_SK, instance = instance)
178 call disp%show("stringNew_SK")
179 call disp%show( stringNew_SK, deliml = SK_"""" )
180
181 call disp%skip()
182 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
183 call disp%show("! Remove vector `pattern` from character array.")
184 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
185 call disp%skip()
186
187 call disp%show("Array_SK")
188 call disp%show( Array_SK, deliml = SK_"""" )
189 call disp%show("ArrayPattern_SK")
190 call disp%show( ArrayPattern_SK, deliml = SK_"""" )
191 call disp%show("instance")
192 call disp%show( instance )
193 call disp%show("ArrayNew_SK = getRemoved(Array_SK, ArrayPattern_SK, instance = instance)")
194 ArrayNew_SK = getRemoved(Array_SK, ArrayPattern_SK, instance = instance)
195 call disp%show("ArrayNew_SK")
196 call disp%show( ArrayNew_SK, deliml = SK_"""" )
197
198 call disp%skip()
199 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
200 call disp%show("! Remove character array with scalar `pattern`.")
201 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
202 call disp%skip()
203
204 call disp%show("Array_SK")
205 call disp%show( Array_SK, deliml = SK_"""" )
206 call disp%show("ArrayPattern_SK(1)")
207 call disp%show( ArrayPattern_SK(1), deliml = SK_"""" )
208 call disp%show("instance")
209 call disp%show( instance )
210 call disp%show("ArrayNew_SK = getRemoved(Array_SK, ArrayPattern_SK(1), instance = instance)")
211 ArrayNew_SK = getRemoved(Array_SK, ArrayPattern_SK(1), instance = instance)
212 call disp%show("ArrayNew_SK")
213 call disp%show( ArrayNew_SK, deliml = SK_"""" )
214
215 call disp%skip()
216 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
217 call disp%show("! Remove logical array with vector `pattern`.")
218 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
219 call disp%skip()
220
221 call disp%show("Array_LK")
222 call disp%show( Array_LK )
223 call disp%show("ArrayPattern_LK")
224 call disp%show( ArrayPattern_LK )
225 call disp%show("instance")
226 call disp%show( instance )
227 call disp%show("ArrayNew_LK = getRemoved(Array_LK, ArrayPattern_LK, instance = instance)")
228 ArrayNew_LK = getRemoved(Array_LK, ArrayPattern_LK, instance = instance)
229 call disp%show("ArrayNew_LK")
230 call disp%show( ArrayNew_LK )
231
232 call disp%skip()
233 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
234 call disp%show("! Remove logical array with scalar `pattern`.")
235 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
236 call disp%skip()
237
238 call disp%show("Array_LK")
239 call disp%show( Array_LK )
240 call disp%show("ArrayPattern_LK(1)")
241 call disp%show( ArrayPattern_LK(1) )
242 call disp%show("instance")
243 call disp%show( instance )
244 call disp%show("ArrayNew_LK = getRemoved(Array_LK, ArrayPattern_LK(1), instance = instance)")
245 ArrayNew_LK = getRemoved(Array_LK, ArrayPattern_LK(1), instance = instance)
246 call disp%show("ArrayNew_LK")
247 call disp%show( ArrayNew_LK )
248
249 call disp%skip()
250 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
251 call disp%show("! Remove integer array with vector `pattern`.")
252 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
253 call disp%skip()
254
255 call disp%show("Array_IK")
256 call disp%show( Array_IK )
257 call disp%show("ArrayPattern_IK")
258 call disp%show( ArrayPattern_IK )
259 call disp%show("instance")
260 call disp%show( instance )
261 call disp%show("ArrayNew_IK = getRemoved(Array_IK, ArrayPattern_IK, instance = instance)")
262 ArrayNew_IK = getRemoved(Array_IK, ArrayPattern_IK, instance = instance)
263 call disp%show("ArrayNew_IK")
264 call disp%show( ArrayNew_IK )
265
266 call disp%skip()
267 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
268 call disp%show("! Remove integer array with scalar `pattern`.")
269 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
270 call disp%skip()
271
272 call disp%show("Array_IK")
273 call disp%show( Array_IK )
274 call disp%show("ArrayPattern_IK(1)")
275 call disp%show( ArrayPattern_IK(1) )
276 call disp%show("instance")
277 call disp%show( instance )
278 call disp%show("ArrayNew_IK = getRemoved(Array_IK, ArrayPattern_IK(1), instance = instance)")
279 ArrayNew_IK = getRemoved(Array_IK, ArrayPattern_IK(1), instance = instance)
280 call disp%show("ArrayNew_IK")
281 call disp%show( ArrayNew_IK )
282
283 call disp%skip()
284 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
285 call disp%show("! Remove complex array with vector `pattern`.")
286 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
287 call disp%skip()
288
289 call disp%show("Array_CK")
290 call disp%show( Array_CK )
291 call disp%show("ArrayPattern_CK")
292 call disp%show( ArrayPattern_CK )
293 call disp%show("instance")
294 call disp%show( instance )
295 call disp%show("ArrayNew_CK = getRemoved(Array_CK, ArrayPattern_CK, instance = instance)")
296 ArrayNew_CK = getRemoved(Array_CK, ArrayPattern_CK, instance = instance)
297 call disp%show("ArrayNew_CK")
298 call disp%show( ArrayNew_CK )
299
300 call disp%skip()
301 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
302 call disp%show("! Remove complex array with scalar `pattern`.")
303 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
304 call disp%skip()
305
306 call disp%show("Array_CK")
307 call disp%show( Array_CK )
308 call disp%show("ArrayPattern_CK(1)")
309 call disp%show( ArrayPattern_CK(1) )
310 call disp%show("instance")
311 call disp%show( instance )
312 call disp%show("ArrayNew_CK = getRemoved(Array_CK, ArrayPattern_CK(1), instance = instance)")
313 ArrayNew_CK = getRemoved(Array_CK, ArrayPattern_CK(1), instance = instance)
314 call disp%show("ArrayNew_CK")
315 call disp%show( ArrayNew_CK )
316
317 call disp%skip()
318 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
319 call disp%show("! Remove real array with vector `pattern`.")
320 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
321 call disp%skip()
322
323 call disp%show("Array_RK")
324 call disp%show( Array_RK )
325 call disp%show("ArrayPattern_RK")
326 call disp%show( ArrayPattern_RK )
327 call disp%show("instance")
328 call disp%show( instance )
329 call disp%show("ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK, instance = instance)")
330 ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK, instance = instance)
331 call disp%show("ArrayNew_RK")
332 call disp%show( ArrayNew_RK )
333
334 call disp%skip()
335 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
336 call disp%show("! Remove real array with scalar `pattern`.")
337 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
338 call disp%skip()
339
340 call disp%show("Array_RK")
341 call disp%show( Array_RK )
342 call disp%show("ArrayPattern_RK(1)")
343 call disp%show( ArrayPattern_RK(1) )
344 call disp%show("instance")
345 call disp%show( instance )
346 call disp%show("ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK(1), instance = instance)")
347 ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK(1), instance = instance)
348 call disp%show("ArrayNew_RK")
349 call disp%show( ArrayNew_RK )
350
351
352 call disp%skip()
353 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
354 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
355 call disp%show("! Remove specific instances with a user-defined equivalence test.")
356 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
357 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
358 call disp%skip()
359
360
361 call disp%skip()
362 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
363 call disp%show("! Remove case-insensitive instances of vector `pattern` within the character array.")
364 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
365 call disp%skip()
366
367 string_SK = "ABBAbbA"
368 stringPattern_SK = "bb"
369
370 call disp%show("string_SK")
371 call disp%show( string_SK, deliml = SK_"""" )
372 call disp%show("stringPattern_SK")
373 call disp%show( stringPattern_SK, deliml = SK_"""" )
374 call disp%show("stringNew_SK = getRemoved(string_SK, stringPattern_SK, iseq = iseq_SK) ! case-insensitive string removal.")
375 stringNew_SK = getRemoved(string_SK, stringPattern_SK, iseq = iseq_SK)
376 call disp%show("stringNew_SK")
377 call disp%show( stringNew_SK, deliml = SK_"""" )
378
379 call disp%skip()
380 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
381 call disp%show("! Remove specific instances of vector `pattern` within the real array.")
382 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
383 call disp%skip()
384
385 Array_RK = [0._RK, 1.01_RK, 1.04_RK, 0.98_RK, 1.0_RK, 1.02_RK]
386 ArrayPattern_RK = [-1._RK, 1._RK]
387 instance = [-2_IK]
388
389 call disp%show("Array_RK")
390 call disp%show( Array_RK )
391 call disp%show("ArrayPattern_RK")
392 call disp%show( ArrayPattern_RK )
393 call disp%show("instance")
394 call disp%show( instance )
395 call disp%show("ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK, iseq = iseq_vec_RK, instance = instance)")
396 ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK, iseq = iseq_vec_RK, instance = instance)
397 call disp%show("ArrayNew_RK")
398 call disp%show( ArrayNew_RK )
399
400 call disp%skip()
401 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
402 call disp%show("! Remove specific instances of scalar `pattern` within the real array.")
403 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
404 call disp%skip()
405
406 call disp%show("Array_RK")
407 call disp%show( Array_RK )
408 call disp%show("ArrayPattern_RK(1)")
409 call disp%show( ArrayPattern_RK(1) )
410 call disp%show("instance")
411 call disp%show( instance )
412 call disp%show("ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK(1), iseq = iseq_RK, instance = instance)")
413 ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK(1), iseq = iseq_RK, instance = instance)
414 call disp%show("ArrayNew_RK")
415 call disp%show( ArrayNew_RK )
416
417contains
418
419 pure function iseq_SK(ArraySegment, pattern) result(equivalent)
420 use pm_strASCII, only: getStrLower
421 character(*, SK), intent(in) :: pattern, ArraySegment
422 logical(LK) :: equivalent
423 equivalent = pattern == getStrLower(ArraySegment)
424 end function
425
426 function iseq_RK(arraysegment, pattern) result(equivalent)
427 real(RK) , intent(in) :: pattern, arraySegment
428 logical(LK) :: equivalent
429 equivalent = abs(abs(pattern) - abs(arraySegment)) < 0.05_RK
430 end function
431
432 function iseq_vec_RK(ArraySegment, pattern, lenPattern) result(equivalent)
433 integer(IK) , intent(in) :: lenPattern
434 real(RK) , intent(in) :: pattern(lenPattern), ArraySegment(lenPattern)
435 logical(LK) :: equivalent
436 equivalent = all(abs(abs(pattern) - abs(ArraySegment)) < 0.05_RK)
437 end function
438
439end 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
Generate and return the input string where the uppercase English alphabets are all converted to lower...
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
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!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4! Remove all instances of pattern in array.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8
9!%%%%%%%%%%%%%%%%%%%%%%%%%
10! Remove character scalar.
11!%%%%%%%%%%%%%%%%%%%%%%%%%
12
13string_SK
14"ParaMonte is a Machine Learning Library "
15stringPattern_SK
16" "
17stringNew_SK = getRemoved(string_SK, stringPattern_SK)
18stringNew_SK
19"ParaMonteisaMachineLearningLibrary"
20
21!%%%%%%%%%%%%%%%%%%%%%%%%
22! Remove character array.
23!%%%%%%%%%%%%%%%%%%%%%%%%
24
25Array_SK
26"ParaMonte", "XXXXXXXXX", "is ", "XXXXXXXXX", "a ", "XXXXXXXXX", "Monte ", "XXXXXXXXX", "Carlo ", "XXXXXXXXX", "Library. ", "XXXXXXXXX"
27ArrayPattern_SK
28"XXXXXXXXX"
29ArrayNew_SK = getRemoved(Array_SK, ArrayPattern_SK)
30ArrayNew_SK
31"ParaMonte", "is ", "a ", "Monte ", "Carlo ", "Library. "
32
33!%%%%%%%%%%%%%%%%%%%%%
34! Remove logical array.
35!%%%%%%%%%%%%%%%%%%%%%
36
37Array_LK
38F, T, F, T, F, T, F
39ArrayPattern_LK
40T
41ArrayNew_LK = getRemoved(Array_LK, ArrayPattern_LK)
42ArrayNew_LK
43F, F, F, F
44
45!%%%%%%%%%%%%%%%%%%%%%%
46! Remove integer array.
47!%%%%%%%%%%%%%%%%%%%%%%
48
49Array_IK
50+1, +0, +2, +0, +3, +0, +4
51ArrayPattern_IK
52+0
53ArrayNew_IK = getRemoved(Array_IK, ArrayPattern_IK)
54ArrayNew_IK
55+1, +2, +3, +4
56
57!%%%%%%%%%%%%%%%%%%%%%%
58! Remove complex array.
59!%%%%%%%%%%%%%%%%%%%%%%
60
61Array_CK
62(+1.0000000000000000, -1.0000000000000000), (+0.0000000000000000, -0.0000000000000000), (+2.0000000000000000, -2.0000000000000000), (+0.0000000000000000, -0.0000000000000000), (+3.0000000000000000, -3.0000000000000000), (+0.0000000000000000, -0.0000000000000000), (+4.0000000000000000, -4.0000000000000000)
63ArrayPattern_CK
64(+0.0000000000000000, -0.0000000000000000)
65ArrayNew_CK = getRemoved(Array_CK, ArrayPattern_CK)
66ArrayNew_CK
67(+1.0000000000000000, -1.0000000000000000), (+2.0000000000000000, -2.0000000000000000), (+3.0000000000000000, -3.0000000000000000), (+4.0000000000000000, -4.0000000000000000)
68
69!%%%%%%%%%%%%%%%%%%%
70! Remove real array.
71!%%%%%%%%%%%%%%%%%%%
72
73Array_RK
74+1.0000000000000000, +0.0000000000000000, +2.0000000000000000, +0.0000000000000000, +3.0000000000000000, +0.0000000000000000, +4.0000000000000000
75ArrayPattern_RK
76+0.0000000000000000
77ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK)
78ArrayNew_RK
79+1.0000000000000000, +2.0000000000000000, +3.0000000000000000, +4.0000000000000000
80
81!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83! Remove only particular instances of pattern in array.
84!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86
87
88!%%%%%%%%%%%%%%%%%%%%%%%%%
89! Remove character scalar.
90!%%%%%%%%%%%%%%%%%%%%%%%%%
91
92string_SK
93"A_A_A_A_A_A_A_A_A"
94stringPattern_SK
95"_"
96instance
97-3, +2, -4
98stringNew_SK = getRemoved(string_SK, stringPattern_SK, instance = instance)
99stringNew_SK
100"A_AA_A_AAA_A_A"
101
102!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103! Remove vector `pattern` from character array.
104!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105
106Array_SK
107"A ", "_ ", "A ", "_ ", "A ", "_ ", "A ", "_ ", "A ", "_ ", "A ", "_ ", "A ", "_ ", "A ", "_ ", "A "
108ArrayPattern_SK
109"_ "
110instance
111-3, +2, -4
112ArrayNew_SK = getRemoved(Array_SK, ArrayPattern_SK, instance = instance)
113ArrayNew_SK
114"A ", "_ ", "A ", "A ", "_ ", "A ", "_ ", "A ", "A ", "A ", "_ ", "A ", "_ ", "A "
115
116!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117! Remove character array with scalar `pattern`.
118!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119
120Array_SK
121"A ", "_ ", "A ", "_ ", "A ", "_ ", "A ", "_ ", "A ", "_ ", "A ", "_ ", "A ", "_ ", "A ", "_ ", "A "
122ArrayPattern_SK(1)
123"_ "
124instance
125-3, +2, -4
126ArrayNew_SK = getRemoved(Array_SK, ArrayPattern_SK(1), instance = instance)
127ArrayNew_SK
128"A ", "_ ", "A ", "A ", "_ ", "A ", "_ ", "A ", "A ", "A ", "_ ", "A ", "_ ", "A "
129
130!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131! Remove logical array with vector `pattern`.
132!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133
134Array_LK
135F, T, F, T, T, F, T, T, F, F
136ArrayPattern_LK
137F
138instance
139-3, +2, -4
140ArrayNew_LK = getRemoved(Array_LK, ArrayPattern_LK, instance = instance)
141ArrayNew_LK
142F, T, T, T, T, T, F, F
143
144!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145! Remove logical array with scalar `pattern`.
146!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147
148Array_LK
149F, T, F, T, T, F, T, T, F, F
150ArrayPattern_LK(1)
151F
152instance
153-3, +2, -4
154ArrayNew_LK = getRemoved(Array_LK, ArrayPattern_LK(1), instance = instance)
155ArrayNew_LK
156F, T, T, T, T, T, F, F
157
158!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159! Remove integer array with vector `pattern`.
160!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161
162Array_IK
163+0, +1, +0, +2, +3, +0, +4, +5, +0, +0
164ArrayPattern_IK
165+0
166instance
167-3, +2, -4
168ArrayNew_IK = getRemoved(Array_IK, ArrayPattern_IK, instance = instance)
169ArrayNew_IK
170+0, +1, +2, +3, +4, +5, +0, +0
171
172!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173! Remove integer array with scalar `pattern`.
174!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175
176Array_IK
177+0, +1, +0, +2, +3, +0, +4, +5, +0, +0
178ArrayPattern_IK(1)
179+0
180instance
181-3, +2, -4
182ArrayNew_IK = getRemoved(Array_IK, ArrayPattern_IK(1), instance = instance)
183ArrayNew_IK
184+0, +1, +2, +3, +4, +5, +0, +0
185
186!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187! Remove complex array with vector `pattern`.
188!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189
190Array_CK
191(+0.0000000000000000, -0.0000000000000000), (+1.0000000000000000, -1.0000000000000000), (+0.0000000000000000, -0.0000000000000000), (+2.0000000000000000, -2.0000000000000000), (+3.0000000000000000, -3.0000000000000000), (+0.0000000000000000, -0.0000000000000000), (+4.0000000000000000, -4.0000000000000000), (+5.0000000000000000, -5.0000000000000000), (+0.0000000000000000, -0.0000000000000000), (+0.0000000000000000, -0.0000000000000000)
192ArrayPattern_CK
193(+0.0000000000000000, -0.0000000000000000)
194instance
195-3, +2, -4
196ArrayNew_CK = getRemoved(Array_CK, ArrayPattern_CK, instance = instance)
197ArrayNew_CK
198(+0.0000000000000000, -0.0000000000000000), (+1.0000000000000000, -1.0000000000000000), (+2.0000000000000000, -2.0000000000000000), (+3.0000000000000000, -3.0000000000000000), (+4.0000000000000000, -4.0000000000000000), (+5.0000000000000000, -5.0000000000000000), (+0.0000000000000000, -0.0000000000000000), (+0.0000000000000000, -0.0000000000000000)
199
200!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201! Remove complex array with scalar `pattern`.
202!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203
204Array_CK
205(+0.0000000000000000, -0.0000000000000000), (+1.0000000000000000, -1.0000000000000000), (+0.0000000000000000, -0.0000000000000000), (+2.0000000000000000, -2.0000000000000000), (+3.0000000000000000, -3.0000000000000000), (+0.0000000000000000, -0.0000000000000000), (+4.0000000000000000, -4.0000000000000000), (+5.0000000000000000, -5.0000000000000000), (+0.0000000000000000, -0.0000000000000000), (+0.0000000000000000, -0.0000000000000000)
206ArrayPattern_CK(1)
207(+0.0000000000000000, -0.0000000000000000)
208instance
209-3, +2, -4
210ArrayNew_CK = getRemoved(Array_CK, ArrayPattern_CK(1), instance = instance)
211ArrayNew_CK
212(+0.0000000000000000, -0.0000000000000000), (+1.0000000000000000, -1.0000000000000000), (+2.0000000000000000, -2.0000000000000000), (+3.0000000000000000, -3.0000000000000000), (+4.0000000000000000, -4.0000000000000000), (+5.0000000000000000, -5.0000000000000000), (+0.0000000000000000, -0.0000000000000000), (+0.0000000000000000, -0.0000000000000000)
213
214!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215! Remove real array with vector `pattern`.
216!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217
218Array_RK
219+0.0000000000000000, +1.0000000000000000, +0.0000000000000000, +2.0000000000000000, +3.0000000000000000, +0.0000000000000000, +4.0000000000000000, +5.0000000000000000, +0.0000000000000000, +0.0000000000000000
220ArrayPattern_RK
221+0.0000000000000000
222instance
223-3, +2, -4
224ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK, instance = instance)
225ArrayNew_RK
226+0.0000000000000000, +1.0000000000000000, +2.0000000000000000, +3.0000000000000000, +4.0000000000000000, +5.0000000000000000, +0.0000000000000000, +0.0000000000000000
227
228!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229! Remove real array with scalar `pattern`.
230!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231
232Array_RK
233+0.0000000000000000, +1.0000000000000000, +0.0000000000000000, +2.0000000000000000, +3.0000000000000000, +0.0000000000000000, +4.0000000000000000, +5.0000000000000000, +0.0000000000000000, +0.0000000000000000
234ArrayPattern_RK(1)
235+0.0000000000000000
236instance
237-3, +2, -4
238ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK(1), instance = instance)
239ArrayNew_RK
240+0.0000000000000000, +1.0000000000000000, +2.0000000000000000, +3.0000000000000000, +4.0000000000000000, +5.0000000000000000, +0.0000000000000000, +0.0000000000000000
241
242!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244! Remove specific instances with a user-defined equivalence test.
245!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247
248
249!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250! Remove case-insensitive instances of vector `pattern` within the character array.
251!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252
253string_SK
254"ABBAbbA"
255stringPattern_SK
256"bb"
257stringNew_SK = getRemoved(string_SK, stringPattern_SK, iseq = iseq_SK) ! case-insensitive string removal.
258stringNew_SK
259"AAA"
260
261!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262! Remove specific instances of vector `pattern` within the real array.
263!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264
265Array_RK
266+0.0000000000000000, +1.0100000000000000, +1.0400000000000000, +0.97999999999999998, +1.0000000000000000, +1.0200000000000000
267ArrayPattern_RK
268-1.0000000000000000, +1.0000000000000000
269instance
270-2
271ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK, iseq = iseq_vec_RK, instance = instance)
272ArrayNew_RK
273+0.0000000000000000, +0.97999999999999998, +1.0000000000000000, +1.0200000000000000
274
275!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276! Remove specific instances of scalar `pattern` within the real array.
277!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278
279Array_RK
280+0.0000000000000000, +1.0100000000000000, +1.0400000000000000, +0.97999999999999998, +1.0000000000000000, +1.0200000000000000
281ArrayPattern_RK(1)
282-1.0000000000000000
283instance
284-2
285ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK(1), iseq = iseq_RK, instance = instance)
286ArrayNew_RK
287+0.0000000000000000, +1.0100000000000000, +1.0400000000000000, +0.97999999999999998, +1.0200000000000000
288
Test:
test_pm_arrayRemove
Bug:

Status: Unresolved
Source: Intel Classic Fortran Compiler ifort version 2021.2.0, GNU Fortran Compiler gfortran version 10, 11
Description: The Intel Classic Fortran Compiler ifort version 2021.2.0 has a bug for the following interface definition
character(len(array,IK),SK), allocatable :: ArrayRemoved(:)

leading to an internal compiler error. For now, the remedy seems to be to redefine the interface as,

character(:, SK), allocatable :: ArrayRemoved(:)

and changing the allocation method accordingly in the implementation to,

allocate(character(len(array, kind = IK)) :: ArrayRemoved(lenArrayRemoved))

However, this introduces internal compiler error: Segmentation fault with GNU Fortran Compiler gfortran versions 10 and 11. Here is a code snippet to regenerate the bug in Intel Classic Fortran Compiler ifort (uncomment the commented line to reproduce the gfortran bug),

module pm_explicitLenResult
implicit none
interface
pure module function bug(array) result(ArrayRemoved)
character(*, SK), intent(in), contiguous :: array(:)
character(len(array),SK) , allocatable :: ArrayRemoved(:) ! catastrophic internal error with ifort 2021.2. Fine with gfortran 10.3
!character(:, SK) , allocatable :: ArrayRemoved(:) ! catastrophic internal error with gfortran 10.3. Fine with ifort 2021.2
end function
end interface
end module pm_explicitLenResult
submodule (pm_explicitLenResult) routines
implicit none
contains
module procedure bug
allocate(ArrayRemoved, source = array)
end procedure
end submodule routines
program main
use pm_explicitLenResult, only: bug
character(2) :: array(3) = ["AA", "BB", "CC"]
character(2), allocatable :: ArrayRemoved(:)
ArrayRemoved = bug(array)
end program main
program main
This is main entry to the tests of the ParaMonte kernel library.
Definition: main.F90:27


Remedy (as of ParaMonte Library version 2.0.0): It turns out that both gfortran and Intel do not tolerate the separation of interface from implementation in the above code snippet.
If one duplicates the interface in the implementation submodule, then both compilers compile and run the code with no errors.
This is the remedy that is currently used in this getRemoved generic interface (interface duplication where the bug exists).
Here is a workaround example for the bug in the above code snippet,

module pm_explicitLenResult
implicit none
interface
pure module function bug(array) result(ArrayRemoved)
character(*, SK), intent(in), contiguous :: array(:)
character(len(array),SK), allocatable :: ArrayRemoved(:) ! catastrophic internal error with ifort 2021.2. Fine with gfortran 10.3
end function
end interface
end module pm_explicitLenResult
submodule (pm_explicitLenResult) routines
implicit none
contains
module procedure bug
allocate(ArrayRemoved, source = array)
end procedure
end submodule routines
program main
use pm_explicitLenResult, only: bug
character(2) :: array(3) = ["AA", "BB", "CC"]
character(2), allocatable :: ArrayRemoved(:)
ArrayRemoved = bug(array)
end program main
Todo:
Low Priority: This generic interface can be extended to 2D input objects.


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 Austin

Definition at line 337 of file pm_arrayRemove.F90.


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