Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linux Gfortran open file question

Status
Not open for further replies.

Jimjim8888

Technical User
Nov 20, 2013
4
US
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
 
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 [tt]access='direct'[/tt]? That's traditionally been the Fortran way, you know, as opposed to [tt]access='sequential'[/tt]. You may want to try the [tt]form='unformatted'[/tt] along with that.

 
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.
 
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?
 
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:
 
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




 

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?
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top