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

READ for REC=1 gives different results

sindizzy
New Contributor I
25,105 Views
I am trying to convert a program from Lahey Fortran to Intel IFORT. One routine is giving me headaches. When I compile the code below in Lahey I get RCNT=13419. which is what is expected. I now put the same code in VS and compile with IFORT and I get RCNT= 0.
 
I don't understand my defect. Is there a switch that I am missing that in the past I may have taken for granted?
 
       PROGRAM NEWCNT
       IMPLICIT NONE
 
       CHARACTER * 255  BinFile, OutFile
       REAL        RCNT
 
      BinFile='C:\docs\CITY.BIN'
      OPEN (UNIT=7, FILE=BinFile, ACCESS='DIRECT', RECL=22000,
+ STATUS='OLD', FORM='UNFORMATTED')
 
      READ (7, REC=1) RCNT
      WRITE (*, '(A,F6.0)') 'RCNT=', RCNT
 
       CLOSE(7)
       END PROGRAM NEWCNT
0 Kudos
44 Replies
JamesParsly
Beginner
441 Views

I ran into this years ago when writing a VB6 program that need to read Fortran direct access files.  There's a comment specific to

reading data from a file created by the lahey Compiler

Sub checklahey(filen)
'
' check the file open as filen to see if it is in
' Lahey binary format.
'
' Lahey files (unless the -nhed option is used) have an extra
' record in the front. The first byte of the extra
' record is F7 followed by the 2 byte record length
'
' if the file is not in lahey format, set laheyflag to 0
' otherwise set it to the record length
'

To read it as a stream I would compute the byte position by adding lahey flag, which would be 0 if not lahey format, or

the correct number of bytes to skip.  Looks like I only had to handle 2 byte record lengths for this case.

0 Kudos
mecej4O
Novice
405 Views

"the lahey Compiler" is ambiguous. Lahey sold 16-bit , 32-bit and 64-bit compilers. Unless you know which of those compilers was used in producing the .BIN file that you are trying to read, and what that file is supposed to contain, you are faced with a possibly impossible task.

0 Kudos
jimdempseyatthecove
Honored Contributor III
146 Views

Maybe this is of help:

OPEN: RECL Specifier

The RECL specifier indicates the length of each record in a file connected for direct access, or the maximum length of a record in a file connected for sequential access.

The RECL specifier takes the following form:

RECL = rl

rl

Is a positive numeric expression indicating the length of records in the file. If necessary, the value is converted to integer data type before use.

If the file is connected for formatted data transfer, the value must be expressed in bytes (characters). Otherwise, the value is expressed in 4-byte units (longwords). If the file is connected for unformatted data transfer, the value can be expressed in bytes if compiler option assume byterecl is specified.

Except for segmented records, the rl is the length for record data only, it does not include space for control information. If rl is too large, you can exhaust your program's virtual memory resources trying to create room for the record.

It might benefit you to look at the file with a hex editor to assure the file does NOT include record headers and trailers (e.g. record lengths).

 

Jim Dempsey

0 Kudos
Reply