本文介绍了使用MINLOC与Fortran语言:在分配不兼容行列0和1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
错误信息
main.f95:5.3:
Error message
main.f95:5.3:
指数= MINLOC(一,MASK =(> 5))
1
错误:不兼容行列0和1的分配在(1)
index = MINLOC(a, MASK=(a > 5)) 1Error: Incompatible ranks 0 and 1 in assignment at (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
搜索
我能找到相关的讨论,但我不找不到它足够详细,我理解上的差异。
Search
Here I could find related discussion but I don't find it sufficiently verbose for me to understand the difference.
推荐答案
您可以修复的第一个版本,获得从 minloc
A标回报,通过使用 DIM
参数:
You can fix the first version, obtaining a scalar return from minloc
, by using the DIM
argument:
index = MINLOC(a, DIM=1, MASK=(a > 5))
P.S。无需分号,除非你把每行多条语句结束语句。 Fortran语言不是C
P.S. No need for semicolons to end statements unless you place multiple statements per line. Fortran isn't C.
这篇关于使用MINLOC与Fortran语言:在分配不兼容行列0和1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!