fortran でファイルの行数を数える。

fortranでファイルの行数を数える方法をメモ

open(1, file = './test.txt', status = 'old')

counter=0

do

read(1,'()',end=999)
counter = counter + 1
end do

999 close(1)

ここで、counterの最後の結果が、ファイルの行数。