program hello
integer a(9)
integer index; ! note no dimension here
a=(/1, 3, 4, 5, 6, 7, 8, 9, 10/)
index =
You can fix the first version, obtaining a scalar return from minloc
, by using the DIM
argument:
index = MINLOC(a, DIM=1, MASK=(a > 5))
P.S. No need for semicolons to end statements unless you place multiple statements per line. Fortran isn't C.
This discussion brings up an important point: MINLOC returns an array, even if it's only one number, it's still an array.
It may be possible to declare index as an array, like mentioned above, or to use a temporary array.
integer :: temp(1)
...
temp=minloc(dist)
index=temp(1)
It is also possible to use DIM argument to avoid manual fiddling with data types, like mentioned in M.S.B's answer.