Returns only the unique elements of the vector (sorted in ascending order).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(:) | :: | vec |
a vector of integers |
|
integer, | intent(in) | :: | chunk_size |
chunk size for adding to arrays |
unique elements of ivec
function unique_real(vec,chunk_size) result(ivec_unique) implicit none real(wp),dimension(:),intent(in) :: vec !! a vector of integers integer,intent(in) :: chunk_size !! chunk size for adding to arrays real(wp),dimension(:),allocatable :: ivec_unique !! unique elements of `ivec` real(wp),dimension(size(vec)) :: ivec !! temp copy of vec integer :: i !! counter integer :: n !! number of unique elements ! first we sort it: ivec = vec ! make a copy call sort_ascending(ivec) ! add the first element: n = 1 ivec_unique = [ivec(1)] ! walk through array and get the unique ones: if (size(ivec)>1) then do i = 2, size(ivec) if (ivec(i)/=ivec(i-1)) then call expand_vector(ivec_unique,n,chunk_size,val=ivec(i)) end if end do call expand_vector(ivec_unique,n,chunk_size,finished=.true.) end if end function unique_real