【问题标题】:Assumed Shape arrays require explicit interface in Fortran [duplicate]假设的形状数组需要 Fortran 中的显式接口 [重复]
【发布时间】:2018-09-14 12:13:10
【问题描述】:

我正在尝试为一个简单程序编写代码,该程序首先要求输入一个数字 n,然后创建一个 nxn 矩阵,其主对角线上为 3,其上为 1,其下为 0,向量 (n) 中为 3不均匀的位置和 2 在偶数的位置。然后它必须包含一个不使用 matmul() 将它们相乘的子例程

program P13

implicit none

integer(4) :: n, i, j
integer, dimension(:), allocatable:: v 
integer, dimension(:,:), allocatable :: m
integer, dimension(:), allocatable :: r


write(*,*) "Insert n"
read(*,*) n



allocate (v(1:n))
allocate (m(1:n,1:n))

v(1:n:2) = 3
v(2:n:2) = 2
m = 0

DO i=1,n,1

   m (i,i:n)=1

END DO

Do i=1,n,1
 m (i,i)=3
 End do 

call matrmul(n, m, v)
end program

subroutine matrmul(n, b, o, t)
implicit none

integer(4), intent(in) :: n
integer(4) :: i, j
integer, dimension(:), intent(in) :: b 
integer, dimension(:,:),intent(in) :: o
integer, dimension(:), intent(out) :: t

DO i=1,n,1

t(i) = sum(b*o(:,i))
END DO

write(*,'(I2)') t

end subroutine 

我收到错误消息“matrmul”在 (1) 处需要显式接口:假设形状参数

我该如何解决这个问题?谢谢

【问题讨论】:

  • 请在所有与fortran相关的问题中添加fortran标签。
  • 除了什么 DanSp.建议也请先查看其他问题中的错误信息。

标签: fortran fortran90


【解决方案1】:

这里有很多关于堆栈溢出的示例,将向您展示如何创建显式接口。但是,由于您在主程序中为所有数组分配内存并将大小传递给子程序,因此只需在子程序中使用 n 声明所有数组。

subroutine matrmul(n, b, o, t)
  implicit none

  integer(4), intent(in) :: n
  integer(4) :: i, j
  integer, dimension(n), intent(in) :: b 
  integer, dimension(n,n),intent(in) :: o
  integer, dimension(n), intent(out) :: t

【讨论】:

    猜你喜欢
    • 2013-05-05
    • 1970-01-01
    • 2011-07-03
    • 2021-02-21
    • 2014-05-08
    • 2016-08-17
    相关资源
    最近更新 更多