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 until end of file 1

Status
Not open for further replies.

ninguno

Technical User
Jan 29, 2003
3
US
sorry to ask such an inane question but i've left my fortran book back at home...

I'd like to

DO i=1,2000
READ(file1) x,y
WRITE(file2) blah,x,blah,y
IF (EOF) THEN
EXIT
END IF
END DO

But I can't figure out how to recognize the end of the file. using IOSTAT shows me 0's all the way until I get the library error.

Thanks in advance for any help!
 
ninguno,
I believe there is an EOF parameter you can put on the read statement where you can define a label of where to jump. I'd suggest doing the following also, in case there are more than 2000 records in your file:

DO WHILE(1.EQ.1)
READ(file1,EOF=200)
WRITE(file2) blah,x,blah,y
END DO
200 CONTINUE

Hope this helps !
 
Thanks, this is what I was looking for!

cheers
 
READ(file1,EOF=200)blah
READ(file1,END=200)blah
Valid syntax in both lines ?
 
EOF= doesn't work on my Fortran compiler but END= does.
 
Sorry about that . . . END is the correct parameter.
 
The EOF does not work on my program, how to fix it?

! Variables
integer, findpos
real yvalue
integer, parameter :: maxval=40

character (len=10) chain_x
character (len=40) chain_y
character *(maxval) garbage
character*1 delimeter
delimeter='='

garbage='siesta: Total ='
findpos = index(garbage,delimeter)

open(66, file='analize.dat')
open(67, file='plotVvsE.dat')

do while(1.eq.1)
read(66,EOF=200) chain_x
read(66,fmt=('A40')) chain_y
!write(*,*) chain_y
read(chain_y(findpos+2:),FMT='f10.6') yvalue
write(67,*) chain_x, yvalue
write(*,*) chain_x, yvalue
end do

200 CONTINUE
write(*,*) Done
close(66)
close(67)
end
 
As I indicated above, I had the wrong keyword. It should be END.
 
Sorry for my inane questions, I have a program that does not work, could anyone of you please be gentle enough to correct this and execute it?.
Thanks!

program test
open(unit=29,file='data.dat', status='old')

do while(1.eq.1)
write(*,*) ' I am here '
read(29,ERR=200) badata
write(*,*) badata
end do

200 write(*,*) 'Done'
continue
end

and data.dat contains
231.23
232.3
2323.2
22.12
34.3
2323.2
123.2

I just want to read values up to the end of file!

Help is apreciated

 
RE TO MYSELF.

THE TRICK IS IN USING THE fmt PARAMETER

! PROGRAMMA VOOR KWADRATEN:
! DIT PROGRAMMA BEVAT EEN LOOP DIE VERLATEN WORDT ALS ER EEN EOF CONDITIE
! ONTDEKT WORDT (DO UNTIL EOF).
!
DOUBLE PRECISION QUADR
!
100 CONTINUE
! open(unit=30,
READ (UNIT=5, FMT=*, END=200) QUADR
WRITE (UNIT=6, FMT=*) 'HET KWADRAAT IS: ', QUADR*QUADR
GO TO 100
!
200 CONTINUE
END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top