fixing the dynamic array
truncate the array after the last valid entry and hence cut off the empty trailing empty entries store the array in the sorted order according to the sorted( ) array
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dyn_longarray_type) | :: | me |
subroutine sorttruncate_da_long(me)
!------------------------------------------------------------------------
type(dyn_longarray_type) :: me !< array to sorttruncate
!------------------------------------------------------------------------
type(dyn_longarray_type) :: tarray !< temporary array
integer :: ival
integer :: dpos
!------------------------------------------------------------------------
! allocate the temporary array
call init( me = tarray, length = me%nvals )
! copy the entries in a sorted fashion into the temporary array
do ival = 1, me%nvals
call append( me = tarray, val = me%val( me%sorted( ival )), &
& pos = dpos)
enddo
call destroy( me = me )
me = tarray
call destroy( me = tarray )
end subroutine sorttruncate_da_long