df_unique_character Function

public function df_unique_character(df, col_index) result(unique_vals)

Get unique values from a character column

Returns array of unique values from the specified character column

@param[in] df The data frame instance @param[in] col_index Column index (1-based) @return Array of unique values (unsorted)

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
integer, intent(in) :: col_index

Return Value character(len=:), allocatable, (:)


Source Code

    function df_unique_character(df, col_index) result(unique_vals)
        type(data_frame), intent(in) :: df
        integer, intent(in) :: col_index
        character(len=:), allocatable :: unique_vals(:)

        character(len=:), allocatable :: col(:), temp_unique(:)
        integer :: i, j, n_unique
        logical :: is_unique

        col = df_get_col_character(df, col_index)
        allocate (character(len=len(col)) :: temp_unique(size(col)))
        n_unique = 0

        do i = 1, size(col)
            is_unique = .true.
            do j = 1, n_unique
                if (trim(col(i)) == trim(temp_unique(j))) then
                    is_unique = .false.
                    exit
                end if
            end do
            if (is_unique) then
                n_unique = n_unique + 1
                temp_unique(n_unique) = col(i)
            end if
        end do

        allocate (character(len=len(col)) :: unique_vals(n_unique))
        unique_vals = temp_unique(1:n_unique)

        deallocate (temp_unique)
    end function df_unique_character