gpt4 book ai didi

function - 函数 ‘array’没有IMPLICIT类型

转载 作者:行者123 更新时间:2023-12-02 10:46:37 26 4
gpt4 key购买 nike

这是我的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。它没有隐式类型,因为您明智地选择了使用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之间应该有区别,因为目前它们始终是相同的值。)

关于function - 函数 ‘array’没有IMPLICIT类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38086475/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com