Re: Read/write binary files in Linux and Windows
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Wed, 24 Oct 2007 01:33:33 -0700
Luis Samaniego <luis.samaniego@xxxxxx> wrote:
in Windows: an array x(5,5,2) in real(4) is 800 bytes[when written to a direct access file with the same recl value]
in Linux: an array x(5,5,2) real(4) is 200 bytes
In my opinion Linux is doing the right thing with respect to the size.
The Windows binary file has trailing zeros.
Does someone know why this happen? What can I do to solve this problem?
First note that it isn't Windows or Linux that is "doing" anything here.
THis is dependent on the compiler - not the OS.
Second, both are right. You are assuming that the units of recl are
bytes. Instead, the units are compiler-dependent. Bytes is the most
common choice of unit, but 4-bytes words is the other. The f2003
standard recommends that bytes be used and most compilers are moving in
that direction. But still, neither answer is "wrong".
Solutions are
1. Most compilers that don't use units of bytes by default have an
option to do so. You could select that option. That does, however,
require you to find the right option for each compiler.
2. The language provides a portable facility to determine the needed
recl value. Use that instead of assuming any particular units of
measure. See the INQUIRE statement - in particular the form with recl=.
Then your code will work as desired for any of the compilers. That's my
recommended solution.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- Follow-Ups:
- Re: Read/write binary files in Linux and Windows
- From: AnotherSquid
- Re: Read/write binary files in Linux and Windows
- References:
- Read/write binary files in Linux and Windows
- From: Luis Samaniego
- Read/write binary files in Linux and Windows
- Prev by Date: Re: Read/write binary files in Linux and Windows
- Next by Date: Re: Read/write binary files in Linux and Windows
- Previous by thread: Re: Read/write binary files in Linux and Windows
- Next by thread: Re: Read/write binary files in Linux and Windows
- Index(es):
Relevant Pages
|
|