resize_storage Subroutine

private subroutine resize_storage(this)

Type Bound

data_frame

Arguments

Type IntentOptional Attributes Name
class(data_frame), intent(inout) :: this

Source Code

    subroutine resize_storage(this)
        class(data_frame), intent(inout) :: this

        type(column), dimension(:), allocatable :: temp_cols
        character(len=:), dimension(:), allocatable :: temp_headers
        integer :: new_size, i

        new_size = this % num_cols + 1

        ! Resize columns array
        if (allocated(this % data_cols)) then
            allocate (temp_cols(size(this % data_cols)))
            do i = 1, size(this % data_cols)
                temp_cols(i) = this % data_cols(i)
            end do
            deallocate (this % data_cols)
        end if

        allocate (this % data_cols(new_size))

        if (allocated(temp_cols)) then
            do i = 1, size(temp_cols)
                this % data_cols(i) = temp_cols(i)
            end do
            deallocate (temp_cols)
        end if

        ! Resize headers array if needed
        if (this % with_headers) then
            if (allocated(this % headers)) then
                allocate (character(len=this % max_char_len) :: temp_headers(size(this % headers)))
                temp_headers = this % headers
                deallocate (this % headers)
            end if

            allocate (character(len=this % max_char_len) :: this % headers(new_size))

            if (allocated(temp_headers)) then
                this % headers(1:size(temp_headers)) = temp_headers
                deallocate (temp_headers)
            end if
        end if
    end subroutine resize_storage