What's the meaning of an inline read in Fortran?

前端 未结 1 804
执笔经年
执笔经年 2021-01-23 21:21

I have found this weird statement in a piece of code:

read(10, *) ((matrix(i, j), i=1, n), j=m, 1, -1)

I am wondering how this inline recursive

1条回答
  •  醉梦人生
    2021-01-23 21:43

    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.

    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=
    integer, parameter :: m=
    , 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
    

    0 讨论(0)
提交回复
热议问题