|
[Sponsors] |
September 6, 2006, 06:55 |
Binary in Fortran
|
#1 |
Guest
Posts: n/a
|
Does anyone know whether it's possible to save binary files in Fortran?
|
|
September 6, 2006, 07:03 |
Re: Binary in Fortran
|
#2 |
Guest
Posts: n/a
|
Yes. Use FORM='binary' in the open statement.
|
|
September 6, 2006, 08:10 |
Re: Binary in Fortran
|
#3 |
Guest
Posts: n/a
|
is there a 'binary' form? how is it different from the standard 'unformatted' form?
you can use form='unformatted' in the open statement, and then simply leave out any format in write statements, i.e. write(id) instead of write(id,'(fmt)') |
|
September 6, 2006, 08:41 |
Re: Binary in Fortran
|
#4 |
Guest
Posts: n/a
|
The general approach is to specify the use of unformatted direct access storage, as Mani points out. This link has more information.
http://cires.colorado.edu/~knowlesk/...fortranio.html Some compilers have a FORM=BINARY option, but that appears to be a compiler-specific option, and thus it may not be portable. I don't believe it is part of the ANSI standard. |
|
September 6, 2006, 09:13 |
Re: Binary in Fortran
|
#5 |
Guest
Posts: n/a
|
It would be sad if it's not ANSI standard, maybe it's ANSI but for F90 only? Maybe someone knows...
Anyway, I'm helped. Thank you all! |
|
September 6, 2006, 11:23 |
Re: Binary in Fortran
|
#6 |
Guest
Posts: n/a
|
unformatted files are files where the data is stored in a "binary" form (no ascii translation) but with the number of bytes after (or before, I don't remember) each record. This form (unformatted) is intrinsic for all Fortran distributions and you'll not have portability problems with your program. It's some Fortran weirdness because only Fortran has this kind of format. Some compilers (most of the more used, like Intel) have a standard binary form as Robert pointed which turns out the binary files more useful since you can easily read them in programs written in other languages like C/C++.
Regards Renato. |
|
September 8, 2006, 05:26 |
Re: Binary in Fortran
|
#7 |
Guest
Posts: n/a
|
A record in a Fortran binary file has an integer header and a footer giving the length of the record. C does not. So you can easily modify a C program to read Fortran binary files but not the other way found.
If you want portable binary files you will have to address the endianess issue which is easy enough to fix. You can also come unstuck with how floating point numbers are stored although this is less of an issue these days. If you want the speed and compactness of binary files but portability as well then a good approach is often to store your data in XDR format. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Fortran Compiler-CFX12.1 | Araz | CFX | 13 | March 27, 2017 06:37 |
Error to re-open fluent case file | J.Gimbun | FLUENT | 0 | April 27, 2006 09:42 |
visual fortran | Monica | Main CFD Forum | 1 | August 28, 2004 21:45 |
Difference betw Binary & Fortran Unformatted? | Ruobo | Main CFD Forum | 3 | April 28, 2002 04:04 |
Sliding mesh error | Karl Kevala | FLUENT | 4 | February 21, 2001 16:52 |