unique32 Function

private function unique32(vec) result(vec_unique)

Return only the unique values from vec.

Arguments

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

Return Value integer, dimension(:), allocatable


Calls

proc~~unique32~~CallsGraph proc~unique32 unique32 interface~sort sort proc~unique32->interface~sort proc~sort_ascending sort_ascending interface~sort->proc~sort_ascending proc~sort_ascending_64 sort_ascending_64 interface~sort->proc~sort_ascending_64 interface~swap swap proc~sort_ascending->interface~swap proc~swap64 swap64 proc~sort_ascending_64->proc~swap64 interface~swap->proc~swap64 proc~swap32 swap32 interface~swap->proc~swap32 proc~swap_str swap_str interface~swap->proc~swap_str

Called by

proc~~unique32~~CalledByGraph proc~unique32 unique32 interface~unique unique interface~unique->proc~unique32

Source Code

    function unique32(vec) result(vec_unique)

        integer,dimension(:),intent(in) :: vec
        integer,dimension(:),allocatable :: vec_unique

        integer :: i,num
        logical,dimension(size(vec)) :: mask

        mask = .false.

        do i=1,size(vec)

            !count the number of occurrences of this element:
            num = count( vec(i)==vec )

            if (num==1) then
                !there is only one, flag it:
                mask(i) = .true.
            else
                !flag this value only if it hasn't already been flagged:
                if (.not. any(vec(i)==vec .and. mask) ) mask(i) = .true.
            end if

        end do

        !return only flagged elements:
        allocate( vec_unique(count(mask)) )
        vec_unique = pack( vec, mask )

        ! also sort it:
        call sort(vec_unique)

    end function unique32