Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading file problem

Status
Not open for further replies.

mikibelavista

Technical User
Jan 18, 2012
32
My file:
3515 2.154
3516 2.126
3517 2.098
3518 2.063
3519 2.084
3520 2.114
3521 2.128
.
.
13093 2.302
13094 2.294
13095 2.29
13096 2.314
13097 2.314
13098 2.294
13099 2.294
13100 2.279

9586 lines in the file.

My code:
program pr2

implicit none

integer :: i,j
real,dimension(9586) :: c
integer,dimension(9586) :: k


open(10,file='gom.dat')

do i=1,9586
read(10,51)k(i),c(i)
51 format(i5,3x,f5.3)
end do

end program

gfortan gives
At line 13 of file pr2.f90 (unit = 10, file = 'gom.dat')
Fortran runtime error: Bad value during integer read
ifort:
forrtl: severe (64): input conversion error, unit 10,

Why?
 
Probably one of the data lines contains data that doesn't much your format.
Try to change reading with format specification
Code:
read(10,51)k(i),c(i)
to reading without format specification
Code:
read(10,*)k(i),c(i)
 
Add some error handling to your read
Code:
do i=1,9586
   read(10,*,end=888,err=999)k(i),c(i)
end do
close(10)
stop
888 print *, 'Premature end of file i=', i
    stop

999 print *, 'Error at i=', i
    stop

end program
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top