Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Binary files with gfortran-4.8

Binary files with gfortran-4.8

Binary files with gfortran-4.8

Using "gfortran-4.8" I want to create and subsequently use a binary file! According to the information I have seen the format specifications "UNFORMATED" and "BINARY" should both be available, the exact difference between these alternatives not being clear to me. But both these alternatives are unknown to the compiler:

mats@linux-ze70blushingWDB> c try

Error: FORM specifier in OPEN statement at (1) has invalid value 'UNFORMATED'
mats@linux-ze70blushingWDB> c try

Error: FORM specifier in OPEN statement at (1) has invalid value 'BINARY'

Sure, because of large storage devices the binary files are less often used as before! But this option should still be available!

How to proceed?

RE: Binary files with gfortran-4.8

And leaving out the option is no solution! Then a "FORMAT" is indeed required!

mats@linux-ze70blushingWDB> cat try.f
mats@linux-ze70blushingWDB> c try
mats@linux-ze70blushingWDB> rm shoreline
mats@linux-ze70blushingWDB> r try
+ test 1 -gt 1
+ fil=try
+ test -f try.i
+ ./try.bin
At line 3 of file try.f (unit = 9, file = 'shoreline')
Fortran runtime error: Missing format for FORMATTED data transfer

RE: Binary files with gfortran-4.8

Hi stamcose,

I have this version of gfortran


$ gfortran --version
GNU Fortran (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
and form='unformatted' works for me. It creates a binary file.

Here is the example I tried


program stamcose
  implicit none
  real :: a, b

  a = 3.14
  b = 0
  ! open file fro writing
  open (9, file='stamcose.dat', form='unformatted', &
       access='sequential', status='replace')
  ! write data
  write(9) a
  write(*,*) 'data written to the file: a =', a   
  ! close file

  ! open file for reading
  open (9, file='stamcose.dat', form='unformatted', &
       access='sequential', status='old')
  ! read data
  read(9) b
  write(*,*) 'data read from the file:  b =', b 
  ! close file
end program 

Compiling and running it I get following output:


$ gfortran stamcose.f95 -o stamcose
$ ./stamcose
 data written to the file: a =   3.14000010    
 data read from the file:  b =   3.14000010 
Using less I could look what's in the unformatted file stamcose.data


$ less stamcose.dat 
"stamcose.dat" may be a binary file.  See it anyway? 
after pressing y it shows me the binary data:


stamcose.dat (END) 

RE: Binary files with gfortran-4.8

Man, now I see what's wrong with your code.
You only have typo in your code !
Instead of FORM='UNFORMATED' you have to use FORM='UNFORMATTED'

RE: Binary files with gfortran-4.8

You are right, it was a typo! Binary files have not been abandonned! Thanks!

RE: Binary files with gfortran-4.8

For binary files, use

.... ACCESS='STREAM'....

It is not the same as "UNFORMATTED" files.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close