Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Reading a binary file.

jello9
Beginner
1,666 Views
Here's an easy one. I am relatively new to FORTRAN
and can't see what the problem is with my READ of a
binary file. I get an IERR of 22. Here is how I am
opening and reading my file:

CHARACTER*512 PATHTAP
REAL*4 DATS(300)
LFCTAP=11
      OPEN(LFCTAP,FILE=PATHTAP,IOSTAT=IERR,
1     FORM='UNFORMATTED',STATUS='OLD',RECL=300)
      READ (LFCTAP,IOSTAT=IERR) DATS


Originally, there was no record length in the open statement.
This gave me the same error.
Can someone please point out what is wrong?
I just can't see it.

Thank you!
Jane

0 Kudos
4 Replies
TimP
Honored Contributor III
1,666 Views
It's not easy, without full information. Was the file written by an Intel compiler, using the same OPEN statement? If the file was written in what Intel compilers refer to as FORM='BINARY' (an extension to standard Fortran), it must be so specified.

Which compiler are you using? That error code is not in the list which comes with my copy of IFL. Neither the error codes nor the exact form of an unformatted file are portable between compiler vendors.
0 Kudos
Steven_L_Intel1
Employee
1,666 Views
Probably CVF. 22 is "input record too long". My guess is that the file was not written by Fortran and needs to be opened with FORM='BINARY', as Tim suggests. The RECL can be removed, it's not needed for this case.

Steve
0 Kudos
kdkeefer
Beginner
1,666 Views
Jane,
At the grave risk of my ego (you have responses from two Intel reps (one also a CVF rep))I'll volunteer an observation. You should always be able to read a partial record if the I/O list is equal or shorter than the physical record being read. The RECL=300 shouldn't change that; the READ stmt input list should override that. The suggestions about FORM='BINARY' are good because the end of record mark can differ in different disk file formats and look like data in one case and the end of the record in another. See if you can find CVF error 22 for a clue, I think the CVF IDE(text editor) has them all indexed.
Regards,
Keith
0 Kudos
jello9
Beginner
1,666 Views
Thank you all for your suggestions. I did try using FORM='BINARY', however, I think I have concluded that there is something more wrong with the file that I was given. I have decided to create my own binary file from the format description and things seem to be going fine. I will be able to get another file from someone else soon, so that will tie me over for now.

Thank you all again for the responses.

Jane
0 Kudos
Reply