Fortran - find loc method - implicit type

耗尽温柔 提交于 2019-12-20 03:34:14

问题


I am learning fortran and need my program to find specific values in an array. A simple program like below:

program hello

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

end program hello 

is giving me the following error:

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

I am compiling it using gfortran on macbook. Will really appreciate if I can get some help regarding findloc


回答1:


The standard intrinsic findloc was introduced to Fortran in the 2008 revision. Support for this function first appeared in gfortran release 9.0.

The error message you see is an indication that the intrinsic is not supported in the version you are using.

You could attempt to use the required version, but at the moment this is still in development.

Fortunately, it is simple enough to loop over the elements of your array, effectively creating your own version of findloc.




回答2:


You have two bugs. Modifying your code slightly makes it work:

program hello

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

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


end program hello


来源:https://stackoverflow.com/questions/54470429/fortran-find-loc-method-implicit-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!