如何在 Fortran 中访问数组中的最后一项? [英] How do I access last item in an array in Fortran?
本文介绍了如何在 Fortran 中访问数组中的最后一项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Matlab 中,end
索引让我可以访问最后一个项目.
In Matlab, end
index lets me access a last item.
> array = [1 2 3 4 5 6 7];
> array(end)
ans = 7
如何在 Fortran 中执行相同的操作?
How do I do the same in Fortran?
program hello
integer array(7)
array = (/1, 2, 3, 4, 5, 6, 7/)
!print *, array(end)
! 1
!Error: Legacy Extension: REAL array index at (1)
! print *, array(-1)
! 1
!Warning: Array reference at (1) is out of bounds (-1 < 1) in dimension 1
! print *, array(0)
! 1
!Warning: Array reference at (1) is out of bounds (0 < 1) in dimension 1
end program Hello
推荐答案
array ( ubound (array) )
size
仅在数组为 1 索引时有效.
size
will only work if the array is 1-indexed.
这篇关于如何在 Fortran 中访问数组中的最后一项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文