validate_column_addition Subroutine

private subroutine validate_column_addition(this, header, col_size)

Type Bound

data_frame

Arguments

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

Source Code

    subroutine validate_column_addition(this, header, col_size)
        class(data_frame), intent(inout) :: this
        character(len=*), intent(in), optional :: header
        integer, intent(in) :: col_size

        ! Check row size consistency
        if (this % num_cols > 0 .and. col_size /= this % nrows()) then
            error stop "column size must match existing columns"
        end if

        ! Handle headers
        if (present(header)) then
            if (this % num_cols == 0) then
                this % with_headers = .true.
                allocate (character(len=this % max_char_len) :: this % headers(0))
            else if (.not. this % with_headers) then
                error stop "cannot add header to data frame without headers"
            end if

            if (this % already_header(header)) then
                error stop "header already exists"
            end if
        else
            if (this % with_headers) then
                error stop "cannot add column without header to data frame with headers"
            end if
        end if
    end subroutine validate_column_addition