df_copy Function

public function df_copy(df) result(new_df)

Create a deep copy of a data frame

Creates a new data frame with all columns and data copied from the source

@param[in] df The source data frame @return new_df New data frame that is a copy of the source

Arguments

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

Return Value type(data_frame)


Source Code

    function df_copy(df) result(new_df)
        type(data_frame), intent(in) :: df
        type(data_frame) :: new_df

        integer :: i
        type(column) :: col

        call new_df % new(df % get_max_char_len())

        do i = 1, df % ncols()
            col = df % get_data_col(i)

            select case (col % get_type())
            case (REAL_NUM)
                if (df % get_with_headers()) then
                    call df_append_real(new_df, col % getr(), df % header(i))
                else
                    call df_append_real(new_df, col % getr())
                end if
            case (INTEGER_NUM)
                if (df % get_with_headers()) then
                    call df_append_integer(new_df, col % geti(), df % header(i))
                else
                    call df_append_integer(new_df, col % geti())
                end if
            case (LOGICAL_NUM)
                if (df % get_with_headers()) then
                    call df_append_logical(new_df, col % getl(), df % header(i))
                else
                    call df_append_logical(new_df, col % getl())
                end if
            case (CHARACTER_NUM)
                if (df % get_with_headers()) then
                    call df_append_character(new_df, col % getch(), df % header(i))
                else
                    call df_append_character(new_df, col % getch())
                end if
            case (COMPLEX_NUM)
                if (df % get_with_headers()) then
                    call df_append_complex(new_df, col % getc(), df % header(i))
                else
                    call df_append_complex(new_df, col % getc())
                end if
            end select
        end do
    end function df_copy