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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to binary fortran 90

Status
Not open for further replies.

riprat

Programmer
Jun 16, 2006
1
US
Relatively inexperienced in writing/diagnosing binary and I've got a problem that is driving me nuts. I'm trying to open and write to a binary file using the following code:

OPEN(123, &
FILE= 'filename', &
FORM='UNFORMATTED', &
ACCESS='DIRECT', &
RECL=32)

**this write statement is contained within a loop
WRITE(123, REC=count) time(count),stn(count),launch(count)

Setting RECL to either 1 or 4 gives an error;
"attempt to read/write past end of record"
So I assume for my compiler (pgf90) that record length refers to the entire file, but not sure.

If I set the record length to an arbitrarily higher number (eg. 128) then the code compiles and executes without errors but the resulting binary file doesn't contain any of the data that should have been written.

Any help/suggestions, appalled gasps at programming style would be appreciated.

Thanks
 
It may be defaulting to read. Add status='old' for read and status='new' for write.

The record length seems to vary from system to system. I have used recl=1 in the past but it only works for some compilers.
 
from man page for ifort (v 9)


-assume byterecl

Specifies that the units for the OPEN statement
RECL specifier (record length) value are in bytes
for unformatted data files, not longwords (four-
byte units). For formatted files, the RECL unit
is always in bytes. The default is -assume
nobyterecl.
INQUIRE returns RECL in bytes if the unit is not
open. INQUIRE returns RECL in longwords if the
file is open for unformatted data (and -assume
byterecl is not specified); otherwise, it returns
RECL in bytes.

O.K. It`s not pgf90 but maybe it has similar options.

HTH

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top