Returns only the unique elements of the vector.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | 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(vec,chunk_size) result(ivec_unique) implicit none integer,dimension(:),intent(in) :: vec !! a vector of integers integer,intent(in) :: chunk_size !! chunk size for adding to arrays integer,dimension(:),allocatable :: ivec_unique !! unique elements of `ivec` integer,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