Print

Print


Terence Wright wrote:
 > >Yes, I DO think that a FIXED LENGTH DIRECT ACCESS file
 > >should have exactly the same bytes if caused to be created
 > >by a particular fortran program compiled and executed for the
 > >same target machine by different compilers.
 > >
 > >I would go as far to say IRREGARDLESS of the target machine.
 > >
 > >It is fundamental to my faith, that fixed length binary records
 > >are the structure of my universe.
 > >This is one of very few ways data files can be reliably
 > >transferred.

I'm afraid that there are quite a few exceptions I've known of.

Others have mentioned byte-order differences, which admitedly don't
change the size, but do mean you need some porting work.  Likewise
for machines that don't use IEEE floats - and yes, there are quite
a few of those still around.

Let us not forget the huge issues of different word sizes.  If you
write a single precision real on some machine where that is 64 bits,
it just is not going to be the same size as a single precision real on
a machine where it is 32-bits).  If your universe is limitted to
machines where single precision is always 32-bits, then I can only say
that it is a limitted universe.

Even ignoring all those things, I've seen multiple exceptions.
Lahey by default adds a header to direct access unformatted files,
and for ELF90, you can't even disable this "feature".  I've also
seen machines (specifics forgotten - something that our simulation
folk used to use) where unformatted direct access records were
"funny".  I think they were blocked into blocks of a system-defined
size, with extra stuff at the beginning of the blocks; I ended up
having to use formatted direct access with "A" format to read binary
direct access files from other machines - a hack, and a horribly slow
one, but it did work.

Not to mention machines where the file structure can be specified
independently of the access method.  For these sometimes you can
specify the structure you expect, but it isn't a given.

Yes, direct access unformatted files are the best way I know of to
transfer data that needs to be in a binary form for efficiency or
other reasons.  Many years ago, I used to use only formatted for
inter-machine transfer, and unformatted for non-portable efficient
use on a single machine.  But as multiple platforms on site became
widespread and data file sizes grew, massive user complaints ensued.
The formatted files were to big and too slow.

But for best portability, don't just just assume that direct access
unformatted is the way to read or write files without system-dependent
stuff.  It usually is.  But if you care about easy porting, treat this
like so many other system-dependent features.  Isolate your dependence
on thsi to a small portion of the code and document the
system-dependence of that portion.  In a case like file I/O, that
isolation shoule be pretty simple.  You have one code module (could be
an f90 module, but doesn't have to be - I Iuse the term more
generically here) that is responsible only for reading and writing the
fixed-size blocks - everything else just calls the subroutines in that
module.

It is "fundamental to my faith" that I can somehow read and write
binary files with no system-dependent extra bytes, and with with block
lengths that are "nice" powers of 2 in bytes (like 1024 or 2048).  I
do not assume that direct access unformatted I/O is always the way to
do this (though it usually is).  There have existed machines where
this is not practical - I've even worked on such in the past (notably
60-bit CDCs, which I used to do a lot in).  But I've decided that such
machines are now oddball enough that my applications just won't be
readily portable to them.

Don't know whether the f2k stream I/o has been mentioned in this
thread.  That will be the standard way to access files like this
in f2k.  Then you won't be restricted to fixed length records.  Plus
the standard will actually specify that the file has no extra "stuff",
rather than just relying on the fact that that's how most vendors
happen to have done direct access unformatted.

--
Richard Maine                |  Good judgement comes from experience;
[log in to unmask]   |  experience comes from bad judgement.
                             |        -- Mark Twain