【问题标题】:Function ‘array’ has no IMPLICIT type函数“数组”没有隐式类型
【发布时间】:2016-06-29 21:55:03
【问题描述】:

这是我的 Fortran 90 代码:

program test
implicit none

integer*4 nxProjPad, cf, numViews, cc, index, indRad, iv, i
real*4 v4, v5, SS
nxProjPad=185
numViews=180
v4 = 0.
v5 = 0.
SS = 0.

cf = NINT(nxProjPad/2.)

do  iv = 1, numViews

do i = 1, nxProjPad

v4 = v4 + array(index)

v5 = v5 + array(indRad)
SS = SS + ABS(array(index))

indRad = indRad + 1

index = index + 1

enddo

enddo


end

我总是得到错误:

test.f90:19:15:

 v4 = v4 + array(index)
               1
Error: Function ‘array’ at (1) has no IMPLICIT type
test.f90:21:15:

 v5 = v5 + array(indRad)
               1
Error: Function ‘array’ at (1) has no IMPLICIT type
test.f90:23:14:

 SS = SS + ABS(array(index))
              1
Error: Function ‘array’ at (1) has no IMPLICIT type

我已经搜索并看到了类似的答案,但仍然无法解决我的问题。欢迎提出任何建议,并提前致谢!

【问题讨论】:

  • 你认为array 是什么?编译器认为这是一个您没有为其提供定义的函数。我看不到任何名为 array 的东西的任何声明。
  • 对您的 Fortran 问题使用标签 fortran 您可以在必要时添加特定版本(不在此处)。

标签: function compiler-errors fortran


【解决方案1】:

您的问题似乎是 array 根本没有声明。它没有隐式类型,因为您明智地选择使用 IMPLICIT NONE 禁用隐式类型。

使用array(<int>) 调用的项目有两种可能的情况:它可能是一个数组或一个函数。编译器无法得出正确的结论,怀疑您可能在某个地方想要声明一个函数:

function array(i)
    implicit none
    integer :: i
    <some type> :: array
    <some code that calculates array>
end function array

但是因为它没有找到任何那种代码,它告诉你你还没有实现它,你也没有声明它。

我怀疑,因为我不仅了解 Fortran,而且在某种程度上也了解英语,因此它更有可能是 REAL*4 类型的数组。

所以试试这个:

program test
    implicit none

    integer*4 nxProjPad, cf, numViews, cc, index, indRad, iv, i 
    real*4 v4, v5, SS

    ! Create an allocatable array (allocatable, because we only know
    ! the size once nxProjPad and numViews have been set.)
    real*4, dimension(:), allocatable :: array

    nxProjPad=185
    numViews=180

    ! both indRad and index get incremented for each
    ! iteration of either loop, so the maximum array index
    ! is the product of numViews and nxProjPad
    allocate(array(numViews*nxProjPad))

    v4 = 0.
    v5 = 0.
    SS = 0.

    ! These weren't originally initialised before their first use.
    ! Correct that
    indRad = 1
    index = 1

    cf = NINT(nxProjPad/2.)

    do  iv = 1, numViews
        do i = 1, nxProjPad
            v4 = v4 + array(index)

            v5 = v5 + array(indRad)
            SS = SS + ABS(array(index))

            indRad = indRad + 1

            index = index + 1
        enddo
    enddo

    ! Properly deallocate the array again
    deallocate(array)
end program test

当然我仍然不知道它应该做什么,而且还有一些奇怪的功能。 (例如,indexindRad 之间是否应该存在差异,因为目前它们始终是相同的值。)

【讨论】:

  • 非常感谢您的回答!我对 Fortran 很陌生,实际上我还有一个问题:为什么 v4、v5 和 SS 的初始值只会是 0,这是一个数字,但我们看到在循环中 v4、v5 和 SS 应该是一个数组,据我了解,因为例如:v4 = v4 + 数组(索引)。既然在其他编程语言中,比如matlab,这行应该表示v4也是一个数组,那为什么v4的首字母只能是0呢? (对于这段代码的含义,我正在编辑别人的fortran代码,这只是开始的一部分。)
  • 我还有一个问题,如果我想要另一个数组,比如说,SS1,我希望 SS1 是 SS 的前 10 个元素,所以我写了 SS1=SS(1:10),为什么它显示错误:“(1) 处的不可分类声明”? (“1”指向SS1。)我应该把这条线放在“deallocate(array)”里面还是外面?谢谢!
  • 像这样声明的任何东西:REAL, DIMENSION(....) :: aREAL :: a(...) 都是一个数组。在这两种情况下,a 将是数组的名称,a(i) 将引用该数组中的第 i 个值。所以在上面的例子中,array(index) 将引用数组array 中的index-th 值。
  • 谢谢!你也可以回答我的第二个问题吗?
  • 你能帮我写这篇文章吗? stackoverflow.com/questions/38139376/…
猜你喜欢
  • 2021-11-12
  • 1970-01-01
  • 1970-01-01
  • 2021-10-28
  • 2021-08-09
  • 1970-01-01
  • 2016-03-26
  • 2020-01-04
相关资源
最近更新 更多