RE: Read a header and then a binary file?
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
RE: Read a header and then a binary file?         


Author: meek
Date: Jul 23, 2008 00:08

In a previous article, badger gmail.com> wrote:
>Hi,
>
>Im new to fortran and Im trying and (failing) to solve my little
>problem. Any help would be much appreciated?!
>
>Im trying to read a text header that I have appended to the top of a
>binary file and then read the binary file
>
>ie.
>
>1
>360
>720
>0
>Blah blah blah
>
>where blah is the start of the binary file.
>
>I can't seem to work out how to read the binary part - i.e. skip over ...
Show full article (2.30Kb)
8 Comments
Re: Read a header and then a binary file?         


Author: badger
Date: Jul 23, 2008 06:44

On 23 Jul, 08:08, m...@skyway.usask.ca wrote:
> In a previous article, badger gmail.com> wrote:
>
>
>
>>Hi,
>
>>Im new to fortran and Im trying and (failing) to solve my little
>>problem. Any help would be much appreciated?!
>
>>Im trying to read a text header that I have appended to the top of a
>>binary file and then read the binary file
>
>>ie.
>
>>1
>>360
>>720
>>0
>>Blah blah blah ...
Show full article (2.94Kb)
no comments
Re: Read a header and then a binary file?         


Author: GaryScott
Date: Jul 23, 2008 07:37

On Jul 23, 8:44 am, badger gmail.com> wrote:
> On 23 Jul, 08:08, m...@skyway.usask.ca wrote:
>
>
>
>
>
>> In a previous article, badger gmail.com> wrote:
>
>>>Hi,
>
>>>Im new to fortran and Im trying and (failing) to solve my little
>>>problem. Any help would be much appreciated?!
>
>>>Im trying to read a text header that I have appended to the top of a
>>>binary file and then read the binary file
>
>>>ie.
>
>>>1 ...
Show full article (3.65Kb)
no comments
Re: Read a header and then a binary file?         


Author: GaryScott
Date: Jul 23, 2008 15:14

On Jul 23, 3:12 pm, Rich Townsend barVOIDtol.udel.edu> wrote:
> GaryScott wrote:
>> On Jul 23, 8:44 am, badger gmail.com> wrote:
>>> On 23 Jul, 08:08, m...@skyway.usask.ca wrote:
>
>>>> In a previous article, badger gmail.com> wrote:
>>>>> Hi,
>>>>> Im new to fortran and Im trying and (failing) to solve my little
>>>>> problem. Any help would be much appreciated?!
>>>>> Im trying to read a text header that I have appended to the top of a
>>>>> binary file and then read the binary file
>>>>> ie.
>>>>> 1
>>>>> 360
>>>>> 720
>>>>> 0
>>>>> Blah blah blah
>>>>> where blah is the start of the binary file.
>>>>> I can't seem to work out how to read the binary part - i.e. skip over
>>>>> the header bit. So far I have ...
Show full article (4.51Kb)
no comments
Re: Read a header and then a binary file?         


Author: nospam
Date: Jul 23, 2008 15:27

Rich Townsend barVOIDtol.udel.edu> wrote:
> Isn't there a big oversight here, that UNFORMATTED is not the same as a
> raw data stream? On many systems, UNFORMATTED has codes inserted that
> describe the size of the next bit of data. These codes will be gibberish
> if you try to read a piece of text as UNFORMATTED.

You are describing unformatted sequential. The "sequential" part is
important; if you leave it off, then the statement is incorrect. There
are also unformatted direct access and unformatted stream. The later two
do not normally have any such extra codes inserted. Unformatted direct
access doesn't have them in the usual implementation, though the
standard doesn't require that implementation.

For unformatted stream, the standard specifies that it must be the raw
data stream. That's usually what people are referring to when they use
the common but inappropriate term "binary".

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
no comments
Re: Read a header and then a binary file?         


Author: Rich Townsend
Date: Jul 23, 2008 20:08

Richard Maine wrote:
> Rich Townsend barVOIDtol.udel.edu> wrote:
>
>> Isn't there a big oversight here, that UNFORMATTED is not the same as a
>> raw data stream? On many systems, UNFORMATTED has codes inserted that
>> describe the size of the next bit of data. These codes will be gibberish
>> if you try to read a piece of text as UNFORMATTED.
>
> You are describing unformatted sequential. The "sequential" part is
> important; if you leave it off, then the statement is incorrect. There
> are also unformatted direct access and unformatted stream. The later two
> do not normally have any such extra codes inserted. Unformatted direct
> access doesn't have them in the usual implementation, though the
> standard doesn't require that implementation.
>
> For unformatted stream, the standard...
Show full article (1.06Kb)
no comments
Re: Read a header and then a binary file?         


Author: nospam
Date: Jul 23, 2008 23:23

Rich Townsend barVOIDtol.udel.edu> wrote:
> Unformatted stream is F2003, right? Whereas direct and sequential go back
to... F77?

Yes, though pretty much all compilers have had a variant of unformatted
stream as an extension for a long time. And sequential unformatted goes
back... well, pretty much forever. Direct access was new to f77 (at
least as a feature of the standard).

In any case, I just wanted to clarify that the structure you were
referring to is specific to unformatted sequential. It does not
generally apply to unformatted per se.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
no comments
Re: Read a header and then a binary file?         


Author: glen herrmannsfeldt
Date: Jul 24, 2008 06:26

Richard Maine wrote:
(snip)
> And sequential unformatted goes back... well, pretty much forever.

Back to Fortran I, with the WRITE TAPE, READ TAPE, WRITE DRUM
and READ DRUM statements, though called binary I/O at the time.

The READ INPUT TAPE statement would do formatted I/O with
BCD (what would later change to BCDIC, before it was
extended to EBCDIC) data.
> Direct access was new to f77 (at least as a feature of the standard).

Non-standard, it goes back at least to OS/360 Fortran 66 compilers,
and likely before that. The IBM form was implemented by others,
including many DEC compilers.

The unformatted direct access form:

READ(a'r) list

and the formatted form:

READ(a'r,b) list

r is the record number.

-- glen
no comments
Re: Read a header and then a binary file?         


Author: glen herrmannsfeldt
Date: Jul 24, 2008 12:43

glen herrmannsfeldt wrote:
> Richard Maine wrote:
(snip)
>> Direct access was new to f77 (at least as a feature of the standard).

After the last post, I realized that READ DRUM and WRITE DRUM
are pretty much direct access I/O. The form is

WRITE DRUM i,j,list

i specifies the drum number, from 1 through 8.
j is the word on the drum to start writing (or reading
for READ DRUM), between 0 and 2047, (modulo 2048 if larger
than 2047).

For timing reasons, either scalar variables or whole arrays
could be read/written. (No implied-DO loops.)

In the days when 2048 words was a large amount of memory...

-- glen
no comments

RELATED THREADS
SubjectArticles qty Group
Create a meta name in HTML header filealt.html ·