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

Reading Unformatted Files Compiled with Lahey Fortran

arney
Beginner
317 Views

How do you read in unformatted data files created with a different compiler (i.e., Lahey Fortran)? Consider the following snippet:

MYFILE.DAT = unformatted data file created by Compiler X.

Open(iout, file='myfile.dat',form='unformatted')

Write(iout)var1, var2, var3

Reader Program Compiled Using IFORT:

Open(in, file='myfile.dat',form='unformatted')

Read(in)var1, var2, var3

0 Kudos
1 Reply
Steven_L_Intel1
Employee
317 Views

Most compilers forWindows and UNIX/Linuxuse a common structure for unformatted sequential data files, and Lahey LF95 is among these. (The older LF90 and Microsoft Fortran PowerStationare not - let me know if you're using one of those and I can provide further help. So in most cases, you don't need to do anything special - just open the file.

The most common structure is that there is a 32-bit length, the record data, then the 32-bit length again. If the file was written on a "big-endian" system (e.g. Sun, IBM, MIPS), then open the file with CONVERT='BIG_ENDIAN'.

An exception I know of is g77/g95/gfortran when run on a 64-bit platform. These compilers force the record lengths to be 64-bits, rendering the files incompatible with most other implementations. Intel Fortran (and DEC/Compaq Fortran compilers of the past seven or so years) use a hybrid method where records shorter than 2GB have 32-bit lengths and longer records are written in "segments" with the length field flagged. This is described in the documentation. This permits interchangeability of most data files while still allowing very large records, without the need for switches or environment variables.

0 Kudos
Reply