Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

values in file

0 views
Skip to first unread message

Elaheh

unread,
Nov 7, 2009, 2:34:27 AM11/7/09
to
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.

fj

unread,
Nov 7, 2009, 5:32:45 AM11/7/09
to

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).

SimonG

unread,
Nov 9, 2009, 4:43:33 AM11/9/09
to

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:

close(10)
open(10,file='data',status='replace')

Simon

fj

unread,
Nov 9, 2009, 9:21:48 AM11/9/09
to
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.

fj

unread,
Nov 9, 2009, 9:49:21 AM11/9/09
to

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).

Terence

unread,
Nov 9, 2009, 10:46:37 PM11/9/09
to
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).

0 new messages