在Fortran中内联读取的含义是什么? [英] What's the meaning of an inline read in Fortran?
问题描述
我在一段代码中发现了这个奇怪的语句:
I have found this weird statement in a piece of code:
read(10, *) ((matrix(i, j), i=1, n), j=m, 1, -1)
我想知道这种内联递归阅读是如何工作的.是什么意思
((matrix(i, j), i=1, n), j=m, 1, -1)
?
I am wondering how this inline recursive reading works. What is the meaning of
((matrix(i, j), i=1, n), j=m, 1, -1)
?
推荐答案
这不是在线递归阅读(不确定您从何处获得此术语),这是一个示例嵌套的暗示执行循环,请参见此处,例如,表示隐式do循环的语法以及这些示例的许多示例.基本上,隐式的do循环是一种在一行上编写do循环的方法.使用嵌套的隐式do循环,您可以在一行上编写多个do循环.
This is not an in-line recursive read (not sure where you got this term from), this is an example of a nested implied do loop, see here, for example, for the syntax of an implied do loop and many examples of these in action. Basically an implied do loop is a way to write a do loop on a single line. With nested implied do loops you can write multiple do loops on a single line.
在您的情况下,您所拥有的等同于(请注意,如果OP应注意任何差异,请在此处更正我)类似的东西(请注意,我已经从外循环向内解开了隐式的do循环) :
In your case, what you have is equivalent to (someone please correct me here if there there are any differences the OP should be aware of) something like (notice that I have unravelled the implied do loop from the outer loop inwards):
integer, parameter :: n=<some-value>
integer, parameter :: m=<some-value>
<some-type>, dimension(n,m) :: matrix
integer :: i, j
do j = m,1,-1
do i = 1,n
read(10,*) matrix(i,j)
end do
end do
这篇关于在Fortran中内联读取的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!