resize_ilut_list Subroutine

private subroutine resize_ilut_list(list, oldSize, newSize)

Arguments

Type IntentOptional Attributes Name
integer(kind=n_int), intent(inout), allocatable :: list(:,:)
integer, intent(in) :: oldSize
integer, intent(in) :: newSize

Contents

Source Code


Source Code

    subroutine resize_ilut_list(list, oldSize, newSize)
        implicit none
        integer, intent(in) :: newSize, oldSize
        integer(n_int), allocatable, intent(inout) :: list(:, :)
        integer(n_int) :: tmp(0:NIfTot, oldSize)
        integer :: ierr
        logical :: tUseTmp
        character(*), parameter :: this_routine = "resize_ilut_list"

        ! We store the current list in a temporary, if existent
        tUseTmp = .false.
        ! If the list is already allocated, clear it
        if (allocated(list)) then
            tmp(:, :) = list(:, :)
            tUseTmp = .true.
            deallocate(list)
        end if

        allocate(list(0:NIfTot, newSize), stat=ierr)
        if (ierr /= 0) call stop_all(this_routine, "Not enough memory to resize ilut list")
        list = 0

        ! Write the old entries of list into the new memory
        if (oldSize < newSize) then
            list(:, 1:oldSize) = tmp(:, 1:oldSize)
        else
            list(:, 1:newSize) = tmp(:, 1:newSize)
        end if

    end subroutine resize_ilut_list