reading data from txt file in fortran

前端 未结 6 1342
渐次进展
渐次进展 2020-12-17 23:53

I am writing a FORTRAN program that reads data from a text file and writing it to the console. the data file looks something like this

1234567890123456 12345         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 00:06

    It is usually better to read data in non fixed format. And to leave some leading spaces so that numbers can fit when writing them out.

    integer(8) :: i
    real(4) :: x, y, z
    open(unit=1, file='data.txt')
    read(1,*)i, x, y, z
    write(*,'(i16, 3f11.3)')i, x, y, z
    end
    

提交回复
热议问题