- #1
marlh
- 12
- 0
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!
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!