Formatted reads and implied do

前端 未结 2 661
无人及你
无人及你 2021-01-25 19:19

In Fortran one has the option to use implied loops. They are usually used for printing and have the following structure.

write(*,\'(5I6)\') (i,i=1,20)

! output          


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-25 19:28

    I would do it like this if you really need the format for some reason

    do i = 1, n, 5
      read(*,'(5I6)') a(i:i+4)
    end do
    

    otherwise the list directed format would work well as suggested by High Performance Mark.

    You could write it as an implied do, but sub-arrays are better.

    I could even imagine a one liner with a format descriptor including /, but why bother?

    (too long for a comment)

提交回复
热议问题