expand_vector_real Subroutine

private pure subroutine expand_vector_real(vec, n, chunk_size, val, finished)

Add elements to the real vector in chunks.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(inout), dimension(:), allocatable :: vec
integer, 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, intent(in) :: chunk_size

allocate vec in blocks of this size (>0)

real(kind=wp), intent(in), optional :: val

the value to add to vec

logical, intent(in), optional :: finished

set to true to return vec as its correct size (n)


Called by

proc~~expand_vector_real~~CalledByGraph proc~expand_vector_real numdiff_utilities_module::expand_vector_real interface~expand_vector numdiff_utilities_module::expand_vector interface~expand_vector->proc~expand_vector_real proc~compute_sparsity_random numerical_differentiation_module::compute_sparsity_random proc~compute_sparsity_random->interface~expand_vector proc~resize_sparsity_vectors numerical_differentiation_module::numdiff_type%resize_sparsity_vectors proc~compute_sparsity_random->proc~resize_sparsity_vectors proc~compute_sparsity_random_2 numerical_differentiation_module::compute_sparsity_random_2 proc~compute_sparsity_random_2->interface~expand_vector proc~compute_sparsity_random_2->proc~resize_sparsity_vectors proc~divide_interval numdiff_utilities_module::divide_interval proc~compute_sparsity_random_2->proc~divide_interval proc~resize_sparsity_vectors->interface~expand_vector proc~unique_int numdiff_utilities_module::unique_int proc~unique_int->interface~expand_vector proc~unique_real numdiff_utilities_module::unique_real proc~unique_real->interface~expand_vector interface~unique numdiff_utilities_module::unique interface~unique->proc~unique_int interface~unique->proc~unique_real proc~divide_interval->interface~unique proc~put_in_cache numdiff_cache_module::function_cache%put_in_cache proc~put_in_cache->interface~unique proc~compute_function_with_cache numerical_differentiation_module::compute_function_with_cache proc~compute_function_with_cache->proc~put_in_cache

Source Code

    pure subroutine expand_vector_real(vec,n,chunk_size,val,finished)

    implicit none

    real(wp),dimension(:),allocatable,intent(inout) :: vec
    integer,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,intent(in)          :: chunk_size  !! allocate `vec` in blocks of this size (>0)
    real(wp),intent(in),optional :: val        !! the value to add to `vec`
    logical,intent(in),optional :: finished    !! set to true to return `vec`
                                               !! as its correct size (`n`)

    real(wp),dimension(:),allocatable :: tmp  !! temporary array

    if (present(val)) then
        if (allocated(vec)) then
            if (n==size(vec)) then
                ! have to add another chunk:
                allocate(tmp(size(vec)+chunk_size))
                tmp(1:size(vec)) = vec
                call move_alloc(tmp,vec)
            end if
            n = n + 1
        else
            ! the first element:
            allocate(vec(chunk_size))
            n = 1
        end if
        vec(n) = val
    end if

    if (present(finished)) then
        if (finished) then
            ! set vec to actual size (n):
            if (allocated(tmp)) deallocate(tmp)
            allocate(tmp(n))
            tmp = vec(1:n)
            call move_alloc(tmp,vec)
        end if
    end if

    end subroutine expand_vector_real