CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Binary in Fortran

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 6, 2006, 06:55
Default Binary in Fortran
  #1
Gerrit
Guest
 
Posts: n/a
Does anyone know whether it's possible to save binary files in Fortran?

  Reply With Quote

Old   September 6, 2006, 07:03
Default Re: Binary in Fortran
  #2
Robert
Guest
 
Posts: n/a
Yes. Use FORM='binary' in the open statement.
  Reply With Quote

Old   September 6, 2006, 08:10
Default Re: Binary in Fortran
  #3
Mani
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)')
  Reply With Quote

Old   September 6, 2006, 08:41
Default Re: Binary in Fortran
  #4
ag
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.
  Reply With Quote

Old   September 6, 2006, 09:13
Default Re: Binary in Fortran
  #5
Gerrit
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!
  Reply With Quote

Old   September 6, 2006, 11:23
Default Re: Binary in Fortran
  #6
Renato.
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.

  Reply With Quote

Old   September 8, 2006, 05:26
Default Re: Binary in Fortran
  #7
andy
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.

  Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 05:48.