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

TYPE declaration

drpierce
Beginner
502 Views
I have the following type declaration in a module
TYPE MDLREC2
CHARACTER :: MODEL*8,MODELDESC*30,MODVER*12
REAL :: XMAC, XLEMAC
CHARACTER :: CTREDX(5)*2
END TYPE
TYPE(MDLREC2) :: AEMODEL

In a subroutine, I attempt to read from a binary file with RECL=68, I get an error message saying that I am trying to read past the end of data.

However, if I declare local variables identical to those in the TYPE array, the READ from the file works perfectly.

I seem to lose 2 bytes somewhere in the real variables. If I modify the TYPE array above to
TYPE MDLREC2
CHARACTER :: MODEL*8,MODELDESC*30,MODVER*12
INTEGER*4 :: XMAC
INTEGER*2 :: XLEMAC
CHARACTER :: CTREDX(5)*2
END TYPE
It reads the line of data without an error. Of course, the variables XMAC and XLEMAC are populated incorrectly.

I have the "Use Bytes as RECL= unit for Unformatted Files" selection checked under Fortran Data in Settings.
0 Kudos
2 Replies
Steven_L_Intel1
Employee
502 Views
You're getting padding due to misaligned fields. In the first example, you have 50 bytes of character stuff, followed by a REAL*4. Since 50 is not a multiple of 4, two bytes of padding are inserted.

Simple solution if you don't want to rearrange things is to add the line SEQUENCE after the TYPE statement.

Steve
0 Kudos
kdkeefer
Beginner
502 Views
Hello,
There is also an INQUIRE(IOLENGTH=recl) item_a, item_b....
Statement that will return the total length, recl, (in presumably consistent units - bytes, words etc.) for the length of the record "item_a, item_b...". It has the advantage that if you change the declaration, the record length will be recalculated.
Regards,
Keith
0 Kudos
Reply