2
votes

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

2

2 Answers

4
votes

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.

0
votes

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