write_results_csp Subroutine

public subroutine write_results_csp(filename, vals, res, tol)

Prints the intermediate results of iterative eigenvalue/singular value decompositions

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename

Output filename. This file will be overwritten

complex(kind=sp), intent(in) :: vals(:)

Intermediate values

real(kind=sp), intent(inout) :: res(:)

Residuals

real(kind=sp), intent(in) :: tol

Convergence tolerance


Source Code

    subroutine write_results_csp(filename, vals, res, tol)
        !! Prints the intermediate results of iterative eigenvalue/singular value decompositions
        implicit none(type, external)
        character(len=*), intent(in) :: filename
        !! Output filename. This file will be overwritten
        complex(sp), intent(in) :: vals(:)
        !! Intermediate values
        real(sp), intent(inout) :: res(:)
        !! Residuals
        real(sp), intent(in) :: tol
        !! Convergence tolerance
        ! internals
        integer :: i, k, idx
        integer, allocatable :: indices(:)
        real(sp) :: modulus
        character(len=*), parameter :: fmt = '(I6,4(2X,E16.9),2X,L4)'
        k = size(vals)
        if (io_rank()) then ! only IO rank writes
            allocate(indices(k))
            call sort_index(res, indices) ! res is returned in sorted order
            open (1234, file=filename, status='replace', action='write')
                write (1234, '(A6,4(A18),A6)') 'Iter', 'Re', 'Im', 'modulus', 'residual', 'conv'
            do i = 1, k
                idx = indices(i)
                    modulus = sqrt(vals(idx)%re**2 + vals(idx)%im**2)
                    write (1234, fmt) k, vals(idx)%re, vals(idx)%im, modulus, res(i), res(i) < tol
            end do 
            close (1234)
        end if
    end subroutine write_results_csp