init_da_int Subroutine

public subroutine init_da_int(me, length)

initialization of a dynamic array

before a dynamic array can be used, it has to be initialized with this routine. the initial length provided here, can avoid reallocations and memory copying, if approximated correctly enough. if none is specified, the provided container initially will be of size 0.

Arguments

Type IntentOptional Attributes Name
type(dyn_intarray_type), intent(out) :: me
integer, intent(in), optional :: length

Called by

proc~~init_da_int~~CalledByGraph proc~init_da_int init_da_int interface~init~7 init interface~init~7->proc~init_da_int

Contents

Source Code


Source Code

  subroutine init_da_int(me, length)
    !-----------------------------------------------------------------
    type(dyn_intarray_type), intent(out) :: me !< dynamic array to init
    integer, intent(in), optional :: length !< initial length of the container
    !-----------------------------------------------------------------

    if (present(length)) then
      me%containersize = length
    else
      me%containersize = zerolength
    end if

    ! deallocate ...
    if( allocated( me%val ) ) deallocate(me%val)
    if( allocated( me%sorted ) ) deallocate(me%sorted)
    ! ... and reallocate
    allocate(me%val(me%containersize))
    allocate(me%sorted(me%containersize))
    me%nvals = 0

  end subroutine init_da_int