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

Allocate or resize (shrink or expand) and refill an input allocatable scalar string or array of rank 1..3 to an arbitrary size while preserving the original contents or a subset of it.
More...

Detailed Description

Allocate or resize (shrink or expand) and refill an input allocatable scalar string or array of rank 1..3 to an arbitrary size while preserving the original contents or a subset of it.

The new array size is set to twice its current size or, to the requested input size(..).
The array contents or a requested subset of it are kept in the original indices in the output resized array or shifted to a new starting location lbc in the output array.
The rest of the elements (including the newly-added elements) are filled with the user-specified fill.

The following figure illustrates example resizing and refilling of a 1D array and transferal of its contents.


Parameters
[in,out]array: The input/output allocatable scalar of
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU)
or array of rank 1..3 of either
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU)
  2. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64)
  3. type logical of kind any supported by the processor (e.g., LK)
  4. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128)
  5. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128)
On output, the array will be (re)allocated to the requested new size with the same lower bound as before (or 1 if unallocated).
[in]fill: The input scalar of the same type and kind as the input array containing the value to fill the new elements (if any) of array. If array is of type character, then
  1. The equality len(fill) == 1 must also hold if array is of zero rank (i.e., a scalar string).
  2. The equality len(fill) <= len(array) must also hold if array is of non-zero rank.
[in]size: The input non-negative scalar or array of type integer of default kind IK representing the new size of the output array.
  1. If array is a scalar or array of rank 1, then size must be a scalar.
  2. If array is an array of rank > 1, then size must be a vector of the same length as rank(array).
(optional, default = 2 * len/shape(array) where the condition 0 < len/shape(array) must hold, otherwise infinite loops within the program can occur.)
[in]lbc: The input scalar or array of type integer of default kind IK, representing the Lower Bound(s) of the Contents in the newly resized output array.
  1. If array is a scalar or array of rank 1, then lbc must be a scalar.
  2. If array is an array of rank > 1, then lbc must be a vector of the same length as rank(array).
(optional, default = lbcold. It can be present only if the size argument is also present.)
[in]lbcold: The input scalar or array of type integer of default kind IK, representing the Lower Bound(s) of the Contents in the original (old) input array that is to be copied to the newly allocated output array starting at the new lower bound(s) lbc.
(optional, default = ubound(array). If array is a scalar string, then default = 1. It can be present only if the size, lbc, and ubcold input arguments are also present.)
[in]ubcold: The input scalar or array of type integer of default kind IK, representing the Upper Bound(s) of the Contents in the original (old) input array that is to be copied to the newly allocated output array starting at the new lower bound(s) lbc.
(optional, default = ubound(array). If array is a scalar string, then default = len(array) It can be present only if the size and lbc and lbcold input arguments are also present.)
[out]failed: The output scalar logical of default kind LK that is .false. if and only if the requested array resizing is successful, otherwise it is set to .true. to signal the occurrence of an allocation error.
The value of failed is .true. only if the stat argument returned by the Fortran intrinsic allocate() statement is non-zero.
(optional, if missing and an allocation error occurs, the processor dictates the program behavior (normally execution stops).)
[out]errmsg: The output scalar character of default kind SK of arbitrary length type parameter.
If the optional output argument failed is present and an error occurs, errmsg will be set to a message describing the nature of the error.
This behavior conforms with the standard Fortran behavior for the intrinsic allocate() statement.
A length type parameter of 127 or more for errmsg should be sufficient for capturing most if not all error messages in entirety.
(optional. Its presence is relevant if and only if the optional output argument failed is also present.)


Possible calling interfaces

call setRefilled(array, fill, failed = failed, errmsg = errmsg) ! Refill to twice as large with the same lower bound as before and optionally gracefully return if reallocation fails.
call setRefilled(array, fill, size, failed = failed, errmsg = errmsg) ! Refill to the requested `size` with the same lower bound as before and optionally gracefully return if reallocation fails.
call setRefilled(array, fill, size, lbc, failed = failed, errmsg = errmsg) ! Refill to the requested `size`, write `array` to the output `array(\@lbc:)`, optionally gracefully return upon failure.
call setRefilled(array, fill, size, lbc, lbcold, ubcold, failed = failed, errmsg = errmsg) ! Refill to the requested `size` with the same lower bound, write `array(\@lbcold:ubcold)` to `array(\@lbc:\@lbc-lbcold+ubcold)`, optionally gracefully return upon failure.
!
Allocate or resize (shrink or expand) and refill an input allocatable scalar string or array of rank ...
This module contains procedures and generic interfaces for resizing allocatable arrays of various typ...
Warning
The condition allocated(array) must hold (the input array must be preallocated) when any or all of the optional input arguments lbc, lbcold, ubcold are present or when the size argument is missing.
The condition all(0_IK <= size) must hold for the corresponding input argument.
The condition all(lbound(array) <= lbcold .and. lbcold <= ubound(array)) must hold for the corresponding input arguments.
The condition all(lbound(array) <= ubcold .and. ubcold <= ubound(array)) must hold for the corresponding input arguments.
The condition all(lbound(array) <= lbc) must hold for the corresponding input arguments.
The condition all(lbc + ubcold - lbcold <= lbound(array) + size - 1) must hold for the corresponding input arguments (i.e., the upper bound(s) of contents cannot overflow the upper bound(s) of the new array).
The equality len(fill) == 1 must also hold if array is of zero rank (i.e., a scalar string).
The equality len(fill) <= len(array) must also hold if array is of non-zero rank.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
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.
Note
If the input array is unallocated, it will be allocated to the requested shape and filled entirely with fill, equivalent to allocate(array(@size), source = fill).
If the initialization of the new elements with fill is not necessary, use setResized to resize arrays without initialization.
While shrinking an array using this generic interface is pointless dues to the lack of the use of fill argument for any purpose, shrinking (without actually doing any refills) is allowed.
This behavior is quite useful for graceful handling of situations where the task (shrinking or expanding) is only determined at runtime or can change from one call to another.
Otherwise, use setResized to shrink arrays or resize arrays without initialization.
The sole purpose of this generic interface is to provide a convenient but fast method of resizing allocatable arrays without losing the contents of the array and refilling the new elements with requested fill.
Developer Remark:
An optional dummy argument stat (instead of failed) for the procedures of this generic interface are impossible as it creates ambiguous interfaces.
See also
setResized
setRebound
setRefilled
setRebilled
getCoreHalo
setCoreHalo
getCentered
setCentered
getPadded
setPadded


Example usage

1! Define an expansion procedure call macro to avoid duplications in the example source file. Check the output file for usage.
2#define REFILL_ARRAY \
3block; \
4 DECLARE; \
5 CONSTRUCT; \
6 call disp%show('array'); \
7 call disp%show( array , deliml = SK_"""" ); \
8 call disp%show('lbound(array)'); \
9 call disp%show( lbound(array) ); \
10 call disp%show('ubound(array)'); \
11 call disp%show( ubound(array) ); \
12 call disp%show('fill'); \
13 call disp%show( FILL , deliml = SK_"""" ); \
14 call disp%show('size'); \
15 call disp%show( SIZE ); \
16 call disp%show('call setRefilled(array, fill, size)'); \
17 call setRefilled(array, FILL, SIZE) ; \
18 call disp%show('array'); \
19 call disp%show( array , deliml = SK_"""" ); \
20 call disp%show('lbound(array)'); \
21 call disp%show( lbound(array) ); \
22 call disp%show('ubound(array)'); \
23 call disp%show( ubound(array) ); \
24end block;
25
26! Define an expansion with contents shifting procedure call macro to avoid duplications in the example source file. Check the output file for usage.
27#define REFILL_SHIFT_ARRAY \
28block; \
29 DECLARE; \
30 CONSTRUCT; \
31 call disp%show('array'); \
32 call disp%show( array , deliml = SK_"""" ); \
33 call disp%show('lbound(array)'); \
34 call disp%show( lbound(array) ); \
35 call disp%show('ubound(array)'); \
36 call disp%show( ubound(array) ); \
37 call disp%show('fill'); \
38 call disp%show( FILL , deliml = SK_"""" ); \
39 call disp%show('size'); \
40 call disp%show( SIZE ); \
41 call disp%show('lbc'); \
42 call disp%show( LBC ); \
43 call disp%show('call setRefilled(array, fill, size, lbc)'); \
44 call setRefilled(array, FILL, SIZE, LBC) ; \
45 call disp%show('array'); \
46 call disp%show( array , deliml = SK_"""" ); \
47 call disp%show('lbound(array)'); \
48 call disp%show( lbound(array) ); \
49 call disp%show('ubound(array)'); \
50 call disp%show( ubound(array) ); \
51end block;
52
53! Define an expansion/shrinkage with contents shifting and subsetting procedure call macro to avoid duplications in the example source file. Check the output file for usage.
54#define REFILL_SHIFT_SUBSET_ARRAY \
55block; \
56 DECLARE; \
57 CONSTRUCT; \
58 call disp%show('array'); \
59 call disp%show( array , deliml = SK_"""" ); \
60 call disp%show('lbound(array)'); \
61 call disp%show( lbound(array) ); \
62 call disp%show('ubound(array)'); \
63 call disp%show( ubound(array) ); \
64 call disp%show('fill'); \
65 call disp%show( FILL , deliml = SK_"""" ); \
66 call disp%show('size'); \
67 call disp%show( SIZE ); \
68 call disp%show('lbc'); \
69 call disp%show( LBC ); \
70 call disp%show('lbcold'); \
71 call disp%show( LBCOLD ); \
72 call disp%show('ubcold'); \
73 call disp%show( UBCOLD ); \
74 call disp%show('call setRefilled(array, fill, size, lbc, lbcold, ubcold)'); \
75 call setRefilled(array, FILL, SIZE, LBC, LBCOLD, UBCOLD) ; \
76 call disp%show('array'); \
77 call disp%show( array , deliml = SK_"""" ); \
78 call disp%show('lbound(array)'); \
79 call disp%show( lbound(array) ); \
80 call disp%show('ubound(array)'); \
81 call disp%show( ubound(array) ); \
82end block;
83
84program example
85
86 use pm_kind, only: SK, IK
87 use pm_kind, only: SKG => SK ! All kinds are supported.
88 use pm_kind, only: LKG => LK ! All kinds are supported.
89 use pm_kind, only: IKG => IK ! All kinds are supported.
90 use pm_kind, only: CKG => CK ! All kinds are supported.
91 use pm_kind, only: RKG => RK ! All kinds are supported.
92 use pm_io, only: display_type
94
95 implicit none
96
97 type(display_type) :: disp
98 disp = display_type(file = "main.out.F90")
99
100 call disp%skip()
101 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
102 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
103 call disp%show("! Expand an array with specific size.")
104 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
105 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
106 call disp%skip()
107
108 call disp%skip()
109 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%")
110 call disp%show("! Expand `character` vector.")
111 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%")
112 call disp%skip()
113
114#define SIZE 9_IK
115#define FILL SKG_"--"
116#define DECLARE character(2,SKG), allocatable :: array(:)
117#define CONSTRUCT allocate(array(3:8)); array(:) = ["AA", "BB", "CC", "DD", "EE", "FF"]
118REFILL_ARRAY
119
120 call disp%skip()
121 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
122 call disp%show("! Expand `integer` vector.")
123 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
124 call disp%skip()
125
126#define SIZE 9_IK
127#define FILL -3_IKG
128#define DECLARE integer(IKG), allocatable :: array(:)
129#define CONSTRUCT allocate(array(3:8)); array(:) = [1, 2, 3, 4, 5, 6]
130REFILL_ARRAY
131
132 call disp%skip()
133 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
134 call disp%show("! Expand `logical` vector.")
135 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
136 call disp%skip()
137
138#define SIZE 9_IK
139#define FILL .false._LKG
140#define DECLARE logical(LKG), allocatable :: array(:)
141#define CONSTRUCT allocate(array(3:8)); array(:) = [.true., .true., .true., .true., .true., .true.]
142REFILL_ARRAY
143
144 call disp%skip()
145 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
146 call disp%show("! Expand `complex` vector.")
147 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
148 call disp%skip()
149
150#define SIZE 9_IK
151#define FILL cmplx(-9.,-9.,CKG)
152#define DECLARE complex(CKG), allocatable :: array(:)
153#define CONSTRUCT allocate(array(3:8)); array(:) = [(1., -1.), (2., -2.), (3., -3.), (4., -4.), (5., -5.), (6., -6.)]
154REFILL_ARRAY
155
156 call disp%skip()
157 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%")
158 call disp%show("! Expand `real` vector.")
159 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%")
160 call disp%skip()
161
162#define SIZE 9_IK
163#define FILL -1._RKG
164#define DECLARE real(RKG), allocatable :: array(:)
165#define CONSTRUCT allocate(array(3:8)); array(:) = [1., 2., 3., 4., 5., 6.]
166REFILL_ARRAY
167
168 call disp%skip()
169 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%")
170 call disp%show("! Expand `character` matrix.")
171 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%")
172 call disp%skip()
173
174#define SIZE [9_IK, 9_IK]
175#define FILL SKG_"--"
176#define DECLARE character(2,SKG), allocatable :: array(:,:)
177#define CONSTRUCT allocate(array(2:3,3:5)); array(:,:) = reshape(["AA", "BB", "CC", "DD", "EE", "FF"], shape = shape(array), order = [2, 1])
178REFILL_ARRAY
179
180 call disp%skip()
181 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
182 call disp%show("! Expand `character` cube.")
183 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
184 call disp%skip()
185
186#define SIZE [9_IK, 9_IK, 3_IK]
187#define FILL SKG_"--"
188#define DECLARE character(2,SKG), allocatable :: array(:,:,:)
189#define CONSTRUCT allocate(array(2:3,3:5,2:2)); array(:,:,:) = reshape(["AA", "BB", "CC", "DD", "EE", "FF"], shape = shape(array), order = [3, 2, 1])
190REFILL_ARRAY
191
192 call disp%skip()
193 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
194 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
195 call disp%show("! Expand an array and shift its contents.")
196 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
197 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
198 call disp%skip()
199
200 call disp%skip()
201 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
202 call disp%show("! Expand and shift `character` vector.")
203 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
204 call disp%skip()
205
206#define SIZE 13_IK
207#define LBC 5_IK
208#define FILL SKG_"--"
209#define DECLARE character(2,SKG), allocatable :: array(:)
210#define CONSTRUCT allocate(array(3:8)); array(:) = ["AA", "BB", "CC", "DD", "EE", "FF"]
211REFILL_SHIFT_ARRAY
212
213 call disp%skip()
214 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
215 call disp%show("! Expand and shift `character` matrix.")
216 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
217 call disp%skip()
218
219#define SIZE [6_IK, 6_IK]
220#define LBC [4_IK, 4_IK]
221#define FILL SKG_"--"
222#define DECLARE character(2,SKG), allocatable :: array(:,:)
223#define CONSTRUCT allocate(array(2:3,3:5)); array(:,:) = reshape(["AA", "BB", "CC", "DD", "EE", "FF"], shape = shape(array), order = [2, 1])
224REFILL_SHIFT_ARRAY
225
226 call disp%skip()
227 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
228 call disp%show("! Expand and shift `character` cube.")
229 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
230 call disp%skip()
231
232#define SIZE [6_IK, 6_IK, 3_IK]
233#define LBC [3_IK, 4_IK, 2_IK]
234#define FILL SKG_"--"
235#define DECLARE character(2,SKG), allocatable :: array(:,:,:)
236#define CONSTRUCT allocate(array(1:2,1:3,1:1)); array(:,:,:) = reshape(["AA", "BB", "CC", "DD", "EE", "FF"], shape = shape(array), order = [3, 2, 1])
237REFILL_SHIFT_ARRAY
238
239 call disp%skip()
240 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
241 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
242 call disp%show("! Expand an array and shift a subset of its contents.")
243 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
244 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
245 call disp%skip()
246
247 call disp%skip()
248 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
249 call disp%show("! Expand and shift `character` vector.")
250 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
251 call disp%skip()
252
253#define SIZE 13_IK
254#define LBC 5_IK
255#define LBCOLD 5_IK
256#define UBCOLD 7_IK
257#define FILL SKG_"--"
258#define DECLARE character(2,SKG), allocatable :: array(:)
259#define CONSTRUCT allocate(array(3:8)); array(:) = ["AA", "BB", "CC", "DD", "EE", "FF"]
260REFILL_SHIFT_SUBSET_ARRAY
261
262 call disp%skip()
263 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
264 call disp%show("! Expand and shift `character` matrix.")
265 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
266 call disp%skip()
267
268#define SIZE [2_IK, 3_IK]
269#define LBC [2_IK, 4_IK]
270#define LBCOLD [2_IK, 4_IK]
271#define UBCOLD [3_IK, 5_IK]
272#define FILL SKG_"--"
273#define DECLARE character(2,SKG), allocatable :: array(:,:)
274#define CONSTRUCT allocate(array(2:3,3:5)); array(:,:) = reshape(["AA", "BB", "CC", "DD", "EE", "FF"], shape = shape(array), order = [2, 1])
275REFILL_SHIFT_SUBSET_ARRAY
276
277 call disp%skip()
278 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
279 call disp%show("! Expand and shift `character` cube.")
280 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
281 call disp%skip()
282
283#define SIZE [2_IK, 2_IK, 4_IK]
284#define LBC [1_IK, 1_IK, 3_IK]
285#define LBCOLD [1_IK, 2_IK, 2_IK]
286#define UBCOLD [2_IK, 3_IK, 2_IK]
287#define FILL SKG_"--"
288#define DECLARE character(2,SKG), allocatable :: array(:,:,:)
289#define CONSTRUCT allocate(array(1:2,1:3,1:2)); array(:,:,:) = reshape(["AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH", "II", "JJ", "KK", "LL"], shape = shape(array), order = [3, 2, 1])
290REFILL_SHIFT_SUBSET_ARRAY
291
292end 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
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
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 LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
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 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! Expand an array with specific size.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8
9!%%%%%%%%%%%%%%%%%%%%%%%%%%%
10! Expand `character` vector.
11!%%%%%%%%%%%%%%%%%%%%%%%%%%%
12
13array
14"AA", "BB", "CC", "DD", "EE", "FF"
15lbound(array)
16+3
17ubound(array)
18+8
19fill
20"--"
21size
22+9
23call setRefilled(array, fill, size)
24array
25"AA", "BB", "CC", "DD", "EE", "FF", "--", "--", "--"
26lbound(array)
27+3
28ubound(array)
29+11
30
31!%%%%%%%%%%%%%%%%%%%%%%%%%
32! Expand `integer` vector.
33!%%%%%%%%%%%%%%%%%%%%%%%%%
34
35array
36"+1", "+2", "+3", "+4", "+5", "+6"
37lbound(array)
38+3
39ubound(array)
40+8
41fill
42"-3"
43size
44+9
45call setRefilled(array, fill, size)
46array
47"+1", "+2", "+3", "+4", "+5", "+6", "-3", "-3", "-3"
48lbound(array)
49+3
50ubound(array)
51+11
52
53!%%%%%%%%%%%%%%%%%%%%%%%%%
54! Expand `logical` vector.
55!%%%%%%%%%%%%%%%%%%%%%%%%%
56
57array
58"T", "T", "T", "T", "T", "T"
59lbound(array)
60+3
61ubound(array)
62+8
63fill
64"F"
65size
66+9
67call setRefilled(array, fill, size)
68array
69"T", "T", "T", "T", "T", "T", "F", "F", "F"
70lbound(array)
71+3
72ubound(array)
73+11
74
75!%%%%%%%%%%%%%%%%%%%%%%%%%
76! Expand `complex` vector.
77!%%%%%%%%%%%%%%%%%%%%%%%%%
78
79array
80"+1.0000000000000000, -1.0000000000000000", "+2.0000000000000000, -2.0000000000000000", "+3.0000000000000000, -3.0000000000000000", "+4.0000000000000000, -4.0000000000000000", "+5.0000000000000000, -5.0000000000000000", "+6.0000000000000000, -6.0000000000000000"
81lbound(array)
82+3
83ubound(array)
84+8
85fill
86"-9.0000000000000000, -9.0000000000000000"
87size
88+9
89call setRefilled(array, fill, size)
90array
91"+1.0000000000000000, -1.0000000000000000", "+2.0000000000000000, -2.0000000000000000", "+3.0000000000000000, -3.0000000000000000", "+4.0000000000000000, -4.0000000000000000", "+5.0000000000000000, -5.0000000000000000", "+6.0000000000000000, -6.0000000000000000", "-9.0000000000000000, -9.0000000000000000", "-9.0000000000000000, -9.0000000000000000", "-9.0000000000000000, -9.0000000000000000"
92lbound(array)
93+3
94ubound(array)
95+11
96
97!%%%%%%%%%%%%%%%%%%%%%%
98! Expand `real` vector.
99!%%%%%%%%%%%%%%%%%%%%%%
100
101array
102"+1.0000000000000000", "+2.0000000000000000", "+3.0000000000000000", "+4.0000000000000000", "+5.0000000000000000", "+6.0000000000000000"
103lbound(array)
104+3
105ubound(array)
106+8
107fill
108"-1.0000000000000000"
109size
110+9
111call setRefilled(array, fill, size)
112array
113"+1.0000000000000000", "+2.0000000000000000", "+3.0000000000000000", "+4.0000000000000000", "+5.0000000000000000", "+6.0000000000000000", "-1.0000000000000000", "-1.0000000000000000", "-1.0000000000000000"
114lbound(array)
115+3
116ubound(array)
117+11
118
119!%%%%%%%%%%%%%%%%%%%%%%%%%%%
120! Expand `character` matrix.
121!%%%%%%%%%%%%%%%%%%%%%%%%%%%
122
123array
124"AA", "BB", "CC"
125"DD", "EE", "FF"
126lbound(array)
127+2, +3
128ubound(array)
129+3, +5
130fill
131"--"
132size
133+9, +9
134call setRefilled(array, fill, size)
135array
136"AA", "BB", "CC", "--", "--", "--", "--", "--", "--"
137"DD", "EE", "FF", "--", "--", "--", "--", "--", "--"
138"--", "--", "--", "--", "--", "--", "--", "--", "--"
139"--", "--", "--", "--", "--", "--", "--", "--", "--"
140"--", "--", "--", "--", "--", "--", "--", "--", "--"
141"--", "--", "--", "--", "--", "--", "--", "--", "--"
142"--", "--", "--", "--", "--", "--", "--", "--", "--"
143"--", "--", "--", "--", "--", "--", "--", "--", "--"
144"--", "--", "--", "--", "--", "--", "--", "--", "--"
145lbound(array)
146+2, +3
147ubound(array)
148+10, +11
149
150!%%%%%%%%%%%%%%%%%%%%%%%%%
151! Expand `character` cube.
152!%%%%%%%%%%%%%%%%%%%%%%%%%
153
154array
155slice(:,:,1) =
156"AA", "BB", "CC"
157"DD", "EE", "FF"
158lbound(array)
159+2, +3, +2
160ubound(array)
161+3, +5, +2
162fill
163"--"
164size
165+9, +9, +3
166call setRefilled(array, fill, size)
167array
168slice(:,:,1) =
169"AA", "BB", "CC", "--", "--", "--", "--", "--", "--"
170"DD", "EE", "FF", "--", "--", "--", "--", "--", "--"
171"--", "--", "--", "--", "--", "--", "--", "--", "--"
172"--", "--", "--", "--", "--", "--", "--", "--", "--"
173"--", "--", "--", "--", "--", "--", "--", "--", "--"
174"--", "--", "--", "--", "--", "--", "--", "--", "--"
175"--", "--", "--", "--", "--", "--", "--", "--", "--"
176"--", "--", "--", "--", "--", "--", "--", "--", "--"
177"--", "--", "--", "--", "--", "--", "--", "--", "--"
178slice(:,:,2) =
179"--", "--", "--", "--", "--", "--", "--", "--", "--"
180"--", "--", "--", "--", "--", "--", "--", "--", "--"
181"--", "--", "--", "--", "--", "--", "--", "--", "--"
182"--", "--", "--", "--", "--", "--", "--", "--", "--"
183"--", "--", "--", "--", "--", "--", "--", "--", "--"
184"--", "--", "--", "--", "--", "--", "--", "--", "--"
185"--", "--", "--", "--", "--", "--", "--", "--", "--"
186"--", "--", "--", "--", "--", "--", "--", "--", "--"
187"--", "--", "--", "--", "--", "--", "--", "--", "--"
188slice(:,:,3) =
189"--", "--", "--", "--", "--", "--", "--", "--", "--"
190"--", "--", "--", "--", "--", "--", "--", "--", "--"
191"--", "--", "--", "--", "--", "--", "--", "--", "--"
192"--", "--", "--", "--", "--", "--", "--", "--", "--"
193"--", "--", "--", "--", "--", "--", "--", "--", "--"
194"--", "--", "--", "--", "--", "--", "--", "--", "--"
195"--", "--", "--", "--", "--", "--", "--", "--", "--"
196"--", "--", "--", "--", "--", "--", "--", "--", "--"
197"--", "--", "--", "--", "--", "--", "--", "--", "--"
198lbound(array)
199+2, +3, +2
200ubound(array)
201+10, +11, +4
202
203!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205! Expand an array and shift its contents.
206!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208
209
210!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211! Expand and shift `character` vector.
212!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213
214array
215"AA", "BB", "CC", "DD", "EE", "FF"
216lbound(array)
217+3
218ubound(array)
219+8
220fill
221"--"
222size
223+13
224lbc
225+5
226call setRefilled(array, fill, size, lbc)
227array
228"--", "--", "AA", "BB", "CC", "DD", "EE", "FF", "--", "--", "--", "--", "--"
229lbound(array)
230+3
231ubound(array)
232+15
233
234!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235! Expand and shift `character` matrix.
236!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237
238array
239"AA", "BB", "CC"
240"DD", "EE", "FF"
241lbound(array)
242+2, +3
243ubound(array)
244+3, +5
245fill
246"--"
247size
248+6, +6
249lbc
250+4, +4
251call setRefilled(array, fill, size, lbc)
252array
253"--", "--", "--", "--", "--", "--"
254"--", "--", "--", "--", "--", "--"
255"--", "AA", "BB", "CC", "--", "--"
256"--", "DD", "EE", "FF", "--", "--"
257"--", "--", "--", "--", "--", "--"
258"--", "--", "--", "--", "--", "--"
259lbound(array)
260+2, +3
261ubound(array)
262+7, +8
263
264!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265! Expand and shift `character` cube.
266!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
267
268array
269slice(:,:,1) =
270"AA", "BB", "CC"
271"DD", "EE", "FF"
272lbound(array)
273+1, +1, +1
274ubound(array)
275+2, +3, +1
276fill
277"--"
278size
279+6, +6, +3
280lbc
281+3, +4, +2
282call setRefilled(array, fill, size, lbc)
283array
284slice(:,:,1) =
285"--", "--", "--", "--", "--", "--"
286"--", "--", "--", "--", "--", "--"
287"--", "--", "--", "--", "--", "--"
288"--", "--", "--", "--", "--", "--"
289"--", "--", "--", "--", "--", "--"
290"--", "--", "--", "--", "--", "--"
291slice(:,:,2) =
292"--", "--", "--", "--", "--", "--"
293"--", "--", "--", "--", "--", "--"
294"--", "--", "--", "AA", "BB", "CC"
295"--", "--", "--", "DD", "EE", "FF"
296"--", "--", "--", "--", "--", "--"
297"--", "--", "--", "--", "--", "--"
298slice(:,:,3) =
299"--", "--", "--", "--", "--", "--"
300"--", "--", "--", "--", "--", "--"
301"--", "--", "--", "--", "--", "--"
302"--", "--", "--", "--", "--", "--"
303"--", "--", "--", "--", "--", "--"
304"--", "--", "--", "--", "--", "--"
305lbound(array)
306+1, +1, +1
307ubound(array)
308+6, +6, +3
309
310!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312! Expand an array and shift a subset of its contents.
313!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
314!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315
316
317!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318! Expand and shift `character` vector.
319!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
320
321array
322"AA", "BB", "CC", "DD", "EE", "FF"
323lbound(array)
324+3
325ubound(array)
326+8
327fill
328"--"
329size
330+13
331lbc
332+5
333lbcold
334+5
335ubcold
336+7
337call setRefilled(array, fill, size, lbc, lbcold, ubcold)
338array
339"--", "--", "CC", "DD", "EE", "--", "--", "--", "--", "--", "--", "--", "--"
340lbound(array)
341+3
342ubound(array)
343+15
344
345!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346! Expand and shift `character` matrix.
347!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
348
349array
350"AA", "BB", "CC"
351"DD", "EE", "FF"
352lbound(array)
353+2, +3
354ubound(array)
355+3, +5
356fill
357"--"
358size
359+2, +3
360lbc
361+2, +4
362lbcold
363+2, +4
364ubcold
365+3, +5
366call setRefilled(array, fill, size, lbc, lbcold, ubcold)
367array
368"--", "BB", "CC"
369"--", "EE", "FF"
370lbound(array)
371+2, +3
372ubound(array)
373+3, +5
374
375!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
376! Expand and shift `character` cube.
377!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
378
379array
380slice(:,:,1) =
381"AA", "CC", "EE"
382"GG", "II", "KK"
383slice(:,:,2) =
384"BB", "DD", "FF"
385"HH", "JJ", "LL"
386lbound(array)
387+1, +1, +1
388ubound(array)
389+2, +3, +2
390fill
391"--"
392size
393+2, +2, +4
394lbc
395+1, +1, +3
396lbcold
397+1, +2, +2
398ubcold
399+2, +3, +2
400call setRefilled(array, fill, size, lbc, lbcold, ubcold)
401array
402slice(:,:,1) =
403"--", "--"
404"--", "--"
405slice(:,:,2) =
406"--", "--"
407"--", "--"
408slice(:,:,3) =
409"DD", "FF"
410"JJ", "LL"
411slice(:,:,4) =
412"--", "--"
413"--", "--"
414lbound(array)
415+1, +1, +1
416ubound(array)
417+2, +2, +4
418
Test:
test_pm_arrayRefill
Bug:

Status: Unresolved
Source: GNU Fortran Compiler gfortran version 10-12
Description: There is an annoying gfortran bug concerning allocation of allocatable arrays of strings with assumed length type parameter.
The typical compiler error message is around line 230: Error allocating 283223642230368 bytes: Cannot allocate memory.
This requires the allocation statement be explicit for character arrays of non-zero rank.
This makes the already complex code superbly more complex and messy.

Remedy (as of ParaMonte Library version 2.0.0): For now, the allocatable arrays of type character are allocated with explicit shape in the allocation statement.
This explicit allocation for character types must be removed and replaced with the generic allocation once the bug is resolved.
Todo:
Very Low Priority: This generic interface can be extended to arrays of higher ranks than currently supported.
Todo:
Normal Priority: This generic interface should be extended to arrays of container type as done in pm_arrayResize.


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 245 of file pm_arrayRefill.F90.


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