- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi I am trying to create and read a text file in fortran 90 the file is created ok and just contains some numbers for now but when I try to read it back in I get a run time error "attempt to read past end of file" how do I read the file back in the code I'm using is below Cheers CHRIS open (55,file='output.txt',form='FORMATTED') WRITE(55,*) anat close(55) open (56,file='output.txt',form='FORMATTED') READ (56) anatomyNumbers close(56)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Thanks that helped I can now read the data using
open (2,file='output.txt')
READ (2,*) anatomyNumbers(1:13)
close(2)
However is there a way to do it in which the 1:13 i.e. the
number of values in the file doesn't have to be specified.
eventually my files will be large and I will not know how many
values are in them.
Also when I define
INTEGER, ALLOCATABLE :: anatomyNumbers(:)
ALLOCATE(anatomyNumbers(13))
the third value has a 12 in it before I do anything to it
Cheers
CHRIS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you ALLOCATE an array, the initial contents are undefined. They could be anything. Zero the array after allocation of that's what you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
To catch most IO-errors in a controlled way, you can use ERR and IOSTAT in the READ statement, for example like this:
READ (*,*, ERR=999, IOSTAT=IERR) A,B,C
IF (IERR .NE. 0) GOTO 999
Then you can decide what to do yourself if there is something fishy with the file you are reading.
I hope this works,
Lars Petter Endresen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the help with this problem I got it to work using
open (4,file='output.txt',FORM='FORMATTED')
write(4,*) nvoxels
close(4)
open (3,file='output.txt',FORM='FORMATTED')
read(3,*,IOSTAT=isEND) anat
if(isEND.NE.0) GOTO 999
999 close(3)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following URLs include many recommendations about textbooks and on-line learning:
http://www.fortran.com/
http://www.polyhedron.com/
The Lawrence book discusses Windows-specific details of Intel compilers.
Metcalf/Reid/Cohen is an unusual combination of suitability for learning, with authoritative accuracy, and errata updates available on line.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page