Fortran - 查找 loc 方法 - 隐式类型

Fortran - find loc method - implicit type

我正在学习 Fortran,需要我的程序在数组中查找特定值。如下所示的简单程序:

program hello

implicit none
integer :: x
x = findloc([4,9,0,2,-9,9,1],9)

end program hello 

给我以下错误:

Error: Function 'findloc' at (1) has no IMPLICIT type

我正在 macbook 上使用 gfortran 编译它。如果我能得到一些关于 findloc

的帮助,我将不胜感激

Fortran 在 2008 年修订版中引入了标准内在函数 findloc。对这个函数的支持首先出现在 gfortran release 9.0.

您看到的错误消息表明您正在使用的版本不支持内部函数。

您可以尝试使用所需的版本,但目前仍在开发中。

幸运的是,遍历数组元素非常简单,有效地创建了您自己的 findloc 版本。

你有两个错误。稍微修改你的代码使其工作:

program hello

  implicit none
  intrinsic :: findloc
  integer :: x(1)

  x = findloc([4,9,0,2,-9,9,1], value = 9)


end program hello