Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Problems reading data from file

alphajet
Beginner
395 Views
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
1 Solution
TimP
Honored Contributor III
395 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
TimP
Honored Contributor III
396 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.
0 Kudos
alphajet
Beginner
395 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
TimP
Honored Contributor III
395 Views
You're welcome. Primary reason for turning computer on holiday, in case anyone is intereseted, replaying tour de france, magnifique!
0 Kudos
Reply