函数'array'没有IMPLICIT类型

时间:2016-06-28 21:18:32

标签: function compiler-errors fortran

这是我的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

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

1 个答案:

答案 0 :(得分: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之间应该存在差异,因为目前它们将始终是相同的值。)