forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Stream I/O problem with write (lu, pos=address) buffer

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2551
Location: Sydney

PostPosted: Thu Nov 25, 2021 4:50 am    Post subject: Stream I/O problem with write (lu, pos=address) buffer Reply with quote

Paul,

(new post of old problem for clean thread)

I am trying to understand what is wrong, so I created a "simpler" example.
This uses records of 256 bytes (no header/footer) and reads a single byte from a random address.

If I:
1) write the records sequentially, without an address, then read randomly using pos=calculated_address appears to work.
2) write the records sequentially, with a calculated address, then read randomly using pos= with the same calculated address approach, it FAILS.
3) write the records randomly, with a calculated address, then read pos= with the same calculated address, it FAILS.
With this random write test 3, the file appears to be truncated, possible after the last write, as I got an end of file error for a valid address in the read test with 2**12 records of 2**8 length. (1MB file)

This program example is possibly easier to follow and identify the problem(s).

Test 1 : gives hope, as the read (pos=) test appears to work, but
Test 2 : write ( pos=) looks to be incorrect.
Test 3 : random write could be worrying for rewriting data ?
All tests appear to work with gFortran, hopefully showing my approach to stream I/O is as expected.

The calculated address:
for record:byte in read > address = (record-1)*256 + byte
for start of record in write > address = (record-1)*256+1
for byte read > byte value = mod (address,record_length)

https://www.dropbox.com/s/jpdu6f8ub0z9d63/stream_read.f90?dl=0

For stream I/O to be a useful approach for large files (> 4GB), pos= needs to support an 8-byte addresses.

This example above does not test Inquire, which also gives an incorrect address. The code below is taken from an earlier post.

Code:
   subroutine get_stream_pos (stream_unit, stream_address)
      integer*4 :: stream_unit
      integer*8 :: stream_address
      integer iostat

      inquire ( unit=stream_unit, pos=stream_address, iostat=iostat )
      write (*,*) 'stream is at', stream_address, ' iostat =',iostat
   end subroutine get_stream_pos
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2551
Location: Sydney

PostPosted: Thu Nov 25, 2021 5:00 am    Post subject: Reply with quote

Paul,

I have not yet tested the latest .dll's you have supplied.
I am using ftn95 Ver 8.80.0. Should I update to the latest version first ?

John
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7912
Location: Salford, UK

PostPosted: Thu Nov 25, 2021 7:59 am    Post subject: Reply with quote

John

Yes. Please test with the DLLs that I sent to you and let me know if it fixes these issues.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group