- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is it possible to rewind and over-write a record in sequential access binary file within the same program in which it is created?
The program opens a file with:
OPEN(UNIT=FID,
file = FileName,
Status='REPLACE',
Access='Sequential',
Form='binary',
IOSTAT=IERR)
The first record written to the file is the number of additional records that the program intends to write. It is possible that during the course of processing, the actual number of records written is less than the number intended.
In this instance, I am trying to update the first record with the correct number. The rewind statement doesn't return an error and neither does the write. However, after closing and opening the file with another program, the original value in the first record persists, the update is not apparent.
Any takers?
Thanks
The program opens a file with:
OPEN(UNIT=FID,
file = FileName,
Status='REPLACE',
Access='Sequential',
Form='binary',
IOSTAT=IERR)
The first record written to the file is the number of additional records that the program intends to write. It is possible that during the course of processing, the actual number of records written is less than the number intended.
In this instance, I am trying to update the first record with the correct number. The rewind statement doesn't return an error and neither does the write. However, after closing and opening the file with another program, the original value in the first record persists, the update is not apparent.
Any takers?
Thanks
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
rewinding a file and then writing a record effectively deletes all previous data that existed or was just written to a sequential file.
you could close the file perserving your updates, then
open(1,file='test.dat',form='binary',access='direct',recl=4)
read (1,rec=1) oldcount
newcount = oldcount+?
write (1,rec=1) newcount
close (1)
you could close the file perserving your updates, then
open(1,file='test.dat',form='binary',access='direct',recl=4)
read (1,rec=1) oldcount
newcount = oldcount+?
write (1,rec=1) newcount
close (1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you use direct access (which requires fixed-length records), you can rewrite individual records. As Dave says, if you use sequential writes, all data following in the file becomes undefined.
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