Appending data to pre-exisiting files
Richard E Maine
Richard.Maine@nasa.gov
Wed Jul 27 17:56:00 GMT 2005
On Jul 27, 2005, at 9:45 AM, Steve Edwards wrote:
> On Wed, 2005-07-27 at 16:08, Richard E Maine wrote:
>> The only standard and portable way to do this in fortran 77 is to open
>> the file and read through it to the end (backspacing after you hit the
>> end of file). Yes, this is a pain - particularly if the file is
>> large.
>> It is enough of a pain that it is sometimes worth doing nonstandard
>> things even though they cause porting problems.
>
> That has been my implementation using g77. I put up with the ugly code
> purely because it *does* have to be portable.
If your only problem is that the code is a bit ugly, then you are in
pretty good shape. Ugly though it may be, it is just a few lines and
isn't *THAT* bad. Sometimes performance can be a significant driver
here. For example, I have applications that append entries to a log
file. The log file can be several megabytes in size - enough to take
noticeable time to read through. Multiple copies of the application (or
multiple applications) sometimes share the same log file, so I can't
just keep the file open for the entire duration of the application run
(possibly as long as hours). Instead, I need to open and close the file
around writing each log entry. If I used the read-to-eof approach, this
would have me reading several megabytes for every line written. That's
basically a non-starter in terms of performance. Normally the log files
aren't a significant performance issue, but that's so bad that they
become one. In f77, I was all but forced to use nonstandard constructs
and pay the price in porting work.
That's one of the many small things that made my life easier when I
moved to f90. The big new features get all the "press", but there were
also a lot of small ones like that.
--
Richard Maine | Good judgment comes from experience;
Richard.Maine@nasa.gov | experience comes from bad judgment.
| -- Mark Twain
More information about the Fortran
mailing list