Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran runtime error: End of file

  1. Oct 13, 2013 #1
    Dear all,
    I want to read file "d1.dat":

    1.025000+7 5.794453+0 1.050000+7 5.770080+0 1.075000+7 5.750135+0
    1.100000+7 5.734860+0 1.125000+7 5.724448+0 1.150000+7 5.719060+0
    1.175000+7 5.718829+0 1.200000+7 5.723865+0 1.219440+7 5.730802+0
    1.225000+7 5.732945+0 1.250000+7 5.743325+0 1.275000+7 5.754911+0
    1.300000+7 5.767697+0 1.325000+7 5.781676+0 1.350000+7 5.796840+0
    1.375000+7 5.813182+0 1.400000+7 5.830690+0 1.425000+7 5.846650+0
    1.450000+7 5.862611+0 1.475000+7 5.878547+0 1.500000+7 5.894463+0
    1.525000+7 5.910365+0 1.550000+7 5.926258+0 1.575000+7 5.942145+0
    1.600000+7 5.958034+0 1.650000+7 5.999165+0 1.700000+7 6.044866+0
    1.750000+7 6.088568+0 1.796240+7 6.122193+0 1.800000+7 6.124515+0
    1.850000+7 6.147738+0 1.900000+7 6.159560+0 1.950000+7 6.165319+0
    2.000000+7 6.169678+0

    then, i write data to a new file "newd1.dat":

    1.025000+7 5.794453+0
    1.050000+7 5.770080+0
    1.075000+7 5.750135+0
    1.100000+7 5.734860+0
    1.125000+7 5.724448+0
    1.150000+7 5.719060+0
    1.175000+7 5.718829+0
    1.200000+7 5.723865+0
    1.219440+7 5.730802+0
    1.225000+7 5.732945+0
    1.250000+7 5.743325+0
    1.275000+7 5.754911+0
    1.300000+7 5.767697+0
    1.325000+7 5.781676+0
    1.350000+7 5.796840+0
    1.375000+7 5.813182+0
    1.400000+7 5.830690+0
    1.425000+7 5.846650+0
    1.450000+7 5.862611+0
    1.475000+7 5.878547+0
    1.500000+7 5.894463+0
    1.525000+7 5.910365+0
    1.550000+7 5.926258+0
    1.575000+7 5.942145+0
    1.600000+7 5.958034+0
    1.650000+7 5.999165+0
    1.700000+7 6.044866+0
    1.750000+7 6.088568+0
    1.796240+7 6.122193+0
    1.800000+7 6.124515+0
    1.850000+7 6.147738+0
    1.900000+7 6.159560+0
    1.950000+7 6.165319+0
    2.000000+7 6.169678+0

    my code:
    !*********************************************
    program readdata

    implicit none
    integer :: i,k
    REAL :: x(6)

    integer:: n
    character(len=60):: cmd
    cmd = "cat d1.dat | grep '[^ ]' | wc -l > nlines.txt"
    call system(cmd)

    open(1,file='nlines.txt')
    read(1,*) n
    print*, "Number of lines are", n
    cmd = 'rm nlines.txt'
    call system(cmd)

    open(10,file="d1.dat",status="old")
    open(11,file="newd1.dat")

    do i = 1,n

    read(10,*) x

    write(11,99) x(1:2)
    write(11,99) x(3:4)
    write(11,99) x(5:6)

    99 format(e12.7,1x,e12.7)
    end do
    close(10)
    close(11)


    end program readdata
    !********************************************
    compiler is ok by gfortran, but when i run, program has error:

    " At line 23 of file readdata.f90 (unit=10,file='d1.dat')
    Fortran runtime error: End of file"

    Please help me,

    Thanks!
     
  2. jcsd
  3. Oct 13, 2013 #2

    jedishrfu

    Staff: Mentor

  4. Oct 14, 2013 #3
    Dear jedishrfu,

    Thanks for your help. I done success. :)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran runtime error: End of file
  1. [FORTRAN] Runtime error (Replies: 12)

Loading...