- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ?!
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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]
[/bash]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're welcome. Primary reason for turning computer on holiday, in case anyone is intereseted, replaying tour de france, magnifique!
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page