read binary file written in fortran from another language
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
read binary file written in fortran from another language         


Author: utab
Date: Sep 3, 2008 16:13

Dear all,

is that possible to read some binary files written by Fortran language in
a different language such as C++?

I read here:

http://www.math.utah.edu/software/c-with-fortran.html

that Fortran uses "records" which makes things hard for other programming
languages to process the bytes in some form of these records. However
since the document is from 2001 and I would like to turn to the group for
an advice or direction. Just curious...

Thx for the replies.
7 Comments
Re: read binary file written in fortran from another language         


Author: dpb
Date: Sep 3, 2008 16:19

utab wrote:
> Dear all,
>
> is that possible to read some binary files written by Fortran language in
> a different language such as C++?
>
> I read here:
>
> http://www.math.utah.edu/software/c-with-fortran.html
>
> that Fortran uses "records" which makes things hard for other programming
> languages to process the bytes in some form of these records. However
> since the document is from 2001 and I would like to turn to the group for
> an advice or direction. Just curious...

"Possible", yes. A quick perusal of the contents of the link indicates
(to me) it is written w/ the the undergrad new programming student in
mind and so makes things that aren't necessarily so absolutes.
Show full article (1.19Kb)
no comments
Re: read binary file written in fortran from another language         


Author: e p chandler
Date: Sep 3, 2008 16:37

On Sep 3, 7:13 pm, utab gmail.com> wrote:
> Dear all,
>
> is that possible to read some binary files written by Fortran language in
> a different language such as C++?
>
> I read here:
>
> http://www.math.utah.edu/software/c-with-fortran.html
>
> that Fortran uses "records" which makes things hard for other programming
> languages to process the bytes in some form of these records. However
> since the document is from 2001 and I would like to turn to the group for
> an advice or direction. Just curious...
>
> Thx for the replies.

If you know the file and record structure, yes. Once you can read an
arbitrary number of bytes in as raw data, the rest is a programming
exercise. [Try it in Pascal with blockread, just for fun!]
Show full article (0.76Kb)
no comments
Re: read binary file written in fortran from another language         


Author: utab
Date: Sep 3, 2008 16:39

On Wed, 03 Sep 2008 18:19:49 -0500, dpb wrote:
> utab wrote:
>> Dear all,
>>
>> is that possible to read some binary files written by Fortran language
>> in a different language such as C++?
>>
>> I read here:
>>
>> http://www.math.utah.edu/software/c...
Show full article (1.84Kb)
no comments
Re: read binary file written in fortran from another language         


Author: dpb
Date: Sep 3, 2008 16:43

utab wrote:
...
> suppose I have this code
>
> program binary_write
>
> double precision :: a = 2.458899, b= 132230.2323
> open(unit=5, file = 'test.bin', form='unformatted')
> write(5) a, b
> close(5)
>
> end program binary_write
>
> which writes two double precision values in an unformatted file and that
> is going to be the file I would like to read in C++. ...

As noted, that's the area that isn't transportable automagically but can
be worked out as noted.
Show full article (1.10Kb)
no comments
Re: read binary file written in fortran from another language         


Author: glen herrmannsfeldt
Date: Sep 3, 2008 16:53

utab wrote:
> is that possible to read some binary files written
> by Fortran language in a different language such as C++?

On most systems the records are indicated by a four byte
length field at the beginning, and on many by another
four byte length at the end of each record. (The latter
makes it easier to do BACKSPACE.)

Assuming you know the length, fread() four bytes and ignore
them, fread() the record (in one or multiple calls), and,
if needed fread() the record end marker.

double precision :: a = 2.458899, b= 132230.2323
open(unit=5, file = 'test.bin', form='unformatted')
write(5) a, b
close(5)
Show full article (0.98Kb)
no comments
Re: read binary file written in fortran from another language         


Author: utab
Date: Sep 3, 2008 16:58

On Wed, 03 Sep 2008 16:53:58 -0800, glen herrmannsfeldt wrote:
> utab wrote:
>
>> is that possible to read some binary files written by Fortran language
>> in a different language such as C++?
>
> On most systems the records are indicated by a four byte length field...
Show full article (1.25Kb)
no comments
Re: read binary file written in fortran from another language         


Author: AnotherSquid
Date: Sep 6, 2008 03:16

On Sep 3, 5:39 pm, utab gmail.com> wrote:
> program binary_write
>
> double precision :: a = 2.458899, b= 132230.2323
> open(unit=5, file = 'test.bin', form='unformatted')
> write(5) a, b
> close(5)
>
> end program binary_write

All of the machines I work on are Unix/Linux (includes Max OS X), so
what I am about to say applies to these. I don't know anything about
doing Fortran in the Microsoft world.
Show full article (1.59Kb)
no comments