My question is more of a quest for confirmation that the conclusions I have drawn are correct and to see if anyone has any smart "work-arounds".
My problems starts with a friend wanting to use maxloc to extract the location of the maximum value of an array and then use this result to read a corresponding element of an other array. I.e in pseudo code:
c = b(maxloc(a))
This however returns the error
Error: Rank mismatch in array reference at (1) (1/2)
(He is working with (N,N) arrays.)
I did some tests and I found that this does indeed not work. My conclusion is that you need to do something like this:
program h
integer :: a(2,2)
integer :: id(2),id2(2)
a(1,1) = 1; a(1,2) = 2; a(2,1) = 3; a(2,2) = 2
id = maxloc(a)
write(*,*) a(id(1),id(2))
end program h
It works and everyone is happy. Well, except me. I want to know if there is a better way of doing it. Is there something I am missing? An easy solution to the problem.