- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Simple solution if you don't want to rearrange things is to add the line SEQUENCE after the TYPE statement.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page