init_da_long Subroutine

public subroutine init_da_long(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_longarray_type), intent(out) :: me
integer, intent(in), optional :: length

Called by

proc~~init_da_long~~CalledByGraph proc~init_da_long init_da_long interface~init~26 init interface~init~26->proc~init_da_long

Source Code

  subroutine init_da_long(me, length)
    !-----------------------------------------------------------------
    type(dyn_longarray_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_long