请教,fortran如何读出文件的行数?
1个回答
展开全部
使用一个计数变量用于记录行数,用iostat检查是否出错,如出错则表示read已经到达文件尾,直接跳出并显示行数
例如:
program r
character (len=100) :: line
real :: x(100)
integer :: i, n, io
open (10, file = 'DATA')
n = 0
do
read (10, '(A)', iostat = io) line
if (io < 0) exit
if (len_trim(line) == 0) cycle
n = n + 1
read (line, *) x(n)
end do
print *, n
print *, (x(i),i=1,n)
end program r
例如:
program r
character (len=100) :: line
real :: x(100)
integer :: i, n, io
open (10, file = 'DATA')
n = 0
do
read (10, '(A)', iostat = io) line
if (io < 0) exit
if (len_trim(line) == 0) cycle
n = n + 1
read (line, *) x(n)
end do
print *, n
print *, (x(i),i=1,n)
end program r
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询