Is the compile error correct? It was not what I expected.
program fred implicit none integer :: n integer :: ip real :: harry(5) harry = [ 1.0, 2.0, 0.5, 4.0, 5.0 ] N = 3 ip = minloc( harry(1:n) ) ! error #6366: The shapes of the array expressions do not conform. [IP] ip = minloc( harry(1:n), dim = 1 ) ! ok end
OK thanks I just read the notes on minloc again and I has missed that point first time. Is just seems strange that for a 1d array if I omit dim=1 I get an array result but with dim=1 I get a scalar! Still it is what it is....maybe it makes more sense when you start looking at more complex usage.
If the argument to DIM was a 2-dimension array, you'd get an array of two values for both indices, etc. When you give DIM, you get only one value, a scalar, for the MINLOC along that dimension. Don't feel bad, this trips up a lot of programmers as most don't think about the less usual cases.