Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

binary I/O with user derived type

martymike
Beginner
128 Views

Our application predates Fortran 90. For speed reasons (mostly) we developed a method of storing the data for the app in binary files using Windows C primatives (e.g. _read, _write). While we might not do this today (probably not), it works very well. We'd like to extend this methodology to handle Fortran derived types. It seems, offhand, that to do so I would need to know the storage length of type in bytes, and be able to be certain that the components are always arranged the same way in storage. Can someone help with these questions or suggest an alternative (other than the obvious one, read/write each component)?

0 Kudos
2 Replies
Steve_Lionel
Black Belt Retired Employee
128 Views

If the derived type is declared with the BIND(C) attribute, you can be reasonably confident it isn't going to get rearranged, not that I know of ANY Fortran compilers that rearrange types. You may or may not get padding in different compilers - BIND(C) will ensure that the layout matches what the "companion C processor" would do.

As for length, that's what STORAGE_SIZE is for.

martymike
Beginner
128 Views

Thank you, Steve. I'll work with those ideas and see where it leads.

Reply