×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

Binary files with gfortran-4.8

Binary files with gfortran-4.8

Binary files with gfortran-4.8

(OP)
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
try.f:1.72:

OPEN(9,FILE='shoreline',ACCESS='SEQUENTIAL',FORM='UNFORMATED')
1
Error: FORM specifier in OPEN statement at (1) has invalid value 'UNFORMATED'
mats@linux-ze70blushingWDB> c try
try.f:1.72:

OPEN(9,FILE='shoreline',ACCESS='SEQUENTIAL',FORM='BINARY')
1
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

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

mats@linux-ze70blushingWDB> cat try.f
F=3.14
OPEN(9,FILE='shoreline',ACCESS='SEQUENTIAL')
WRITE(9) F
STOP
END
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

CODE

$ 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
stamcose.f95

CODE

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
  close(9)

  ! 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
  close(9)
end program 

Compiling and running it I get following output:

CODE

$ 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

CODE

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

CODE

^D^@^@^@<C3><F5>H@^D^@^@^@
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'
smile

RE: Binary files with gfortran-4.8

(OP)
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!

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