Poor man implementation of a dynamic array, a là std::vector (but without preallocation and smart doubling...)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xy_lattice), | intent(inout) | :: | vec | |||
type(xy_site), | intent(in) | :: | val |
pure subroutine push_back(vec,val) !! Poor man implementation of a dynamic !! array, a là std::vector (but without !! preallocation and smart doubling...) class(xy_lattice),intent(inout) :: vec type(xy_site),intent(in) :: val type(xy_site),allocatable :: tmp(:) integer :: len if (allocated(vec%site)) then len = size(vec%site) allocate(tmp(len+1)) tmp(:len) = vec%site call move_alloc(tmp,vec%site) len = len + 1 else len = 1 allocate(vec%site(len)) end if !PUSH val at the BACK vec%site(len) = val !Increade formal size vec%size = len end subroutine push_back