Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion record length in an unformatted (binary) file

Received: by 10.204.6.19 with SMTP id 19mr17549bkx.8.1349942822080;
        Thu, 11 Oct 2012 01:07:02 -0700 (PDT)
MIME-Version: 1.0
Path: q11ni134269243wiw.1!nntp.google.com!feeder1.cambriumusenet.nl!feeder3.cambriumusenet.nl!feed.tweaknews.nl!216.40.29.245.MISMATCH!novia!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!news.glorb.com!aioe.org!.POSTED!not-for-mail
From: glen herrmannsfeldt <g...@ugcs.caltech.edu>
Newsgroups: comp.lang.fortran
Subject: Re: record length in an unformatted (binary) file
Date: Sun, 7 Oct 2012 22:09:15 +0000 (UTC)
Organization: Aioe.org NNTP Server
Lines: 47
Message-ID: <k4suib$aq3$1@speranza.aioe.org>
References: <c4d2eba4-91cb-43df-b23f-1efa605abcab@googlegroups.com> <ad09cjF9qivU1@mid.individual.net> <k4er9g$ogh$4@speranza.aioe.org> <1krbvw4.ot6uri1f1xykoN%nospam@see.signature> <f0e747d7-ea0f-42dc-9a7c-b5a6c373b26e@googlegroups.com> <1krfwji.vqax2417ngrl8N%nospam@see.signature> <b031d619-d2d8-4045-bd99-cb60a3d15486@googlegroups.com>
NNTP-Posting-Host: 0usSS01PZ8AI54GFz6in7A.user.speranza.aioe.org
X-Complaints-To: abuse@aioe.org
User-Agent: tin/1.9.6-20100522 ("Lochruan") (UNIX) (Linux/2.6.32-5-amd64 (x86_64))
X-Notice: Filtered by postfilter v. 0.8.2
Bytes: 3121

marcio.pmz <mtnobrega....@gmail.com> wrote:
>> Also, it looks to me like you have an off-by-one error unless the code
>> compensates for it elsewhere. After exiting the loop, the value of ireg
>> is the one that failed rather than the last one that worked.

> Surely there is this off-by-one error, which I haven't noticed and didn't know 
> had a name, but I won't forget. I corrected it, thank you!

> Still concern this issue of record length I am curious: what 
> about the unit length of it? I know that it is 32 bits (word) 
> by default, and it is supposed to work fine for integer kind 4 
> and real kind 4, in Intel Compiler, but if I wished to read a 
> real kind 8 (64 bits)? Would I have to use double recl, 
> multiply by 2? I mean, if I need to read one value from a 
> file it would be like this?

> real(8)::var
> open(1,file='file.fil',access='direct',recl=2)
> read(1,rec=1)var

As well as I understand it, the read should follow as closely
as possible to the actual case. 

Though the standard requires (though implementations might not
comply) the default INTEGER, REAL, and LOGICAL to have the same
size, relying on it might cause problems. As far as I know, it
isn't usual to do alignment padding for UNFORMATTED I/O, but
you probably shouldn't count on it not being done.

Interestingly there is right now in anohter newsgroup discussion
on the RECFM=VBS data format used by OS/360 and successors, 
including the current z/OS. It seems that the record length is
not allowed to be zero. Normally, that shouldn't cause any 
problem, but if you tried to test for it you wouldn't be able
to distinguish 0 bytes from 1 byte. (An array of LOGICAL*1.)

I don't know that the standard prohibits any kind of padding, maybe
rounding to the next multiply of 8 or 16 bytes, or even 512 byte
block. (That, in addition to the previously mentioned lack of
requirement to report the error at all.)

I do remember using BASIC systems years ago that padded direct access
I/O to whole block boundaries. It was usual to carefully construct
records of 256 or 512 bytes.

-- glen