Hi, I use a file in my code (in fortran90) by using “open ( 10,file=’data’)”, that have saved an array in this file. I want to clean values in this file and save another array at file, during running of my code.
On 7 nov, 08:34, Elaheh <elaheh.ad...@gmail.com> wrote:
> Hi, > I use a file in my code (in fortran90) by using “open > ( 10,file=’data’)”, that have saved an array in this file. I want to > clean values in this file and save another array at file, during > running of my code.
> How can I do this > work? > Thanks in advance.
Apparently, you just need to rewind the file with the instruction :
REWIND(10)
After that, you can write something else in the file 10 (these WRITE statements will overwrite the previous contents).
> On 7 nov, 08:34, Elaheh <elaheh.ad...@gmail.com> wrote:
> > Hi, > > I use a file in my code (in fortran90) by using “open > > ( 10,file=’data’)”, that have saved an array in this file. I want to > > clean values in this file and save another array at file, during > > running of my code.
> > How can I do this > > work? > > Thanks in advance.
> Apparently, you just need to rewind the file with the instruction :
> REWIND(10)
> After that, you can write something else in the file 10 (these WRITE > statements will overwrite the previous contents).
But if you don't write as many values I don't think that all the old ones will be deleted. A safer way would be to close and reopen the file as a replacement:
> On Nov 7, 10:32 am, fj <francois.j...@irsn.fr> wrote:
> > On 7 nov, 08:34, Elaheh <elaheh.ad...@gmail.com> wrote:
> > > Hi, > > > I use a file in my code (in fortran90) by using “open > > > ( 10,file=’data’)”, that have saved an array in this file. I want to > > > clean values in this file and save another array at file, during > > > running of my code.
> > > How can I do this > > > work? > > > Thanks in advance.
> > Apparently, you just need to rewind the file with the instruction :
> > REWIND(10)
> > After that, you can write something else in the file 10 (these WRITE > > statements will overwrite the previous contents).
> But if you don't write as many values I don't think that all the old > ones will be deleted.
No, the old values will be entirely deleted because a final CLOSE(10) will be executed automatically at the end of the run, fixing the new file end position.
> On 9 nov, 10:43, SimonG <si...@whiteowl.co.uk> wrote:
> > On Nov 7, 10:32 am, fj <francois.j...@irsn.fr> wrote:
> > > On 7 nov, 08:34, Elaheh <elaheh.ad...@gmail.com> wrote:
> > > > Hi, > > > > I use a file in my code (in fortran90) by using “open > > > > ( 10,file=’data’)”, that have saved an array in this file. I want to > > > > clean values in this file and save another array at file, during > > > > running of my code.
> > > > How can I do this > > > > work? > > > > Thanks in advance.
> > > Apparently, you just need to rewind the file with the instruction :
> > > REWIND(10)
> > > After that, you can write something else in the file 10 (these WRITE > > > statements will overwrite the previous contents).
> > But if you don't write as many values I don't think that all the old > > ones will be deleted.
> No, the old values will be entirely deleted because a final CLOSE(10) > will be executed automatically at the end of the run, fixing the new > file end position.
I forgot the key point : this new file end position is always located just after the last written record (if no WRITE statement occurs, then the old file end position remains unchanged).
Better still is to first read the NEW file and write a NEW one, then at the end of the program, EITHER call funtions to save the old file with a new name and rename the new file with the original name, OR, copy the OLD file to a back-up named file, and then copy the new FILE OVER the old FILE (by opening the old file and writing to it).