df_write_console Subroutine

public subroutine df_write_console(df, unit)

Display data frame in console

Prints the data frame in a formatted table to the console or specified unit. Includes headers (if present) and a separator line.

@param[in] df The data frame to display @param[in] unit Optional output unit (default: 6 for stdout)

Note

Column width is fixed at 12 characters

Arguments

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

Source Code

    subroutine df_write_console(df, unit)
        type(data_frame), intent(in) :: df
        integer, intent(in), optional :: unit

        integer :: out_unit, i, j, dtype, col_width
        integer :: num_cols, num_rows
        type(column) :: data_col
        logical :: has_headers

        if (present(unit)) then
            out_unit = unit
        else
            out_unit = 6  ! stdout
        end if

        num_cols = df % ncols()
        num_rows = df % nrows()
        has_headers = df % get_with_headers()

        if (num_cols == 0) then
            write (out_unit, '(a)') "Empty data frame"
            return
        end if

        col_width = 12  ! Fixed column width for formatting

        ! Write headers if present
        if (has_headers) then
            do i = 1, num_cols
                write (out_unit, '(a12)', advance='no') df % header(i)
            end do
            write (out_unit, '(a)') ''

            ! Write separator line
            do i = 1, num_cols
                write (out_unit, '(a12)', advance='no') repeat('-', col_width)
            end do
            write (out_unit, '(a)') ''
        end if

        ! Write data
        do j = 1, num_rows
            do i = 1, num_cols
                data_col = df % get_data_col(i)
                dtype = data_col % get_type()

                select case (dtype)
                case (REAL_NUM)
                    write (out_unit, '(g12.4)', advance='no') data_col % getr(j)
                case (INTEGER_NUM)
                    write (out_unit, '(i12)', advance='no') data_col % geti(j)
                case (LOGICAL_NUM)
                    if (data_col % getl(j)) then
                        write (out_unit, '(a12)', advance='no') 'T'
                    else
                        write (out_unit, '(a12)', advance='no') 'F'
                    end if
                case (CHARACTER_NUM)
                    write (out_unit, '(a12)', advance='no') data_col % getch(j)
                case (COMPLEX_NUM)
                    write (out_unit, '("(",f5.2,",",f5.2,")")', advance='no') data_col % getc(j)
                end select
            end do
            write (out_unit, '(a)') ''
        end do
    end subroutine df_write_console