unique Function

public function unique(vec, chunk_size) result(ivec_unique)

Returns only the unique elements of the vector.

Arguments

Type IntentOptional Attributes Name
integer, intent(in), dimension(:) :: vec

a vector of integers

integer, intent(in) :: chunk_size

chunk size for adding to arrays

Return Value integer, dimension(:), allocatable

unique elements of ivec


Calls

proc~~unique~~CallsGraph proc~unique unique proc~expand_vector expand_vector proc~unique->proc~expand_vector proc~sort_ascending sort_ascending proc~unique->proc~sort_ascending proc~swap swap proc~sort_ascending->proc~swap

Called by

proc~~unique~~CalledByGraph proc~unique unique proc~read_csv_file csv_file%read_csv_file proc~read_csv_file->proc~unique

Source Code

    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