Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
18 Views

Problems reading data from file

Jump to solution
Actually I know this is supposed to be quite simple, but I've been stuggling with this for hours !
I simply need to write an array of data to file, so that I would read it somewhere else in a different computer, so I tried the procedure on a given array I have,I firstly used the following code:
[bash]open(unit=2, file='a.dat', status='replace') do i=1,NZ write(2,*), MatrixCSR(i) enddo do i=1,NZ read(2,*), MatrixCSR2(i) enddo [/bash]But then I got the fort(24) error concerning the end of file during read, so I modified the code to be:
[bash]open(unit=2, file='a.dat', status='replace') do i=1,NZ write(2,*), MatrixCSR(i) enddo do i=1,NZ read(2,*,END=1), MatrixCSR2(i) enddo 1 CONTINUE[/bash]Now it's going without errors, but the destination array "MatrixCSR2" just includes zeros, so no data was imported at all, what's wrong with this simple snippet ?!
0 Kudos

Accepted Solutions
Highlighted
Black Belt
18 Views
You would need to endfile and rewind unit 2 (if you are an f66 fan) or close and reopen the file between writing and reading.

View solution in original post

0 Kudos
3 Replies
Highlighted
Black Belt
19 Views
You would need to endfile and rewind unit 2 (if you are an f66 fan) or close and reopen the file between writing and reading.

View solution in original post

0 Kudos
Highlighted
Beginner
18 Views
Sir, you're totally right ! and I must use status='old' during the open line intended for read, I don't even need to check for the end of file (END=1 statement)
[bash]open(unit=2, file='a.dat', status='replace') do i=1,NZ write(2,*), MatrixCSR(i) enddo close(2) open(unit=2, file='a.dat', status='old') do i=1,NZ read(2,*), MatrixCSR2(i) enddo
[/bash]
0 Kudos
Highlighted
Black Belt
18 Views
You're welcome. Primary reason for turning computer on holiday, in case anyone is intereseted, replaying tour de france, magnifique!
0 Kudos