×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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

Linux Gfortran open file question

Linux Gfortran open file question

Linux Gfortran open file question

(OP)
Hi,
I am using Gfortran to read a unformatted binary file like the following:

open(.......,access='stream',form='unformatted',.....)

it works fine if the gfortran version is 4.5 or up. However, if I compile the code on machines which Gfortran version less than 4.5, the job failed to read the data although there is no any error in compiling.

So I want to know whether there is any other option to set "access=...." for Gfortran version less than 4.5.

By the way, who can recommend a good Gfortran manual or user guider?

Thanks
Jim

RE: Linux Gfortran open file question

That 'stream' stuff sounds like C++ lingo to me, then again, I don't do Fortran 2003 and beyond. I only do up to Fortran 90.

Have you tried access='direct'? That's traditionally been the Fortran way, you know, as opposed to access='sequential'. You may want to try the form='unformatted' along with that.

RE: Linux Gfortran open file question

Just any Fortran book will do - are you looking for any features in particular? There are lots of online tutorials.

In fact any Fortran 95 manual from any manufacturer is good enough to get you started. Doesn't have to be gfortran.

RE: Linux Gfortran open file question

(OP)
thanks for all your suggestions. The data I am read is not direct access, so access='direct' doesn't work.
What I am looking for is the GFORTRAN manual where I can find all the options for "access=" in open file statement. Anyone know where I can find this?

RE: Linux Gfortran open file question

Gfortran is just a compiler and you are not going to learn Fortran from it. So, no, there is no gfortran documentation about the OPEN statement or its 'access=' parameter.

Like xwb says, Fortran is Fortran and any book or reference will do. The Fortran language has a standard and new ones are created every so often...you can either search for f77 or f90 or 2003 or 2008.

Granted, you need to know what standard a given compiler guarantees to implement and whether it implements its own options and which options may implement from future standards.

It may be that what you want to do is not quite possible. If you are writing binary files with a newer version of Fortran that uses 'stream', it may be impossible to read such file from a version of Fortran that did not have 'stream'...the file formats are simply different and there is only so much you can do with plain vanilla Fortran (it is not a systems programming language).

...are you aware of how binary files are written? Before 'stream', Fortran wrote some useful information that you did not ask for (record length) along every record. Read up on 'flat' and 'not flat' binary files.

When reading binary files the pre-'stream' days, you need: form='unformatted', access='direct', and recl=n, where n (number of bytes) needs to be known to you, otherwise, you cannot expect to be able to read a binary file without knowing how long the record is. Also, when reading binary, you need to have your variables in the same order as they were written and they need to be of the same length.

So, three (rhetorical) questions:
Did you write the binary file that you are trying to read?
Are you writing and reading the file with the same program, compiled with the same compiler and in the same platform? or are you mixing?

References:
http://cs.ubishops.ca/ljensen/fortran/fortran.htm#...
http://www.atmos.washington.edu/~salathe/osx_unix/...


RE: Linux Gfortran open file question

(OP)
the data is from third party, I don't have clue on what platform/compiler he used.

with AIX machine xlf90, the data can be read successfully with
open(...,access='stream',form='unformatted')

with Linux ifort
the data can be read successfully with
open(...,access='sequentail',form='binary')

with Linux gfrotran, if the gfortran version is higher than 4.5
the data can be read successfully with
open(...,access='stream',form='unformatted')

However, I only have gfortran 4.1 and 4.4 on my two Linux machines, with the above setting, job failed at read data though there is no error or warning in compiling. This is why I am looking to see if there is any other option to set in "access" and "form"

Any suggestions?

Thanks




RE: Linux Gfortran open file question


Can you upgrade your 4.1 and 4.4 machines up to 4.5? It is not like they charge for it, you know?

Can you simply copy your executable from the 4.5 machine to the other ones?

RE: Linux Gfortran open file question

(OP)
now I realized that the "stream" option on gfortran only works for version4.5 or up. There is no way to read this kind of data with low version of gfrotran although there is no error in compiling.

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