Expand
Expand method expands a vector (if necessary) and add an element to it.
Calling example
CALL Expand(vec, n=0, chunk_size)
CALL Expand(vec, n, chunk_size, finished=.TRUE.)
Interface
- ܀ Interface
- ️܀ See example
- ↢
MODULE PURE SUBROUTINE Expand(vec, n, chunk_size, val, finished)
INTEGER(Int8| Int16 | Int32 | Int64) | REAL(Real32| Real64), ALLOCATABLE, INTENT(INOUT) :: vec(:)
INTEGER(I4B), INTENT(INOUT) :: n
!! counter for last element added to `vec`.
!! must be initialized to `size(vec)`
!! (or 0 if not allocated) before first call
INTEGER(I4B), INTENT(IN) :: chunk_size
!! allocate `vec` in blocks of this size (>0)
INTEGER(Int8| Int16 | Int32 | Int64) | REAL(Real32| Real64), OPTIONAL, INTENT(IN) :: val
!! the value to add to `vec`
LOGICAL(LGT), OPTIONAL, INTENT(IN) :: finished
!! set to true to return `vec`
!! as its correct size (`n`)
END SUBROUTINE Expand
program main
use easifemBase
implicit none
integer(I4B), allocatable :: aintvec(:)
integer(I4B) :: n, val
First call We set n = 0, as aintvec is not allocated.
val = 1
n = 0
CALL Expand(vec=aintvec, n=n, chunk_size=10_I4B, val=val, finished=.FALSE.)
CALL Display(aintvec, "aintvec = ")
CALL Display(n, "n = ")
CALL Display(size(aintvec), "size of aintvec = " )
results
n = 1
size of aintvec = 10
Let's finish.
val = 2
CALL Expand(vec=aintvec, n=n, chunk_size=10_I4B, val=val, finished=.TRUE.)
CALL Display(aintvec, "aintvec= ")
CALL Display(n, "n = ")
CALL Display(size(aintvec), "size of aintvec = " )
results
aintvec=
---------
1
2
n = 2
size of aintvec = 2
end program main