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)