1
integer, parameter :: m=100, n=200
real :: x(m), y(n), z(m,n),loc(2)
integer :: i, j

do i=1,m
do j=1,n
 z(i,j)=x(i)+y(j)
enddo
enddo

loc=maxloc(z)
write(*,*) "peaking at ", x(loc(1)), y(loc(2))

Is it possible to avoid using the temporary array loc(2)? In other words, is there a method of directly accessing the result of maxloc in the above case, e.g., x(maxloc(z)(1))?

Youjun Hu
  • 991
  • 6
  • 18
  • 2
    Please ignore the (slightly related) [linked question](https://stackoverflow.com/questions/53389803/type-conflict-of-maxloc-in-fortran): I pressed the wrong button, `maxloc(z, dim=...)` is related, but actually does something slightly different from what you want. It's perfect when `z` is rank-1, not for higher ranks. – francescalus Dec 14 '21 at 10:47

0 Answers0