program hello
integer a(9)
integer index; ! note no dimension here
a=(/1, 3, 4, 5, 6, 7, 8, 9, 10/)
index = MINLOC(a, MASK=(a > 5))
Print *, index
end program Hello
Run Code Online (Sandbox Code Playgroud)
main.f95:5.3:
index = MINLOC(a,MASK =(a> 5))1错误:在(1)的赋值中不匹配的等级0和1
program hello
integer a(9)
integer index(1) ! note dimension 1 here which looks redundant at first
a=(/1, 3, 4, 5, 6, 7, 8, 9, 10/)
index = MINLOC(a, MASK=(a > 5))
Print *, index
end program Hello
Run Code Online (Sandbox Code Playgroud)
在这里,我可以找到相关的讨论,但我发现它并不足以让我理解其中的差异.
您可以minloc使用DIM参数修复第一个版本,从中获取标量返回:
index = MINLOC(a, DIM=1, MASK=(a > 5))
Run Code Online (Sandbox Code Playgroud)
PS除非每行放置多个语句,否则不需要分号来结束语句.Fortran不是C.