我正在尝试决定这两个选项中哪一个是最好的:
subroutine sqtrace( Msize, Matrix, Value )
integer, intent(in) :: Msize
real*8, intent(in) :: Matrix(Msize, Msize)
real*8, intent(out) :: Value
[instructions...]
end subroutine sqtrace
VS
subroutine sqtrace( Matrix, Value )
real*8, intent(in) :: Matrix(:,:)
real*8, intent(out) :: Value
if ( size(Matrix,1) /= size(Matrix,2) ) then
[error case instructions]
end if
[instructions...]
end subroutine sqtrace
我了解到,当您使用警告进行编译时,第一种情况应在编译时自动检查是否调用
sqtrace
与指定大小相符。然而,我不知道当给定的参数是可分配的时,编译器是否可以在这些检查中执行,例如(更多地取决于其他在运行时确定的事物)。第二种方法需要显式接口并具有更多代码(检查),但似乎可以捕获更多错误。每种方法使用的优缺点是什么,在哪些情况下应该选择其中之一?