program test
real, dimension(5) :: x
integer :: n
x = (/1., 2., 4., 3., 1./)
n = maxloc(x) + 1
print *, n
end
a.f90(5): error #6366: The shapes of the array expressions do not conform. [N]
n = maxloc(x) + 1
----^
compilation aborted for a.f90 (code 1)
因为,maxloc的输出值是数组
即使p是一个一维数组
即使maxloc(p)输出只有一个值
但是你还是不得不定义一个只有一个元素的数组来接收,即
integer i4(1)
i4 = maxloc(p)