- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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
- Balises:
- Intel® Fortran Compiler
Lien copié
2 Réponses
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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)
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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.
Répondre
Options du sujet
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable