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

Find out if file was written using direct or sequential access

jirina
New Contributor I
811 Views

Is there a way how to find out if a binary file was written using direct or sequential access without opening it and reading values from it?

If I have to open the file and start reading values, how would I know that opened the file using an  access that is different from the one used to write the file?

Thank you in advance for any suggestions.

0 Kudos
1 Solution
Arjen_Markus
Honored Contributor I
804 Views

In the old days (let's say around 1980 thereabout) (some?) computer systems used to distinguish between direct-access and sequential-access, but nowadays there is no such difference anymore, at least not with current-day compilers and run-time systems that I am aware of.

There is a difference between binary and unformatted sequential files, but if your file is indeed binary (so no inherent record structure, as opposed to unformatted sequential files), then direct-access simply means a different way of positioning the read/write action within a file for all intents and purposes.

In fact, stream access should work fine even if the file was written as direct-access. (I know in the past some compilers might add some marker in the file to make sure the record length was correct, but that was years ago).

View solution in original post

2 Replies
Arjen_Markus
Honored Contributor I
805 Views

In the old days (let's say around 1980 thereabout) (some?) computer systems used to distinguish between direct-access and sequential-access, but nowadays there is no such difference anymore, at least not with current-day compilers and run-time systems that I am aware of.

There is a difference between binary and unformatted sequential files, but if your file is indeed binary (so no inherent record structure, as opposed to unformatted sequential files), then direct-access simply means a different way of positioning the read/write action within a file for all intents and purposes.

In fact, stream access should work fine even if the file was written as direct-access. (I know in the past some compilers might add some marker in the file to make sure the record length was correct, but that was years ago).

jirina
New Contributor I
698 Views

Thank you for pointing me in the right direction - the stream access works well for what I need to do, even for direct access written files.

0 Kudos
Reply