public function pad(s, width) result(padded)
function to pad a string with a certain number of characters for nice printing
Arguments
Type |
Intent | Optional | Attributes |
|
Name |
|
character(len=*),
|
intent(in) |
|
|
:: |
s |
|
integer(kind=default_int),
|
intent(in) |
|
|
:: |
width |
|
Return Value
character(len=:), allocatable
Variables
Type |
Visibility | Attributes |
|
Name |
| Initial | |
integer(kind=default_int),
|
private |
|
:: |
len_s |
|
|
|
Source Code
function pad(s, width) result(padded)
!! function to pad a string with a certain number of characters for nice printing
character(len=*), intent(in) :: s
integer(default_int), intent(in) :: width
character(len=:), allocatable :: padded
integer(default_int) :: len_s
len_s = len_trim(s)
if (len_s >= width) then
padded = s(1:width)
else
padded = repeat(" ", width - len_s)//s
end if
end function pad