find_header_index Function

private pure function find_header_index(this, header) result(index)

Type Bound

data_frame

Arguments

Type IntentOptional Attributes Name
class(data_frame), intent(in) :: this
character(len=*), intent(in) :: header

Return Value integer


Source Code

    pure function find_header_index(this, header) result(index)
        class(data_frame), intent(in) :: this
        character(len=*), intent(in) :: header
        integer :: index

        integer :: i
        character(len=:), allocatable :: trimmed_header

        if (.not. this % with_headers) error stop "data frame has no headers"

        trimmed_header = trim(adjustl(header))
        index = -1

        do i = 1, this % num_cols
            if (trim(adjustl(this % headers(i))) == trimmed_header) then
                index = i
                exit
            end if
        end do

        if (index == -1) error stop "header not found"
    end function find_header_index