Fortran语言编程实现读取数据文件行数

来源:互联网 发布:淘宝怎样上下架时间 编辑:程序博客网 时间:2024/05/28 16:09

在编写Fortran语言程序进行数值计算时,经常需要对未知大小的数据文件进行计算,在运用动态数组的过程中会遇到问题,即事先不知道数据文件的行数,需要使用编程实现这个步骤,以“data.txt”为例:

代码示例

call line_no('data.txt',n)subroutine line_no(file_name,n)    character*80 file_name    integer n    n=0    open(10,file=file_name,status='old')    do while (not(eof(10)))         read(10,*)       n=n+1    end do    close(10)end subroutine line_no
0 0