我正在尝试编写一个将矩阵(2D数组)作为输入并将其很好地打印到标准控制台输出的子例程。
error #6634: The shape matching rules of actual arguments and dummy arguments have been violated. ['U']
打印矩阵的子程序在此模块中
MODULE LinearSystems
IMPLICIT NONE
private
...
public showMatrix
...
contains
subroutine showMatrix(a, n, m, name)
implicit none
double precision, dimension(:,:), intent(in) :: a
character, dimension(:), intent(in), optional :: name
integer, intent(in) :: n,m
integer :: i, j
write(*,*) "*** Show Matrix ", name, " ***"
do i = 1, n
do j = 1, m
write(*,'(F8.4)',advance="no") a(i,j)
end do
write(*,*)
end do
end subroutine showMatrix
并且主程序调用它
program PoisonEquation
...
use LinearSystems
implicit none
double precision, dimension(:,:), allocatable :: u,...
integer :: n = 700
allocate(u(n-1,n-1))
...
call showMatrix(u, n-1,n-1, "U")
我很期待收到有关如何改进此代码的提示,并使其摆脱错误。
名称哑元名称是假定的形状数组(请参见dimension(:)
声明)。用于实际参数的“ U”文字是标量(错误消息引用此文字)。
如果虚拟参数是假定的形状数组,则实际参数的等级应与虚拟参数的等级相同(F2018 15.5.2.4p16)。
找出要传递/接收数组还是标量,并修复代码。