Can someone please help.
I am using Fortran77
How can I open a file and empty the contents ready for use further
use.
Thanks
Harvey
I think the simplest way is:
open( 10, file = filename )
close( 10, status = 'delete' )
open( 10, file = filename )
- you would simply re-create the file.
Note that if you write into an existing file, the contents
is lost too. So, in that case you would not need to do
anything special. With the above fragment you simply
create a new file with the same name.
Regards,
Arjen
> On 18 nov, 14:11, Harvey <harveypoll...@talktalk.net> wrote:
> > I am using Fortran77
> >
> > How can I open a file and empty the contents ready for use further
> > use.
> I think the simplest way is:
>
> open( 10, file = filename )
> close( 10, status = 'delete' )
> open( 10, file = filename )
Note that this is not robust. In fact, there really isn't a completely
reliable way to do this in f77. F90 adds status='replace', which does
the job much better.
The problem in f77 (and I'll ignore the lack of error handling above for
cases like the file not existing, because that is easily fixed) is that
the OPEN is not guaranteed to work unless you get some things about the
existing file right. In particular, the above open is (by default) for a
formatted sequential file. If the file is not actually a formatted
sequential file, the compiler is quite within its rights to fail to open
it. Yes, I have seen things like that happen.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain