df_insert_column_complex Subroutine

public subroutine df_insert_column_complex(df, data, position, header)

Insert a complex column at a specific position

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(inout) :: df
complex(kind=rk), intent(in), dimension(:) :: data
integer, intent(in) :: position
character(len=*), intent(in), optional :: header

Source Code

    subroutine df_insert_column_complex(df, data, position, header)
        type(data_frame), intent(inout) :: df
        complex(rk), dimension(:), intent(in) :: data
        integer, intent(in) :: position
        character(len=*), intent(in), optional :: header

        type(data_frame) :: temp_df
        integer :: i, original_cols

        if (position < 1 .or. position > df % ncols() + 1) error stop "invalid insertion position"
        if (df % nrows() > 0 .and. size(data) /= df % nrows()) error stop "data size must match number of rows"

        original_cols = df % ncols()
        call temp_df % new(df % get_max_char_len())

        do i = 1, position - 1
            call copy_column_to_df(df, i, temp_df)
        end do

        if (present(header)) then
            call df_append_complex(temp_df, data, header)
        else
            call df_append_complex(temp_df, data)
        end if

        do i = position, original_cols
            call copy_column_to_df(df, i, temp_df)
        end do

        call df % destroy()
        df = temp_df
    end subroutine df_insert_column_complex