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

Generate a resized copy of the input array by padding it to the left with the requested paddings and optionally adding margins to the left of the padded array optionally filled with the corresponding fills. More...

Detailed Description

Generate a resized copy of the input array by padding it to the left with the requested paddings and optionally adding margins to the left of the padded array optionally filled with the corresponding fills.

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), or
  • type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64), or
  • type logical of kind any supported by the processor (e.g., LK), 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).
If the lmsize input argument is missing, then the size of the output arrayPadded is lenArray + lpsize, otherwise the length of the output arrayPadded is lenArray + lmsize + lpsize.
[in]lpsize: The input scalar of type integer of default kind IK representing the number of lpfill to add to the left of the array.
[in]lpfill: The input scalar of the same type and kind as the input array containing the value to fill the left padding (if any) of the output arrayPadded. If array is of type character, then
  1. the equality len(lpfill) == 1 must also hold if array is a scalar string.
  2. the equality len(lpfill) == len(array) must also hold if array is an array of strings.
[in]lmsize: The input scalar integer of default kind IK representing the size of the left-margin of the output arrayPadded
(optional, default = 0).
[in]lmfill: The input scalar of the same type and kind as the input array containing the value to fill the left margin (if any) of newly allocated array. If array is of type character, then
  1. the equality len(fill) == 1 must also hold if array is a scalar string.
  2. the equality len(fill) == len(array) must also hold if array is an array of strings.
(optional, if missing, the left-margin will remain uninitialized. It can be present only if lmsize is also present).
Returns
arrayPadded : The output object of the same type, kind, and rank as the input array with the same lower bound, whose size is lenArray + lpsize + lmsize, whose contents are the same as the contents of array but padded to the left, optionally with the specified left margin.


Possible calling interfaces

arrayPadded = getPaddedl(array, lpsize, lpfill)
arrayPadded = getPaddedl(array, lpsize, lpfill, lmsize, lmfill = lmfill)
Generate a resized copy of the input array by padding it to the left with the requested paddings and ...
This module contains procedures and generic interfaces for resizing an input array and padding them w...
Definition: pm_arrayPad.F90:30
Warning
The left margin elements will not be initialized to any particular values unless the corresponding lmfill argument is present.
The input lpsize and lmsize arguments must be non-negative input arguments.
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.
See also
setResized
setRebound
setRefilled
setRebilled
getCoreHalo
setCoreHalo
getCentered
setCentered
getPadded
setPadded


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
9 use pm_arrayPad, only: getPaddedl
10
11 implicit none
12
13 character(:, SK), allocatable :: string_SK
14 character(2, SK), allocatable :: Array_SK(:) ! Can be any processor-supported kind.
15 logical(LK) , allocatable :: Array_LK(:) ! Can be any processor-supported kind.
16 integer(IK) , allocatable :: Array_IK(:) ! Can be any processor-supported kind.
17 complex(CK) , allocatable :: Array_CK(:) ! Can be any processor-supported kind.
18 real(RK) , allocatable :: Array_RK(:) ! Can be any processor-supported kind.
19
20 type(display_type) :: disp
21
22 disp = display_type(file = "main.out.F90")
23
24 call disp%skip()
25 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
26 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
27 call disp%show("! Pad an array to the left with symbols.")
28 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
29 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
30 call disp%skip()
31
32 call reset()
33
34 allocate(Array_SK(3:8), source = [SK_"AA", SK_"BB", SK_"CC", SK_"DD", SK_"EE", SK_"FF"])
35 allocate(Array_IK(3:8), source = [1_IK, 2_IK, 3_IK, 4_IK, 5_IK, 6_IK])
36 allocate(Array_RK(3:8), source = [1._RK, 2._RK, 3._RK, 4._RK, 5._RK, 6._RK])
37 allocate(Array_CK(3:8), source = [(1._CK, -1._CK), (2._CK, -2._CK), (3._CK, -3._CK), (4._CK, -4._CK), (5._CK, -5._CK), (6._CK, -6._CK)])
38 allocate(Array_LK(3:8), source = [.true._LK, .true._LK, .true._LK, .true._LK, .true._LK, .true._LK])
39
40 call disp%skip()
41 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%")
42 call disp%show("! Pad a character scalar.")
43 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%")
44 call disp%skip()
45
46 string_SK = SK_"In God We Trust"
47 call disp%show("string_SK")
48 call disp%show( string_SK, deliml = SK_"""" )
49 call disp%show("len(string_SK)")
50 call disp%show( len(string_SK) )
51 call disp%show("string_SK = getPaddedl(string_SK, lpsize = 5_IK, lpfill = SK_'-')")
52 string_SK = getPaddedl(string_SK, lpsize = 5_IK, lpfill = SK_'-')
53 call disp%show("string_SK")
54 call disp%show( string_SK, deliml = SK_"""" )
55 call disp%show("len(string_SK)")
56 call disp%show( len(string_SK) )
57 call disp%skip()
58
59 string_SK = SK_"In Science We Invest"
60 call disp%show("string_SK")
61 call disp%show( string_SK, deliml = SK_"""" )
62 call disp%show("len(string_SK)")
63 call disp%show( len(string_SK) )
64 call disp%show("string_SK = getPaddedl(string_SK, lpsize = 4_IK, lpfill = SK_' ', lmsize = 4_IK, lmfill = SK_'*')")
65 string_SK = getPaddedl(string_SK, lpsize = 4_IK, lpfill = SK_' ', lmsize = 4_IK, lmfill = SK_'*')
66 call disp%show("string_SK")
67 call disp%show( string_SK, deliml = SK_"""" )
68 call disp%show("len(string_SK)")
69 call disp%show( len(string_SK) )
70
71 call disp%skip()
72 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%")
73 call disp%show("! Pad a character array.")
74 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%")
75 call disp%skip()
76
77 call disp%show("Array_SK")
78 call disp%show( Array_SK, deliml = SK_"""" )
79 call disp%show("lbound(Array_SK), ubound(Array_SK)")
80 call disp%show([lbound(Array_SK), ubound(Array_SK)])
81 call disp%show("Array_SK = getPaddedl(Array_SK, lpsize = 5_IK, lpfill = SK_' ')")
82 Array_SK = getPaddedl(Array_SK, lpsize = 5_IK, lpfill = SK_' ')
83 call disp%show("Array_SK")
84 call disp%show( Array_SK, deliml = SK_"""" )
85 call disp%show("lbound(Array_SK), ubound(Array_SK)")
86 call disp%show([lbound(Array_SK), ubound(Array_SK)])
87
88 call disp%skip()
89 call disp%show("!%%%%%%%%%%%%%%%%%%%%%")
90 call disp%show("! Pad a logical array.")
91 call disp%show("!%%%%%%%%%%%%%%%%%%%%%")
92 call disp%skip()
93
94 call disp%show("Array_LK")
95 call disp%show( Array_LK )
96 call disp%show("lbound(Array_LK), ubound(Array_LK)")
97 call disp%show([lbound(Array_LK), ubound(Array_LK)])
98 call disp%show("Array_LK = getPaddedl(Array_LK, lpsize = 5_IK, lpfill = .false._LK)")
99 Array_LK = getPaddedl(Array_LK, lpsize = 5_IK, lpfill = .false._LK)
100 call disp%show("Array_LK")
101 call disp%show( Array_LK )
102 call disp%show("lbound(Array_LK), ubound(Array_LK)")
103 call disp%show([lbound(Array_LK), ubound(Array_LK)])
104
105 call disp%skip()
106 call disp%show("!%%%%%%%%%%%%%%%%%%%%%")
107 call disp%show("! Pad an integer array.")
108 call disp%show("!%%%%%%%%%%%%%%%%%%%%%")
109 call disp%skip()
110
111 call disp%show("Array_IK")
112 call disp%show( Array_IK )
113 call disp%show("lbound(Array_IK), ubound(Array_IK)")
114 call disp%show([lbound(Array_IK), ubound(Array_IK)])
115 call disp%show("Array_IK = getPaddedl(Array_IK, lpsize = 5_IK, lpfill = -0_IK)")
116 Array_IK = getPaddedl(Array_IK, lpsize = 5_IK, lpfill = -0_IK)
117 call disp%show("Array_IK")
118 call disp%show( Array_IK )
119 call disp%show("lbound(Array_IK), ubound(Array_IK)")
120 call disp%show([lbound(Array_IK), ubound(Array_IK)])
121
122 call disp%skip()
123 call disp%show("!%%%%%%%%%%%%%%%%%%%%%")
124 call disp%show("! Pad a complex array.")
125 call disp%show("!%%%%%%%%%%%%%%%%%%%%%")
126 call disp%skip()
127
128 call disp%show("Array_CK")
129 call disp%show( Array_CK )
130 call disp%show("lbound(Array_CK), ubound(Array_CK)")
131 call disp%show([lbound(Array_CK), ubound(Array_CK)])
132 call disp%show("Array_CK = getPaddedl(Array_CK, lpsize = 5_IK, lpfill = (-999._CK,-999._CK))")
133 Array_CK = getPaddedl(Array_CK, lpsize = 5_IK, lpfill = (-999._CK,-999._CK))
134 call disp%show("Array_CK")
135 call disp%show( Array_CK )
136 call disp%show("lbound(Array_CK), ubound(Array_CK)")
137 call disp%show([lbound(Array_CK), ubound(Array_CK)])
138
139 call disp%skip()
140 call disp%show("!%%%%%%%%%%%%%%%%%%")
141 call disp%show("! Pad a real array.")
142 call disp%show("!%%%%%%%%%%%%%%%%%%")
143 call disp%skip()
144
145 call disp%show("Array_RK")
146 call disp%show( Array_RK )
147 call disp%show("lbound(Array_RK), ubound(Array_RK)")
148 call disp%show([lbound(Array_RK), ubound(Array_RK)])
149 call disp%show("Array_RK = getPaddedl(Array_RK, lpsize = 5_IK, lpfill = -0._RK)")
150 Array_RK = getPaddedl(Array_RK, lpsize = 5_IK, lpfill = -0._RK)
151 call disp%show("Array_RK")
152 call disp%show( Array_RK )
153 call disp%show("lbound(Array_RK), ubound(Array_RK)")
154 call disp%show([lbound(Array_RK), ubound(Array_RK)])
155
156contains
157
158 subroutine reset()
159 if (allocated(Array_SK)) deallocate(Array_SK)
160 if (allocated(Array_IK)) deallocate(Array_IK)
161 if (allocated(Array_RK)) deallocate(Array_RK)
162 if (allocated(Array_CK)) deallocate(Array_CK)
163 if (allocated(Array_LK)) deallocate(Array_LK)
164 end subroutine
165
166end 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! Pad an array to the left with symbols.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8
9!%%%%%%%%%%%%%%%%%%%%%%%%
10! Pad a character scalar.
11!%%%%%%%%%%%%%%%%%%%%%%%%
12
13string_SK
14"In God We Trust"
15len(string_SK)
16+15
17string_SK = getPaddedl(string_SK, lpsize = 5_IK, lpfill = SK_'-')
18string_SK
19"-----In God We Trust"
20len(string_SK)
21+20
22
23string_SK
24"In Science We Invest"
25len(string_SK)
26+20
27string_SK = getPaddedl(string_SK, lpsize = 4_IK, lpfill = SK_' ', lmsize = 4_IK, lmfill = SK_'*')
28string_SK
29"**** In Science We Invest"
30len(string_SK)
31+28
32
33!%%%%%%%%%%%%%%%%%%%%%%%
34! Pad a character array.
35!%%%%%%%%%%%%%%%%%%%%%%%
36
37Array_SK
38"AA", "BB", "CC", "DD", "EE", "FF"
39lbound(Array_SK), ubound(Array_SK)
40+3, +8
41Array_SK = getPaddedl(Array_SK, lpsize = 5_IK, lpfill = SK_' ')
42Array_SK
43" ", " ", " ", " ", " ", "AA", "BB", "CC", "DD", "EE", "FF"
44lbound(Array_SK), ubound(Array_SK)
45+1, +11
46
47!%%%%%%%%%%%%%%%%%%%%%
48! Pad a logical array.
49!%%%%%%%%%%%%%%%%%%%%%
50
51Array_LK
52T, T, T, T, T, T
53lbound(Array_LK), ubound(Array_LK)
54+3, +8
55Array_LK = getPaddedl(Array_LK, lpsize = 5_IK, lpfill = .false._LK)
56Array_LK
57F, F, F, F, F, T, T, T, T, T, T
58lbound(Array_LK), ubound(Array_LK)
59+1, +11
60
61!%%%%%%%%%%%%%%%%%%%%%
62! Pad an integer array.
63!%%%%%%%%%%%%%%%%%%%%%
64
65Array_IK
66+1, +2, +3, +4, +5, +6
67lbound(Array_IK), ubound(Array_IK)
68+3, +8
69Array_IK = getPaddedl(Array_IK, lpsize = 5_IK, lpfill = -0_IK)
70Array_IK
71+0, +0, +0, +0, +0, +1, +2, +3, +4, +5, +6
72lbound(Array_IK), ubound(Array_IK)
73+1, +11
74
75!%%%%%%%%%%%%%%%%%%%%%
76! Pad a complex array.
77!%%%%%%%%%%%%%%%%%%%%%
78
79Array_CK
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_CK), ubound(Array_CK)
82+3, +8
83Array_CK = getPaddedl(Array_CK, lpsize = 5_IK, lpfill = (-999._CK,-999._CK))
84Array_CK
85(-999.00000000000000, -999.00000000000000), (-999.00000000000000, -999.00000000000000), (-999.00000000000000, -999.00000000000000), (-999.00000000000000, -999.00000000000000), (-999.00000000000000, -999.00000000000000), (+1.0000000000000000, -1.0000000000000000), (+2.0000000000000000, -2.0000000000000000), (+3.0000000000000000, -3.0000000000000000), (+4.0000000000000000, -4.0000000000000000), (+5.0000000000000000, -5.0000000000000000), (+6.0000000000000000, -6.0000000000000000)
86lbound(Array_CK), ubound(Array_CK)
87+1, +11
88
89!%%%%%%%%%%%%%%%%%%
90! Pad a real array.
91!%%%%%%%%%%%%%%%%%%
92
93Array_RK
94+1.0000000000000000, +2.0000000000000000, +3.0000000000000000, +4.0000000000000000, +5.0000000000000000, +6.0000000000000000
95lbound(Array_RK), ubound(Array_RK)
96+3, +8
97Array_RK = getPaddedl(Array_RK, lpsize = 5_IK, lpfill = -0._RK)
98Array_RK
99-0.0000000000000000, -0.0000000000000000, -0.0000000000000000, -0.0000000000000000, -0.0000000000000000, +1.0000000000000000, +2.0000000000000000, +3.0000000000000000, +4.0000000000000000, +5.0000000000000000, +6.0000000000000000
100lbound(Array_RK), ubound(Array_RK)
101+1, +11
102
Test:
test_pm_arrayPad
Todo:
Normal Priority: Two new optional input scalar lbcold and ubcold arguments can be added to procedures to specify a subset of the contents of the original array that has to be kept in the newly allocated padded array.


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 2063 of file pm_arrayPad.F90.


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