Changes the size of an array of Lagrangian objects. To avoid excessive reallocating, the object array will be reallocated only if the new size is (1+RESIZE_INCREMENT) larger or (1-RESIZE_INCREMENT) smaller than previous size. When the size change does not justify reallocating, the excess objects at the end tail of the object array will be marked as inactive with a large negative ID.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(lagrangian_set), | intent(inout) | :: | this |
A set of Lagrangian objects |
||
| integer, | intent(in) | :: | n |
New target size |
pure subroutine lagrangian_set_Resize(this,n) !> Changes the size of an array of Lagrangian objects. ! To avoid excessive reallocating, the object array will ! be reallocated only if the new size is (1+RESIZE_INCREMENT) ! larger or (1-RESIZE_INCREMENT) smaller than previous size. ! When the size change does not justify reallocating, the ! excess objects at the end tail of the object array will ! be marked as inactive with a large negative ID. implicit none class(lagrangian_set), intent(inout) :: this !! A set of Lagrangian objects integer, intent(in) :: n !! New target size ! Work variables class(lagrangian_obj), & allocatable :: lagrangian_array(:) integer :: size_old integer :: size_new integer :: i ! Resize array to size n if (.not.allocated(this%p)) then ! the array is of size 0 if (n.ne.0) then allocate(this%p(n),source=this%sample) this%p(1:n)%id=-huge(int(0,leapI8)) end if else if (n.eq.0) then ! the array is allocated, but we want to empty it deallocate(this%p) else ! Update non zero size to another non zero size size_old = size(this%p) if (n.gt.size_old) then ! Increase from size_old to size_new size_new = max(n,int(size_old*(1+RESIZE_INCREMENT))) ! Allocate temporary array allocate(lagrangian_array(size_new),source=this%sample) ! Store values do i=1,size_old lagrangian_array(i)=this%p(i) end do ! Move the allocation from the ! temporary array to the final one call move_alloc(lagrangian_array,this%p) this%p(size_old+1:size_new)%id=-huge(int(0,leapI8)) else if (n.lt.size_old*(1-RESIZE_INCREMENT)) then ! Decrease from size_old to size_new ! Allocate temporary array allocate(lagrangian_array(n),source=this%sample) ! Store values do i=1,n lagrangian_array(i)=this%p(i) end do ! Move the allocation from the ! temporary array to the final one call move_alloc(lagrangian_array,this%p) end if end if ! Update count info this%count_=n return end subroutine lagrangian_set_Resize