subroutinepush
subroutine push(list, s)
Append s to list, allocating it if needed.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| list | type(string_t) | inout | allocatabledimension(:) | the list |
| s | character(len=*) | in | the string to append |
Source
Show the code
subroutine push(list, s)
type(string_t), allocatable, intent(inout) :: list(:) !! the list
character(len=*), intent(in) :: s !! the string to append
type(string_t), allocatable :: tmp(:)
integer :: n, k
n = 0
if (allocated(list)) n = size(list)
allocate (tmp(n + 1))
do k = 1, n
call move_alloc(list(k)%s, tmp(k)%s)
end do
tmp(n + 1)%s = s
call move_alloc(tmp, list)
end subroutine push