Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

minloc error message

andrew_4619
Honored Contributor II
666 Views

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

 

0 Kudos
3 Replies
Steve_Lionel
Honored Contributor III
666 Views

Yes, it is correct. If you omit DIM=, the result of MINLOC is an array which does not conform to a scalar.

0 Kudos
andrew_4619
Honored Contributor II
666 Views

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. 

0 Kudos
Steve_Lionel
Honored Contributor III
666 Views

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.

0 Kudos
Reply