Utility to grow type(hex) arrays, it is a poor man implementation of a dynamic array insertion, a là std::vector (but with no preallocation and smart doubling...)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(hex), | intent(inout), | allocatable | :: | vec(:) | ||
type(hex), | intent(in) | :: | val |
pure subroutine hex_insert(vec,val) !! Utility to grow type(hex) arrays, it is a !! poor man implementation of a dynamic array !! insertion, a là std::vector (but with no !! preallocation and smart doubling...) type(hex),intent(inout),allocatable :: vec(:) type(hex),intent(in) :: val type(hex),allocatable :: tmp(:) integer :: len if(allocated(vec))then len = size(vec) allocate(tmp(len+1)) tmp(:len) = vec call move_alloc(tmp,vec) len = len + 1 else len = 1 allocate(vec(len)) end if ! Insert val at back vec(len) = val end subroutine hex_insert