Output a 2D-matrix of real in a well formatted way
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | trans |
It the matrix is transposed or not |
||
character(len=*), | intent(in) | :: | label |
Label to be printed before the matrix |
||
real(kind=rp), | intent(in), | dimension(:, :) | :: | matrix |
Matrix to be printed |
|
integer(kind=ip), | intent(in), | optional | :: | ofunit |
Unit where the matrix should be printed, if not present iof_mmpol is used. |
subroutine d2_print_matrix(trans, label, matrix, ofunit)
!! Output a 2D-matrix of real in a well formatted way
implicit none
logical, intent(in) :: trans
!! It the matrix is transposed or not
character(len=*), intent(in) :: label
!! Label to be printed before the matrix
real(rp), dimension(:, :), intent(in) :: matrix
!! Matrix to be printed
integer(ip), intent(in), optional :: ofunit
!! Unit where the matrix should be printed, if not present [[iof_mmpol]]
!! is used.
integer(ip) :: i, j, nbatch, nres, out_unit, nrow, ncol
integer(ip), parameter :: colperrow = 5
integer(ip), dimension(colperrow) :: icol
character (len=24) :: iform, rform
if(present(ofunit)) then
out_unit = ofunit
else
out_unit = iof_mmpol
end if
nrow = size(matrix, 1)
ncol = size(matrix, 2)
icol = [(i, i=1, colperrow)]
1000 format(t3,a)
1010 format(t3,5i16)
1020 format(t3,5f16.8)
write(out_unit,1000) label
if(trans) then
nbatch = nrow/colperrow
nres = mod(nrow, colperrow)
write(iform,'("(t3,",i1,"i16)")') nres
write(rform,'("(t3,",i1,"f16.8)")') nres
do i = 1, nbatch
write(out_unit, 1010) icol(1:colperrow)
do j = 1, ncol
write(out_unit, 1020) matrix(icol(1):icol(colperrow), j)
end do
write(out_unit,'("")')
icol = icol + colperrow
end do
if (nres > 0) then
write(out_unit,iform) icol(1:nres)
do j = 1, ncol
write(out_unit,rform) matrix(icol(1):icol(nres),j)
end do
end if
else
nbatch = ncol/colperrow
nres = mod(ncol,colperrow)
write(iform,'("(t3,",i1,"i16)")') nres
write(rform,'("(t3,",i1,"f16.8)")') nres
do i = 1, nbatch
write(out_unit,1010) icol(1:colperrow)
do j = 1, nrow
write(out_unit,1020) matrix(j,icol(1):icol(colperrow))
end do
write(out_unit,*)
icol = icol + colperrow
end do
if(nres.ne.0) then
write(out_unit,iform) icol(1:nres)
do j = 1, nrow
write(out_unit,rform) matrix(j,icol(1):icol(nres))
end do
end if
end if
end subroutine d2_print_matrix