×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

reading file problem

reading file problem

reading file problem

(OP)
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?

RE: reading file problem

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) 

RE: reading file problem

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close